aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps/MapScripts.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-03-14 11:37:32 +0100
committerShauren <shauren.trinity@gmail.com>2024-03-14 21:04:24 +0100
commit0dcff2624e6df1c27d7a4d6a66ebcc0b2d698413 (patch)
tree667e812489cf06c39bde9d53e60e4e2854a09122 /src/server/game/Maps/MapScripts.cpp
parentb64e261e942e093be906e0591c8b4232706ee0e7 (diff)
Core/Objects: Added ToWorldObject and ToItem
(cherry picked from commit 6f6af6a1a1508508d0e42b90f0acf4f363cf91bd)
Diffstat (limited to 'src/server/game/Maps/MapScripts.cpp')
-rw-r--r--src/server/game/Maps/MapScripts.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp
index 8c22fe3d873..9972c3f4a29 100644
--- a/src/server/game/Maps/MapScripts.cpp
+++ b/src/server/game/Maps/MapScripts.cpp
@@ -42,7 +42,7 @@ void Map::ScriptsStart(std::map<uint32, std::multimap<uint32, ScriptInfo>> const
// prepare static data
ObjectGuid sourceGUID = source ? source->GetGUID() : ObjectGuid::Empty; //some script commands doesn't have source
ObjectGuid targetGUID = target ? target->GetGUID() : ObjectGuid::Empty;
- ObjectGuid ownerGUID = (source && source->GetTypeId() == TYPEID_ITEM) ? ((Item*)source)->GetOwnerGUID() : ObjectGuid::Empty;
+ ObjectGuid ownerGUID = [&] { if (Item* item = Object::ToItem(source)) return item->GetOwnerGUID(); return ObjectGuid::Empty; }();
///- Schedule script execution for all scripts in the script map
ScriptMap const* s2 = &(s->second);
@@ -77,7 +77,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
// prepare static data
ObjectGuid sourceGUID = source ? source->GetGUID() : ObjectGuid::Empty;
ObjectGuid targetGUID = target ? target->GetGUID() : ObjectGuid::Empty;
- ObjectGuid ownerGUID = (source && source->GetTypeId() == TYPEID_ITEM) ? ((Item*)source)->GetOwnerGUID() : ObjectGuid::Empty;
+ ObjectGuid ownerGUID = [&] { if (Item* item = Object::ToItem(source)) return item->GetOwnerGUID(); return ObjectGuid::Empty; }();
ScriptAction sa;
sa.sourceGUID = sourceGUID;
@@ -192,7 +192,7 @@ inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, ScriptInfo const* s
Unit* unit = nullptr;
if (!obj)
TC_LOG_ERROR("scripts", "{} {} object is NULL.", scriptInfo->GetDebugInfo(), isSource ? "source" : "target");
- else if (!obj->isType(TYPEMASK_UNIT))
+ else if (!obj->IsUnit())
TC_LOG_ERROR("scripts", "{} {} object is not unit {}, skipping.",
scriptInfo->GetDebugInfo(), isSource ? "source" : "target", obj->GetGUID().ToString());
else
@@ -268,7 +268,7 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, ScriptInfo c
TC_LOG_ERROR("scripts", "{} door guid is not specified.", scriptInfo->GetDebugInfo());
else if (!source)
TC_LOG_ERROR("scripts", "{} source object is NULL.", scriptInfo->GetDebugInfo());
- else if (!source->isType(TYPEMASK_UNIT))
+ else if (!source->IsUnit())
TC_LOG_ERROR("scripts", "{} source object is not unit {}, skipping.", scriptInfo->GetDebugInfo(),
source->GetGUID().ToString());
else
@@ -289,9 +289,8 @@ inline void Map::_ScriptProcessDoor(Object* source, Object* target, ScriptInfo c
{
pDoor->UseDoorOrButton(nTimeToToggle);
- if (target && target->isType(TYPEMASK_GAMEOBJECT))
+ if (GameObject* goTarget = Object::ToGameObject(target))
{
- GameObject* goTarget = target->ToGameObject();
if (goTarget && goTarget->GetGoType() == GAMEOBJECT_TYPE_BUTTON)
goTarget->UseDoorOrButton(nTimeToToggle);
}