Core/Objects: Added ToWorldObject and ToItem

Port From (https://github.com/TrinityCore/TrinityCore/commit/6f6af6a1a1508508d0e42b90f0acf4f363cf91bd)
This commit is contained in:
hondacrx
2024-03-14 11:26:01 -04:00
parent 4bbf49a17a
commit 9d7a84d3a3
8 changed files with 56 additions and 56 deletions
+10 -9
View File
@@ -3880,7 +3880,10 @@ namespace Game.Maps
// prepare static data
ObjectGuid sourceGUID = source != null ? source.GetGUID() : ObjectGuid.Empty; //some script commands doesn't have source
ObjectGuid targetGUID = target != null ? target.GetGUID() : ObjectGuid.Empty;
ObjectGuid ownerGUID = (source != null && source.IsTypeMask(TypeMask.Item)) ? ((Item)source).GetOwnerGUID() : ObjectGuid.Empty;
ObjectGuid ownerGUID = ObjectGuid.Empty;
var item = source?.ToItem();
if (item != null)
ownerGUID = item.GetOwnerGUID();
// Schedule script execution for all scripts in the script map
bool immedScript = false;
@@ -4027,7 +4030,7 @@ namespace Game.Maps
if (obj == null)
Log.outError(LogFilter.Scripts, "{0} {1} object is NULL.", scriptInfo.GetDebugInfo(),
isSource ? "source" : "target");
else if (!obj.IsTypeMask(TypeMask.Unit))
else if (!obj.IsUnit())
Log.outError(LogFilter.Scripts,
"{0} {1} object is not unit (TypeId: {2}, Entry: {3}, GUID: {4}), skipping.", scriptInfo.GetDebugInfo(), isSource ? "source" : "target", obj.GetTypeId(), obj.GetEntry(), obj.GetGUID().ToString());
else
@@ -4105,7 +4108,7 @@ namespace Game.Maps
Log.outError(LogFilter.Scripts, "{0} door guid is not specified.", scriptInfo.GetDebugInfo());
else if (source == null)
Log.outError(LogFilter.Scripts, "{0} source object is NULL.", scriptInfo.GetDebugInfo());
else if (!source.IsTypeMask(TypeMask.Unit))
else if (!source.IsUnit())
Log.outError(LogFilter.Scripts,
"{0} source object is not unit (TypeId: {1}, Entry: {2}, GUID: {3}), skipping.", scriptInfo.GetDebugInfo(), source.GetTypeId(), source.GetEntry(), source.GetGUID().ToString());
else
@@ -4124,12 +4127,10 @@ namespace Game.Maps
{
pDoor.UseDoorOrButton((uint)nTimeToToggle);
if (target != null && target.IsTypeMask(TypeMask.GameObject))
{
GameObject goTarget = target.ToGameObject();
if (goTarget != null && goTarget.GetGoType() == GameObjectTypes.Button)
goTarget.UseDoorOrButton((uint)nTimeToToggle);
}
GameObject goTarget = target?.ToGameObject();
if (goTarget != null && goTarget.GetGoType() == GameObjectTypes.Button)
goTarget.UseDoorOrButton((uint)nTimeToToggle);
}
}
}