Example #1
0
        //applies damage to target based on character stats + power used
        public void Apply(Character obj, Character target)
        {
            if (obj.Mp - manaCost >= 0)
            {
                float rand        = Random.Range(1, 100);
                float MissRange   = 10 + target.GetComponent <Character>().Agi - obj.GetComponent <Character>().Dex;
                float IncomingDmg = 0;

                //if the random number from 1-100 is less than the miss range, the attack hits
                if (rand >= MissRange)
                {
                    IncomingDmg = CalculateDamage(obj, target);
                    //loops over current effects on this power, applies them to the target
                    for (int i = 0; i < currentEffects.Count; i++)
                    {
                        currentEffects[i].Apply(target, duration);
                    }
                }

                //plays miss text if attack misses
                else if (rand < MissRange)
                {
                    GetScreenLoc tempLoc  = new GetScreenLoc();
                    Vector2      location = tempLoc.getScreenPos(target.transform);
                    FloatingTextController.CreateMissText(("Miss!").ToString(), location);
                }


                //plays damage ammount animations if damage is delt
                if (IncomingDmg != 0)
                {
                    Debug.Log("Applying Damage");
                    GetScreenLoc tempLoc  = new GetScreenLoc();
                    Vector2      location = tempLoc.getScreenPos(target.transform);
                    if (target.tag == "Enemy")
                    {
                        FloatingTextController.CreateDamageEnemyText((IncomingDmg).ToString(), location);
                    }
                    else if (target.tag == "Player")
                    {
                        FloatingTextController.CreateDamageAllyText((IncomingDmg).ToString(), location);
                    }
                }

                target.Hp -= IncomingDmg;
                obj.Mp    -= manaCost;
            }
        }