public override async Task UpdateAsync() { await base.UpdateAsync(); ElapsedTime += DeltaTime; if (Battlefield.Resources.Count < myResourceCount) { AddResource(); } if (Battlefield.Weapons.Count < myWeaponsCount) { AddWeapon(); } if (Battlefield.FirstAidKits.Count < myFirstAidKitCount) { AddFirstAidKit(); } var bulletTasks = Battlefield.Bullets.ToList() .OfType <Bullet>().Select(b => b.UpdateAsync()); await Task.WhenAll(bulletTasks); var botTasks = Bots.Select(b => b.UpdateAsync()); await Task.WhenAll(botTasks); var hospitalTasks = Battlefield.Hospitals.ToList() .OfType <Hospital>().Select(b => b.UpdateAsync()); await Task.WhenAll(hospitalTasks); var explosionTasks = Battlefield.Explosions.ToList() .OfType <Explosion>().Select(b => b.UpdateAsync()); await Task.WhenAll(explosionTasks); await Task.Delay(TimeSpan.FromMilliseconds(myTurnDelay)); }
public Battlefield ExportState() { var arena = new Battlefield(Board.GetLength(0), Board.GetLength(1)); Board.ForEveryElement((x, y, val) => { arena.Board[x, y] = val; }); arena.Bots = Bots.Select(bot => new TankBlasterBot(bot)).ToList(); arena.Bombs = Bombs.Select(bomb => new Bomb(bomb)).ToList(); arena.Missiles = Missiles.Select(missile => new Missile(missile)).ToList(); return(arena); }
public BattleContext GetContext() { var ret = new BattleContext(); ret.AutohostName = Founder.Name; ret.Map = MapName; ret.Mod = ModName; ret.Players = Users.Where(x => x.SyncStatus != SyncStatuses.Unknown).Select(x => new PlayerTeam() { AllyID = x.AllyNumber, Name = x.Name, LobbyID = x.LobbyUser.LobbyID, TeamID = x.TeamNumber, IsSpectator = x.IsSpectator }).ToList(); ret.Bots = Bots.Select(x => new BotTeam() { BotName = x.Name, AllyID = x.AllyNumber, TeamID = x.TeamNumber, Owner = x.owner, BotAI = x.aiLib }).ToList(); return(ret); }