diff --git a/Source/ACE.Server/Physics/Animation/MotionInterp.cs b/Source/ACE.Server/Physics/Animation/MotionInterp.cs index c6435c701f..b469bb71bc 100644 --- a/Source/ACE.Server/Physics/Animation/MotionInterp.cs +++ b/Source/ACE.Server/Physics/Animation/MotionInterp.cs @@ -176,7 +176,7 @@ public void HitGround() { if (PhysicsObj == null) return; - if (WeenieObj != null && !WeenieObj.IsCreature()) return; + if (WeenieObj != null && !WeenieObj.IsCreature) return; if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity)) return; @@ -193,7 +193,7 @@ public void LeaveGround() { if (PhysicsObj == null) return; - if (WeenieObj != null && !WeenieObj.IsCreature()) return; + if (WeenieObj != null && !WeenieObj.IsCreature) return; if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity)) return; @@ -265,7 +265,7 @@ public void ReportExhaustion() { if (PhysicsObj == null || !Initted) return; - if (WeenieObj == null || WeenieObj.IsCreature() && PhysicsObj.movement_is_autonomous()) + if (WeenieObj == null || WeenieObj.IsCreature && PhysicsObj.movement_is_autonomous()) apply_raw_movement(false, false); else apply_interpreted_movement(false, false); @@ -393,7 +393,7 @@ public void add_to_queue(int contextID, uint motion, WeenieError jumpErrorCode) public void adjust_motion(ref uint motion, ref float speed, HoldKey holdKey) { - if (WeenieObj != null && !WeenieObj.IsCreature()) + if (WeenieObj != null && !WeenieObj.IsCreature) return; switch (motion) @@ -431,7 +431,7 @@ public void apply_current_movement(bool cancelMoveTo, bool allowJump) { if (PhysicsObj == null || !Initted) return; - if (WeenieObj != null && !WeenieObj.IsCreature() || !PhysicsObj.movement_is_autonomous()) + if (WeenieObj != null && !WeenieObj.IsCreature || !PhysicsObj.movement_is_autonomous()) apply_interpreted_movement(cancelMoveTo, allowJump); else apply_raw_movement(cancelMoveTo, allowJump); @@ -588,7 +588,7 @@ public bool contact_allows_move(uint motion) if (motion == (uint)MotionCommand.Dead || motion == (uint)MotionCommand.Falling || motion >= (uint)MotionCommand.TurnRight && motion <= (uint)MotionCommand.TurnLeft) return true; - if (WeenieObj != null && !WeenieObj.IsCreature()) + if (WeenieObj != null && !WeenieObj.IsCreature) return true; if (!PhysicsObj.State.HasFlag(PhysicsState.Gravity)) @@ -744,7 +744,7 @@ public WeenieError jump_is_allowed(float extent, int staminaCost) if (PhysicsObj == null) return WeenieError.NoPhysicsObject; - if (WeenieObj == null && !WeenieObj.IsCreature() || !PhysicsObj.State.HasFlag(PhysicsState.Gravity) || + if (WeenieObj == null && !WeenieObj.IsCreature || !PhysicsObj.State.HasFlag(PhysicsState.Gravity) || PhysicsObj.TransientState.HasFlag(TransientStateFlags.Contact | TransientStateFlags.OnWalkable)) { if (PhysicsObj.IsFullyConstrained()) @@ -811,7 +811,7 @@ public bool move_to_interpreted_state(InterpretedMotionState state) if (diff) { - if (WeenieObj != null && WeenieObj.IsCreature() || action.Autonomous) + if (WeenieObj != null && WeenieObj.IsCreature || action.Autonomous) { ServerActionStamp = action.Stamp; movementParams.Speed = action.Speed; diff --git a/Source/ACE.Server/Physics/Common/WeenieObject.cs b/Source/ACE.Server/Physics/Common/WeenieObject.cs index feb4181ea6..b6b4b11744 100644 --- a/Source/ACE.Server/Physics/Common/WeenieObject.cs +++ b/Source/ACE.Server/Physics/Common/WeenieObject.cs @@ -11,39 +11,58 @@ namespace ACE.Server.Physics.Common { - public class WeenieObject + public sealed class WeenieObject { private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public uint ID; - public double UpdateTime; + // public readonly uint ID; + // public readonly double UpdateTime; public readonly WorldObjectInfo WorldObjectInfo; public WorldObject WorldObject => WorldObjectInfo?.TryGetWorldObject(); - public bool IsMonster { get; set; } - public bool IsCombatPet { get; set; } + public readonly bool IsPlayer; + public readonly bool IsCreature; + public readonly bool IsStorage; + public readonly bool IsCorpse; - public bool IsFactionMob { get; set; } + public readonly bool IsMonster; - public FactionBits Faction1Bits { get; set; } + public readonly bool IsCombatPet; - public CreatureType? FoeType { get; set; } + public readonly bool IsFactionMob; - public PlayerKillerStatus PlayerKillerStatus { get; set; } + public readonly FactionBits Faction1Bits; - public WeenieObject() { } + public readonly CreatureType? FoeType; + + public readonly PlayerKillerStatus PlayerKillerStatus; + + private WeenieObject() { } + + public static readonly WeenieObject DummyObject = new(); public WeenieObject(WorldObject worldObject) { WorldObjectInfo = new WorldObjectInfo(worldObject); - - if (!(worldObject is Creature creature)) + if (worldObject is not Creature creature) + { + if (worldObject is Corpse) + IsCorpse = true; + else if (worldObject is Storage) + IsStorage = true; return; + } + + IsCreature = true; - IsCombatPet = worldObject is CombatPet; + if (creature is Player) + IsPlayer = true; + else if (creature is CombatPet) + IsCombatPet = true; + else if (creature.IsMonster) + IsMonster = true; - IsMonster = creature.IsMonster && !IsCombatPet; Faction1Bits = creature.Faction1Bits ?? FactionBits.None; @@ -74,6 +93,9 @@ public bool InqJumpVelocity(float extent, out float velocity_z) { velocity_z = 0.0f; + if (!IsPlayer) + return false; + var player = WorldObject as Player; if (player == null) @@ -103,6 +125,9 @@ public bool InqJumpVelocity(float extent, out float velocity_z) /// public float? InqBurden() { + if (!IsPlayer) + return null; + var player = WorldObject as Player; if (player == null) @@ -134,39 +159,19 @@ public bool InqRunRate(ref float rate) return true; } - public bool IsCorpse() - { - return WorldObject is Corpse; - } - public bool IsImpenetrable() { - return WorldObject is Player player && player.PlayerKillerStatus == PlayerKillerStatus.Free; + return IsPlayer && WorldObject is Player player && player.PlayerKillerStatus == PlayerKillerStatus.Free; } public bool IsPK() { - return WorldObject is Player player && player.IsPK; + return IsPlayer && WorldObject is Player player && player.IsPK; } public bool IsPKLite() { - return WorldObject is Player player && player.IsPKL; - } - - public bool IsPlayer() - { - return WorldObject is Player; - } - - public bool IsCreature() - { - return WorldObject is Creature; - } - - public bool IsStorage() - { - return WorldObject is Storage; + return IsPlayer && WorldObject is Player player && player.IsPKL; } public float JumpStaminaCost(float extent, int staminaCost) @@ -179,20 +184,21 @@ public void InqCollisionProfile(ObjCollisionProfile prof) if (WorldObject == null) return; - prof.WCID = ID; + // prof.WCID = ID; prof.ItemType = WorldObject.ItemType; - if (WorldObject is Creature) + if (IsCreature) + { prof.Flags |= ObjCollisionProfileFlags.Creature; - if (WorldObject is Player) - prof.Flags |= ObjCollisionProfileFlags.Player; + if (IsPlayer) + prof.Flags |= ObjCollisionProfileFlags.Player; + } + else if (WorldObject is Door) + prof.Flags |= ObjCollisionProfileFlags.Door; if (WorldObject.Attackable) prof.Flags |= ObjCollisionProfileFlags.Attackable; - - if (WorldObject is Door) - prof.Flags |= ObjCollisionProfileFlags.Door; } public int DoCollision(ObjCollisionProfile prof, ObjectGuid guid, PhysicsObj target) @@ -232,7 +238,7 @@ public int DoCollision(EnvCollisionProfile prof, ObjectGuid guid, PhysicsObj tar if (wo == null) return 0; - if (wo is Player player) + if (IsPlayer && wo is Player player) player.HandleFallingDamage(prof); else wo.OnCollideEnvironment(); diff --git a/Source/ACE.Server/Physics/ObjectInfo.cs b/Source/ACE.Server/Physics/ObjectInfo.cs index aba39d3317..f7edfb32d6 100644 --- a/Source/ACE.Server/Physics/ObjectInfo.cs +++ b/Source/ACE.Server/Physics/ObjectInfo.cs @@ -52,7 +52,7 @@ public void Init(PhysicsObj obj, ObjectInfoState state) { if (wobj.IsImpenetrable()) State |= ObjectInfoState.IsImpenetrable; - if (wobj.IsPlayer()) + if (wobj.IsPlayer) State |= ObjectInfoState.IsPlayer; if (wobj.IsPK()) State |= ObjectInfoState.IsPK; @@ -86,7 +86,7 @@ public bool MissileIgnore(PhysicsObj collideObj) { if (collideObj.WeenieObj != null && collideObj.ID != TargetID) { - if (collideObj.State.HasFlag(PhysicsState.Ethereal) || TargetID != 0 && collideObj.WeenieObj.IsCreature()) + if (collideObj.State.HasFlag(PhysicsState.Ethereal) || TargetID != 0 && collideObj.WeenieObj.IsCreature) return true; } } diff --git a/Source/ACE.Server/Physics/PhysicsEngine.cs b/Source/ACE.Server/Physics/PhysicsEngine.cs index fa2541b3e3..d6f3aedb77 100644 --- a/Source/ACE.Server/Physics/PhysicsEngine.cs +++ b/Source/ACE.Server/Physics/PhysicsEngine.cs @@ -93,7 +93,7 @@ public static bool SetObjectMovement(PhysicsObj obj, object buffer, int size, in else return false; - var isPlayer = obj.WeenieObj != null && !obj.WeenieObj.IsPlayer(); + var isPlayer = obj.WeenieObj != null && !obj.WeenieObj.IsPlayer; if (!isPlayer || !autonomous) { obj.LastMoveWasAutonomous = autonomous; diff --git a/Source/ACE.Server/Physics/PhysicsObj.cs b/Source/ACE.Server/Physics/PhysicsObj.cs index 642ea6118f..e5c127e66d 100644 --- a/Source/ACE.Server/Physics/PhysicsObj.cs +++ b/Source/ACE.Server/Physics/PhysicsObj.cs @@ -148,7 +148,7 @@ public PhysicsObj() // todo: only allocate these for server objects // get rid of 'DatObject', use the existing WeenieObj == null - WeenieObj = new WeenieObject(); + WeenieObj = WeenieObject.DummyObject; ObjMaint = new ObjectMaint(this); if (PhysicsEngine.Instance != null && PhysicsEngine.Instance.Server) @@ -385,7 +385,7 @@ public TransitionState FindObjCollisions(Transition transition) if (State.HasFlag(PhysicsState.Ethereal) && State.HasFlag(PhysicsState.IgnoreCollisions)) return TransitionState.OK; - if (WeenieObj != null && transition.ObjectInfo.State.HasFlag(ObjectInfoState.IsViewer) && WeenieObj.IsCreature()) + if (WeenieObj != null && transition.ObjectInfo.State.HasFlag(ObjectInfoState.IsViewer) && WeenieObj.IsCreature) return TransitionState.OK; if (State.HasFlag(PhysicsState.Ethereal) || !State.HasFlag(PhysicsState.Static) && transition.ObjectInfo.Ethereal) @@ -400,13 +400,13 @@ public TransitionState FindObjCollisions(Transition transition) // TODO: reverse this check to make it more readable // TODO: investigate not initting WeenieObj for DatObjects - var exemption = !( /*WeenieObj == null*/ DatObject || !WeenieObj.IsPlayer() || !state.HasFlag(ObjectInfoState.IsPlayer) || + var exemption = !( /*WeenieObj == null*/ DatObject || !WeenieObj.IsPlayer || !state.HasFlag(ObjectInfoState.IsPlayer) || state.HasFlag(ObjectInfoState.IsImpenetrable) || WeenieObj.IsImpenetrable() || state.HasFlag(ObjectInfoState.IsPK) && WeenieObj.IsPK() || state.HasFlag(ObjectInfoState.IsPKLite) && WeenieObj.IsPKLite()); var missileIgnore = transition.ObjectInfo.MissileIgnore(this); - var isCreature = State.HasFlag(PhysicsState.Missile) || WeenieObj != null && WeenieObj.IsCreature(); + var isCreature = State.HasFlag(PhysicsState.Missile) || WeenieObj != null && WeenieObj.IsCreature; //isCreature = false; // hack? if (!State.HasFlag(PhysicsState.HasPhysicsBSP) || missileIgnore || exemption) @@ -1289,7 +1289,7 @@ public SetPositionError SetPositionInternal(Position pos, SetPosition setPos, Tr return SetPositionError.OK; } - if (WeenieObj != null && (WeenieObj.IsStorage() || WeenieObj.IsCorpse())) + if (WeenieObj != null && (WeenieObj.IsStorage || WeenieObj.IsCorpse)) return ForceIntoCell(newCell, pos); //if (setPos.Flags.HasFlag(SetPositionFlags.DontCreateCells))