diff --git a/Intersect.Server.Core/Entities/Npc.cs b/Intersect.Server.Core/Entities/Npc.cs index 492cad45dd..118855cdbb 100644 --- a/Intersect.Server.Core/Entities/Npc.cs +++ b/Intersect.Server.Core/Entities/Npc.cs @@ -65,6 +65,7 @@ public Entity DamageMapHighest //Moving public long LastRandomMove; + private byte _randomMoveRange; //Pathfinding private Pathfinder mPathFinder; @@ -1158,54 +1159,25 @@ public override void Update(long timeMs) CheckForResetLocation(); - //Move randomly - if (targetMap != Guid.Empty) - { - return; - } - - if (LastRandomMove >= Timing.Global.Milliseconds || IsCasting) - { - return; - } - - if (Descriptor.Movement == (int)NpcMovement.StandStill) - { - LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 3000); - - return; - } - else if (Descriptor.Movement == (int)NpcMovement.TurnRandomly) + if (targetMap != Guid.Empty || LastRandomMove >= Timing.Global.Milliseconds || IsCasting) { - ChangeDir(Randomization.NextDirection()); - LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 3000); - return; } - var i = Randomization.Next(0, 1); - if (i == 0) + switch (Descriptor.Movement) { - var direction = Randomization.NextDirection(); - if (CanMoveInDirection(direction)) - { - //check if NPC is snared or stunned - foreach (var status in CachedStatuses) - { - if (status.Type == SpellEffect.Stun || - status.Type == SpellEffect.Snare || - status.Type == SpellEffect.Sleep) - { - return; - } - } - - Move(direction, null); - } + case (int)NpcMovement.StandStill: + LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 3000); + return; + case (int)NpcMovement.TurnRandomly: + ChangeDir(Randomization.NextDirection()); + LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 3000); + return; + case (int)NpcMovement.MoveRandomly: + MoveRandomly(); + break; } - LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 3000); - if (fleeing) { LastRandomMove = Timing.Global.Milliseconds + (long)GetMovementTime(); @@ -1242,6 +1214,40 @@ public override void Update(long timeMs) } } + private void MoveRandomly() + { + if (_randomMoveRange <= 0) + { + Dir = Randomization.NextDirection(); + LastRandomMove = Timing.Global.Milliseconds + Randomization.Next(1000, 2000); + _randomMoveRange = (byte)Randomization.Next(0, Descriptor.SightRange + Randomization.Next(0, 3)); + } + else if (CanMoveInDirection(Dir)) + { + foreach (var status in CachedStatuses) + { + if (status.Type is SpellEffect.Stun or SpellEffect.Snare or SpellEffect.Sleep) + { + return; + } + } + + Move(Dir, null); + LastRandomMove = Timing.Global.Milliseconds + (long)GetMovementTime(); + + if (_randomMoveRange <= Randomization.Next(0, 3)) + { + Dir = Randomization.NextDirection(); + } + + _randomMoveRange--; + } + else + { + Dir = Randomization.NextDirection(); + } + } + /// /// Resets the NPCs position to be "pulled" from ///