Core/Objects: Added ToWorldObject and ToItem
Port From (https://github.com/TrinityCore/TrinityCore/commit/6f6af6a1a1508508d0e42b90f0acf4f363cf91bd)
This commit is contained in:
@@ -1331,7 +1331,7 @@ namespace Game.Entities
|
||||
return true;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,9 @@ namespace Game.Entities
|
||||
if (IsInWorld)
|
||||
{
|
||||
Log.outFatal(LogFilter.Misc, "WorldObject.Dispose() {0} deleted but still in world!!", GetGUID().ToString());
|
||||
if (IsTypeMask(TypeMask.Item))
|
||||
Log.outFatal(LogFilter.Misc, "Item slot {0}", ((Item)this).GetSlot());
|
||||
Item item = ToItem();
|
||||
if (item != null)
|
||||
Log.outFatal(LogFilter.Misc, "Item slot {0}", item.GetSlot());
|
||||
Cypher.Assert(false);
|
||||
}
|
||||
|
||||
@@ -3016,7 +3017,8 @@ namespace Game.Entities
|
||||
if (!player.HaveAtClient(this))
|
||||
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;
|
||||
|
||||
DestroyForPlayer(player);
|
||||
@@ -3088,6 +3090,7 @@ namespace Game.Entities
|
||||
public bool IsDestroyedObject() { return _isDestroyedObject; }
|
||||
public void SetDestroyedObject(bool destroyed) { _isDestroyedObject = destroyed; }
|
||||
|
||||
public bool IsWorldObject() { return IsTypeMask(TypeMask.WorldObject); }
|
||||
public bool IsCreature() { return GetTypeId() == TypeId.Unit; }
|
||||
public bool IsPlayer() { return GetTypeId() == TypeId.Player; }
|
||||
public bool IsGameObject() { return GetTypeId() == TypeId.GameObject; }
|
||||
@@ -3097,6 +3100,7 @@ namespace Game.Entities
|
||||
public bool IsAreaTrigger() { return GetTypeId() == TypeId.AreaTrigger; }
|
||||
public bool IsConversation() { return GetTypeId() == TypeId.Conversation; }
|
||||
public bool IsSceneObject() { return GetTypeId() == TypeId.SceneObject; }
|
||||
public bool IsItem() { return GetTypeId() == TypeId.Item; }
|
||||
|
||||
public Creature ToCreature() { return IsCreature() ? (this as Creature) : 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 Conversation ToConversation() { return IsConversation() ? (this as Conversation) : 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; }
|
||||
|
||||
@@ -3448,7 +3453,12 @@ namespace Game.Entities
|
||||
{
|
||||
float newZ = GetMapHeight(x, y, z);
|
||||
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)
|
||||
|
||||
@@ -820,12 +820,8 @@ namespace Game.Entities
|
||||
{
|
||||
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(quest.SourceSpellID, GetMap().GetDifficultyID());
|
||||
Unit caster = this;
|
||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastAccept) && !spellInfo.HasTargetType(Targets.UnitCaster) && !spellInfo.HasTargetType(Targets.DestCasterSummon))
|
||||
{
|
||||
Unit unit = questGiver.ToUnit();
|
||||
if (unit != null)
|
||||
caster = unit;
|
||||
}
|
||||
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastAccept) && !spellInfo.HasTargetType(Targets.UnitCaster) && !spellInfo.HasTargetType(Targets.DestCasterSummon))
|
||||
caster = questGiver.ToUnit();
|
||||
|
||||
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());
|
||||
Unit caster = this;
|
||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||
{
|
||||
Unit unit = questGiver.ToUnit();
|
||||
if (unit != null)
|
||||
caster = unit;
|
||||
}
|
||||
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||
caster = questGiver.ToUnit();
|
||||
|
||||
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());
|
||||
Unit caster = this;
|
||||
if (questGiver != null && questGiver.IsTypeMask(TypeMask.Unit) && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||
{
|
||||
Unit unit = questGiver.ToUnit();
|
||||
if (unit != null)
|
||||
caster = unit;
|
||||
}
|
||||
if (questGiver != null && questGiver.IsUnit() && !quest.HasFlag(QuestFlags.PlayerCastComplete) && !spellInfo.HasTargetType(Targets.UnitCaster))
|
||||
caster = questGiver.ToUnit();
|
||||
|
||||
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
|
||||
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.
|
||||
// Send next quest
|
||||
|
||||
@@ -875,15 +875,12 @@ namespace Game.Entities
|
||||
|
||||
public void StopCastingBindSight()
|
||||
{
|
||||
WorldObject target = GetViewpoint();
|
||||
Unit target = GetViewpoint()?.ToUnit();
|
||||
if (target != null)
|
||||
{
|
||||
if (target.IsTypeMask(TypeMask.Unit))
|
||||
{
|
||||
((Unit)target).RemoveAurasByType(AuraType.BindSight, GetGUID());
|
||||
((Unit)target).RemoveAurasByType(AuraType.ModPossess, GetGUID());
|
||||
((Unit)target).RemoveAurasByType(AuraType.ModPossessPet, GetGUID());
|
||||
}
|
||||
target.RemoveAurasByType(AuraType.BindSight, GetGUID());
|
||||
target.RemoveAurasByType(AuraType.ModPossess, GetGUID());
|
||||
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
|
||||
// send data at target visibility change (adding to client)
|
||||
if (target.IsTypeMask(TypeMask.Unit))
|
||||
SendInitialVisiblePackets(target.ToUnit());
|
||||
SendInitialVisiblePackets(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7438,8 +7437,9 @@ namespace Game.Entities
|
||||
// farsight dynobj or puppet may be very far away
|
||||
UpdateVisibilityOf(target);
|
||||
|
||||
if (target.IsTypeMask(TypeMask.Unit) && target != GetVehicleBase())
|
||||
target.ToUnit().AddPlayerToVision(this);
|
||||
Unit targetUnit = target.ToUnit();
|
||||
if (targetUnit != null && targetUnit != GetVehicleBase())
|
||||
targetUnit.AddPlayerToVision(this);
|
||||
SetSeer(target);
|
||||
}
|
||||
else
|
||||
@@ -7454,8 +7454,9 @@ namespace Game.Entities
|
||||
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_activePlayerData).ModifyValue(m_activePlayerData.FarsightObject), ObjectGuid.Empty);
|
||||
|
||||
if (target.IsTypeMask(TypeMask.Unit) && target != GetVehicleBase())
|
||||
target.ToUnit().RemovePlayerFromVision(this);
|
||||
Unit targetUnit = target.ToUnit();
|
||||
if (targetUnit != null && targetUnit != GetVehicleBase())
|
||||
targetUnit.RemovePlayerFromVision(this);
|
||||
|
||||
//must immediately set seer back otherwise may crash
|
||||
SetSeer(this);
|
||||
|
||||
Reference in New Issue
Block a user