Written within 45 mins... Working quite good.
Maybe you can get an idea on how to implement an AI based on this.
But don't ask for support.
Code:
public async void StartAI()
{
if (cancel)
return;
await Task.Delay(100);
if (this.state == ThinkState.Attacking)
{
if (Program.Maps[this.mapId].Users.ContainsKey(this.atackingId))
{
if (!Program.Maps[this.mapId].IsInALienMoveRange(this.x + "|" + this.y, Program.Maps[this.mapId].Users[this.atackingId].Ship.X + "|" + Program.Maps[this.mapId].Users[this.atackingId].Ship.Y))
{
myMovement.MoveTo(this.Id, this.mapId, (int.Parse(Program.Maps[this.mapId].Users[this.atackingId].Ship.X) - 200).ToString(), (int.Parse(Program.Maps[this.mapId].Users[this.atackingId].Ship.Y) - 150).ToString());
}
if (brunonce)
{
this.Atack();
brunonce = false;
}
}
}
else if (this.state == ThinkState.Moving)
{
if (arrived)
{
await Task.Delay(20000);
myMovement.Speed = 300;
myRand = new Random();
myMovement.MoveTo(this.Id, this.mapId, myRand.Next(0, 19000).ToString(), myRand.Next(0, 11000).ToString());
arrived = false;
}
}
if (this.Agressive)
{
var usr = Program.Maps[this.mapId].GetClosestUser(700, this.x + "|" + this.y);
if (usr != null)
{
Program.Maps[this.mapId].alienManager.NotifyAtack(usr.userid, this.Id);
this.state = ThinkState.Attacking;
}
}
StartAI();
}