Core/Scripts: Implemented new aura script hook OnEnterLeaveCombat
Port From (https://github.com/TrinityCore/TrinityCore/commit/2420f4e7a10c430ea28b2d71a17f54da0c244a54)
This commit is contained in:
@@ -65,6 +65,7 @@ namespace Framework.Constants
|
||||
CheckAreaTarget,
|
||||
Dispel,
|
||||
AfterDispel,
|
||||
EnterLeaveCombat,
|
||||
// Spell Proc Hooks
|
||||
CheckProc,
|
||||
CheckEffectProc,
|
||||
|
||||
@@ -2210,7 +2210,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, GetStat((Stats)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.DodgePercentage);
|
||||
|
||||
@@ -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 IsValidRace(Race _race) { return Convert.ToBoolean((ulong)SharedConst.GetMaskForRace(_race) & SharedConst.RaceMaskAllPlayable); }
|
||||
|
||||
public void OnCombatExit()
|
||||
public override void OnCombatExit()
|
||||
{
|
||||
base.OnCombatExit();
|
||||
|
||||
UpdatePotionCooldown();
|
||||
m_combatExitTime = Time.GetMSTime();
|
||||
}
|
||||
|
||||
@@ -285,8 +285,8 @@ namespace Game.Entities
|
||||
else if (!IsCharmed())
|
||||
return;
|
||||
}
|
||||
else
|
||||
ToPlayer().OnCombatExit();
|
||||
|
||||
OnCombatExit();
|
||||
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.LeavingCombat);
|
||||
}
|
||||
@@ -328,6 +328,15 @@ namespace Game.Entities
|
||||
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)
|
||||
{
|
||||
if (!IsAlive())
|
||||
@@ -1428,6 +1437,12 @@ namespace Game.Entities
|
||||
foreach (var unit in m_Controlled)
|
||||
unit.SetInCombatState(PvP, enemy);
|
||||
|
||||
foreach (var pair in m_appliedAuras)
|
||||
{
|
||||
AuraApplication aurApp = pair.Value;
|
||||
aurApp.GetBase().CallScriptEnterLeaveCombatHandlers(aurApp, true);
|
||||
}
|
||||
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.EnteringCombat);
|
||||
ProcSkillsAndAuras(enemy, ProcFlags.EnterCombat, ProcFlags.None, ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, null, null, null);
|
||||
}
|
||||
|
||||
@@ -777,6 +777,7 @@ namespace Game.Scripting
|
||||
public delegate bool AuraCheckEffectProcDelegate(AuraEffect aura, ProcEventInfo info);
|
||||
public delegate void AuraProcDelegate(ProcEventInfo info);
|
||||
public delegate void AuraEffectProcDelegate(AuraEffect aura, ProcEventInfo info);
|
||||
public delegate void AuraEnterLeaveCombatFnType(bool isNowInCombat);
|
||||
|
||||
public class CheckAreaTargetHandler
|
||||
{
|
||||
@@ -975,7 +976,6 @@ namespace Game.Scripting
|
||||
|
||||
AuraCheckEffectProcDelegate _HandlerScript;
|
||||
}
|
||||
|
||||
public class AuraProcHandler
|
||||
{
|
||||
public AuraProcHandler(AuraProcDelegate handlerScript)
|
||||
@@ -1003,7 +1003,20 @@ namespace Game.Scripting
|
||||
|
||||
AuraEffectProcDelegate _EffectHandlerScript;
|
||||
}
|
||||
public class EnterLeaveCombatHandler
|
||||
{
|
||||
public EnterLeaveCombatHandler(AuraEnterLeaveCombatFnType handlerScript)
|
||||
{
|
||||
_handlerScript = handlerScript;
|
||||
}
|
||||
public void Call(bool isNowInCombat)
|
||||
{
|
||||
_handlerScript(isNowInCombat);
|
||||
}
|
||||
|
||||
AuraEnterLeaveCombatFnType _handlerScript;
|
||||
}
|
||||
|
||||
public AuraScript()
|
||||
{
|
||||
m_aura = null;
|
||||
@@ -1295,6 +1308,11 @@ namespace Game.Scripting
|
||||
// where function is: void function (AuraEffect aurEff, ProcEventInfo& procInfo);
|
||||
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
|
||||
|
||||
// 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.EffectProc:
|
||||
case AuraScriptHookType.EffectAfterProc:
|
||||
case AuraScriptHookType.EnterLeaveCombat:
|
||||
return m_auraApplication.GetTarget();
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
Reference in New Issue
Block a user