public async Task <BotInfo> CreateBot(BotToCreate botToCreate) { var arena = await _arenaLogic.GetArena(); var bots = await GetBots(); var bot = new Bot { Name = botToCreate.Name, Orientation = _randomHelper.Get <PossibleOrientations>(), MaximumStamina = 100, CurrentStamina = 100, Move = PossibleMoves.Idling, Memory = new Dictionary <string, string>().Serialize(), Script = botToCreate.Script }; var freeLocations = GetFreeLocation(arena, bots); (bot.X, bot.Y) = freeLocations[_randomHelper.Get(freeLocations.Count)]; await _dbContext.Bots.AddAsync(bot); await _dbContext.SaveChangesAsync(); return(new BotInfo { Id = bot.Id, Name = bot.Name, Orientation = bot.Orientation, X = bot.X, Y = bot.Y, Move = bot.Move, MaximumStamina = bot.MaximumStamina, CurrentStamina = bot.CurrentStamina }); }
public Task <IActionResult> CreateBot([FromBody] BotToCreate botToCreate) { return(Created(l => l.CreateBot(botToCreate))); }