Core/MapScripts: Allow GameObjects to be caster of SCRIPT_COMMAND_CAST_SPELL

Port From (https://github.com/TrinityCore/TrinityCore/commit/3acb4204440f5dcbbc0f17816de24a3244e53771)
This commit is contained in:
hondacrx
2021-11-23 21:36:51 -05:00
parent ebc28748b9
commit dab1702214
+13 -14
View File
@@ -4666,49 +4666,48 @@ namespace Game.Maps
} }
case ScriptCommands.CastSpell: case ScriptCommands.CastSpell:
{ {
//@todo Allow gameobjects to be targets and casters
if (source == null && target == null) if (source == null && target == null)
{ {
Log.outError(LogFilter.Scripts, "{0} source and target objects are NULL.", step.script.GetDebugInfo()); Log.outError(LogFilter.Scripts, "{0} source and target objects are NULL.", step.script.GetDebugInfo());
break; break;
} }
Unit uSource = null; WorldObject uSource = null;
Unit uTarget = null; WorldObject uTarget = null;
// source/target cast spell at target/source (script.datalong2: 0: s.t 1: s.s 2: t.t 3: t.s // source/target cast spell at target/source (script.datalong2: 0: s.t 1: s.s 2: t.t 3: t.s
switch (step.script.CastSpell.Flags) switch (step.script.CastSpell.Flags)
{ {
case eScriptFlags.CastspellSourceToTarget: // source . target case eScriptFlags.CastspellSourceToTarget: // source . target
uSource = source?.ToUnit(); uSource = source;
uTarget = target?.ToUnit(); uTarget = target;
break; break;
case eScriptFlags.CastspellSourceToSource: // source . source case eScriptFlags.CastspellSourceToSource: // source . source
uSource = source?.ToUnit(); uSource = source;
uTarget = uSource; uTarget = uSource;
break; break;
case eScriptFlags.CastspellTargetToTarget: // target . target case eScriptFlags.CastspellTargetToTarget: // target . target
uSource = target?.ToUnit(); uSource = target;
uTarget = uSource; uTarget = uSource;
break; break;
case eScriptFlags.CastspellTargetToSource: // target . source case eScriptFlags.CastspellTargetToSource: // target . source
uSource = target?.ToUnit(); uSource = target;
uTarget = source?.ToUnit(); uTarget = source;
break; break;
case eScriptFlags.CastspellSearchCreature: // source . creature with entry case eScriptFlags.CastspellSearchCreature: // source . creature with entry
uSource = source?.ToUnit(); uSource = source;
uTarget = uSource?.FindNearestCreature((uint)Math.Abs(step.script.CastSpell.CreatureEntry), step.script.CastSpell.SearchRadius); uTarget = uSource?.FindNearestCreature((uint)Math.Abs(step.script.CastSpell.CreatureEntry), step.script.CastSpell.SearchRadius);
break; break;
} }
if (uSource == null || !uSource.IsTypeMask(TypeMask.Unit)) if (uSource == null)
{ {
Log.outError(LogFilter.Scripts, "{0} no source unit found for spell {1}", step.script.GetDebugInfo(), step.script.CastSpell.SpellID); Log.outError(LogFilter.Scripts, "{0} no source worldobject found for spell {1}", step.script.GetDebugInfo(), step.script.CastSpell.SpellID);
break; break;
} }
if (uTarget == null || !uTarget.IsTypeMask(TypeMask.Unit)) if (uTarget == null)
{ {
Log.outError(LogFilter.Scripts, "{0} no target unit found for spell {1}", step.script.GetDebugInfo(), step.script.CastSpell.SpellID); Log.outError(LogFilter.Scripts, "{0} no target worldobject found for spell {1}", step.script.GetDebugInfo(), step.script.CastSpell.SpellID);
break; break;
} }