Esempio n. 1
1
        public void Execute(IDice dice, Combatant attacker, Combatant defender, IList<CombatLogEntry> combatLog)
        {
            int attack = attacker.ToHitAttack;
            int defend = defender.ToHitDefense;

            var toHitThreshold = ((attack + ((attacker.Level - defender.Level) / 2)) / ((double)attack + defend)).ConstrainWithinBounds(0.20, 0.80);
            Debug.WriteLine("{0} has a {1:P0} chance to hit {2}", attacker.Name, toHitThreshold, defender.Name);

            if (dice.Random() < toHitThreshold)
            {
                var damage = Math.Max(1, attacker.GetAttackDamage(dice));
                defender.LowerHealth(damage);
                combatLog.Add(new CombatLogEntryFromAction<Attack>(Name)
                {
                    Text = string.Format("{0} hits {1} with {2} for {3} points!", attacker.Name, defender.Name, Name, damage),
                    Attacker = attacker,
                    CombatEffect = new CombatOutcome() { Damage = damage }
                });
            }
            else
            {
                combatLog.Add(
                    new CombatLogEntry
                    {
                        Text = string.Format("{0} attempts to hit {1} with {2} and fails miserably!", attacker.Name, defender.Name, Name),
                        Attacker = attacker
                    });
            }
        }
Esempio n. 2
0
        public void Execute(IDice dice, Combatant attacker, Combatant defender, IList<CombatLogEntry> combatLog)
        {
            int attackerFleeRating = Math.Max(1, attacker.Level + attacker.Agility.GetStatModifier());
            int defenderFleeRating = Math.Max(1, defender.Level + defender.Agility.GetStatModifier());

            var toFleeThreshold = ((attackerFleeRating) / ((double)attackerFleeRating + defenderFleeRating)).ConstrainWithinBounds(0.20, 0.80);
            Debug.WriteLine("{0} has a {1:P0} chance to flee from {2}", attacker.Name, toFleeThreshold, defender.Name);

            if (dice.Random() < toFleeThreshold)
            {
                attacker.HasFledCombat = true;
                combatLog.Add(new CombatLogEntryFromAction<Flee>(Name)
                {
                    Text = string.Format("{0} has fled the battle!", attacker.Name),
                    Attacker = attacker,
                    CombatEffect = CombatOutcome.Empty
                });
            }
            else
            {
                combatLog.Add(new CombatLogEntryFromAction<Flee>(Name)
                {
                    Text = string.Format("{0} attempts to flee but {1} gets in the way!", attacker.Name, defender.Name),
                    Attacker = attacker,
                    CombatEffect = CombatOutcome.Empty
                });
            }
        }
Esempio n. 3
0
        public void Execute(IDice dice, Combatant attacker, Combatant defender, IList<CombatLogEntry> combatLog)
        {
            var combatItem = _item as ICombatItem;
            if (combatItem != null)
            {
                int attack;
                int defend;

                if (combatItem.IsMagic)
                {
                    attack = attacker.ToHitMagicAttack;
                    defend = defender.ToHitMagicDefense;
                }
                else
                {
                    attack = attacker.ToHitAttack;
                    defend = defender.ToHitDefense;
                }

                var toHitThreshold = Math.Min(Math.Max((attack + ((attacker.Level - defender.Level) / 2)) / ((double)attack + defend), 0.10), 0.90);
                Debug.WriteLine("{0} has a {1:P0} chance to use {2} on {3}", attacker.Name, _item.GetLeveledName(), toHitThreshold, defender.Name);

                if (dice.Random() < toHitThreshold)
                {
                    var logEntry = combatItem.Use(dice, attacker, defender);
                    combatLog.Add(logEntry);
                }
                else
                {
                    combatLog.Add(
                        new CombatLogEntry
                        {
                            Text = string.Format("{0} attempts to use {1} on {2} and fails miserably!", attacker.Name, _item.GetLeveledName(), defender.Name),
                            Attacker = attacker
                        });
                }
            }

            var nonCombatItem = _item as INonCombatItem;
            if (nonCombatItem != null)
            {
                var logEntry = nonCombatItem.Use(dice, attacker);
                combatLog.Add(logEntry);
            }
        }
Esempio n. 4
0
        public void Execute(IDice dice, Combatant attacker, Combatant defender, IList<CombatLogEntry> combatLog)
        {
            var combatSpell = _spell as ICombatSpell;
            if (combatSpell != null)
            {
                int attack = attacker.ToHitMagicAttack;
                int defend = defender.ToHitMagicDefense;

                var toHitThreshold = Math.Min(Math.Max((attack + ((attacker.Level - defender.Level) / 2)) / ((double)attack + defend), 0.10), 0.90);
                Debug.WriteLine("{0} has a {1:P0} chance to cast {2} on {3}", attacker.Name, toHitThreshold, _spell.GetLeveledName(), defender.Name);

                if (dice.Random() < toHitThreshold)
                {
                    var logEntry = combatSpell.Cast(dice, attacker, defender);
                    combatLog.Add(logEntry);
                }
                else
                {
                    combatLog.Add(
                        new CombatLogEntry
                        {
                            Text = string.Format("{0} attempts to cast {1} on {2} and fails miserably!", attacker.Name, _spell.GetLeveledName(), defender.Name),
                            Attacker = attacker
                        });
                }

                attacker.CurrentEnergy = Math.Max(0, attacker.CurrentEnergy - _spell.EnergyCost);
            }

            var nonCombatSpell = _spell as INonCombatSpell;
            if (nonCombatSpell != null)
            {
                var logEntry = nonCombatSpell.Cast(dice, attacker);
                combatLog.Add(logEntry);
            }
        }