Core/Loot: Move loot generation out of Player::SendLoot

Port From (https://github.com/TrinityCore/TrinityCore/commit/8c20f620d7b070b13b40803095e5fa97f9349512)
This commit is contained in:
hondacrx
2022-09-18 22:13:40 -04:00
parent aa88c5bb2f
commit 6c7991c28f
6 changed files with 185 additions and 230 deletions
+24 -17
View File
@@ -176,6 +176,11 @@ namespace Game
}
public bool Invoke(Creature creature)
{
return IsValidAELootTarget(creature);
}
public bool IsValidLootTarget(Creature creature)
{
if (creature.IsAlive())
return false;
@@ -189,6 +194,14 @@ namespace Game
return _looter.IsAllowedToLoot(creature);
}
bool IsValidAELootTarget(Creature creature)
{
if (creature.GetGUID() == _mainLootTarget)
return false;
return IsValidLootTarget(creature);
}
Player _looter;
ObjectGuid _mainLootTarget;
}
@@ -200,6 +213,14 @@ namespace Game
if (!GetPlayer().IsAlive() || !packet.Unit.IsCreatureOrVehicle())
return;
Creature lootTarget = ObjectAccessor.GetCreature(GetPlayer(), packet.Unit);
if (!lootTarget)
return;
AELootCreatureCheck check = new(_player, packet.Unit);
if (!check.IsValidLootTarget(lootTarget))
return;
// interrupt cast
if (GetPlayer().IsNonMeleeSpellCast(false))
GetPlayer().InterruptNonMeleeSpells(false);
@@ -207,7 +228,6 @@ namespace Game
GetPlayer().RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Looting);
List<Creature> corpses = new();
AELootCreatureCheck check = new(_player, packet.Unit);
CreatureListSearcher searcher = new(_player, corpses, check);
Cell.VisitGridObjects(_player, searcher, AELootCreatureCheck.LootDistance);
@@ -247,6 +267,8 @@ namespace Game
if (player.GetLootGUID() == lguid)
player.SetLootGUID(ObjectGuid.Empty);
//Player is not looking at loot list, he doesn't need to see updates on the loot list
loot.RemoveLooter(player.GetGUID());
player.SendLootRelease(lguid);
player.GetAELootView().Remove(loot.GetGUID());
@@ -264,12 +286,7 @@ namespace Game
if (!go || ((go.GetOwnerGUID() != player.GetGUID() && go.GetGoType() != GameObjectTypes.FishingHole) && !go.IsWithinDistInMap(player)))
return;
if (go.GetGoType() == GameObjectTypes.Door)
{
// locked doors are opened with spelleffect openlock, prevent remove its as looted
go.UseDoorOrButton();
}
else if (loot.IsLooted() || go.GetGoType() == GameObjectTypes.FishingNode)
if (loot.IsLooted() || go.GetGoType() == GameObjectTypes.FishingNode || go.GetGoType() == GameObjectTypes.FishingHole)
{
if (go.GetGoType() == GameObjectTypes.FishingHole)
{ // The fishing hole used once more
@@ -288,10 +305,6 @@ namespace Game
{
// not fully looted object
go.SetLootState(LootState.Activated, player);
// if the round robin player release, reset it.
if (player.GetGUID() == loot.roundRobinPlayer)
loot.roundRobinPlayer.Clear();
}
}
else if (lguid.IsCorpse()) // ONLY remove insignia at BG
@@ -342,12 +355,6 @@ namespace Game
if (creature == null)
return;
if (!creature.IsWithinDistInMap(player, AELootCreatureCheck.LootDistance))
return;
if (creature.IsAlive() != (loot != null && loot.loot_type == LootType.Pickpocketing))
return;
if (loot.IsLooted())
{
creature.RemoveDynamicFlag(UnitDynFlags.Lootable);