示例#1
0
        private void BotAttack(
            DataAccessLayer.Models.Fight fight, DataAccessLayer.Models.Player player,
            DataAccessLayer.Models.Player bot, DataAccessLayer.Models.FightLog lastLog)
        {
            string abilityText = "";
            int    damage      = bot.Damage;

            if (bot.Abilities.Count() > 0 && rnd.Next(100) < 20) //It has 20% chance by default to use its speacial attack
            {
                var ability = bot.Abilities.ElementAt(rnd.Next(bot.Abilities.Count()));
                damage      = ability.Damage;
                abilityText = String.Format("Used an ability({0}). ", ability.Name);
            }
            //Bot rolls for an attack
            if (RollAttack(player.ArmorClass))
            {
                int currentHP = lastLog.PlayerHitPoint;

                if (currentHP > damage) //If its not the final blow
                {
                    lastLog = _fightLogService.CreateFightLog(
                        new DataAccessLayer.Models.FightLog
                    {
                        FightId        = fight.Id,
                        PlayerHitPoint = lastLog.PlayerHitPoint - damage,
                        BotHitPoint    = lastLog.BotHitPoint,
                        Turn           = lastLog.Turn + 1,
                        LogEntry       = String.Format("Bot {0}: {3}Dealt {1} damage to the Player {2}.", bot.Id, damage, player.Id, abilityText)
                    });
                }
                else
                {
                    lastLog = _fightLogService.CreateFightLog(
                        new DataAccessLayer.Models.FightLog
                    {
                        FightId        = fight.Id,
                        PlayerHitPoint = 0,
                        BotHitPoint    = lastLog.BotHitPoint,
                        Turn           = lastLog.Turn + 1,
                        LogEntry       = String.Format("Bot {0}: {3}Dealt {1} damage to the Player {2}. Bot won!", bot.Id, lastLog.PlayerHitPoint, player.Id, abilityText)
                    });
                }
            }
            else
            {
                lastLog = _fightLogService.CreateFightLog(
                    new DataAccessLayer.Models.FightLog
                {
                    FightId        = fight.Id,
                    PlayerHitPoint = lastLog.PlayerHitPoint,
                    BotHitPoint    = lastLog.BotHitPoint,
                    Turn           = lastLog.Turn + 1,
                    LogEntry       = String.Format("Bot {0}: {1}Couldn't exceed the armor class.", bot.Id, abilityText)
                });
            }
        }
示例#2
0
        public async void CreatePlayer(Player p)
        {
            DataAccessLayer.Models.Player player = new DataAccessLayer.Models.Player();
            player.Id    = p.Id;
            player.Name  = p.Name;
            player.Lives = p.Lives;
            player.Score = p.Score;
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(API_BASE + "/players", player);

            httpResponseMessage.EnsureSuccessStatusCode();
        }