public override void Update(DateTime date)
{
if (Position == null)
{
return;
}
if (IsDead)
{
if (!DeathTriggered)
{
Die();
return; // Wait till 3 seconds are over, then remove
}
else if (_nextUpdate <= date)
{
Map.RemoveObject(this.MapObjectID);
Position = null;
return;
}
return;
}
if (AttackingSequence != null && Target != null)
{
if (Vector2.Distance(Target.Position, Position) < 50)
{
AttackingSequence.Update(date);
if (AttackingSequence.State == AttackSequence.AnimationState.Ended)
{
AttackingSequence = null;
Target = null;
}
}
else
{
_nextUpdate = _nextUpdate.AddDays(-1);
}
}
if (_nextUpdate > date) return;
if (Target != null)
{
_nextUpdate = Program.CurrentTime.AddSeconds(1);
// Try to move to target's pos
// Might glitch the fuck out. lol
if (Target.Map != Map)
{
Target = null; // Stop aggro-ing >:(
}
else
{
if (Vector2.Distance(Target.Position, Position) < 800)
{
if (Map.Block.CanWalk(Target.Position.X, Target.Position.Y))
{
Move(Position.X, Position.Y, Target.Position.X, Target.Position.Y, false, false);
}
}
else
{
Target = null; // Stop aggro-ing >:(
}
}
return;
}
else
{
_nextUpdate = Program.CurrentTime.AddSeconds(Program.Randomizer.Next(10, 60)); // Around 10 seconds to 1 minute before new movement is made
// Move to random spot.
Vector2 newpos = new Vector2(Position);
bool ok = false;
for (int i = 1; i <= 20; i++)
{
// Generate new position, and check if it's in valid bounds, else recheck
newpos = Vector2.GetRandomSpotAround(Program.Randomizer, newpos, 60);
if (newpos.X > 0 && newpos.Y > 0 && Map.Block.CanWalk(newpos.X, newpos.Y) && PositionIsInBoundries(newpos))
{
ok = true;
break;
}
/*
int t = Program.Randomizer.Next() % 11;
if (t <= 2)
{
// All +
newx += Program.Randomizer.Next(MinMovement, MaxMovement);
newy += Program.Randomizer.Next(MinMovement, MaxMovement);
}
else if (t <= 5)
{
newx -= Program.Randomizer.Next(MinMovement, MaxMovement);
newy += Program.Randomizer.Next(MinMovement, MaxMovement);
}
else if (t <= 8)
{
newx += Program.Randomizer.Next(MinMovement, MaxMovement);
newy -= Program.Randomizer.Next(MinMovement, MaxMovement);
}
else
{
newx -= Program.Randomizer.Next(MinMovement, MaxMovement);
newy -= Program.Randomizer.Next(MinMovement, MaxMovement);
}
Vector2 test = newpos + new Vector2(newx, newy);
if (Map.Block.CanWalk(test.X, test.Y) && PositionIsInBoundries(test))
{
newpos = test;
break;
}
*/
}
if (ok)
{
Move(Position.X, Position.Y, newpos.X, newpos.Y, false, false);
}
}
}