コード例 #1
0
ファイル: Enemy.cs プロジェクト: mnurilov/Hero-Quest
        private int CastDamageSpell(Player player, DamageSpell damageSpell, ref GameSession.BattleResult battleResult)
        {
            int spellDamage = 0;

            //If the enemy would dodge the attack do not calculate spell damage
            if (RandomNumberGenerator.RandomNumberBetween(1, 100) <= player.DodgeChanceRate)
            {
                battleResult = GameSession.BattleResult.Missed;
                CurrentMana -= damageSpell.ManaCost;
                return(0);
            }

            //If the player would critical strike the enemy then calculate the spell damage accordingly
            if (RandomNumberGenerator.RandomNumberBetween(1, 100) <= CriticalChanceRate)
            {
                //Increase damage by critical damage modifier
                battleResult = GameSession.BattleResult.Critical;
                if (player.TotalResistance <= -10)
                {
                    spellDamage = (int)(((damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + 1)))
                                         * (Math.Abs((double)player.TotalResistance) / 10)) * CriticalDamageModifier);
                }
                else if (player.TotalResistance <= 0)
                {
                    spellDamage = (int)((damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + 1))) * CriticalDamageModifier);
                }
                else
                {
                    spellDamage = (int)((damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + player.TotalResistance))) * CriticalDamageModifier);
                }
                CurrentMana -= damageSpell.ManaCost;
            }
            //Else the player would normally strike the enemy then calculate the spell damage accordingly
            else
            {
                battleResult = GameSession.BattleResult.Normal;
                if (player.TotalResistance <= -10)
                {
                    spellDamage = (int)((damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + 1))) * (Math.Abs((double)player.TotalResistance) / 10));
                }
                else if (player.TotalResistance <= 0)
                {
                    spellDamage = (int)(damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + 1)));
                }
                else
                {
                    spellDamage = (int)(damageSpell.DamageValue + ((Intellect * Intellect) / (Intellect + player.TotalResistance)));
                }
                CurrentMana -= damageSpell.ManaCost;
            }

            return(spellDamage);
        }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: mnurilov/Hero-Quest
        private int Attack(Player player, ref GameSession.BattleResult battleResult)
        {
            int damage = 0;

            //If the player would dodge the attack do not calculate the damage
            if (RandomNumberGenerator.RandomNumberBetween(1, 100) <= player.DodgeChanceRate)
            {
                battleResult = GameSession.BattleResult.Missed;
                return(damage);
            }

            //If the enemy would critical strike the player then calculate the damage accordingly
            if (RandomNumberGenerator.RandomNumberBetween(1, 100) <= CriticalChanceRate)
            {
                //Increase damage by critical damage modifier
                battleResult = GameSession.BattleResult.Critical;
                if (player.TotalDefense <= -10)
                {
                    damage = (int)(((((Strength * Strength) / (Strength + 1)) * 2) * (Math.Abs((double)player.TotalDefense) / 10)) * CriticalDamageModifier);
                }
                else if (player.TotalDefense <= 0)
                {
                    damage = (int)((((Strength * Strength) / (Strength + 1)) * 2) * CriticalDamageModifier);
                }
                else
                {
                    damage = (int)((((Strength * Strength) / (Strength + player.TotalDefense)) * 2) * CriticalDamageModifier);
                }
            }
            //Else the enemy would normally strike the player then calculate the damage accordingly
            else
            {
                battleResult = GameSession.BattleResult.Normal;
                if (player.TotalDefense <= -10)
                {
                    damage = (int)((((Strength * Strength) / (Strength + 1)) * 2) * (Math.Abs((double)player.TotalDefense) / 10));
                }
                else if (player.TotalDefense <= 0)
                {
                    damage = (int)(((Strength * Strength) / (Strength + 1)) * 2);
                }
                else
                {
                    damage = ((Strength * Strength) / (Strength + player.TotalDefense)) * 2;
                }
            }

            return(damage);
        }
コード例 #3
0
ファイル: Enemy.cs プロジェクト: mnurilov/Hero-Quest
        //<----------Combat Actions---------->
        public int CombatAction(Player player, ref GameSession.BattleResult battleResult, ref GameSession.EnemyChoiceTaken enemyChoiceTaken,
                                ref string spellName)
        {
            if (RandomNumberGenerator.RandomNumberBetween(1, 100) <= SpellCastRate)
            {
                Spell spellToBeCasted = PickRandomSpell();
                int   attempts        = 0;

                //While the current spell selected cannot be cast due to insufficent mana keep looking for a different spell
                //I set 100 as the amount of attempts the enemy gets to cast a spell if they still cannot cast that spell
                //It means that most likely they don't have enough mana for any spell and they should attack instead
                while (CurrentMana < spellToBeCasted.ManaCost && attempts < 100)
                {
                    spellToBeCasted = PickRandomSpell();
                    attempts++;
                }

                if (CurrentMana < spellToBeCasted.ManaCost)
                {
                    enemyChoiceTaken = GameSession.EnemyChoiceTaken.Attack;
                    return(Attack(player, ref battleResult));
                }

                if (spellToBeCasted is DamageSpell)
                {
                    enemyChoiceTaken = GameSession.EnemyChoiceTaken.CastSpell;
                    spellName        = spellToBeCasted.Name;
                    return(CastDamageSpell(player, (DamageSpell)spellToBeCasted, ref battleResult));
                }
                else if (spellToBeCasted is ReplenishSpell)
                {
                    enemyChoiceTaken = GameSession.EnemyChoiceTaken.Replenish;
                    spellName        = spellToBeCasted.Name;
                    return(CastReplenishSpell((ReplenishSpell)spellToBeCasted));
                }
                else
                {
                    throw new Exception("Somehow the spell isn't a damage or replenish spell");
                }
            }
            else
            {
                enemyChoiceTaken = GameSession.EnemyChoiceTaken.Attack;
                return(Attack(player, ref battleResult));
            }
        }