Example #1
0
        private string GenerateNotes(CombatDamageCalculatorInputData data)
        {
            if (data.Attacker.NumberOfHits > 1)
            {
                return("x" + data.Attacker.NumberOfHits.ToString());
            }

            // Cavaliers / Champions
            if ((data.Attacker.Id == 10) || (data.Attacker.Id == 11))
            {
                return("+ jousting bonus damage");
            }

            return(null);
        }
Example #2
0
        public CombatDamageCalculatorInputData InverseData()
        {
            CombatDamageCalculatorInputData data = new CombatDamageCalculatorInputData();

            data.Attacker = Defender;
            data.Defender = Attacker;

            data.AttackerCount = DefenderCount;
            data.DefenderCount = AttackerCount;

            data.AttackerHeroStats = DefenderHeroStats;
            data.DefenderHeroStats = AttackerHeroStats;

            data.AttackerSpells = DefenderSpells;
            data.DefenderSpells = AttackerSpells;

            data.Terrain = Terrain;

            return(data);
        }
        public void CalculateDamage(CombatDamageCalculatorInputData data, out int minDamage, out int maxDamage, out string notes)
        {
            if (data.AttackerCount == 0)
            {
                minDamage = 0;
                maxDamage = 0;
                notes = null;
                return;
            }

            CombatDamageModifier damageModifier = new CombatDamageModifier();
            AttackData attackData = new AttackData { Attacker = data.Attacker, Defender = data.Defender };

            List<ICombatUnitStatsModifier> attackerStatsModifiers = new List<ICombatUnitStatsModifier>();
            List<ICombatUnitStatsModifier> defenderStatsModifiers = new List<ICombatUnitStatsModifier>();
            List<ICombatDamageModifierProvider> attackerDamageModifierProviders = new List<ICombatDamageModifierProvider>();
            List<ICombatDamageModifierProvider> defenderDamageModifierProviders = new List<ICombatDamageModifierProvider>();

            if (data.Terrain != null)
            {
                attackerStatsModifiers.Add(data.Terrain);
                defenderStatsModifiers.Add(data.Terrain);
            }

            if (data.AttackerHeroStats != null)
            {
                attackerStatsModifiers.Add(data.AttackerHeroStats);
                attackerDamageModifierProviders.Add(data.AttackerHeroStats);
            }

            if (data.DefenderHeroStats != null)
            {
                defenderStatsModifiers.Add(data.DefenderHeroStats);
                defenderDamageModifierProviders.Add(data.DefenderHeroStats);
            }

            if (data.AttackerSpells != null)
            {
                attackerStatsModifiers.AddRange(data.AttackerSpells);
                attackerDamageModifierProviders.AddRange(data.AttackerSpells);
            }

            if (data.DefenderSpells != null)
            {
                defenderStatsModifiers.AddRange(data.DefenderSpells);
                defenderDamageModifierProviders.AddRange(data.DefenderSpells);
            }

            attackerStatsModifiers.Add(UnitUniqueTraitManager.Instance);
            defenderStatsModifiers.Add(UnitUniqueTraitManager.Instance);
            attackerDamageModifierProviders.Add(UnitUniqueTraitManager.Instance);
            defenderDamageModifierProviders.Add(UnitUniqueTraitManager.Instance);

            /////////////////////////

            UnitStats modifiedAttackerStats = data.Attacker.InitialStats.Copy();
            UnitStats modifiedDefenderStats = data.Defender.InitialStats.Copy();

            foreach (ICombatUnitStatsModifier modifier in attackerStatsModifiers)
            {
                modifier.ApplyPermanently(data.Attacker, modifiedAttackerStats);
                modifier.ApplyOnAttack(attackData, modifiedAttackerStats);
            }

            foreach (ICombatUnitStatsModifier modifier in defenderStatsModifiers)
            {
                modifier.ApplyPermanently(data.Defender, modifiedDefenderStats);
                modifier.ApplyOnDefense(attackData, modifiedDefenderStats);
            }

            int totalAttack = modifiedAttackerStats.Attack;
            int totalDefense = modifiedDefenderStats.Defense;

            if (totalAttack > totalDefense)
            {
                double primarySkillBonus = Math.Min((totalAttack - totalDefense) * 0.05, 3.0);
                damageModifier.DamageBonuses.Add(primarySkillBonus);
            }
            else if (totalAttack < totalDefense)
            {
                double primarySkillReduction = Math.Min((totalDefense - totalAttack) * 0.025, 0.7);
                damageModifier.DamageReductions.Add(primarySkillReduction);
            }

            /////////////////////////

            foreach (ICombatDamageModifierProvider provider in attackerDamageModifierProviders)
            {
                provider.ApplyOnAttack(attackData, damageModifier);
            }

            foreach (ICombatDamageModifierProvider provider in defenderDamageModifierProviders)
            {
                provider.ApplyOnDefense(attackData, damageModifier);
            }

            int minBaseDamage = data.AttackerCount * modifiedAttackerStats.MinDamage;
            int maxBaseDamage = data.AttackerCount * modifiedAttackerStats.MaxDamage;

            minDamage = PerformCalculation(minBaseDamage, damageModifier);
            maxDamage = PerformCalculation(maxBaseDamage, damageModifier);
            notes = GenerateNotes(data);
        }
        public CombatDamageCalculatorInputData InverseData()
        {
            CombatDamageCalculatorInputData data = new CombatDamageCalculatorInputData();

            data.Attacker = Defender;
            data.Defender = Attacker;

            data.AttackerCount = DefenderCount;
            data.DefenderCount = AttackerCount;

            data.AttackerHeroStats = DefenderHeroStats;
            data.DefenderHeroStats = AttackerHeroStats;

            data.AttackerSpells = DefenderSpells;
            data.DefenderSpells = AttackerSpells;

            data.Terrain = Terrain;

            return data;
        }
        private string GenerateNotes(CombatDamageCalculatorInputData data)
        {
            if (data.Attacker.NumberOfHits > 1)
            {
                return "x" + data.Attacker.NumberOfHits.ToString();
            }

            // Cavaliers / Champions
            if ((data.Attacker.Id == 10) || (data.Attacker.Id == 11))
            {
                return "+ jousting bonus damage";
            }

            return null;
        }
