コード例 #1
0
        public ActionResult <Fight> StartFight(Guid id)
        {
            //Create Bot with default vaules for new fight
            var botId = Guid.Parse("b5774a2a-95da-e911-a603-80fa5b0fc197");
            var bot   = _playerService.GetPlayer(botId);

            //Get player
            var player = _playerService.GetPlayer(id);

            //Create new fight between player and bot
            var fight = _fightService.CreateFight(
                new DataAccessLayer.Models.Fight
            {
                PlayerId = id,
                BotId    = bot.Id
            });

            //Add initial fight log to database
            var log = _fightLogService.CreateFightLog(
                new DataAccessLayer.Models.FightLog
            {
                FightId        = fight.Id,
                PlayerHitPoint = player.HitPoint,
                BotHitPoint    = bot.HitPoint,
                Turn           = 0,
                LogEntry       = String.Format("Fight started between Player: {0} and Bot: {1}", player.Id, bot.Id)
            });

            return(Ok(new Fight
            {
                Id = fight.Id,
                PlayerId = fight.PlayerId,
                BotId = fight.BotId,
                FightLogs = _fightLogService
                            .GetLogsByFightId(fight.Id)
                            .ToList()
                            .Select(l => new FightLog
                {
                    Id = l.Id,
                    Turn = l.Turn,
                    PlayerHitPoint = l.PlayerHitPoint,
                    BotHitPoint = l.BotHitPoint,
                    LogEntry = l.LogEntry
                })
            }));
        }