Core/Scripts: Implemented new aura script hook OnEnterLeaveCombat

Port From (https://github.com/TrinityCore/TrinityCore/commit/2420f4e7a10c430ea28b2d71a17f54da0c244a54)
This commit is contained in:
hondacrx
2021-03-29 12:29:41 -04:00
parent 6977599b1b
commit e8959b884e
6 changed files with 55 additions and 5 deletions
@@ -65,6 +65,7 @@ namespace Framework.Constants
CheckAreaTarget, CheckAreaTarget,
Dispel, Dispel,
AfterDispel, AfterDispel,
EnterLeaveCombat,
// Spell Proc Hooks // Spell Proc Hooks
CheckProc, CheckProc,
CheckEffectProc, CheckEffectProc,
+1 -1
View File
@@ -2210,7 +2210,7 @@ namespace Game.Entities
stmt.AddValue(index++, GetStat((Stats)i)); stmt.AddValue(index++, GetStat((Stats)i));
for (int i = 0; i < (int)SpellSchools.Max; ++i) for (int i = 0; i < (int)SpellSchools.Max; ++i)
stmt.AddValue(index++, GetResistance((SpellSchools)i))); stmt.AddValue(index++, GetResistance((SpellSchools)i));
stmt.AddValue(index++, (float)m_activePlayerData.BlockPercentage); stmt.AddValue(index++, (float)m_activePlayerData.BlockPercentage);
stmt.AddValue(index++, (float)m_activePlayerData.DodgePercentage); stmt.AddValue(index++, (float)m_activePlayerData.DodgePercentage);
+3 -1
View File
@@ -3912,8 +3912,10 @@ namespace Game.Entities
public static bool IsValidClass(Class _class) { return Convert.ToBoolean((1 << ((int)_class - 1)) & (int)Class.ClassMaskAllPlayable); } public static bool IsValidClass(Class _class) { return Convert.ToBoolean((1 << ((int)_class - 1)) & (int)Class.ClassMaskAllPlayable); }
public static bool IsValidRace(Race _race) { return Convert.ToBoolean((ulong)SharedConst.GetMaskForRace(_race) & SharedConst.RaceMaskAllPlayable); } public static bool IsValidRace(Race _race) { return Convert.ToBoolean((ulong)SharedConst.GetMaskForRace(_race) & SharedConst.RaceMaskAllPlayable); }
public void OnCombatExit() public override void OnCombatExit()
{ {
base.OnCombatExit();
UpdatePotionCooldown(); UpdatePotionCooldown();
m_combatExitTime = Time.GetMSTime(); m_combatExitTime = Time.GetMSTime();
} }
+17 -2
View File
@@ -285,8 +285,8 @@ namespace Game.Entities
else if (!IsCharmed()) else if (!IsCharmed())
return; return;
} }
else
ToPlayer().OnCombatExit(); OnCombatExit();
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.LeavingCombat); RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.LeavingCombat);
} }
@@ -328,6 +328,15 @@ namespace Game.Entities
return fThreat * m_threatModifier[(int)school]; return fThreat * m_threatModifier[(int)school];
} }
public virtual void OnCombatExit()
{
foreach (var pair in m_appliedAuras)
{
AuraApplication aurApp = pair.Value;
aurApp.GetBase().CallScriptEnterLeaveCombatHandlers(aurApp, false);
}
}
public bool IsTargetableForAttack(bool checkFakeDeath = true) public bool IsTargetableForAttack(bool checkFakeDeath = true)
{ {
if (!IsAlive()) if (!IsAlive())
@@ -1428,6 +1437,12 @@ namespace Game.Entities
foreach (var unit in m_Controlled) foreach (var unit in m_Controlled)
unit.SetInCombatState(PvP, enemy); unit.SetInCombatState(PvP, enemy);
foreach (var pair in m_appliedAuras)
{
AuraApplication aurApp = pair.Value;
aurApp.GetBase().CallScriptEnterLeaveCombatHandlers(aurApp, true);
}
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.EnteringCombat); RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.EnteringCombat);
ProcSkillsAndAuras(enemy, ProcFlags.EnterCombat, ProcFlags.None, ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null); ProcSkillsAndAuras(enemy, ProcFlags.EnterCombat, ProcFlags.None, ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
} }
+20 -1
View File
@@ -777,6 +777,7 @@ namespace Game.Scripting
public delegate bool AuraCheckEffectProcDelegate(AuraEffect aura, ProcEventInfo info); public delegate bool AuraCheckEffectProcDelegate(AuraEffect aura, ProcEventInfo info);
public delegate void AuraProcDelegate(ProcEventInfo info); public delegate void AuraProcDelegate(ProcEventInfo info);
public delegate void AuraEffectProcDelegate(AuraEffect aura, ProcEventInfo info); public delegate void AuraEffectProcDelegate(AuraEffect aura, ProcEventInfo info);
public delegate void AuraEnterLeaveCombatFnType(bool isNowInCombat);
public class CheckAreaTargetHandler public class CheckAreaTargetHandler
{ {
@@ -975,7 +976,6 @@ namespace Game.Scripting
AuraCheckEffectProcDelegate _HandlerScript; AuraCheckEffectProcDelegate _HandlerScript;
} }
public class AuraProcHandler public class AuraProcHandler
{ {
public AuraProcHandler(AuraProcDelegate handlerScript) public AuraProcHandler(AuraProcDelegate handlerScript)
@@ -1003,7 +1003,20 @@ namespace Game.Scripting
AuraEffectProcDelegate _EffectHandlerScript; AuraEffectProcDelegate _EffectHandlerScript;
} }
public class EnterLeaveCombatHandler
{
public EnterLeaveCombatHandler(AuraEnterLeaveCombatFnType handlerScript)
{
_handlerScript = handlerScript;
}
public void Call(bool isNowInCombat)
{
_handlerScript(isNowInCombat);
}
AuraEnterLeaveCombatFnType _handlerScript;
}
public AuraScript() public AuraScript()
{ {
m_aura = null; m_aura = null;
@@ -1295,6 +1308,11 @@ namespace Game.Scripting
// where function is: void function (AuraEffect aurEff, ProcEventInfo& procInfo); // where function is: void function (AuraEffect aurEff, ProcEventInfo& procInfo);
public List<EffectProcHandler> AfterEffectProc = new(); public List<EffectProcHandler> AfterEffectProc = new();
// executed when target enters or leaves combat
// example: OnEnterLeaveCombat += AuraEnterLeaveCombatFn(class::function)
// where function is: void function (bool isNowInCombat);
public List<EnterLeaveCombatHandler> OnEnterLeaveCombat = new();
// AuraScript interface - hook/effect execution manipulators // AuraScript interface - hook/effect execution manipulators
// prevents default action of a hook from being executed (works only while called in a hook which default action can be prevented) // prevents default action of a hook from being executed (works only while called in a hook which default action can be prevented)
@@ -1413,6 +1431,7 @@ namespace Game.Scripting
case AuraScriptHookType.AfterProc: case AuraScriptHookType.AfterProc:
case AuraScriptHookType.EffectProc: case AuraScriptHookType.EffectProc:
case AuraScriptHookType.EffectAfterProc: case AuraScriptHookType.EffectAfterProc:
case AuraScriptHookType.EnterLeaveCombat:
return m_auraApplication.GetTarget(); return m_auraApplication.GetTarget();
default: default:
Log.outError(LogFilter.Scripts, "Script: `{0}` Spell: `{1}` AuraScript.GetTarget called in a hook in which the call won't have effect!", m_scriptName, m_scriptSpellId); Log.outError(LogFilter.Scripts, "Script: `{0}` Spell: `{1}` AuraScript.GetTarget called in a hook in which the call won't have effect!", m_scriptName, m_scriptSpellId);
+13
View File
@@ -2145,6 +2145,19 @@ namespace Game.Spells
} }
} }
public void CallScriptEnterLeaveCombatHandlers(AuraApplication aurApp, bool isNowInCombat)
{
foreach (var loadedScript in m_loadedScripts)
{
loadedScript._PrepareScriptCall(AuraScriptHookType.EnterLeaveCombat, aurApp);
foreach (var hook in loadedScript.OnEnterLeaveCombat)
hook.Call(isNowInCombat);
loadedScript._FinishScriptCall();
}
}
public bool CallScriptCheckProcHandlers(AuraApplication aurApp, ProcEventInfo eventInfo) public bool CallScriptCheckProcHandlers(AuraApplication aurApp, ProcEventInfo eventInfo)
{ {
bool result = true; bool result = true;