Example #6
0
        public void CalculateDamage(CombatDamageCalculatorInputData data, out int minDamage, out int maxDamage, out string notes)
        {
            if (data.AttackerCount == 0)
            {
                minDamage = 0;
                maxDamage = 0;
                notes     = null;
                return;
            }

            CombatDamageModifier damageModifier = new CombatDamageModifier();
            AttackData           attackData     = new AttackData {
                Attacker = data.Attacker, Defender = data.Defender
            };

            List <ICombatUnitStatsModifier>      attackerStatsModifiers          = new List <ICombatUnitStatsModifier>();
            List <ICombatUnitStatsModifier>      defenderStatsModifiers          = new List <ICombatUnitStatsModifier>();
            List <ICombatDamageModifierProvider> attackerDamageModifierProviders = new List <ICombatDamageModifierProvider>();
            List <ICombatDamageModifierProvider> defenderDamageModifierProviders = new List <ICombatDamageModifierProvider>();

            if (data.Terrain != null)
            {
                attackerStatsModifiers.Add(data.Terrain);
                defenderStatsModifiers.Add(data.Terrain);
            }

            if (data.AttackerHeroStats != null)
            {
                attackerStatsModifiers.Add(data.AttackerHeroStats);
                attackerDamageModifierProviders.Add(data.AttackerHeroStats);
            }

            if (data.DefenderHeroStats != null)
            {
                defenderStatsModifiers.Add(data.DefenderHeroStats);
                defenderDamageModifierProviders.Add(data.DefenderHeroStats);
            }

            if (data.AttackerSpells != null)
            {
                attackerStatsModifiers.AddRange(data.AttackerSpells);
                attackerDamageModifierProviders.AddRange(data.AttackerSpells);
            }

            if (data.DefenderSpells != null)
            {
                defenderStatsModifiers.AddRange(data.DefenderSpells);
                defenderDamageModifierProviders.AddRange(data.DefenderSpells);
            }

            attackerStatsModifiers.Add(UnitUniqueTraitManager.Instance);
            defenderStatsModifiers.Add(UnitUniqueTraitManager.Instance);
            attackerDamageModifierProviders.Add(UnitUniqueTraitManager.Instance);
            defenderDamageModifierProviders.Add(UnitUniqueTraitManager.Instance);

            /////////////////////////

            UnitStats modifiedAttackerStats = data.Attacker.InitialStats.Copy();
            UnitStats modifiedDefenderStats = data.Defender.InitialStats.Copy();

            foreach (ICombatUnitStatsModifier modifier in attackerStatsModifiers)
            {
                modifier.ApplyPermanently(data.Attacker, modifiedAttackerStats);
                modifier.ApplyOnAttack(attackData, modifiedAttackerStats);
            }

            foreach (ICombatUnitStatsModifier modifier in defenderStatsModifiers)
            {
                modifier.ApplyPermanently(data.Defender, modifiedDefenderStats);
                modifier.ApplyOnDefense(attackData, modifiedDefenderStats);
            }

            int totalAttack  = modifiedAttackerStats.Attack;
            int totalDefense = modifiedDefenderStats.Defense;

            if (totalAttack > totalDefense)
            {
                double primarySkillBonus = Math.Min((totalAttack - totalDefense) * 0.05, 3.0);
                damageModifier.DamageBonuses.Add(primarySkillBonus);
            }
            else if (totalAttack < totalDefense)
            {
                double primarySkillReduction = Math.Min((totalDefense - totalAttack) * 0.025, 0.7);
                damageModifier.DamageReductions.Add(primarySkillReduction);
            }

            /////////////////////////

            foreach (ICombatDamageModifierProvider provider in attackerDamageModifierProviders)
            {
                provider.ApplyOnAttack(attackData, damageModifier);
            }

            foreach (ICombatDamageModifierProvider provider in defenderDamageModifierProviders)
            {
                provider.ApplyOnDefense(attackData, damageModifier);
            }

            int minBaseDamage = data.AttackerCount * modifiedAttackerStats.MinDamage;
            int maxBaseDamage = data.AttackerCount * modifiedAttackerStats.MaxDamage;

            minDamage = PerformCalculation(minBaseDamage, damageModifier);
            maxDamage = PerformCalculation(maxBaseDamage, damageModifier);
            notes     = GenerateNotes(data);
        }
