Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 47 additions & 41 deletions Intersect.Server.Core/Entities/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Entity DamageMapHighest

//Moving
public long LastRandomMove;
private byte _randomMoveRange;

//Pathfinding
private Pathfinder mPathFinder;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}

/// <summary>
/// Resets the NPCs position to be "pulled" from
/// </summary>
Expand Down
Loading