Example #1
0
        //Action Methods
        public double attack(ref Monster Target)
        {
            Random random = new Random();

            //Calculate Initial Damage
            double damage = random.Next((int)defaultAttack.getMinDamage(), (int)defaultAttack.getMaxDamage() + 1);

            //Crit or not
            bool crit;
            crit = (defaultAttack.getCritPercent() >= random.Next(1, 11));

            //Calculate final damage
            if (crit)
            {
                damage = damage * 1.5;
            }

            Target.setHP(Target.getHP() - (int)damage);

            return damage;
        }
Example #2
0
        public KeyValuePair<bool, int[]> useSpell(string spellName, ref Monster Target)  //Key: whether item was used successfully; Value: int[0] = damage, int[1] = spellIndex; int[i] = -1 if !used
        {
            bool used = false;  //whether item was used
            int[] spellResult = new int[2];
            spellResult[0] = -1;
            spellResult[1] = -1;
            KeyValuePair<bool, int[]> totalResult;

            for (int i = 0; i < spellList.Length; i++)
            {
                if (spellList[i] == null)
                {
                    break;
                }

                else if (spellName == spellList[i].getName())
                {
                    if (mp > spellList[i].getMPCost())
                    {
                        mp -= spellList[i].getMPCost();

                        Random random = new Random();

                        //Calculate Initial Damage
                        double damage = random.Next((int)spellList[i].getMinDamage(), (int)spellList[i].getMaxDamage() + 1);

                        //Crit or not
                        bool crit;
                        crit = (spellList[i].getCritPercent() >= random.Next(1, 11));

                        //Calculate final damage
                        if (crit)
                        {
                            damage = damage * 1.5;
                        }

                        Target.setHP(Target.getHP() - (int)damage);

                        used = true;
                        spellResult[0] = (int)damage;
                        spellResult[1] = i;

                        totalResult = new KeyValuePair<bool, int[]>(used, spellResult);
                    }
                    break;
                }
            }
            totalResult = new KeyValuePair<bool, int[]>(used, spellResult);
            return totalResult;
        }