Example #7
0
        void UpdateDataFromControls(CombatDamageCalculatorInputData data)
        {
            data.Attacker = attackerPickPanel.Data.Unit;
            data.Defender = defenderPickPanel.Data.Unit;

            data.Terrain = (Terrain)terrainComboBox.SelectedValue;
            if (data.Terrain.Id == -1)
            {
                data.Terrain = null;
            }

            data.AttackerHeroStats = attackerPickPanel.Data.HeroStats;
            data.AttackerSpells = attackerPickPanel.Data.Spells;

            data.DefenderHeroStats = defenderPickPanel.Data.HeroStats;
            data.DefenderSpells = defenderPickPanel.Data.Spells;

            data.AttackerCount = (int)attackerCountUpDn.Value;
            data.DefenderCount = (int)defenderCountUpDn.Value;
        }
Example #8
0
        void SetControlsWithData(CombatDamageCalculatorInputData data)
        {
            dataUpdateSuspended = true;

            PickPanelData panelData = attackerPickPanel.Data;
            panelData.Unit = data.Attacker;
            panelData.HeroStats = data.AttackerHeroStats;
            panelData.Spells = data.AttackerSpells;
            attackerPickPanel.Data = panelData;

            panelData = defenderPickPanel.Data;
            panelData.Unit = data.Defender;
            panelData.HeroStats = data.DefenderHeroStats;
            panelData.Spells = data.DefenderSpells;
            defenderPickPanel.Data = panelData;

            if (data.Terrain != null)
            {
                terrainComboBox.SelectedValue = data.Terrain;
            }
            else
            {
                terrainComboBox.SelectedIndex = 0;
            }

            attackerCountUpDn.Value = data.AttackerCount;
            defenderCountUpDn.Value = data.DefenderCount;

            dataUpdateSuspended = false;
        }