Пример #1
0
        public void EnemyTurn()
        {
            var highestPresence = Combatants.Max(u => u.Player.Stats.Presence);

            AttackTarget = Combatants.Where(u => u.Player.Stats.Presence == highestPresence).First();
            if (AttackTarget == null)
            {
                Target.Combat = null;
                return;
            }
            if (AttackTarget.Player.Stats.CurrHealth <= 0)
            {
                Target.Combat = null;
                return;
            }
            // Roll to see if the monster lands a hit
            int hit    = Roll(100);
            int attack = Strike;

            if (hit >= AttackTarget.Player.Stats.Agility)
            {
                // Check if the attack is a critical
                int crit = Roll(100);
                if (crit >= AttackTarget.Player.Stats.CritAvoid)
                {
                    AttackTarget.Connection.SendMessage(AttackCriticalFlavor);
                    attack = attack + (Strike / 2);
                }
                if (crit < AttackTarget.Player.Stats.CritAvoid)
                {
                    // If it's not critical, check if it's weak
                    int weak = Roll(100);
                    if (weak <= AttackTarget.Player.Stats.Luck)
                    {
                        AttackTarget.Connection.SendMessage(AttackWeakFlavor);
                        attack = attack - (Strike / 2);
                    }
                    AttackTarget.Connection.SendMessage(AttackSuccessFlavor);
                }
                // If the player is blocking, attack gets a further strike to damage
                if (AttackTarget.Player.IsBlocking)
                {
                    attack = attack - AttackTarget.Player.Stats.Defense;
                    if (attack < 0)
                    {
                        attack = 0;
                    }
                    CombatSay($"{Target.Name} is blocked by {AttackTarget.Name}!");
                }
                AttackTarget.Player.TakeDamage(attack);
                CombatSay($"{Target.Name} deals {Strike} damage to {AttackTarget.Name}");
                AttackTarget.Connection.SendMessage($"Your current health is {AttackTarget.Player.Stats.CurrHealth}");
                return;
            }
            AttackTarget.Connection.SendMessage(AttackFailFlavor);
            AttackTarget.Connection.SendMessage($"Your current health is {AttackTarget.Player.Stats.CurrHealth}");
        }
Пример #2
0
        private void Add()
        {
            int initiative;

            if (!int.TryParse(Initiative, out initiative))
            {
                throw new Exception($"{Initiative} is not a valid value.");
            }

            bool initiativeTied = Combatants.Any(c => c.Initiative == initiative);
            var  newCombatant   = new Combatant(Name, initiative, Combatants.Count == 0);

            Combatants.Add(newCombatant);
            if (initiativeTied && InitiativeTied != null)
            {
                newCombatant.TieBreaker = Combatants.Max(c => c.TieBreaker) + 1;
                InitiativeTied?.Invoke(this, new TieInitiativeEventArgs(Combatants.Where(c => c.Initiative == initiative)));
            }
            Combatants.Sort();
            Name       = null;
            Initiative = null;
        }