Core/Objects: Added ToWorldObject and ToItem
Port From (https://github.com/TrinityCore/TrinityCore/commit/6f6af6a1a1508508d0e42b90f0acf4f363cf91bd)
This commit is contained in:
@@ -38,7 +38,9 @@ namespace Framework.Constants
|
|||||||
AreaTrigger = 0x800,
|
AreaTrigger = 0x800,
|
||||||
SceneObject = 0x1000,
|
SceneObject = 0x1000,
|
||||||
Conversation = 0x2000,
|
Conversation = 0x2000,
|
||||||
Seer = Player | Unit | DynamicObject
|
|
||||||
|
Seer = Player | Unit | DynamicObject,
|
||||||
|
WorldObject = Unit | GameObject | DynamicObject | Corpse | AreaTrigger | SceneObject | Conversation
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum HighGuid
|
public enum HighGuid
|
||||||
|
|||||||
@@ -1331,7 +1331,7 @@ namespace Game.Entities
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
Unit owner = GetOwner();
|
Unit owner = GetOwner();
|
||||||
if (owner != null && seer.IsTypeMask(TypeMask.Unit) && owner.IsFriendlyTo(seer.ToUnit()))
|
if (owner != null && seer.IsUnit() && owner.IsFriendlyTo(seer.ToUnit()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ namespace Game.Entities
|
|||||||
if (IsInWorld)
|
if (IsInWorld)
|
||||||
{
|
{
|
||||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() {0} deleted but still in world!!", GetGUID().ToString());
|
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() {0} deleted but still in world!!", GetGUID().ToString());
|
||||||
if (IsTypeMask(TypeMask.Item))
|
Item item = ToItem();
|
||||||
Log.outFatal(LogFilter.Misc, "Item slot {0}", ((Item)this).GetSlot());
|
if (item != null)
|
||||||
|
Log.outFatal(LogFilter.Misc, "Item slot {0}", item.GetSlot());
|
||||||
Cypher.Assert(false);
|
Cypher.Assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3016,7 +3017,8 @@ namespace Game.Entities
|
|||||||
if (!player.HaveAtClient(this))
|
if (!player.HaveAtClient(this))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (IsTypeMask(TypeMask.Unit) && (ToUnit().GetCharmerGUID() == player.GetGUID()))// @todo this is for puppet
|
Unit unit = ToUnit();
|
||||||
|
if (unit != null && unit.GetCharmerGUID() == player.GetGUID())// @todo this is for puppet
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DestroyForPlayer(player);
|
DestroyForPlayer(player);
|
||||||
@@ -3088,6 +3090,7 @@ namespace Game.Entities
|
|||||||
public bool IsDestroyedObject() { return _isDestroyedObject; }
|
public bool IsDestroyedObject() { return _isDestroyedObject; }
|
||||||
public void SetDestroyedObject(bool destroyed) { _isDestroyedObject = destroyed; }
|
public void SetDestroyedObject(bool destroyed) { _isDestroyedObject = destroyed; }
|
||||||
|
|
||||||
|
public bool IsWorldObject() { return IsTypeMask(TypeMask.WorldObject); }
|
||||||
public bool IsCreature() { return GetTypeId() == TypeId.Unit; }
|
public bool IsCreature() { return GetTypeId() == TypeId.Unit; }
|
||||||
public bool IsPlayer() { return GetTypeId() == TypeId.Player; }
|
public bool IsPlayer() { return GetTypeId() == TypeId.Player; }
|
||||||
public bool IsGameObject() { return GetTypeId() == TypeId.GameObject; }
|
public bool IsGameObject() { return GetTypeId() == TypeId.GameObject; }
|
||||||
@@ -3097,6 +3100,7 @@ namespace Game.Entities
|
|||||||
public bool IsAreaTrigger() { return GetTypeId() == TypeId.AreaTrigger; }
|
public bool IsAreaTrigger() { return GetTypeId() == TypeId.AreaTrigger; }
|
||||||
public bool IsConversation() { return GetTypeId() == TypeId.Conversation; }
|
public bool IsConversation() { return GetTypeId() == TypeId.Conversation; }
|
||||||
public bool IsSceneObject() { return GetTypeId() == TypeId.SceneObject; }
|
public bool IsSceneObject() { return GetTypeId() == TypeId.SceneObject; }
|
||||||
|
public bool IsItem() { return GetTypeId() == TypeId.Item; }
|
||||||
|
|
||||||
public Creature ToCreature() { return IsCreature() ? (this as Creature) : null; }
|
public Creature ToCreature() { return IsCreature() ? (this as Creature) : null; }
|
||||||
public Player ToPlayer() { return IsPlayer() ? (this as Player) : null; }
|
public Player ToPlayer() { return IsPlayer() ? (this as Player) : null; }
|
||||||
@@ -3107,6 +3111,7 @@ namespace Game.Entities
|
|||||||
public AreaTrigger ToAreaTrigger() { return IsAreaTrigger() ? (this as AreaTrigger) : null; }
|
public AreaTrigger ToAreaTrigger() { return IsAreaTrigger() ? (this as AreaTrigger) : null; }
|
||||||
public Conversation ToConversation() { return IsConversation() ? (this as Conversation) : null; }
|
public Conversation ToConversation() { return IsConversation() ? (this as Conversation) : null; }
|
||||||
public SceneObject ToSceneObject() { return IsSceneObject() ? (this as SceneObject) : null; }
|
public SceneObject ToSceneObject() { return IsSceneObject() ? (this as SceneObject) : null; }
|
||||||
|
public Item ToItem() { return IsItem() ? (this as Item) : null; }
|
||||||
|
|
||||||
public virtual uint GetLevelForTarget(WorldObject target) { return 1; }
|
public virtual uint GetLevelForTarget(WorldObject target) { return 1; }
|
||||||
|
|
||||||
@@ -3448,7 +3453,12 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
float newZ = GetMapHeight(x, y, z);
|
float newZ = GetMapHeight(x, y, z);
|
||||||
if (newZ > MapConst.InvalidHeight)
|
if (newZ > MapConst.InvalidHeight)
|
||||||
z = newZ + (IsUnit() ? ToUnit().GetHoverOffset() : 0.0f);
|
{
|
||||||
|
z = newZ;
|
||||||
|
Unit unit = ToUnit();
|
||||||
|
if (unit != null)
|
||||||
|
z += ToUnit().GetHoverOffset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateAllowedPositionZ(float x, float y, ref float z)
|
public void UpdateAllowedPositionZ(float x, float y, ref float z)
|
||||||
|
|||||||
@@ -820,12 +820,8 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(quest.SourceSpellID, GetMap().GetDifficultyID());
|
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(quest.SourceSpellID, GetMap().GetDifficultyID());
|
||||||
Unit caster = this;
|
Unit caster = this;
|
||||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastAccept) && !spellInfo.HasTargetType(Targets.UnitCaster) && !spellInfo.HasTargetType(Targets.DestCasterSummon))
|
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastAccept) && !spellInfo.HasTargetType(Targets.UnitCaster) && !spellInfo.HasTargetType(Targets.DestCasterSummon))
|
||||||
{
|
caster = questGiver.ToUnit();
|
||||||
Unit unit = questGiver.ToUnit();
|
|
||||||
if (unit != null)
|
|
||||||
caster = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
||||||
}
|
}
|
||||||
@@ -1169,12 +1165,8 @@ namespace Game.Entities
|
|||||||
{
|
{
|
||||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(quest.RewardSpell, GetMap().GetDifficultyID());
|
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(quest.RewardSpell, GetMap().GetDifficultyID());
|
||||||
Unit caster = this;
|
Unit caster = this;
|
||||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||||
{
|
caster = questGiver.ToUnit();
|
||||||
Unit unit = questGiver.ToUnit();
|
|
||||||
if (unit != null)
|
|
||||||
caster = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
||||||
}
|
}
|
||||||
@@ -1189,12 +1181,8 @@ namespace Game.Entities
|
|||||||
|
|
||||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(displaySpell.SpellId, GetMap().GetDifficultyID());
|
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(displaySpell.SpellId, GetMap().GetDifficultyID());
|
||||||
Unit caster = this;
|
Unit caster = this;
|
||||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||||
{
|
caster = questGiver.ToUnit();
|
||||||
Unit unit = questGiver.ToUnit();
|
|
||||||
if (unit != null)
|
|
||||||
caster = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
caster.CastSpell(this, spellInfo.Id, new CastSpellExtraArgs(TriggerCastFlags.FullMask).SetCastDifficulty(spellInfo.Difficulty));
|
||||||
}
|
}
|
||||||
@@ -1229,7 +1217,7 @@ namespace Game.Entities
|
|||||||
//lets remove flag for delayed teleports
|
//lets remove flag for delayed teleports
|
||||||
SetCanDelayTeleport(false);
|
SetCanDelayTeleport(false);
|
||||||
|
|
||||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit | TypeMask.GameObject))
|
if (questGiver != null && questGiver.IsWorldObject())
|
||||||
{
|
{
|
||||||
//For AutoSubmition was added plr case there as it almost same exclute AI script cases.
|
//For AutoSubmition was added plr case there as it almost same exclute AI script cases.
|
||||||
// Send next quest
|
// Send next quest
|
||||||
|
|||||||
@@ -875,15 +875,12 @@ namespace Game.Entities
|
|||||||
|
|
||||||
public void StopCastingBindSight()
|
public void StopCastingBindSight()
|
||||||
{
|
{
|
||||||
WorldObject target = GetViewpoint();
|
Unit target = GetViewpoint()?.ToUnit();
|
||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
if (target.IsTypeMask(TypeMask.Unit))
|
target.RemoveAurasByType(AuraType.BindSight, GetGUID());
|
||||||
{
|
target.RemoveAurasByType(AuraType.ModPossess, GetGUID());
|
||||||
((Unit)target).RemoveAurasByType(AuraType.BindSight, GetGUID());
|
target.RemoveAurasByType(AuraType.ModPossessPet, GetGUID());
|
||||||
((Unit)target).RemoveAurasByType(AuraType.ModPossess, GetGUID());
|
|
||||||
((Unit)target).RemoveAurasByType(AuraType.ModPossessPet, GetGUID());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6148,8 +6148,7 @@ namespace Game.Entities
|
|||||||
|
|
||||||
// target aura duration for caster show only if target exist at caster client
|
// target aura duration for caster show only if target exist at caster client
|
||||||
// send data at target visibility change (adding to client)
|
// send data at target visibility change (adding to client)
|
||||||
if (target.IsTypeMask(TypeMask.Unit))
|
SendInitialVisiblePackets(target);
|
||||||
SendInitialVisiblePackets(target.ToUnit());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7438,8 +7437,9 @@ namespace Game.Entities
|
|||||||
// farsight dynobj or puppet may be very far away
|
// farsight dynobj or puppet may be very far away
|
||||||
UpdateVisibilityOf(target);
|
UpdateVisibilityOf(target);
|
||||||
|
|
||||||
if (target.IsTypeMask(TypeMask.Unit) && target != GetVehicleBase())
|
Unit targetUnit = target.ToUnit();
|
||||||
target.ToUnit().AddPlayerToVision(this);
|
if (targetUnit != null && targetUnit != GetVehicleBase())
|
||||||
|
targetUnit.AddPlayerToVision(this);
|
||||||
SetSeer(target);
|
SetSeer(target);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -7454,8 +7454,9 @@ namespace Game.Entities
|
|||||||
|
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_activePlayerData).ModifyValue(m_activePlayerData.FarsightObject), ObjectGuid.Empty);
|
SetUpdateFieldValue(m_values.ModifyValue(m_activePlayerData).ModifyValue(m_activePlayerData.FarsightObject), ObjectGuid.Empty);
|
||||||
|
|
||||||
if (target.IsTypeMask(TypeMask.Unit) && target != GetVehicleBase())
|
Unit targetUnit = target.ToUnit();
|
||||||
target.ToUnit().RemovePlayerFromVision(this);
|
if (targetUnit != null && targetUnit != GetVehicleBase())
|
||||||
|
targetUnit.RemovePlayerFromVision(this);
|
||||||
|
|
||||||
//must immediately set seer back otherwise may crash
|
//must immediately set seer back otherwise may crash
|
||||||
SetSeer(this);
|
SetSeer(this);
|
||||||
|
|||||||
+10
-9
@@ -3880,7 +3880,10 @@ namespace Game.Maps
|
|||||||
// prepare static data
|
// prepare static data
|
||||||
ObjectGuid sourceGUID = source != null ? source.GetGUID() : ObjectGuid.Empty; //some script commands doesn't have source
|
ObjectGuid sourceGUID = source != null ? source.GetGUID() : ObjectGuid.Empty; //some script commands doesn't have source
|
||||||
ObjectGuid targetGUID = target != null ? target.GetGUID() : ObjectGuid.Empty;
|
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
|
// Schedule script execution for all scripts in the script map
|
||||||
bool immedScript = false;
|
bool immedScript = false;
|
||||||
@@ -4027,7 +4030,7 @@ namespace Game.Maps
|
|||||||
if (obj == null)
|
if (obj == null)
|
||||||
Log.outError(LogFilter.Scripts, "{0} {1} object is NULL.", scriptInfo.GetDebugInfo(),
|
Log.outError(LogFilter.Scripts, "{0} {1} object is NULL.", scriptInfo.GetDebugInfo(),
|
||||||
isSource ? "source" : "target");
|
isSource ? "source" : "target");
|
||||||
else if (!obj.IsTypeMask(TypeMask.Unit))
|
else if (!obj.IsUnit())
|
||||||
Log.outError(LogFilter.Scripts,
|
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());
|
"{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
|
else
|
||||||
@@ -4105,7 +4108,7 @@ namespace Game.Maps
|
|||||||
Log.outError(LogFilter.Scripts, "{0} door guid is not specified.", scriptInfo.GetDebugInfo());
|
Log.outError(LogFilter.Scripts, "{0} door guid is not specified.", scriptInfo.GetDebugInfo());
|
||||||
else if (source == null)
|
else if (source == null)
|
||||||
Log.outError(LogFilter.Scripts, "{0} source object is NULL.", scriptInfo.GetDebugInfo());
|
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,
|
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());
|
"{0} source object is not unit (TypeId: {1}, Entry: {2}, GUID: {3}), skipping.", scriptInfo.GetDebugInfo(), source.GetTypeId(), source.GetEntry(), source.GetGUID().ToString());
|
||||||
else
|
else
|
||||||
@@ -4124,12 +4127,10 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
pDoor.UseDoorOrButton((uint)nTimeToToggle);
|
pDoor.UseDoorOrButton((uint)nTimeToToggle);
|
||||||
|
|
||||||
if (target != null && target.IsTypeMask(TypeMask.GameObject))
|
GameObject goTarget = target?.ToGameObject();
|
||||||
{
|
if (goTarget != null && goTarget.GetGoType() == GameObjectTypes.Button)
|
||||||
GameObject goTarget = target.ToGameObject();
|
goTarget.UseDoorOrButton((uint)nTimeToToggle);
|
||||||
if (goTarget != null && goTarget.GetGoType() == GameObjectTypes.Button)
|
|
||||||
goTarget.UseDoorOrButton((uint)nTimeToToggle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2608,10 +2608,11 @@ namespace Game.Spells
|
|||||||
createInfo.CasterGUID = createInfo.Caster.GetGUID();
|
createInfo.CasterGUID = createInfo.Caster.GetGUID();
|
||||||
|
|
||||||
// check if aura can be owned by owner
|
// check if aura can be owned by owner
|
||||||
if (createInfo.GetOwner().IsTypeMask(TypeMask.Unit))
|
Unit ownerUnit = createInfo.GetOwner().ToUnit();
|
||||||
if (!createInfo.GetOwner().IsInWorld || createInfo.GetOwner().ToUnit().IsDuringRemoveFromWorld())
|
if (ownerUnit != null)
|
||||||
|
if (!ownerUnit.IsInWorld || ownerUnit.IsDuringRemoveFromWorld())
|
||||||
// owner not in world so don't allow to own not self casted single target auras
|
// owner not in world so don't allow to own not self casted single target auras
|
||||||
if (createInfo.CasterGUID != createInfo.GetOwner().GetGUID() && createInfo.GetSpellInfo().IsSingleTarget())
|
if (createInfo.CasterGUID != ownerUnit.GetGUID() && createInfo.GetSpellInfo().IsSingleTarget())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Aura aura;
|
Aura aura;
|
||||||
@@ -2805,7 +2806,7 @@ namespace Game.Spells
|
|||||||
case SpellEffectName.ApplyAuraOnPet:
|
case SpellEffectName.ApplyAuraOnPet:
|
||||||
{
|
{
|
||||||
Unit pet = Global.ObjAccessor.GetUnit(GetUnitOwner(), GetUnitOwner().GetPetGUID());
|
Unit pet = Global.ObjAccessor.GetUnit(GetUnitOwner(), GetUnitOwner().GetPetGUID());
|
||||||
if (pet != null)
|
if (pet != null)
|
||||||
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(pet, refe, condList))
|
if (condList == null || Global.ConditionMgr.IsObjectMeetToConditions(pet, refe, condList))
|
||||||
units.Add(pet);
|
units.Add(pet);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user