From 387c101475ba9fa00379c1a17da63dc3892a2909 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 23 Nov 2021 22:54:42 -0500 Subject: [PATCH] Core/MapScripts: Add support to GameObjects to SCRIPT_COMMAND_DESPAWN_SELF Port From (https://github.com/TrinityCore/TrinityCore/commit/b8396f682cebfcbd9ecc15a42194119a74185627) --- Source/Game/Maps/Map.cs | 42 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 33fc15933..fed0f4ead 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -4188,6 +4188,38 @@ namespace Game.Maps return creature; } + private GameObject _GetScriptGameObjectSourceOrTarget(WorldObject source, WorldObject target, ScriptInfo scriptInfo, bool bReverse) + { + GameObject gameobject = null; + if (source == null && target == null) + Log.outError(LogFilter.MapsScript, $"{scriptInfo.GetDebugInfo()} source and target objects are NULL."); + else + { + if (bReverse) + { + // Check target first, then source. + if (target != null) + gameobject = target.ToGameObject(); + if (gameobject == null && source != null) + gameobject = source.ToGameObject(); + } + else + { + // Check source first, then target. + if (source != null) + gameobject = source.ToGameObject(); + if (gameobject == null && target != null) + gameobject = target.ToGameObject(); + } + + if (gameobject == null) + Log.outError(LogFilter.MapsScript, $"{scriptInfo.GetDebugInfo()} neither source nor target are gameobjects " + + $"(source: TypeId: {(source != null ? source.GetTypeId() : 0)}, Entry: {(source != null ? source.GetEntry() : 0)}, {(source != null ? source.GetGUID() : ObjectGuid.Empty)}; " + + $"target: TypeId: {(target != null ? target.GetTypeId() : 0)}, Entry: {(target != null ? target.GetEntry() : 0)}, {(target != null ? target.GetGUID() : ObjectGuid.Empty)}), skipping."); + } + return gameobject; + } + private Unit _GetScriptUnit(WorldObject obj, bool isSource, ScriptInfo scriptInfo) { Unit unit = null; @@ -4761,10 +4793,16 @@ namespace Game.Maps case ScriptCommands.DespawnSelf: { - // Target or source must be Creature. + // First try with target or source creature, then with target or source gameobject Creature cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script, true); - if (cSource) + if (cSource != null) cSource.DespawnOrUnsummon(step.script.DespawnSelf.DespawnDelay); + else + { + GameObject goSource = _GetScriptGameObjectSourceOrTarget(source, target, step.script, true); + if (goSource != null) + goSource.DespawnOrUnsummon(TimeSpan.FromMilliseconds(step.script.DespawnSelf.DespawnDelay)); + } break; } case ScriptCommands.LoadPath: