aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackpoz <giacomopoz@gmail.com>2019-02-24 13:51:59 +0100
committerShauren <shauren.trinity@gmail.com>2021-11-24 00:02:08 +0100
commitb8396f682cebfcbd9ecc15a42194119a74185627 (patch)
treeb66708bfcfa23bdc560ee8d69437f80c79e63a7a /src
parent49e1ff34b726fdf451fe98dee3e24b158b665f44 (diff)
Core/MapScripts: Add support to GameObjects to SCRIPT_COMMAND_DESPAWN_SELF
(cherry picked from commit da19ad117e3c4c15793ba8f84738efaecb4d1428)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Maps/Map.h1
-rw-r--r--src/server/game/Maps/MapScripts.cpp37
2 files changed, 37 insertions, 1 deletions
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index d4e0452a400..15b986cad26 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -675,6 +675,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
private:
Player* _GetScriptPlayerSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo) const;
Creature* _GetScriptCreatureSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo, bool bReverse = false) const;
+ GameObject* _GetScriptGameObjectSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo, bool bReverse = false) const;
Unit* _GetScriptUnit(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
Player* _GetScriptPlayer(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
Creature* _GetScriptCreature(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp
index 541fdcf76b9..c49a8bab1da 100644
--- a/src/server/game/Maps/MapScripts.cpp
+++ b/src/server/game/Maps/MapScripts.cpp
@@ -155,6 +155,39 @@ inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* t
return creature;
}
+inline GameObject* Map::_GetScriptGameObjectSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo, bool bReverse) const
+{
+ GameObject* gameobject = nullptr;
+ if (!source && !target)
+ TC_LOG_ERROR("scripts", "%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str());
+ else
+ {
+ if (bReverse)
+ {
+ // Check target first, then source.
+ if (target)
+ gameobject = target->ToGameObject();
+ if (!gameobject && source)
+ gameobject = source->ToGameObject();
+ }
+ else
+ {
+ // Check source first, then target.
+ if (source)
+ gameobject = source->ToGameObject();
+ if (!gameobject && target)
+ gameobject = target->ToGameObject();
+ }
+
+ if (!gameobject)
+ TC_LOG_ERROR("scripts", "%s neither source nor target are gameobjects (source: TypeId: %u, Entry: %u, %s; target: TypeId: %u, Entry: %u, %s), skipping.",
+ scriptInfo->GetDebugInfo().c_str(),
+ source ? source->GetTypeId() : 0, source ? source->GetEntry() : 0, (source ? source->GetGUID() : ObjectGuid::Empty).ToString().c_str(),
+ target ? target->GetTypeId() : 0, target ? target->GetEntry() : 0, (target ? target->GetGUID() : ObjectGuid::Empty).ToString().c_str());
+ }
+ return gameobject;
+}
+
inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const
{
Unit* unit = nullptr;
@@ -719,9 +752,11 @@ void Map::ScriptsProcess()
break;
case SCRIPT_COMMAND_DESPAWN_SELF:
- // Target or source must be Creature.
+ // First try with target or source creature, then with target or source gameobject
if (Creature* cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script, true))
cSource->DespawnOrUnsummon(step.script->DespawnSelf.DespawnDelay);
+ else if (GameObject* goSource = _GetScriptGameObjectSourceOrTarget(source, target, step.script, true))
+ goSource->DespawnOrUnsummon(Milliseconds(step.script->DespawnSelf.DespawnDelay));
break;
case SCRIPT_COMMAND_LOAD_PATH: