Exemple #1
0
        public void CharacterAttacks(Character character, Monster monster)
        {
            int applyDamage = character.Attack; //will calculate if character attack with modifiers
            //roll and if roll is greater than monster damage land attack
            int monsterEXP = monster.GivenExperience(applyDamage);

            ApplyDamageToMonster(monster, applyDamage);
            character.AddExperience(monsterEXP);
            character.CheckExperience();
        }
Exemple #2
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 ";
            }
        }