Ejemplo n.º 1
0
    //this function actually applies the spell effect to the target
    public void castAbility(CharacterStatus target, float damage, float healing, float apCost, float armorPen, float magicPen, float buff, bool isMagic)
    {
        _unit.UnhighlightWalkableTiles();
        _unit.CmdLookAt(target.gameObject);
        //if the target is not dead
        if (target.currentHealth > 0)
        {
            float resistance = 0;
            //check if the caster has enough AP to cast a spell - currently redundant
            if (_casterStatus.currentAction >= apCost)
            {
                //use casters ability points
                _casterStatus.CmdLoseAction(apCost);

                //check if the spell effect is reduced by magic resistance or armor
                if (isMagic)
                {
                    magicPen += _casterStatus.tempMagicPen;
                    if (magicPen == 0)
                    {
                        resistance = target.magicArmor + target.tempPhysicalArmor;
                    }
                    else
                    {
                        resistance = (target.magicArmor + target.tempMagicArmor) * (1 - magicPen);
                    }
                    //ensure penetration doesnt add damage and that resistance doesn't cause healing
                    if (resistance < 0)
                    {
                        resistance = 0;
                    }
                    if (resistance >= 1)
                    {
                        resistance = 1;
                    }
                    target.tempMagicArmor      -= .1f;
                    _casterStatus.tempMagicPen -= .1f;
                    if (target.tempMagicArmor < 0)
                    {
                        target.tempMagicArmor = 0;
                    }
                    if (_casterStatus.tempMagicPen < 0)
                    {
                        _casterStatus.tempMagicPen = 0;
                    }
                    //deal damage wieghted by resistance
                    target.loseHealth(damage * (1 - resistance));
                }
                else
                {
                    armorPen += _casterStatus.tempArmorPen;
                    if (armorPen == 0)
                    {
                        resistance = target.physicalArmor + target.tempPhysicalArmor;
                    }
                    else
                    {
                        resistance = target.physicalArmor * (1 - armorPen);
                    }

                    //ensure penetration doesnt add damage and that resistance doesn't cause healing
                    if (resistance < 0)
                    {
                        resistance = 0;
                    }
                    if (resistance >= 1)
                    {
                        resistance = 1;
                    }

                    target.tempPhysicalArmor   -= .1f;
                    _casterStatus.tempArmorPen -= .1f;
                    if (target.tempPhysicalArmor < 0)
                    {
                        target.tempPhysicalArmor = 0;
                    }
                    if (_casterStatus.tempArmorPen < 0)
                    {
                        _casterStatus.tempArmorPen = 0;
                    }

                    //deal damage weighted by resistance
                    target.loseHealth(damage * (1 - resistance));
                }

                //check if target is dead - may have received damage before healing
                if (target.currentHealth <= 0)
                {
                    target.GetComponent <CapsuleCollider>().enabled = false;
                    target.currentHealth = 0;
                    target.GetComponentInChildren <StatusBars>().gameObject.SetActive(false);
                    if (target.isLeader)
                    {
                        _casterStatus.CmdEndGame(target.teamNum);
                    }
                }
                else
                {
                    //if alive heal the target
                    target.gainHealth(healing);
                    if (target.currentHealth > target.maxHealth)
                    {
                        target.currentHealth = target.maxHealth;
                    }
                    if (buff > 0)
                    {
                        if (isMagic)
                        {
                            target.maxAction += buff;
                        }
                        else
                        {
                            target.maxHealth += buff;
                        }
                    }
                }

                //ability is finished set boolean
                usingAbility = false;
            }
            else
            {
                //not enough AP - set boolean
                usingAbility = false;
            }

            //syncs the server values with those of the clinet
            target.CmdSyncValues(target.teamNum, target.maxAction, target.currentAction,
                                 target.maxHealth, target.currentHealth, target.physicalArmor, target.magicArmor);
        }
    }