Core/SAI: Rename LeavingWorld to OnDespawn & use it in SAI

Port From (https://github.com/TrinityCore/TrinityCore/commit/b0164fb2b9cc35663e337d48660d5bca1e973d99)
This commit is contained in:
hondacrx
2022-09-05 21:57:54 -04:00
parent 747c91bf73
commit 0a28bd434a
7 changed files with 16 additions and 6 deletions
+2 -1
View File
@@ -240,8 +240,9 @@ namespace Framework.Constants
OnSpellCast = 83, // SpellID, CooldownMin, CooldownMax OnSpellCast = 83, // SpellID, CooldownMin, CooldownMax
OnSpellFailed = 84, // SpellID, CooldownMin, CooldownMax OnSpellFailed = 84, // SpellID, CooldownMin, CooldownMax
OnSpellStart = 85, // SpellID, CooldownMin, CooldownMax OnSpellStart = 85, // SpellID, CooldownMin, CooldownMax
OnDespawn = 86, // NONE
End = 86 End
} }
public enum SmartActions public enum SmartActions
+1 -1
View File
@@ -518,7 +518,7 @@ namespace Game.AI
public virtual void JustExitedCombat() { } public virtual void JustExitedCombat() { }
// Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing, player logging out etc.) // Called when the unit is about to be removed from the world (despawn, grid unload, corpse disappearing, player logging out etc.)
public virtual void LeavingWorld() { } public virtual void OnDespawn() { }
// Called at any Damage to any victim (before damage apply) // Called at any Damage to any victim (before damage apply)
public virtual void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType) { } public virtual void DamageDealt(Unit victim, ref uint damage, DamageEffectType damageType) { }
+5
View File
@@ -726,6 +726,11 @@ namespace Game.AI
GetScript().ProcessEventsFor(SmartEvents.CorpseRemoved, null, (uint)respawnDelay); GetScript().ProcessEventsFor(SmartEvents.CorpseRemoved, null, (uint)respawnDelay);
} }
public override void OnDespawn()
{
GetScript().ProcessEventsFor(SmartEvents.OnDespawn);
}
public override void PassengerBoarded(Unit passenger, sbyte seatId, bool apply) public override void PassengerBoarded(Unit passenger, sbyte seatId, bool apply)
{ {
GetScript().ProcessEventsFor(apply ? SmartEvents.PassengerBoarded : SmartEvents.PassengerRemoved, passenger, (uint)seatId, 0, apply); GetScript().ProcessEventsFor(apply ? SmartEvents.PassengerBoarded : SmartEvents.PassengerRemoved, passenger, (uint)seatId, 0, apply);
@@ -634,7 +634,8 @@ namespace Game.AI
SmartEvents.OnSpellCast => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellCast => Marshal.SizeOf(typeof(SmartEvent.SpellCast)),
SmartEvents.OnSpellFailed => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellFailed => Marshal.SizeOf(typeof(SmartEvent.SpellCast)),
SmartEvents.OnSpellStart => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellStart => Marshal.SizeOf(typeof(SmartEvent.SpellCast)),
_ => Marshal.SizeOf(typeof(SmartEvent.Raw)), SmartEvents.OnDespawn => 0,
_ => Marshal.SizeOf(typeof(SmartEvent.Raw)),
}; };
int rawCount = Marshal.SizeOf(typeof(SmartEvent.Raw)) / sizeof(uint); int rawCount = Marshal.SizeOf(typeof(SmartEvent.Raw)) / sizeof(uint);
@@ -1296,6 +1297,7 @@ namespace Game.AI
case SmartEvents.JustCreated: case SmartEvents.JustCreated:
case SmartEvents.FollowCompleted: case SmartEvents.FollowCompleted:
case SmartEvents.OnSpellclick: case SmartEvents.OnSpellclick:
case SmartEvents.OnDespawn:
case SmartEvents.SceneStart: case SmartEvents.SceneStart:
case SmartEvents.SceneCancel: case SmartEvents.SceneCancel:
case SmartEvents.SceneComplete: case SmartEvents.SceneComplete:
@@ -2425,6 +2427,7 @@ namespace Game.AI
SmartEvents.OnSpellCast => SmartScriptTypeMaskId.Creature, SmartEvents.OnSpellCast => SmartScriptTypeMaskId.Creature,
SmartEvents.OnSpellFailed => SmartScriptTypeMaskId.Creature, SmartEvents.OnSpellFailed => SmartScriptTypeMaskId.Creature,
SmartEvents.OnSpellStart => SmartScriptTypeMaskId.Creature, SmartEvents.OnSpellStart => SmartScriptTypeMaskId.Creature,
SmartEvents.OnDespawn => SmartScriptTypeMaskId.Creature,
_ => 0, _ => 0,
}; };
@@ -3211,6 +3211,7 @@ namespace Game.AI
case SmartEvents.JustCreated: case SmartEvents.JustCreated:
case SmartEvents.FollowCompleted: case SmartEvents.FollowCompleted:
case SmartEvents.OnSpellclick: case SmartEvents.OnSpellclick:
case SmartEvents.OnDespawn:
ProcessAction(e, unit, var0, var1, bvar, spell, gob); ProcessAction(e, unit, var0, var1, bvar, spell, gob);
break; break;
case SmartEvents.GossipHello: case SmartEvents.GossipHello:
+1 -1
View File
@@ -481,7 +481,7 @@ namespace Game.Entities
m_duringRemoveFromWorld = true; m_duringRemoveFromWorld = true;
UnitAI ai = GetAI(); UnitAI ai = GetAI();
if (ai != null) if (ai != null)
ai.LeavingWorld(); ai.OnDespawn();
if (IsVehicle()) if (IsVehicle())
RemoveVehicleKit(true); RemoveVehicleKit(true);
+2 -2
View File
@@ -53,7 +53,7 @@ namespace Scripts.Pets
{ {
public npc_pet_gen_soul_trader(Creature creature) : base(creature) { } public npc_pet_gen_soul_trader(Creature creature) : base(creature) { }
public override void LeavingWorld() public override void OnDespawn()
{ {
Unit owner = me.GetOwner(); Unit owner = me.GetOwner();
if (owner != null) if (owner != null)
@@ -77,7 +77,7 @@ namespace Scripts.Pets
{ {
public npc_pet_lich(Creature creature) : base(creature) { } public npc_pet_lich(Creature creature) : base(creature) { }
public override void LeavingWorld() public override void OnDespawn()
{ {
Unit owner = me.GetOwner(); Unit owner = me.GetOwner();
if (owner != null) if (owner != null)