First try at making spells in SmartAI
Signed-off-by: hondacrx <prelude_20032002@yahoo.com>
This commit is contained in:
@@ -1048,6 +1048,48 @@ namespace Game.AI
|
||||
SmartScript mScript;
|
||||
}
|
||||
|
||||
public class SmartSpell : SpellScript
|
||||
{
|
||||
public override bool Load()
|
||||
{
|
||||
mScript.OnInitialize(GetSpell());
|
||||
scriptHolders = Global.SmartAIMgr.GetScript((int)GetSpellInfo().Id, SmartScriptType.Spell);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandleEffectHit(uint effIndex)
|
||||
{
|
||||
mScript.ProcessEventsFor(SmartEvents.SpellEffectHit);
|
||||
}
|
||||
|
||||
void HandleEffectHitTarget(uint effIndex)
|
||||
{
|
||||
mScript.ProcessEventsFor(SmartEvents.SpellEffectHitTarget);
|
||||
}
|
||||
|
||||
public override void Register()
|
||||
{
|
||||
foreach (var holder in scriptHolders)
|
||||
{
|
||||
switch (holder.GetEventType())
|
||||
{
|
||||
case SmartEvents.SpellEffectHit:
|
||||
OnEffectHit.Add(new EffectHandler(HandleEffectHit, holder.Event.spell.effIndex, SpellEffectName.ScriptEffect));
|
||||
OnEffectHit.Add(new EffectHandler(HandleEffectHit, holder.Event.spell.effIndex, SpellEffectName.Dummy));
|
||||
break;
|
||||
case SmartEvents.SpellEffectHitTarget:
|
||||
OnEffectHitTarget.Add(new EffectHandler(HandleEffectHitTarget, holder.Event.spell.effIndex, SpellEffectName.ScriptEffect));
|
||||
OnEffectHitTarget.Add(new EffectHandler(HandleEffectHitTarget, holder.Event.spell.effIndex, SpellEffectName.Dummy));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List<SmartScriptHolder> scriptHolders = new List<SmartScriptHolder>();
|
||||
SmartScript mScript = new SmartScript();
|
||||
}
|
||||
|
||||
[Script]
|
||||
class SmartTrigger : AreaTriggerScript
|
||||
{
|
||||
@@ -1060,7 +1102,7 @@ namespace Game.AI
|
||||
|
||||
Log.outDebug(LogFilter.ScriptsAi, "AreaTrigger {0} is using SmartTrigger script", trigger.Id);
|
||||
SmartScript script = new SmartScript();
|
||||
script.OnInitialize(null, trigger);
|
||||
script.OnInitialize(trigger);
|
||||
script.ProcessEventsFor(SmartEvents.AreatriggerOntrigger, player, trigger.Id);
|
||||
return true;
|
||||
}
|
||||
@@ -1074,28 +1116,28 @@ namespace Game.AI
|
||||
public override void OnSceneStart(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate)
|
||||
{
|
||||
SmartScript smartScript = new SmartScript();
|
||||
smartScript.OnInitialize(null, null, sceneTemplate);
|
||||
smartScript.OnInitialize(sceneTemplate);
|
||||
smartScript.ProcessEventsFor(SmartEvents.SceneStart, player);
|
||||
}
|
||||
|
||||
public override void OnSceneTriggerEvent(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate, string triggerName)
|
||||
{
|
||||
SmartScript smartScript = new SmartScript();
|
||||
smartScript.OnInitialize(null, null, sceneTemplate);
|
||||
smartScript.OnInitialize(sceneTemplate);
|
||||
smartScript.ProcessEventsFor(SmartEvents.SceneTrigger, player, 0, 0, false, null, null, triggerName);
|
||||
}
|
||||
|
||||
public override void OnSceneCancel(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate)
|
||||
{
|
||||
SmartScript smartScript = new SmartScript();
|
||||
smartScript.OnInitialize(null, null, sceneTemplate);
|
||||
smartScript.OnInitialize(sceneTemplate);
|
||||
smartScript.ProcessEventsFor(SmartEvents.SceneCancel, player);
|
||||
}
|
||||
|
||||
public override void OnSceneComplete(Player player, uint sceneInstanceID, SceneTemplate sceneTemplate)
|
||||
{
|
||||
SmartScript smartScript = new SmartScript();
|
||||
smartScript.OnInitialize(null, null, sceneTemplate);
|
||||
smartScript.OnInitialize(sceneTemplate);
|
||||
smartScript.ProcessEventsFor(SmartEvents.SceneComplete, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,15 @@ namespace Game.AI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SmartScriptType.Spell:
|
||||
{
|
||||
if (!Global.SpellMgr.HasSpellInfo((uint)temp.entryOrGuid))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "SmartAIMgr.LoadSmartAIFromDB: Scene id ({0}) does not exist, skipped loading.", temp.entryOrGuid);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SmartScriptType.TimedActionlist:
|
||||
break;//nothing to check, really
|
||||
default:
|
||||
@@ -318,6 +327,7 @@ namespace Game.AI
|
||||
case SmartTargets.Stored:
|
||||
case SmartTargets.LootRecipients:
|
||||
case SmartTargets.VehicleAccessory:
|
||||
case SmartTargets.Caster:
|
||||
break;
|
||||
default:
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartAIMgr: Not handled target_type({0}), Entry {1} SourceType {2} Event {3} Action {4}, skipped.", e.GetTargetType(), e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
|
||||
@@ -689,6 +699,7 @@ namespace Game.AI
|
||||
case SmartEvents.SceneCancel:
|
||||
case SmartEvents.SceneComplete:
|
||||
case SmartEvents.SceneTrigger:
|
||||
case SmartEvents.SpellEffectHit:
|
||||
break;
|
||||
default:
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartAIMgr: Not handled event_type({0}), Entry {1} SourceType {2} Event {3} Action {4}, skipped.", e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
|
||||
@@ -1512,7 +1523,8 @@ namespace Game.AI
|
||||
{ SmartEvents.SceneStart, SmartScriptTypeMaskId.Scene },
|
||||
{ SmartEvents.SceneTrigger, SmartScriptTypeMaskId.Scene },
|
||||
{ SmartEvents.SceneCancel, SmartScriptTypeMaskId.Scene },
|
||||
{ SmartEvents.SceneComplete, SmartScriptTypeMaskId.Scene }
|
||||
{ SmartEvents.SceneComplete, SmartScriptTypeMaskId.Scene },
|
||||
{ SmartEvents.SpellEffectHit, SmartScriptTypeMaskId.Spell }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1691,6 +1703,9 @@ namespace Game.AI
|
||||
[FieldOffset(16)]
|
||||
public Scene scene;
|
||||
|
||||
[FieldOffset(16)]
|
||||
public Spell spell;
|
||||
|
||||
[FieldOffset(16)]
|
||||
public Raw raw;
|
||||
|
||||
@@ -1897,6 +1912,10 @@ namespace Game.AI
|
||||
{
|
||||
public uint sceneId;
|
||||
}
|
||||
public struct Spell
|
||||
{
|
||||
public uint effIndex;
|
||||
}
|
||||
public struct Raw
|
||||
{
|
||||
public uint param1;
|
||||
|
||||
@@ -528,9 +528,13 @@ namespace Game.AI
|
||||
}
|
||||
else if (go)
|
||||
go.CastSpell(obj.ToUnit(), e.Action.cast.spell, triggerFlag);
|
||||
else if (spellTemplate != null)
|
||||
{
|
||||
spellTemplate.GetCaster().CastSpell(obj.ToUnit(), e.Action.cast.spell, triggerFlag);
|
||||
}
|
||||
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.ProcessAction. SMART_ACTION_CAST. Creature {0} casts spell {1} on target {2} with castflags {3}",
|
||||
me.GetGUID().ToString(), e.Action.cast.spell, obj.GetGUID().ToString(), e.Action.cast.castFlags);
|
||||
//Log.outDebug(LogFilter.ScriptsAi, "SmartScript.ProcessAction. SMART_ACTION_CAST. Creature {0} casts spell {1} on target {2} with castflags {3}",
|
||||
// me.GetGUID().ToString(), e.Action.cast.spell, obj.GetGUID().ToString(), e.Action.cast.castFlags);
|
||||
}
|
||||
else
|
||||
Log.outDebug(LogFilter.ScriptsAi, "Spell {0} not casted because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (Guid: {1} Entry: {2} Type: {3}) already has the aura",
|
||||
@@ -2850,6 +2854,12 @@ namespace Game.AI
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SmartTargets.Caster:
|
||||
{
|
||||
if (spellTemplate != null)
|
||||
l.Add(spellTemplate.GetCaster());
|
||||
break;
|
||||
}
|
||||
case SmartTargets.Position:
|
||||
default:
|
||||
break;
|
||||
@@ -3428,6 +3438,9 @@ namespace Game.AI
|
||||
ProcessAction(e, unit, var0, 0, false, null, null, varString);
|
||||
break;
|
||||
}
|
||||
case SmartEvents.SpellEffectHit:
|
||||
ProcessAction(e, null, var0);
|
||||
break;
|
||||
default:
|
||||
Log.outError(LogFilter.Sql, "SmartScript.ProcessEvent: Unhandled Event type {0}", e.GetEventType());
|
||||
break;
|
||||
@@ -3623,7 +3636,7 @@ namespace Game.AI
|
||||
}
|
||||
}
|
||||
|
||||
void FillScript(List<SmartScriptHolder> e, WorldObject obj, AreaTriggerRecord at, SceneTemplate scene)
|
||||
void FillScript(List<SmartScriptHolder> e, WorldObject obj, AreaTriggerRecord at, SceneTemplate scene, Spell spell = null)
|
||||
{
|
||||
if (e.Empty())
|
||||
{
|
||||
@@ -3633,6 +3646,8 @@ namespace Game.AI
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript: EventMap for AreaTrigger {0} is empty but is using SmartScript.", at.Id);
|
||||
if (scene != null)
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript: EventMap for SceneId {0} is empty but is using SmartScript.", scene.SceneId);
|
||||
if (spell != null)
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript: EventMap for SceneId {0} is empty but is using SmartScript.", scene.SceneId);
|
||||
return;
|
||||
}
|
||||
foreach (var holder in e)
|
||||
@@ -3656,6 +3671,8 @@ namespace Game.AI
|
||||
Log.outError(LogFilter.Sql, "SmartScript: AreaTrigger {0} has events but no events added to list because of instance flags. NOTE: triggers can not handle any instance flags.", at.Id);
|
||||
if (mEvents.Empty() && scene != null)
|
||||
Log.outError(LogFilter.Sql, "SmartScript: SceneId {0} has events but no events added to list because of instance flags. NOTE: scenes can not handle any instance flags.", scene.SceneId);
|
||||
if (mEvents.Empty() && spell != null)
|
||||
Log.outError(LogFilter.Sql, "SmartScript: Spell {0} has events but no events added to list because of instance flags. NOTE: scenes can not handle any instance flags.", spell.GetSpellInfo().Id);
|
||||
}
|
||||
|
||||
void GetScript()
|
||||
@@ -3685,9 +3702,14 @@ namespace Game.AI
|
||||
e = Global.SmartAIMgr.GetScript((int)sceneTemplate.SceneId, mScriptType);
|
||||
FillScript(e, null, null, sceneTemplate);
|
||||
}
|
||||
else if (spellTemplate != null)
|
||||
{
|
||||
e = Global.SmartAIMgr.GetScript((int)spellTemplate.GetSpellInfo().Id, mScriptType);
|
||||
FillScript(e, null, null, null, spellTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnInitialize(WorldObject obj, AreaTriggerRecord at = null, SceneTemplate scene = null)
|
||||
public void OnInitialize(WorldObject obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
@@ -3708,21 +3730,9 @@ namespace Game.AI
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (at != null)
|
||||
{
|
||||
mScriptType = SmartScriptType.AreaTrigger;
|
||||
trigger = at;
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.OnInitialize: source is AreaTrigger {0}", trigger.Id);
|
||||
}
|
||||
else if (scene != null)
|
||||
{
|
||||
mScriptType = SmartScriptType.Scene;
|
||||
sceneTemplate = scene;
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.OnInitialize: source is Scene with id {0}", scene.SceneId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartScript.OnInitialize: !WARNING! Initialized objects are Null.");
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartScript.OnInitialize: !WARNING! Initialized WorldObject is Null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3736,6 +3746,72 @@ namespace Game.AI
|
||||
ProcessEventsFor(SmartEvents.JustCreated);
|
||||
}
|
||||
|
||||
public void OnInitialize(AreaTriggerRecord at)
|
||||
{
|
||||
if (at != null)
|
||||
{
|
||||
mScriptType = SmartScriptType.AreaTrigger;
|
||||
trigger = at;
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.OnInitialize: AreaTrigger {0}", trigger.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartScript.OnInitialize: !WARNING! Initialized AreaTrigger is Null.");
|
||||
return;
|
||||
}
|
||||
|
||||
GetScript();//load copy of script
|
||||
|
||||
foreach (var holder in mEvents)
|
||||
InitTimer(holder);//calculate timers for first time use
|
||||
|
||||
InstallEvents();
|
||||
}
|
||||
|
||||
public void OnInitialize(SceneTemplate scene)
|
||||
{
|
||||
if (scene != null)
|
||||
{
|
||||
mScriptType = SmartScriptType.Scene;
|
||||
sceneTemplate = scene;
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.OnInitialize: Scene with id {0}", scene.SceneId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartScript.OnInitialize: !WARNING! Initialized Scene is Null.");
|
||||
return;
|
||||
}
|
||||
|
||||
GetScript();//load copy of script
|
||||
|
||||
foreach (var holder in mEvents)
|
||||
InitTimer(holder);//calculate timers for first time use
|
||||
|
||||
InstallEvents();
|
||||
}
|
||||
|
||||
public void OnInitialize(Spell spell)
|
||||
{
|
||||
if (spell != null)
|
||||
{
|
||||
mScriptType = SmartScriptType.Spell;
|
||||
spellTemplate = spell;
|
||||
Log.outDebug(LogFilter.ScriptsAi, "SmartScript.OnInitialize: Spell id {0}", spell.GetSpellInfo().Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, "SmartScript.OnInitialize: !WARNING! Initialized Spell is Null.");
|
||||
return;
|
||||
}
|
||||
|
||||
GetScript();//load copy of script
|
||||
|
||||
foreach (var holder in mEvents)
|
||||
InitTimer(holder);//calculate timers for first time use
|
||||
|
||||
InstallEvents();
|
||||
}
|
||||
|
||||
public void OnMoveInLineOfSight(Unit who)
|
||||
{
|
||||
ProcessEventsFor(SmartEvents.OocLos, who);
|
||||
@@ -4039,6 +4115,7 @@ namespace Game.AI
|
||||
ObjectGuid goOrigGUID;
|
||||
AreaTriggerRecord trigger;
|
||||
SceneTemplate sceneTemplate;
|
||||
Spell spellTemplate;
|
||||
SmartScriptType mScriptType;
|
||||
uint mEventPhase;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user