Exemple #1
0
        //Calculate attack roll for monster
        public void MonsterAttacks(Character character, Monster monster)
        {
            //Hold hitchance for monster
            int hitChance = 0;

            //Hold misschance for character
            int missChance = 0;

            //New dice bag
            DiceRoll DiceBag = new DiceRoll();

            //Roll d20 dice
            int roll = DiceBag.Roll(DiceRoll.Dice.D20);

            //If roll is  1, guarantee miss attack
            if (roll == 1)
            {
                hitChance  = 0;
                missChance = 20;
            }
            //else if roll is 20, guarantee hit attack
            else if (roll == 20)
            {
                hitChance  = 20;
                missChance = 0;
            }
            //else Calculate hitchance/misschance to see if successfull hit
            else
            {
                //HitChance = D20 dice roll + monster level + monster attack
                hitChance = roll + monster.Level + monster.Attack;

                //Miss change = character defense, level, and attribute modifiers
                missChance = character.Defense + character.Level + character.StatModifier(AttributeEnum.Defense);
            }


            Debug.WriteLine("Char defense:" + character.Defense + " character.Level" + character.Level);
            Debug.WriteLine("character: roll:" + roll + " hitchance:" + hitChance + " Misschance:" + missChance + " ");
            //If hitchance is greater than misschance
            if (hitChance >= missChance)
            {
                //Calculate damage to apply
                int applyDamage = Convert.ToInt32(Math.Ceiling(monster.Level * (.25)) + monster.Attack);

                //Call method to apply damage to character
                ApplyDamageToCharacter(character, applyDamage);

                //Damage string
                MonsterAttack = " for " + applyDamage + " damage. ";
            }

            //Else if hitchance is less than misschance
            else
            {
                //Miss string
                MonsterAttack = " Misses attack ";
            }
        }
Exemple #2
0
        //Method to update character Maxhealth and currentHealth
        public void HealthAdjust(Character character)
        {
            //New DiceRoll
            DiceRoll bag = new DiceRoll();

            //Holds int's from multiroll in list
            List <int> rolls = bag.MultiRoll(DiceRoll.Dice.D10, character.Level);

            //Set's rollsum to 0
            int rollsum = 0;

            //Character's current HP
            int currentHP = character.CurrentHealth;

            //Characters maximum HP
            int oldmax = character.MaximumHealth;

            //Loops though rolls list and add's values to rollsum
            for (int i = 0; i < rolls.Count; i++)
            {
                rollsum += rolls[i];
            }

            //Sets new MaximumHealth to currentMax + rollsum
            character.MaximumHealth = character.MaximumHealth + rollsum;

            //Maximum HP is 20d10
            if (character.MaximumHealth > 200)
            {
                character.MaximumHealth = 200;
            }


            //Set's characters CurrentHealth to CurrentMaximum -(OldMaximumHealth - currentHP)
            character.CurrentHealth = (character.MaximumHealth - (oldmax - currentHP));

            //if Health of 200 exceeded, set to 200
            if (character.CurrentHealth > 200)
            {
                character.CurrentHealth = 200;
            }
        }
Exemple #3
0
        //Calculate Attack roll for Character
        public void CharacterAttacks(Character character, Monster monster)
        {
            //Hold character chance to hit
            int hitChance = 0;

            //Hold misschance for monster
            int missChance = 0;

            //New Seed Every Attack
            DiceRoll DiceBag = new DiceRoll();

            //Dice Roll with d20
            int roll = DiceBag.Roll(DiceRoll.Dice.D20);

            //If roll is  1, guarantee miss attack
            if (roll == 1)
            {
                hitChance  = 0;
                missChance = 20;
            }

            //else if roll is 20, guarantee hit attack
            else if (roll == 20)
            {
                hitChance  = 20;
                missChance = 0;
            }

            //else Calculate hitchance/misschance to see if successfull hit
            else
            {
                //HitChance = D20 dice roll + character level + attack from items
                hitChance = roll + character.Level + character.StatModifier(AttributeEnum.Attack);


                //Miss change = monster defense, level
                missChance = monster.Defense + monster.Level;
            }


            Debug.WriteLine("character: roll:" + roll + " hitchance:" + hitChance + " Misschance:" + missChance);
            Debug.WriteLine("Char defense:" + character.Defense + " character.Level" + character.Level);


            //If hitchance is greater than misschance
            if (hitChance >= missChance)
            {
                //Calcuate damage to apply to monster
                int applyDamage = Convert.ToInt32(Math.Ceiling(character.Level * (.25)) + character.Attack + character.WeaponDamage(AttributeEnum.Attack));

                //Calcuate experience to get from monster to character for % of damage done by character
                int monsterEXP = monster.GivenExperience(applyDamage);

                //Applys damage to monster by calling method
                ApplyDamageToMonster(monster, applyDamage);

                //Add's experience to character corresponding to the percent of damage done
                character.AddExperience(monsterEXP);

                //Add's the experience gained to the score page
                score.ExperienceGainedTotal += monsterEXP;

                //Checks character experience to see if leveled up
                character.CheckExperience();

                //Damage output string
                CharacterAttack = " for " + applyDamage + " damage. ";
            }

            //Hitchance less than misschance
            else
            {
                //Miss string
                CharacterAttack = " Misses attack ";
            }
        }