Core/SAI: Rename LeavingWorld to OnDespawn & use it in SAI (#28059)

(cherry picked from commit b9450bcdd0)
This commit is contained in:
offl
2022-06-26 21:48:41 +03:00
committed by Shauren
parent 496eba4e8d
commit b0164fb2b9
8 changed files with 18 additions and 5 deletions

View File

@@ -295,7 +295,7 @@ class TC_GAME_API UnitAI
virtual void JustExitedCombat() { }
// Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing, player logging out etc.)
virtual void LeavingWorld() { }
virtual void OnDespawn() { }
// Called at any Damage to any victim (before damage apply)
virtual void DamageDealt(Unit* /*victim*/, uint32& /*damage*/, DamageEffectType /*damageType*/) { }

View File

@@ -676,6 +676,11 @@ void SmartAI::CorpseRemoved(uint32& respawnDelay)
GetScript()->ProcessEventsFor(SMART_EVENT_CORPSE_REMOVED, nullptr, respawnDelay);
}
void SmartAI::OnDespawn()
{
GetScript()->ProcessEventsFor(SMART_EVENT_ON_DESPAWN);
}
void SmartAI::PassengerBoarded(Unit* who, int8 seatId, bool apply)
{
GetScript()->ProcessEventsFor(apply ? SMART_EVENT_PASSENGER_BOARDED : SMART_EVENT_PASSENGER_REMOVED, who, uint32(seatId), 0, apply);

View File

@@ -159,6 +159,9 @@ class TC_GAME_API SmartAI : public CreatureAI
// called when the corpse of this creature gets removed
void CorpseRemoved(uint32& respawnDelay) override;
// Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing)
void OnDespawn() override;
// Called when a Player/Creature enters the creature (vehicle)
void PassengerBoarded(Unit* who, int8 seatId, bool apply) override;

View File

@@ -3155,6 +3155,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
case SMART_EVENT_JUST_CREATED:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
case SMART_EVENT_ON_DESPAWN:
ProcessAction(e, unit, var0, var1, bvar, spell, gob);
break;
case SMART_EVENT_GOSSIP_HELLO:

View File

@@ -846,6 +846,7 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
case SMART_EVENT_ON_SPELL_CAST: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_SPELL_FAILED: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_SPELL_START: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_DESPAWN: return NO_PARAMS;
default:
TC_LOG_WARN("sql.sql", "SmartAIMgr: Entry " SI64FMTD " SourceType %u Event %u Action %u is using an event with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
@@ -1479,6 +1480,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_EVENT_JUST_CREATED:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
case SMART_EVENT_ON_DESPAWN:
case SMART_EVENT_SCENE_START:
case SMART_EVENT_SCENE_CANCEL:
case SMART_EVENT_SCENE_COMPLETE:

View File

@@ -184,8 +184,9 @@ enum SMART_EVENT
SMART_EVENT_ON_SPELL_CAST = 83, // SpellID, CooldownMin, CooldownMax
SMART_EVENT_ON_SPELL_FAILED = 84, // SpellID, CooldownMin, CooldownMax
SMART_EVENT_ON_SPELL_START = 85, // SpellID, CooldownMin, CooldownMax
SMART_EVENT_ON_DESPAWN = 86, // NONE
SMART_EVENT_END = 86
SMART_EVENT_END = 87
};
struct SmartEvent
@@ -1569,6 +1570,7 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
{SMART_EVENT_ON_SPELL_CAST, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_SPELL_FAILED, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_SPELL_START, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_DESPAWN, SMART_SCRIPT_TYPE_MASK_CREATURE },
};
enum SmartEventFlags

View File

@@ -9335,7 +9335,7 @@ void Unit::RemoveFromWorld()
{
m_duringRemoveFromWorld = true;
if (UnitAI* ai = GetAI())
ai->LeavingWorld();
ai->OnDespawn();
if (IsVehicle())
RemoveVehicleKit(true);

View File

@@ -124,7 +124,7 @@ struct npc_pet_gen_soul_trader : public ScriptedAI
{
npc_pet_gen_soul_trader(Creature* creature) : ScriptedAI(creature) { }
void LeavingWorld() override
void OnDespawn() override
{
if (Unit* owner = me->GetOwner())
DoCast(owner, SPELL_ETHEREAL_PET_REMOVE_AURA);
@@ -150,7 +150,7 @@ struct npc_pet_lich : public ScriptedAI
{
npc_pet_lich(Creature* creature) : ScriptedAI(creature) { }
void LeavingWorld() override
void OnDespawn() override
{
if (Unit* owner = me->GetOwner())
DoCast(owner, SPELL_LICH_REMOVE_AURA);