Exemple #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
                    });
            }
        }
Exemple #2
0
        public CombatLogEntry Use(IDice dice, Combatant combatant)
        {
            combatant.AddSpellToSpellBook(Spell);
            combatant.RemoveItemFromInventory(this);

            return null;
        }
Exemple #3
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
                });
            }
        }
Exemple #4
0
 public CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return new CombatOutcome
     {
         Damage = (int)Math.Round(attacker.Weapon.Damage.GetAverageValue(), MidpointRounding.AwayFromZero) + attacker.Strength.GetStatModifier()
     };
 }
Exemple #5
0
 public bool CanUse(Combatant combatant, IContext context)
 {
     return !context.IsCombat
         && combatant.Inventory.Any(x => ReferenceEquals(x, this))
         && Quantity > 0
         && combatant.Intelligence >= Spell.RequiredIntelligence;
 }
        public EffectOutcome Execute(IDice dice, Combatant attacker, Combatant defender)
        {
            var damage = (int) Math.Round(dice.Roll(Magnitude) * (1 + ((double)attacker.Intelligence.GetStatModifier() / 9)), MidpointRounding.AwayFromZero);
            defender.LowerHealth(damage);

            return new EffectOutcome()
                {
                    Description = string.Format("{0} takes {1} points of damage!", defender.Name, damage),
                    Damage = damage
                };
        }
        public override EffectOutcome Execute(IDice dice, Combatant combatant)
        {
            int healthBeforeHeal = combatant.CurrentHitPoints;
            var healAmount = (int)Math.Round(dice.Roll(Magnitude) * (1 + ((double)combatant.Wisdom.GetStatModifier() / 9)), MidpointRounding.AwayFromZero);
            combatant.RestoreHealth(healAmount);
            int actualHealAmount = combatant.CurrentHitPoints - healthBeforeHeal;

            return new EffectOutcome()
            {
                Healing = actualHealAmount,
                Description = string.Format("{0} healed for {1} hit points", combatant.Name, actualHealAmount)
            };
        }
        public override EffectOutcome Execute(IDice dice, Combatant combatant)
        {
            int energyBeforeHeal = combatant.CurrentEnergy;
            var restoreAmount = (int)Math.Round(dice.Roll(Magnitude) * (1 + ((double)combatant.Wisdom.GetStatModifier() / 9)), MidpointRounding.AwayFromZero);
            combatant.RestoreEnergy(restoreAmount);
            int actualRestoreAmount = combatant.CurrentHitPoints - energyBeforeHeal;

            return new EffectOutcome()
            {
                Healing = actualRestoreAmount,
                Description = string.Format("{0} regained {1} energy points", combatant.Name, actualRestoreAmount)
            };
        }
Exemple #9
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);
            }
        }
Exemple #10
0
        public CombatLogEntry Use(IDice dice, Combatant attacker, Combatant defender)
        {
            var outcomes = Effects.Select(x => x.Execute(dice, attacker, defender)).ToList();

            var logEntry = new CombatLogEntry
            {
                Attacker = attacker,
                CombatEffect = new CombatOutcome
                {
                    Healing = outcomes.Aggregate(0, (healing, outcome) => healing + outcome.Healing),
                    Damage = outcomes.Aggregate(0, (damage, outcome) => damage + outcome.Damage),
                },
                Text = string.Format(
                    "{0} used {1} on {2}.{3}{4}",
                    attacker.Name,
                    this.GetLeveledName(),
                    defender.Name,
                    Environment.NewLine,
                    string.Join(Environment.NewLine, outcomes.Select(x => x.Description)))
            };

            return logEntry;
        }
Exemple #11
0
        public CombatLogEntry Use(IDice dice, Combatant combatant)
        {
            var outcomes = Effects.Select(x => x.Execute(dice, combatant)).ToList();

            var logEntry = new CombatLogEntry
            {
                Attacker = combatant,
                CombatEffect = new CombatOutcome
                {
                    Healing = outcomes.Aggregate(0, (healing, outcome) => healing + outcome.Healing),
                    Damage = outcomes.Aggregate(0, (damage, outcome) => damage + outcome.Damage),
                },
                Text = string.Format(
                    "{0} used {1}.{2}{3}",
                    combatant.Name,
                    this.GetLeveledName(),
                    Environment.NewLine,
                    string.Join(Environment.NewLine, outcomes.Select(x => x.Description)))
            };

            combatant.RemoveItemFromInventory(this);

            return logEntry;
        }
        public CombatLogEntry Cast(IDice dice, Combatant caster)
        {
            var outcomes = Effects.Select(x => x.Execute(dice, caster)).ToList();

            var logEntry = new CombatLogEntry
            {
                Attacker = caster,
                CombatEffect = new CombatOutcome
                {
                    Healing = outcomes.Aggregate(0, (healing, outcome) => healing + outcome.Healing),
                    Damage = outcomes.Aggregate(0, (damage, outcome) => damage + outcome.Damage),
                },
                Text = string.Format(
                    "{0} cast {1}.{2}{3}",
                    caster.Name,
                    this.GetLeveledName(),
                    Environment.NewLine,
                    string.Join(Environment.NewLine, outcomes.Select(x => x.Description)))
            };

            caster.CurrentEnergy = Math.Max(0, caster.CurrentEnergy - EnergyCost);

            return logEntry;
        }
Exemple #13
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);
            }
        }
 public CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return new CombatOutcome() { Damage = (int)Magnitude.GetAverageValue() };
 }
Exemple #15
0
 public CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return Effects.Aggregate(CombatOutcome.Empty, (outcome, effect) => outcome + effect.GetPotentialCombatOutcome(attacker));
 }
Exemple #16
0
 /// <summary>
 /// Returns whether the item can be used by the given user in the given context.
 /// </summary>
 public bool CanUse(Combatant user, IContext context)
 {
     return context.IsCombat && user.Inventory.Any(x => ReferenceEquals(x, this)) && Quantity > 0;
 }
Exemple #17
0
 public bool CanUse(Combatant combatant, IContext context)
 {
     return !context.IsCombat
         && combatant.Inventory.Any(x => ReferenceEquals(x, this))
         && Quantity > 0
         && combatant.Strength >= RequiredStrength;
 }
Exemple #18
0
        public CombatLogEntry Use(IDice dice, Combatant combatant)
        {
            if (!combatant.Weapon.Equals(BareHands))
            {
                combatant.AddItemToInventory(combatant.Weapon);
            }

            combatant.RemoveItemFromInventory(this);
            combatant.Weapon = this.DeepClone();
            combatant.Weapon.Quantity = 1;

            return null;
        }
Exemple #19
0
 public CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return CombatOutcome.Empty;
 }
 public override CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return new CombatOutcome() { }; // AI does not value energy restoration
 }
 public abstract EffectOutcome Execute(IDice dice, Combatant combatant);
 /// <summary>
 /// Returns whether the spell can be cast by the given caster in the given context.
 /// </summary>
 public bool CanCast(Combatant caster, IContext context)
 {
     return caster.CurrentEnergy >= EnergyCost;
 }
 public EffectOutcome Execute(IDice dice, Combatant attacker, Combatant defender)
 {
     return Execute(dice, attacker);
 }
 public abstract CombatOutcome GetPotentialCombatOutcome(Combatant attacker);
Exemple #25
0
 public CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return _item.GetPotentialCombatOutcome(attacker);
 }
 public override CombatOutcome GetPotentialCombatOutcome(Combatant attacker)
 {
     return new CombatOutcome() { Healing = (int)Math.Min(attacker.MaxHitPoints - attacker.CurrentHitPoints, Magnitude.GetAverageValue()) };
 }