diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-03-14 11:37:32 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-03-14 11:37:32 +0100 |
commit | 6f6af6a1a1508508d0e42b90f0acf4f363cf91bd (patch) | |
tree | 74ed8a08cfc9bb54045fd1195010254eb531eb3c /src/server/game/Maps/MapScripts.cpp | |
parent | 9402c66e8423243d13dbc19e8713e298bea0ac7b (diff) |
Core/Objects: Added ToWorldObject and ToItem
Diffstat (limited to 'src/server/game/Maps/MapScripts.cpp')
-rw-r--r-- | src/server/game/Maps/MapScripts.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp index 8c88d07b81c..299fef61b80 100644 --- a/src/server/game/Maps/MapScripts.cpp +++ b/src/server/game/Maps/MapScripts.cpp @@ -41,7 +41,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->isType(TYPEMASK_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); @@ -76,7 +76,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->isType(TYPEMASK_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; @@ -191,7 +191,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 @@ -267,7 +267,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 @@ -288,9 +288,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); } |