diff --git a/Framework/Constants/SmartAIConst.cs b/Framework/Constants/SmartAIConst.cs index 459f0a3c4..b243874eb 100644 --- a/Framework/Constants/SmartAIConst.cs +++ b/Framework/Constants/SmartAIConst.cs @@ -362,7 +362,7 @@ namespace Framework.Constants LootRecipients = 27, // all players that have tagged this creature (for kill credit) Farthest = 28, // maxDist, playerOnly, isInLos VehicleAccessory = 29, // seat number (vehicle can target it's own accessory) - Caster = 30, + SpellTarget = 30, End = 31 } diff --git a/Game/AI/SmartScripts/SmartAI.cs b/Game/AI/SmartScripts/SmartAI.cs index 12045736d..c82141779 100644 --- a/Game/AI/SmartScripts/SmartAI.cs +++ b/Game/AI/SmartScripts/SmartAI.cs @@ -1059,7 +1059,7 @@ namespace Game.AI void HandleEffectHit(uint effIndex) { - mScript.ProcessEventsFor(SmartEvents.SpellEffectHit); + mScript.ProcessEventsFor(SmartEvents.SpellEffectHit, GetCaster()); } void HandleEffectHitTarget(uint effIndex) diff --git a/Game/AI/SmartScripts/SmartAIManager.cs b/Game/AI/SmartScripts/SmartAIManager.cs index 09820c791..cb763b742 100644 --- a/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Game/AI/SmartScripts/SmartAIManager.cs @@ -28,12 +28,19 @@ namespace Game.AI { public class SmartAIManager : Singleton { - SmartAIManager() { } + SmartAIManager() + { + for (byte i = 0; i < (int)SmartScriptType.Max; i++) + mEventMap[i] = new MultiMap(); + } public void LoadFromDB() { uint oldMSTime = Time.GetMSTime(); + for (byte i = 0; i < (int)SmartScriptType.Max; i++) + mEventMap[i].Clear(); //Drop Existing SmartAI List + PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_SMART_SCRIPTS); SQLResult result = DB.World.Query(stmt); if (result.IsEmpty()) @@ -158,15 +165,13 @@ namespace Game.AI continue; // creature entry / guid not found in storage, create empty event list for it and increase counters - if (mEventMap[(int)source_type] == null) - mEventMap[(int)source_type] = new MultiMap(); - if (!mEventMap[(int)source_type].ContainsKey(temp.entryOrGuid)) ++count; // store the new event - mEventMap[(uint)source_type].Add(temp.entryOrGuid, temp); - } while (result.NextRow()); + mEventMap[(int)source_type].Add(temp.entryOrGuid, temp); + } + while (result.NextRow()); // Post Loading Validation for (byte i = 0; i < (int)SmartScriptType.Max; ++i) @@ -327,7 +332,7 @@ namespace Game.AI case SmartTargets.Stored: case SmartTargets.LootRecipients: case SmartTargets.VehicleAccessory: - case SmartTargets.Caster: + case SmartTargets.SpellTarget: 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()); @@ -1524,7 +1529,8 @@ namespace Game.AI { SmartEvents.SceneTrigger, SmartScriptTypeMaskId.Scene }, { SmartEvents.SceneCancel, SmartScriptTypeMaskId.Scene }, { SmartEvents.SceneComplete, SmartScriptTypeMaskId.Scene }, - { SmartEvents.SpellEffectHit, SmartScriptTypeMaskId.Spell } + { SmartEvents.SpellEffectHit, SmartScriptTypeMaskId.Spell }, + { SmartEvents.SpellEffectHitTarget, SmartScriptTypeMaskId.Spell } }; } diff --git a/Game/AI/SmartScripts/SmartScript.cs b/Game/AI/SmartScripts/SmartScript.cs index 0591eb0e4..8d13a5549 100644 --- a/Game/AI/SmartScripts/SmartScript.cs +++ b/Game/AI/SmartScripts/SmartScript.cs @@ -528,10 +528,8 @@ 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); - } + else if (obj != null) + obj.ToUnit().CastSpell(obj.ToUnit(), e.Action.cast.spell); //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); @@ -2854,10 +2852,10 @@ namespace Game.AI } break; } - case SmartTargets.Caster: + case SmartTargets.SpellTarget: { if (spellTemplate != null) - l.Add(spellTemplate.GetCaster()); + l.Add(spellTemplate.m_targets.GetUnitTarget()); break; } case SmartTargets.Position: @@ -3439,7 +3437,7 @@ namespace Game.AI break; } case SmartEvents.SpellEffectHit: - ProcessAction(e, null, var0); + ProcessAction(e, unit, var0); break; default: Log.outError(LogFilter.Sql, "SmartScript.ProcessEvent: Unhandled Event type {0}", e.GetEventType()); @@ -3923,7 +3921,7 @@ namespace Game.AI return summoner; } - bool IsUnit(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Unit) || obj.IsTypeId(TypeId.Player); } + bool IsUnit(WorldObject obj) { return obj != null && (obj.IsTypeId(TypeId.Unit) || obj.IsTypeId(TypeId.Player)); } public bool IsPlayer(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Player); } bool IsCreature(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Unit); } static bool IsCreatureInControlOfSelf(WorldObject obj)