예제 #1
0
        private Action PerformMeleeAttack_GetPostMovementCallback(
            IUnit attacker, IUnit defender, IHexCell defenderLocation, Action successAction, Action failAction
            )
        {
            return(delegate() {
                if (!CanPerformMeleeAttack(attacker, defender))
                {
                    failAction();
                }
                else
                {
                    int attackerStartingHealth = attacker.CurrentHitpoints;
                    int defenderStartingHealth = defender.CurrentHitpoints;

                    var combatInfo = CombatInfoLogic.GetAttackInfo(attacker, defender, defenderLocation, CombatType.Melee);

                    CommonCombatExecutionLogic.PerformCommonCombatTasks(attacker, defender, combatInfo);

                    UnitSignals.MeleeCombatWithUnit.OnNext(
                        new UnitCombatResults(
                            attacker, defender,
                            attackerStartingHealth - attacker.CurrentHitpoints,
                            defenderStartingHealth - defender.CurrentHitpoints,
                            combatInfo
                            )
                        );

                    successAction();
                }
            });
        }
 public float EstimateComparativeStrength(IUnit unit, IUnit defender, IHexCell location)
 {
     if (unit.RangedAttackStrength > 0)
     {
         var attackInfo = CombatInfoLogic.GetAttackInfo(unit, defender, location, CombatType.Ranged);
         return(unit.RangedAttackStrength * (1f + attackInfo.AttackerCombatModifier));
     }
     else
     {
         var attackInfo = CombatInfoLogic.GetAttackInfo(unit, defender, location, CombatType.Melee);
         return(unit.CombatStrength * (1f + attackInfo.AttackerCombatModifier));
     }
 }
        public UnitCombatResults EstimateMeleeAttackResults(IUnit attacker, IUnit defender, IHexCell location)
        {
            if (attacker == null)
            {
                throw new ArgumentNullException("attacker");
            }
            if (defender == null)
            {
                throw new ArgumentNullException("defender");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            var combatInfo = CombatInfoLogic.GetAttackInfo(attacker, defender, location, CombatType.Melee);

            Tuple <int, int> results = CombatCalculator.CalculateCombat(attacker, defender, combatInfo);

            return(new UnitCombatResults(attacker, defender, results.Item1, results.Item2, combatInfo));
        }