Core/GameObjects: Only start loot restock timer if loot contents were modified and ignore it for personal loot

Port From (https://github.com/TrinityCore/TrinityCore/commit/a3ef01f87bd56e553972277a38cf9a98a3397495)
This commit is contained in:
hondacrx
2023-07-18 07:43:30 -04:00
parent 7de6a839fa
commit a700760b88
3 changed files with 19 additions and 7 deletions
@@ -709,9 +709,6 @@ namespace Game.Entities
case GameObjectTypes.Chest:
loot?.Update();
foreach (var (_, loot) in m_personalLoot)
loot.Update();
// Non-consumable chest was partially looted and restock time passed, restock all loot now
if (GetGoInfo().Chest.consumable == 0 && GetGoInfo().Chest.chestRestockTime != 0 && GameTime.GetGameTime() >= m_restockTime)
{
@@ -720,6 +717,10 @@ namespace Game.Entities
ClearLoot();
UpdateDynamicFlagsForNearbyPlayers();
}
foreach (var (_, loot) in m_personalLoot)
loot.Update();
break;
case GameObjectTypes.Trap:
{
@@ -2897,7 +2898,7 @@ namespace Game.Entities
GetAI().OnLootStateChanged((uint)state, unit);
// Start restock timer if the chest is partially looted or not looted at all
if (GetGoType() == GameObjectTypes.Chest && state == LootState.Activated && GetGoInfo().Chest.chestRestockTime > 0 && m_restockTime == 0)
if (GetGoType() == GameObjectTypes.Chest && state == LootState.Activated && GetGoInfo().Chest.chestRestockTime > 0 && m_restockTime == 0 && loot != null && loot.IsChanged())
m_restockTime = GameTime.GetGameTime() + GetGoInfo().Chest.chestRestockTime;
// only set collision for doors on SetGoState
+1 -2
View File
@@ -22,7 +22,6 @@ namespace Game
Player player = GetPlayer();
AELootResult aeResult = player.GetAELootView().Count > 1 ? new AELootResult() : null;
// @todo Implement looting by LootObject guid
foreach (LootRequest req in packet.Loot)
{
Loot loot = player.GetAELootView().LookupByKey(req.Object);
@@ -143,7 +142,7 @@ namespace Game
SendPacket(packet);
}
loot.gold = 0;
loot.LootMoney();
// Delete the money loot record from the DB
if (loot.loot_type == LootType.Item)
+13 -1
View File
@@ -728,6 +728,12 @@ namespace Game.Loots
return allLooted;
}
public void LootMoney()
{
gold = 0;
_changed = true;
}
public LootItem GetItemInSlot(uint lootListId)
{
if (lootListId < items.Count)
@@ -902,6 +908,9 @@ namespace Game.Loots
if (!lootRoll.TryToStart(map, this, lootListId, maxEnchantingSkill))
_rolls.Remove(lootListId);
}
if (!_rolls.Empty())
_changed = true;
}
else if (_lootMethod == LootMethod.MasterLoot)
{
@@ -973,6 +982,7 @@ namespace Game.Loots
if (is_looted)
return null;
_changed = true;
return item;
}
@@ -1064,7 +1074,8 @@ namespace Game.Loots
}
public bool IsLooted() { return gold == 0 && unlootedCount == 0; }
public bool IsChanged() { return _changed; }
public void AddLooter(ObjectGuid guid) { PlayersLooting.Add(guid); }
public void RemoveLooter(ObjectGuid guid) { PlayersLooting.Remove(guid); }
@@ -1099,6 +1110,7 @@ namespace Game.Loots
ObjectGuid _lootMaster;
List<ObjectGuid> _allowedLooters = new();
bool _wasOpened; // true if at least one player received the loot content
bool _changed;
uint _dungeonEncounterId;
}