More work on smartAI for spells. got the Orb of Translocations working.

SQL files to follow someday :)

Signed-off-by: hondacrx <prelude_20032002@yahoo.com>
This commit is contained in:
hondacrx
2017-07-11 00:04:18 -04:00
parent 809e601945
commit a63a3360b6
4 changed files with 22 additions and 18 deletions
+1 -1
View File
@@ -362,7 +362,7 @@ namespace Framework.Constants
LootRecipients = 27, // all players that have tagged this creature (for kill credit) LootRecipients = 27, // all players that have tagged this creature (for kill credit)
Farthest = 28, // maxDist, playerOnly, isInLos Farthest = 28, // maxDist, playerOnly, isInLos
VehicleAccessory = 29, // seat number (vehicle can target it's own accessory) VehicleAccessory = 29, // seat number (vehicle can target it's own accessory)
Caster = 30, SpellTarget = 30,
End = 31 End = 31
} }
+1 -1
View File
@@ -1059,7 +1059,7 @@ namespace Game.AI
void HandleEffectHit(uint effIndex) void HandleEffectHit(uint effIndex)
{ {
mScript.ProcessEventsFor(SmartEvents.SpellEffectHit); mScript.ProcessEventsFor(SmartEvents.SpellEffectHit, GetCaster());
} }
void HandleEffectHitTarget(uint effIndex) void HandleEffectHitTarget(uint effIndex)
+14 -8
View File
@@ -28,12 +28,19 @@ namespace Game.AI
{ {
public class SmartAIManager : Singleton<SmartAIManager> public class SmartAIManager : Singleton<SmartAIManager>
{ {
SmartAIManager() { } SmartAIManager()
{
for (byte i = 0; i < (int)SmartScriptType.Max; i++)
mEventMap[i] = new MultiMap<int, SmartScriptHolder>();
}
public void LoadFromDB() public void LoadFromDB()
{ {
uint oldMSTime = Time.GetMSTime(); 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); PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_SMART_SCRIPTS);
SQLResult result = DB.World.Query(stmt); SQLResult result = DB.World.Query(stmt);
if (result.IsEmpty()) if (result.IsEmpty())
@@ -158,15 +165,13 @@ namespace Game.AI
continue; continue;
// creature entry / guid not found in storage, create empty event list for it and increase counters // 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<int, SmartScriptHolder>();
if (!mEventMap[(int)source_type].ContainsKey(temp.entryOrGuid)) if (!mEventMap[(int)source_type].ContainsKey(temp.entryOrGuid))
++count; ++count;
// store the new event // store the new event
mEventMap[(uint)source_type].Add(temp.entryOrGuid, temp); mEventMap[(int)source_type].Add(temp.entryOrGuid, temp);
} while (result.NextRow()); }
while (result.NextRow());
// Post Loading Validation // Post Loading Validation
for (byte i = 0; i < (int)SmartScriptType.Max; ++i) for (byte i = 0; i < (int)SmartScriptType.Max; ++i)
@@ -327,7 +332,7 @@ namespace Game.AI
case SmartTargets.Stored: case SmartTargets.Stored:
case SmartTargets.LootRecipients: case SmartTargets.LootRecipients:
case SmartTargets.VehicleAccessory: case SmartTargets.VehicleAccessory:
case SmartTargets.Caster: case SmartTargets.SpellTarget:
break; break;
default: 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()); 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.SceneTrigger, SmartScriptTypeMaskId.Scene },
{ SmartEvents.SceneCancel, SmartScriptTypeMaskId.Scene }, { SmartEvents.SceneCancel, SmartScriptTypeMaskId.Scene },
{ SmartEvents.SceneComplete, SmartScriptTypeMaskId.Scene }, { SmartEvents.SceneComplete, SmartScriptTypeMaskId.Scene },
{ SmartEvents.SpellEffectHit, SmartScriptTypeMaskId.Spell } { SmartEvents.SpellEffectHit, SmartScriptTypeMaskId.Spell },
{ SmartEvents.SpellEffectHitTarget, SmartScriptTypeMaskId.Spell }
}; };
} }
+6 -8
View File
@@ -528,10 +528,8 @@ namespace Game.AI
} }
else if (go) else if (go)
go.CastSpell(obj.ToUnit(), e.Action.cast.spell, triggerFlag); go.CastSpell(obj.ToUnit(), e.Action.cast.spell, triggerFlag);
else if (spellTemplate != null) else if (obj != null)
{ obj.ToUnit().CastSpell(obj.ToUnit(), e.Action.cast.spell);
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}", //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); // me.GetGUID().ToString(), e.Action.cast.spell, obj.GetGUID().ToString(), e.Action.cast.castFlags);
@@ -2854,10 +2852,10 @@ namespace Game.AI
} }
break; break;
} }
case SmartTargets.Caster: case SmartTargets.SpellTarget:
{ {
if (spellTemplate != null) if (spellTemplate != null)
l.Add(spellTemplate.GetCaster()); l.Add(spellTemplate.m_targets.GetUnitTarget());
break; break;
} }
case SmartTargets.Position: case SmartTargets.Position:
@@ -3439,7 +3437,7 @@ namespace Game.AI
break; break;
} }
case SmartEvents.SpellEffectHit: case SmartEvents.SpellEffectHit:
ProcessAction(e, null, var0); ProcessAction(e, unit, var0);
break; break;
default: default:
Log.outError(LogFilter.Sql, "SmartScript.ProcessEvent: Unhandled Event type {0}", e.GetEventType()); Log.outError(LogFilter.Sql, "SmartScript.ProcessEvent: Unhandled Event type {0}", e.GetEventType());
@@ -3923,7 +3921,7 @@ namespace Game.AI
return summoner; 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); } public bool IsPlayer(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Player); }
bool IsCreature(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Unit); } bool IsCreature(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Unit); }
static bool IsCreatureInControlOfSelf(WorldObject obj) static bool IsCreatureInControlOfSelf(WorldObject obj)