Ejemplo n.º 1
0
        public AttackResult AttackEnemy(Guid id)
        {
            var enemy           = _room.Enemies.FirstOrDefault(e => e.Id == id);
            var attackableEnemy = enemy as IAttackable;

            if (attackableEnemy == null)
            {
                return(new AttackResult
                {
                    ValidAttack = false,
                    Message = "The enemy targeted is not attackable."
                });
            }

            var attackAttempt = new AttackAttempt
            {
                HitRoll = DiceRoller.Roll(1, DiceType.d20)
            };

            return(attackableEnemy.Attack(attackAttempt));
        }
Ejemplo n.º 2
0
        public AttackResult Attack(AttackAttempt attackAttempt)
        {
            var result = new AttackResult();

            if (HitPoints == 0)
            {
                result.Message = $"The {Type} is already dead.";
                return(result);
            }

            result.ValidAttack = true;

            var hitRoll = DiceRoller.Roll(1, DiceType.d20);

            if (hitRoll >= ArmorClass)
            {
                result.DidHit = true;
                var damage = DiceRoller.Roll(1, DiceType.d4);
                result.Damage = damage;
                HitPoints     = Math.Max(HitPoints - damage, 0);
                if (HitPoints == 0)
                {
                    result.Killed  = true;
                    result.Message = $"The {Type} was hit for {damage} and was killed.";
                }
                else
                {
                    result.Message = $"The {Type} was hit for {damage} but was not killed.";
                }
            }
            else
            {
                result.Message = $"The attack missed the {Type}!";
            }
            result.HitRoll            = hitRoll;
            result.RemainingHitPoints = HitPoints;
            result.TargetAC           = ArmorClass;

            return(result);
        }