Core/Spells: Fixes errors in scriptstate for spells
This commit is contained in:
@@ -17,14 +17,38 @@
|
|||||||
|
|
||||||
namespace Framework.Constants
|
namespace Framework.Constants
|
||||||
{
|
{
|
||||||
// AuraScript interface - enum used for runtime checks of script function calls
|
public enum SpellScriptState
|
||||||
public enum AuraScriptHookType
|
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
Registration,
|
Registration,
|
||||||
Loading,
|
Loading,
|
||||||
Unloading,
|
Unloading,
|
||||||
EffectApply,
|
}
|
||||||
|
|
||||||
|
// SpellScript interface - enum used for runtime checks of script function calls
|
||||||
|
public enum SpellScriptHookType
|
||||||
|
{
|
||||||
|
Launch = SpellScriptState.Unloading + 1,
|
||||||
|
LaunchTarget,
|
||||||
|
EffectHit,
|
||||||
|
EffectHitTarget,
|
||||||
|
EffectSuccessfulDispel,
|
||||||
|
BeforeHit,
|
||||||
|
OnHit,
|
||||||
|
AfterHit,
|
||||||
|
ObjectAreaTargetSelect,
|
||||||
|
ObjectTargetSelect,
|
||||||
|
DestinationTargetSelect,
|
||||||
|
CheckCast,
|
||||||
|
BeforeCast,
|
||||||
|
OnCast,
|
||||||
|
AfterCast
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuraScript interface - enum used for runtime checks of script function calls
|
||||||
|
public enum AuraScriptHookType
|
||||||
|
{
|
||||||
|
EffectApply = SpellScriptState.Unloading + 1,
|
||||||
EffectAfterApply,
|
EffectAfterApply,
|
||||||
EffectRemove,
|
EffectRemove,
|
||||||
EffectAfterRemove,
|
EffectAfterRemove,
|
||||||
@@ -52,28 +76,4 @@ namespace Framework.Constants
|
|||||||
//Apply,
|
//Apply,
|
||||||
//Remove
|
//Remove
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpellScript interface - enum used for runtime checks of script function calls
|
|
||||||
public enum SpellScriptHookType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Registration,
|
|
||||||
Loading,
|
|
||||||
Unloading,
|
|
||||||
Launch,
|
|
||||||
LaunchTarget,
|
|
||||||
EffectHit,
|
|
||||||
EffectHitTarget,
|
|
||||||
EffectSuccessfulDispel,
|
|
||||||
BeforeHit,
|
|
||||||
OnHit,
|
|
||||||
AfterHit,
|
|
||||||
ObjectAreaTargetSelect,
|
|
||||||
ObjectTargetSelect,
|
|
||||||
DestinationTargetSelect,
|
|
||||||
CheckCast,
|
|
||||||
BeforeCast,
|
|
||||||
OnCast,
|
|
||||||
AfterCast
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ using Game.Entities;
|
|||||||
using Game.Spells;
|
using Game.Spells;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.Contracts;
|
|
||||||
|
|
||||||
namespace Game.Scripting
|
namespace Game.Scripting
|
||||||
{
|
{
|
||||||
@@ -31,7 +30,7 @@ namespace Game.Scripting
|
|||||||
// DO NOT OVERRIDE THESE IN SCRIPTS
|
// DO NOT OVERRIDE THESE IN SCRIPTS
|
||||||
public BaseSpellScript()
|
public BaseSpellScript()
|
||||||
{
|
{
|
||||||
m_currentScriptState = SpellScriptHookType.None;
|
m_currentScriptState = (byte)SpellScriptState.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool _Validate(SpellInfo entry)
|
public virtual bool _Validate(SpellInfo entry)
|
||||||
@@ -61,20 +60,20 @@ namespace Game.Scripting
|
|||||||
|
|
||||||
public void _Register()
|
public void _Register()
|
||||||
{
|
{
|
||||||
m_currentScriptState = SpellScriptHookType.Registration;
|
m_currentScriptState = (byte)SpellScriptState.Registration;
|
||||||
Register();
|
Register();
|
||||||
m_currentScriptState = SpellScriptHookType.None;
|
m_currentScriptState = (byte)SpellScriptState.None;
|
||||||
}
|
}
|
||||||
public void _Unload()
|
public void _Unload()
|
||||||
{
|
{
|
||||||
m_currentScriptState = SpellScriptHookType.Unloading;
|
m_currentScriptState = (byte)SpellScriptState.Unloading;
|
||||||
Unload();
|
Unload();
|
||||||
m_currentScriptState = SpellScriptHookType.None;
|
m_currentScriptState = (byte)SpellScriptState.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _Init(string scriptname, uint spellId)
|
public void _Init(string scriptname, uint spellId)
|
||||||
{
|
{
|
||||||
m_currentScriptState = SpellScriptHookType.None;
|
m_currentScriptState = (byte)SpellScriptState.None;
|
||||||
m_scriptName = scriptname;
|
m_scriptName = scriptname;
|
||||||
m_scriptSpellId = spellId;
|
m_scriptSpellId = spellId;
|
||||||
}
|
}
|
||||||
@@ -88,7 +87,7 @@ namespace Game.Scripting
|
|||||||
protected EffectHook(uint effIndex)
|
protected EffectHook(uint effIndex)
|
||||||
{
|
{
|
||||||
// effect index must be in range <0;2>, allow use of special effindexes
|
// effect index must be in range <0;2>, allow use of special effindexes
|
||||||
Contract.Assert(_effIndex == SpellConst.EffectAll || _effIndex == SpellConst.EffectFirstFound || _effIndex < SpellConst.MaxEffects);
|
Cypher.Assert(_effIndex == SpellConst.EffectAll || _effIndex == SpellConst.EffectFirstFound || _effIndex < SpellConst.MaxEffects);
|
||||||
_effIndex = effIndex;
|
_effIndex = effIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +122,7 @@ namespace Game.Scripting
|
|||||||
uint _effIndex;
|
uint _effIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellScriptHookType m_currentScriptState { get; set; }
|
public byte m_currentScriptState { get; set; }
|
||||||
public AuraScriptHookType m_currentAuraScriptState { get; set; }
|
|
||||||
public string m_scriptName { get; set; }
|
public string m_scriptName { get; set; }
|
||||||
public uint m_scriptSpellId { get; set; }
|
public uint m_scriptSpellId { get; set; }
|
||||||
|
|
||||||
@@ -393,7 +391,7 @@ namespace Game.Scripting
|
|||||||
public bool _Load(Spell spell)
|
public bool _Load(Spell spell)
|
||||||
{
|
{
|
||||||
m_spell = spell;
|
m_spell = spell;
|
||||||
_PrepareScriptCall(SpellScriptHookType.Loading);
|
_PrepareScriptCall((SpellScriptHookType)SpellScriptState.Loading);
|
||||||
bool load = Load();
|
bool load = Load();
|
||||||
_FinishScriptCall();
|
_FinishScriptCall();
|
||||||
return load;
|
return load;
|
||||||
@@ -407,19 +405,19 @@ namespace Game.Scripting
|
|||||||
public bool _IsDefaultEffectPrevented(uint effIndex) { return Convert.ToBoolean(m_hitPreventDefaultEffectMask & (1 << (int)effIndex)); }
|
public bool _IsDefaultEffectPrevented(uint effIndex) { return Convert.ToBoolean(m_hitPreventDefaultEffectMask & (1 << (int)effIndex)); }
|
||||||
public void _PrepareScriptCall(SpellScriptHookType hookType)
|
public void _PrepareScriptCall(SpellScriptHookType hookType)
|
||||||
{
|
{
|
||||||
m_currentScriptState = hookType;
|
m_currentScriptState = (byte)hookType;
|
||||||
}
|
}
|
||||||
public void _FinishScriptCall()
|
public void _FinishScriptCall()
|
||||||
{
|
{
|
||||||
m_currentScriptState = SpellScriptHookType.None;
|
m_currentScriptState = (byte)SpellScriptState.None;
|
||||||
}
|
}
|
||||||
public bool IsInCheckCastHook()
|
public bool IsInCheckCastHook()
|
||||||
{
|
{
|
||||||
return m_currentScriptState == SpellScriptHookType.CheckCast;
|
return m_currentScriptState == (byte)SpellScriptHookType.CheckCast;
|
||||||
}
|
}
|
||||||
public bool IsInTargetHook()
|
public bool IsInTargetHook()
|
||||||
{
|
{
|
||||||
switch (m_currentScriptState)
|
switch ((SpellScriptHookType)m_currentScriptState)
|
||||||
{
|
{
|
||||||
case SpellScriptHookType.LaunchTarget:
|
case SpellScriptHookType.LaunchTarget:
|
||||||
case SpellScriptHookType.EffectHitTarget:
|
case SpellScriptHookType.EffectHitTarget:
|
||||||
@@ -433,12 +431,12 @@ namespace Game.Scripting
|
|||||||
}
|
}
|
||||||
public bool IsInHitPhase()
|
public bool IsInHitPhase()
|
||||||
{
|
{
|
||||||
return (m_currentScriptState >= SpellScriptHookType.EffectHit && m_currentScriptState < SpellScriptHookType.AfterHit + 1);
|
return (m_currentScriptState >= (byte)SpellScriptHookType.EffectHit && m_currentScriptState < (byte)SpellScriptHookType.AfterHit + 1);
|
||||||
}
|
}
|
||||||
public bool IsInEffectHook()
|
public bool IsInEffectHook()
|
||||||
{
|
{
|
||||||
return (m_currentScriptState >= SpellScriptHookType.Launch && m_currentScriptState <= SpellScriptHookType.EffectHitTarget)
|
return (m_currentScriptState >= (byte)SpellScriptHookType.Launch && m_currentScriptState <= (byte)SpellScriptHookType.EffectHitTarget)
|
||||||
|| m_currentScriptState == SpellScriptHookType.EffectSuccessfulDispel;
|
|| m_currentScriptState == (byte)SpellScriptHookType.EffectSuccessfulDispel;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spell m_spell;
|
Spell m_spell;
|
||||||
@@ -705,8 +703,7 @@ namespace Game.Scripting
|
|||||||
|
|
||||||
public SpellEffectInfo GetEffectInfo()
|
public SpellEffectInfo GetEffectInfo()
|
||||||
{
|
{
|
||||||
Contract.Assert(IsInEffectHook(),
|
Cypher.Assert(IsInEffectHook(), $"Script: `{m_scriptName}` Spell: `{m_scriptSpellId}`: function SpellScript::GetEffectInfo was called, but function has no effect in current hook!");
|
||||||
$"Script: `{m_scriptName}` Spell: `{m_scriptSpellId}`: function SpellScript::GetEffectInfo was called, but function has no effect in current hook!");
|
|
||||||
|
|
||||||
return m_spell.effectInfo;
|
return m_spell.effectInfo;
|
||||||
}
|
}
|
||||||
@@ -1116,29 +1113,29 @@ namespace Game.Scripting
|
|||||||
public bool _Load(Aura aura)
|
public bool _Load(Aura aura)
|
||||||
{
|
{
|
||||||
m_aura = aura;
|
m_aura = aura;
|
||||||
_PrepareScriptCall(AuraScriptHookType.Loading, null);
|
_PrepareScriptCall((AuraScriptHookType)SpellScriptState.Loading, null);
|
||||||
bool load = Load();
|
bool load = Load();
|
||||||
_FinishScriptCall();
|
_FinishScriptCall();
|
||||||
return load;
|
return load;
|
||||||
}
|
}
|
||||||
public void _PrepareScriptCall(AuraScriptHookType hookType, AuraApplication aurApp = null)
|
public void _PrepareScriptCall(AuraScriptHookType hookType, AuraApplication aurApp = null)
|
||||||
{
|
{
|
||||||
m_scriptStates.Push(new ScriptStateStore((byte)m_currentScriptState, m_auraApplication, m_defaultActionPrevented));
|
m_scriptStates.Push(new ScriptStateStore(m_currentScriptState, m_auraApplication, m_defaultActionPrevented));
|
||||||
m_currentAuraScriptState = hookType;
|
m_currentScriptState = (byte)hookType;
|
||||||
m_defaultActionPrevented = false;
|
m_defaultActionPrevented = false;
|
||||||
m_auraApplication = aurApp;
|
m_auraApplication = aurApp;
|
||||||
}
|
}
|
||||||
public void _FinishScriptCall()
|
public void _FinishScriptCall()
|
||||||
{
|
{
|
||||||
ScriptStateStore stateStore = m_scriptStates.Peek();
|
ScriptStateStore stateStore = m_scriptStates.Peek();
|
||||||
m_currentAuraScriptState = (AuraScriptHookType)stateStore._currentScriptState;
|
m_currentScriptState = stateStore._currentScriptState;
|
||||||
m_auraApplication = stateStore._auraApplication;
|
m_auraApplication = stateStore._auraApplication;
|
||||||
m_defaultActionPrevented = stateStore._defaultActionPrevented;
|
m_defaultActionPrevented = stateStore._defaultActionPrevented;
|
||||||
m_scriptStates.Pop();
|
m_scriptStates.Pop();
|
||||||
}
|
}
|
||||||
public bool _IsDefaultActionPrevented()
|
public bool _IsDefaultActionPrevented()
|
||||||
{
|
{
|
||||||
switch (m_currentAuraScriptState)
|
switch ((AuraScriptHookType)m_currentScriptState)
|
||||||
{
|
{
|
||||||
case AuraScriptHookType.EffectApply:
|
case AuraScriptHookType.EffectApply:
|
||||||
case AuraScriptHookType.EffectRemove:
|
case AuraScriptHookType.EffectRemove:
|
||||||
@@ -1150,8 +1147,7 @@ namespace Game.Scripting
|
|||||||
case AuraScriptHookType.EffectProc:
|
case AuraScriptHookType.EffectProc:
|
||||||
return m_defaultActionPrevented;
|
return m_defaultActionPrevented;
|
||||||
default:
|
default:
|
||||||
Contract.Assert(false, "AuraScript._IsDefaultActionPrevented is called in a wrong place");
|
throw new Exception("AuraScript._IsDefaultActionPrevented is called in a wrong place");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1303,7 +1299,7 @@ namespace Game.Scripting
|
|||||||
// 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)
|
||||||
public void PreventDefaultAction()
|
public void PreventDefaultAction()
|
||||||
{
|
{
|
||||||
switch (m_currentAuraScriptState)
|
switch ((AuraScriptHookType)m_currentScriptState)
|
||||||
{
|
{
|
||||||
case AuraScriptHookType.EffectApply:
|
case AuraScriptHookType.EffectApply:
|
||||||
case AuraScriptHookType.EffectRemove:
|
case AuraScriptHookType.EffectRemove:
|
||||||
@@ -1397,7 +1393,7 @@ namespace Game.Scripting
|
|||||||
// return null is when the call happens in an unsupported hook, in other cases, it is always valid
|
// return null is when the call happens in an unsupported hook, in other cases, it is always valid
|
||||||
public Unit GetTarget()
|
public Unit GetTarget()
|
||||||
{
|
{
|
||||||
switch (m_currentAuraScriptState)
|
switch ((AuraScriptHookType)m_currentScriptState)
|
||||||
{
|
{
|
||||||
case AuraScriptHookType.EffectApply:
|
case AuraScriptHookType.EffectApply:
|
||||||
case AuraScriptHookType.EffectRemove:
|
case AuraScriptHookType.EffectRemove:
|
||||||
|
|||||||
Reference in New Issue
Block a user