//Function called whenever this effect heals the target character
    private void HealCharacter()
    {
        //Making sure the character isn't dead before healing
        if (this.characterToEffect.charPhysState.currentHealth <= 0)
        {
            return;
        }

        //Seeing if this effect will trigger
        float triggerRoll = Random.Range(0, 1);

        if (triggerRoll > this.chanceToTrigger)
        {
            //If we roll over the trigger chance, nothing happens and we don't tick
            return;
        }

        //Finding out how much health we heal this tick
        int damagehealed = Mathf.RoundToInt(Random.Range(this.healPerTickRange.x, this.healPerTickRange.y));

        //Finding out if we crit
        float critRoll    = Random.Range(0, 1);
        bool  didThisCrit = false;

        if (critRoll < this.critChance)
        {
            //If we crit this tick, the amount healed is multiplied
            damagehealed = damagehealed * this.critMultiplier;
            didThisCrit  = true;
        }

        //Looping through the perks of the character that used this ability to see if they have any damage type boost perks
        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.healType == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost)
            {
                damagehealed += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(this.characterWhoTriggered, didThisCrit, true, this.healType);
            }
        }

        //Looping through the defending character's perks to see if they have any spell resist or absorb perks
        SpellResistTypes magicResistType = SpellResistTypes.Normal;

        foreach (Perk defPerk in this.characterToEffect.charPerks.allPerks)
        {
            if (defPerk.GetType() == typeof(SpellResistAbsorbPerk))
            {
                SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>();

                //Checking to see if the current heal type is the same as this spell resist perk
                if (resistPerk.typeToResist == this.healType)
                {
                    //Checking to see if the heal is negated entirely
                    if (resistPerk.negateAllDamage)
                    {
                        magicResistType = SpellResistTypes.Negate;
                    }
                    //Otherwise we just get the amount that it normally resists
                    else
                    {
                        damagehealed -= resistPerk.GetSpellResistAmount(this.characterToEffect, didThisCrit, false);
                    }
                }
            }
        }

        //Subtracting any magic resistance from the amount that we're trying to heal
        switch (this.healType)
        {
        case CombatManager.DamageType.Arcane:
            damagehealed -= this.characterToEffect.charInventory.totalArcaneResist;
            break;

        case CombatManager.DamageType.Fire:
            damagehealed -= this.characterToEffect.charInventory.totalFireResist;
            break;

        case CombatManager.DamageType.Water:
            damagehealed -= this.characterToEffect.charInventory.totalWaterResist;
            break;

        case CombatManager.DamageType.Electric:
            damagehealed -= this.characterToEffect.charInventory.totalElectricResist;
            break;

        case CombatManager.DamageType.Wind:
            damagehealed -= this.characterToEffect.charInventory.totalWindResist;
            break;

        case CombatManager.DamageType.Nature:
            damagehealed -= this.characterToEffect.charInventory.totalNatureResist;
            break;

        case CombatManager.DamageType.Holy:
            damagehealed -= this.characterToEffect.charInventory.totalHolyResist;
            break;

        case CombatManager.DamageType.Dark:
            damagehealed -= this.characterToEffect.charInventory.totalDarkResist;
            break;
            //Pure damage type has no resist
        }

        //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect
        int bonusThreat = 0;

        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            //If the perk is a threat boosting perk
            if (charPerk.GetType() == typeof(ThreatBoostPerk))
            {
                ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>();

                //If the perk has the same damage type as this HoT or it affects all damage types
                if (threatPerk.damageTypeToThreaten == this.healType || threatPerk.threatenAllDamageTypes)
                {
                    bonusThreat += threatPerk.GetAddedActionThreat(damagehealed, didThisCrit, true);
                }
            }
        }

        //If the heal was negated completely
        if (magicResistType == SpellResistTypes.Negate)
        {
            //Telling the combat manager to display that no damage was healed
            CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, 0, this.healType, healedCharTile, didThisCrit, true);
        }
        //Otherwise, the heal happens normally
        else
        {
            //Healing the damage to the effected character
            this.characterToEffect.charPhysState.HealCharacter(damagehealed);

            //Telling the combat manager to display the damage healed
            CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, damagehealed, this.healType, healedCharTile, didThisCrit, true);

            //If the target character and the character who cast this effect are player characters, we need to increase threat
            if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>() && !this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
            {
                //Applying threat to all enemies for the amount that's healed
                CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, damagehealed + bonusThreat, true);
            }
        }

        //Creating the visual effect for this effect
        CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(this.characterToEffect);

        this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform);

        //If this effect isn't unlimited, we need to reduce the ticks remaining
        if (!this.unlimitedTicks)
        {
            this.ticksLeft -= 1;

            //If there are no more ticks left, this effect is over and the object is destroyed
            if (this.ticksLeft <= 0)
            {
                this.RemoveEffect();
            }
        }
    }
    //Overrided function from Effect.cs to trigger this heal effect
    public override void TriggerEffect(Character usingCharacter_, Character targetCharacter_, float timeDelay_ = 0)
    {
        //Setting the character references of who is attacking and who is being attacked
        this.characterToEffect     = targetCharacter_;
        this.characterWhoTriggered = usingCharacter_;

        //Int to hold the heal total for the effect
        int totalHeal = 0;

        //Adding the base heal
        totalHeal += this.baseHeal;

        //Looping through each individual die rolled
        for (int d = 0; d < this.diceRolled; ++d)
        {
            //Finding the value rolled on the current die
            totalHeal += Random.Range(1, this.diceSides);
        }

        //Rolling to see if this effect crits
        float critRoll = Random.Range(0, 1);
        bool  isCrit   = false;

        if (critRoll < this.critChance)
        {
            totalHeal = Mathf.RoundToInt(totalHeal * this.critMultiplier);
        }

        //Looping through the perks of the character that used this ability to see if they have any damage type boost perks
        foreach (Perk charPerk in usingCharacter_.charPerks.allPerks)
        {
            //If the perk boosts a damage type that's the same as this damage (heal) type, we boost it
            if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost)
            {
                totalHeal += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(usingCharacter_, isCrit, false, this.type);
            }
        }

        //Looping through the defending character's perks to see if they have any spell resist or absorb perks
        SpellResistTypes magicResistType = SpellResistTypes.Normal;

        foreach (Perk defPerk in this.characterToEffect.charPerks.allPerks)
        {
            if (defPerk.GetType() == typeof(SpellResistAbsorbPerk))
            {
                SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>();

                //Checking to see if the current heal type is the same as this spell resist perk
                if (resistPerk.typeToResist == this.type)
                {
                    //Checking to see if the heal is negated entirely
                    if (resistPerk.negateAllDamage)
                    {
                        magicResistType = SpellResistTypes.Negate;
                    }
                    //Otherwise we just get the amount that it normally resists
                    else
                    {
                        totalHeal -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false);
                    }
                }
            }
        }

        //Subtracting the target character's magic resistances
        switch (this.type)
        {
        case CombatManager.DamageType.Slashing:
            if (targetCharacter_.charInventory.totalSlashingArmor > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalSlashingArmor;
            }
            break;

        case CombatManager.DamageType.Stabbing:
            if (targetCharacter_.charInventory.totalStabbingArmor > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalStabbingArmor;
            }
            break;

        case CombatManager.DamageType.Crushing:
            if (targetCharacter_.charInventory.totalCrushingArmor > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalCrushingArmor;
            }
            break;

        case CombatManager.DamageType.Fire:
            if (targetCharacter_.charInventory.totalFireResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalFireResist;
            }
            break;

        case CombatManager.DamageType.Water:
            if (targetCharacter_.charInventory.totalWaterResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalWaterResist;
            }
            break;

        case CombatManager.DamageType.Electric:
            if (targetCharacter_.charInventory.totalElectricResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalElectricResist;
            }
            break;

        case CombatManager.DamageType.Wind:
            if (targetCharacter_.charInventory.totalWindResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalWindResist;
            }
            break;

        case CombatManager.DamageType.Nature:
            if (targetCharacter_.charInventory.totalNatureResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalNatureResist;
            }
            break;

        case CombatManager.DamageType.Arcane:
            if (targetCharacter_.charInventory.totalArcaneResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalArcaneResist;
            }
            break;

        case CombatManager.DamageType.Holy:
            if (targetCharacter_.charInventory.totalHolyResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalHolyResist;
            }
            break;

        case CombatManager.DamageType.Dark:
            if (targetCharacter_.charInventory.totalDarkResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalDarkResist;
            }
            break;

        case CombatManager.DamageType.Bleed:
            if (targetCharacter_.charInventory.totalBleedResist > 0)
            {
                totalHeal -= targetCharacter_.charInventory.totalBleedResist;
            }
            break;
        }

        //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect
        int bonusThreat = 0;

        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            //If the perk is a threat boosting perk
            if (charPerk.GetType() == typeof(ThreatBoostPerk))
            {
                ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>();

                //If the perk has the same damage type as this effect or it affects all damage types
                if (threatPerk.damageTypeToThreaten == this.type || threatPerk.threatenAllDamageTypes)
                {
                    bonusThreat += threatPerk.GetAddedActionThreat(totalHeal, isCrit, false);
                }
            }
        }

        //Finding the combat tile that the target character is on
        CombatTile targetCharTile = CombatManager.globalReference.FindCharactersTile(targetCharacter_);

        //If the heal was negated completely
        if (magicResistType == SpellResistTypes.Negate)
        {
            //Telling the combat manager to display that no damage was healed
            CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, 0, this.type, healedCharTile, isCrit, true);
        }
        //Otherwise, the heal happens normally
        else
        {
            //Healing the damage to the effected character
            this.characterToEffect.charPhysState.HealCharacter(totalHeal);

            //Telling the combat manager to display the damage healed
            CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, totalHeal, this.type, healedCharTile, isCrit, true);

            //If the acting character is a player character, we need to increase the threat against them
            if (!this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
            {
                //If this character DOESN'T have the EnemyCombatAI component, we increase the threat for the character who put this effect on
                if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>())
                {
                    //Applying threat to all enemies based on the amount healed
                    CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, totalHeal + bonusThreat, true);
                }
            }
        }

        //Creating the visual effect for this effect
        CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(targetCharacter_);

        this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform);

        //Destroying this effect once everything is finished up
        Destroy(this.gameObject);
    }
    //Function called whenever this effect deals damage
    private void DamageCharacter()
    {
        //Making sure the character isn't dead before dealing damage
        if (this.characterToEffect == null || this.characterToEffect.charPhysState.currentHealth <= 0)
        {
            return;
        }

        //Seeing if this effect will trigger
        float triggerRoll = Random.Range(0, 1);

        if (triggerRoll > this.chanceToTrigger)
        {
            //If we roll over the trigger chance, nothing happens and we don't tick
            return;
        }

        //Finding out how much damage we deal this tick
        int damageDealt = Mathf.RoundToInt(Random.Range(this.damagePerTickRange.x, this.damagePerTickRange.y));

        //Finding out if we crit
        float critRoll    = Random.Range(0, 1);
        bool  didThisCrit = false;

        if (critRoll < this.critChance)
        {
            //If we crit this tick, the damage is multiplied
            damageDealt = damageDealt * this.critMultiplier;
            didThisCrit = true;
        }

        //Looping through the perks of the character that used this ability to see if they have any damage type boost perks
        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.damageType == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost)
            {
                damageDealt += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(this.characterWhoTriggered, didThisCrit, true, this.damageType);
            }
        }

        //Looping through the defending character's perks to see if they have any spell resist or absorb perks
        SpellResistTypes magicResistType = SpellResistTypes.Normal;

        foreach (Perk defPerk in this.characterToEffect.charPerks.allPerks)
        {
            if (defPerk.GetType() == typeof(SpellResistAbsorbPerk))
            {
                SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>();

                //Checking to see if the current damage type is the same as this spell resist perk
                if (resistPerk.typeToResist == this.damageType)
                {
                    //Checking to see if the damage is negated entirely
                    if (resistPerk.negateAllDamage)
                    {
                        //If the resist type for this spell isn't on absorb, we can negate it. ALWAYS have preference to absorb because it heals
                        if (magicResistType != SpellResistTypes.Absorb)
                        {
                            magicResistType = SpellResistTypes.Negate;
                        }
                    }
                    //Checking to see if the damage is absorbed to heal the target
                    else if (resistPerk.absorbDamage)
                    {
                        magicResistType = SpellResistTypes.Absorb;
                        //Applying the damage reduction so the defender isn't healed as much
                        damageDealt -= resistPerk.GetSpellResistAmount(this.characterToEffect, didThisCrit, false);
                    }
                    //Otherwise we just get the amount that it normally resists
                    else
                    {
                        damageDealt -= resistPerk.GetSpellResistAmount(this.characterToEffect, didThisCrit, false);
                    }
                }
            }
        }

        //Subtracting any magic resistance from the damage that we're trying to deal
        switch (this.damageType)
        {
        case DamageType.Arcane:
            damageDealt -= this.characterToEffect.charEquipment.totalArcaneResist;
            break;

        case DamageType.Enchant:
            damageDealt -= this.characterToEffect.charEquipment.totalEnchantResist;
            break;

        case DamageType.Holy:
            damageDealt -= this.characterToEffect.charEquipment.totalHolyResist;
            break;

        case DamageType.Dark:
            damageDealt -= this.characterToEffect.charEquipment.totalDarkResist;
            break;

        case DamageType.Fire:
            damageDealt -= this.characterToEffect.charEquipment.totalFireResist;
            break;

        case DamageType.Water:
            damageDealt -= this.characterToEffect.charEquipment.totalWaterResist;
            break;

        case DamageType.Electric:
            damageDealt -= this.characterToEffect.charEquipment.totalElectricResist;
            break;

        case DamageType.Wind:
            damageDealt -= this.characterToEffect.charEquipment.totalWindResist;
            break;

        case DamageType.Stone:
            damageDealt -= this.characterToEffect.charEquipment.totalStoneResist;
            break;
        }

        //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect
        int bonusThreat = 0;

        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            //If the perk is a threat boosting perk
            if (charPerk.GetType() == typeof(ThreatBoostPerk))
            {
                ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>();

                //If the perk has the same damage type as this DoT or it affects all damage types
                if (threatPerk.damageTypeToThreaten == this.damageType || threatPerk.threatenAllDamageTypes)
                {
                    bonusThreat += threatPerk.GetAddedActionThreat(damageDealt, didThisCrit, true);
                }
            }
        }

        //If the damage was dealt normally
        if (magicResistType == SpellResistTypes.Normal)
        {
            //Dealing the damage to the effected character
            this.characterToEffect.charPhysState.DamageCharacter(damageDealt);

            //Telling the combat manager to display the damage dealt
            CombatTile3D damagedCharTile = CombatManager.globalReference.tileHandler.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];

            CombatManager.globalReference.DisplayDamageDealt(0, damageDealt, this.damageType, damagedCharTile, didThisCrit);

            //If this character has the EnemyCombatAI component, we increase the threat for the character who put this effect on
            if (this.characterToEffect.GetComponent <EnemyCombatAI_Basic>())
            {
                //If the character who cast this effect is a player character, we make the enemies hate that character
                if (!this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
                {
                    //If the attack didn't crit
                    if (!didThisCrit)
                    {
                        //Applying threat to the targeted character
                        this.characterToEffect.GetComponent <EnemyCombatAI_Basic>().IncreaseThreat(this.characterWhoTriggered, damageDealt + bonusThreat);
                    }
                    //If the attack did crit, we boost threat against all enemies by 25%
                    else
                    {
                        //Finding the bonus amount of threat that's applied to all enemies
                        int boostedThreat = damageDealt + bonusThreat;
                        boostedThreat = Mathf.RoundToInt(boostedThreat * 0.25f);
                        CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, boostedThreat, true);

                        //Applying the rest of the threat to the target character
                        CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, this.characterToEffect, damageDealt + bonusThreat - boostedThreat, false);
                    }
                }
            }
        }
        //If the damage was negated completely
        else if (magicResistType == SpellResistTypes.Negate)
        {
            //Telling the combat manager to display no damage dealt
            CombatTile3D damagedCharTile = CombatManager.globalReference.tileHandler.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, 0, this.damageType, damagedCharTile, didThisCrit);
        }
        //If the damage was absorbed and healed the character
        else if (magicResistType == SpellResistTypes.Absorb)
        {
            //Healing the damage to the effected character
            this.characterToEffect.charPhysState.HealCharacter(damageDealt);

            //Telling the combat manager to display the damage healed
            CombatTile3D damagedCharTile = CombatManager.globalReference.tileHandler.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow];
            CombatManager.globalReference.DisplayDamageDealt(0, damageDealt, this.damageType, damagedCharTile, didThisCrit, true);

            //If the caster of this effect and the target are player characters, we increase the threat for the character who put this effect on them
            if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>() && !this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
            {
                //Applying threat to all enemies for the amount that's healed
                CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, damageDealt + bonusThreat, true);
            }
        }

        //Creating the visual effect for this effect
        GameObject targetCharModel = CombatManager.globalReference.characterHandler.GetCharacterModel(this.characterToEffect);

        this.SpawnVisualAtLocation(targetCharModel.transform.localPosition, targetCharModel.transform);

        //If this effect isn't unlimited, we need to reduce the ticks remaining
        if (!this.unlimitedTicks)
        {
            this.ticksLeft -= 1;

            //If there are no more ticks left, this effect is over and the object is destroyed
            if (this.ticksLeft <= 0)
            {
                this.RemoveEffect();
            }
        }
    }
예제 #4
0
    //Function inherited from AttackAction.cs and called from CombatManager.cs so we can attack a target
    public override void PerformAction(CombatTile3D targetTile_)
    {
        //Calling the base function to start the cooldown time
        this.BeginActionCooldown();

        //Reference to the character performing this attack
        Character actingChar = CombatManager.globalReference.initiativeHandler.actingCharacters[0];
        //Reference to the character that's being attacked
        Character defendingChar;

        //Getting the tile that the acting character is on
        CombatTile3D actingCharTile = CombatManager.globalReference.tileHandler.FindCharactersTile(actingChar);
        GameObject   charModel      = CombatManager.globalReference.characterHandler.GetCharacterModel(actingChar);

        //Setting the direction the acting character faces
        this.SetDirectionFacing(targetTile_, actingCharTile, charModel);

        //Looping through and triggering all combat effects on the acting character that happen on attack
        foreach (Effect e in actingChar.charCombatStats.combatEffects)
        {
            e.EffectOnAttack();

            //Checking to see if the character has died due to some effect. If so, we break the loop
            if (actingChar.charPhysState.currentHealth <= 0)
            {
                break;
            }
        }

        //Looping through and creating each of the launched projectiles for this attack
        Vector3 casterTile = CombatManager.globalReference.tileHandler.FindCharactersTile(CombatManager.globalReference.initiativeHandler.actingCharacters[0]).transform.position;

        foreach (ProjectileLauncher projectile in this.projectilesToLaunch)
        {
            GameObject newProjectile = GameObject.Instantiate(projectile.gameObject, casterTile, new Quaternion());
            //Parenting the projectile to the combat manager canvas
            newProjectile.transform.SetParent(CombatManager.globalReference.transform);
            //Telling the projectile to start moving
            newProjectile.GetComponent <ProjectileLauncher>().StartTravelPath(casterTile, targetTile_.transform.position);
        }

        //Making sure there's a character on the targeted tile
        if (targetTile_.objectOnThisTile != null && targetTile_.objectOnThisTile.GetComponent <Character>())
        {
            defendingChar = targetTile_.objectOnThisTile.GetComponent <Character>();
        }
        //If there isn't a character on the tile, nothing happens because it misses anything it could hit
        else
        {
            //If there are no attack damage rolls (like if the attack was just to inflict an effect) the "Miss" text isn't shown
            if (this.damageDealt.Count > 0)
            {
                CombatManager.globalReference.uiHandler.DisplayMissedAttack(this.timeToCompleteAction, targetTile_);
            }

            //If the visual effect doesn't require a hit to be spawned, we create it at the target tile
            if (this.spawnVisualOnMiss && this.visualEffectOnHit != null)
            {
                GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform);
            }

            //Looping through each effect that this attack can apply to see if any don't require the attack to land
            foreach (AttackEffect efc in this.effectsOnHit)
            {
                //If the effect doesn't require the attack to land, it's triggered
                if (!efc.requireHit)
                {
                    this.TriggerEffect(efc, targetTile_, actingChar);
                }
            }

            return;
        }

        //Before calculating damage, we need to find out if this attack hit. We start by rolling 1d100 to hit and adding this attack's accuracy bonus
        int hitRoll = this.FindAttackRoll(actingChar, defendingChar);

        //If the hit roll is still above 20%, they hit. If not, the attack misses
        if (hitRoll <= CombatManager.baseHitDC)
        {
            //If there are no attack damage rolls (like if the attack was just to inflict an effect) the "Miss" text isn't shown
            if (this.damageDealt.Count > 0)
            {
                //Miss
                CombatManager.globalReference.uiHandler.DisplayMissedAttack(this.timeToCompleteAction, targetTile_);
            }

            //If the visual effect doesn't require a hit to be spawned, we create it at the target tile
            if (this.spawnVisualOnMiss && this.visualEffectOnHit != null)
            {
                GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform);
            }

            //Looping through each effect that this attack can apply to see if any don't require the attack to land
            foreach (AttackEffect efc in this.effectsOnHit)
            {
                //If the effect doesn't require the attack to land, it's triggered
                if (!efc.requireHit)
                {
                    this.TriggerEffect(efc, targetTile_, actingChar);
                }
            }

            //Giving the attacking character skill EXP for a miss
            this.GrantSkillEXP(actingChar, this.weaponSkillUsed, true);

            return;
        }

        //Giving the attacking character skill EXP for a hit
        this.GrantSkillEXP(actingChar, this.weaponSkillUsed, false);

        //Looping through for each time this action hits
        for (int h = 0; h < this.numberOfHits; ++h)
        {
            //Checking to see if this attack crits
            float critMultiplier = 1; //Set to 1 in case we don't crit so it won't change anything
            float critRoll       = Random.Range(0, 1);
            bool  isCrit         = false;

            //Float for the bonus damage multiplier from perks
            float critMultiplierBoost = 0;

            //Looping through all of the acting character's perks to see if they have perks for crit chance or multiplier
            foreach (Perk charPerk in actingChar.charPerks.allPerks)
            {
                //If the current perk increases crit chance, we need to see if it applies to this attack
                if (charPerk.GetType() == typeof(CritChanceBoostPerk))
                {
                    CritChanceBoostPerk critPerk = charPerk.GetComponent <CritChanceBoostPerk>();

                    //If the perk applies to this attack's required skill check
                    if (critPerk.boostAllSkills || critPerk.skillCritToBoost == this.weaponSkillUsed)
                    {
                        //If the perk applies to any kind of weapon size or the size requirement matches this action's required size, we increase the crit chance
                        if (critPerk.noSizeRequirement || critPerk.weaponSizeRequirement == this.requiredWeaponHand)
                        {
                            critRoll -= critPerk.critChanceBoost;
                        }
                    }
                }
                //If the current perk increases crit damage multipliers, we see if it applies to this attack
                else if (charPerk.GetType() == typeof(CritMultiplierPerk))
                {
                    CritMultiplierPerk critPerk = charPerk.GetComponent <CritMultiplierPerk>();

                    //If the perk applies to this attack's required skill check
                    if (critPerk.boostAllSkills || critPerk.skillCritToBoost == this.weaponSkillUsed)
                    {
                        //If the perk applies to any kind of weapon size or the size requirement matches this action's required size, we increase the crit chance
                        if (critPerk.noSizeRequirement || critPerk.weaponSizeRequirement == this.requiredWeaponHand)
                        {
                            critMultiplierBoost += critPerk.critMultiplierBoost;
                        }
                    }
                }
            }

            //If the crit roll is below the crit chance, the attack crits and we change the multiplier
            if (critRoll < this.critChance)
            {
                critMultiplier = this.critMultiplier + critMultiplierBoost;
                isCrit         = true;
            }

            //Dictionary for the total amount of damage for each type that will be dealt with this attack
            Dictionary <DamageType, int> damageTypeTotalDamage = new Dictionary <DamageType, int>();
            //Dictionary for if all of the spell damage types for if the damage is completely negated
            Dictionary <DamageType, SpellResistTypes> spellResistDictionary = new Dictionary <DamageType, SpellResistTypes>();

            //Initializing the dictionaries correctly
            this.InitializeDamageDictionaries(damageTypeTotalDamage, spellResistDictionary);

            //Getting the damage from the used weapon
            this.GetWeaponDamage(actingChar, damageTypeTotalDamage, h);

            //Looping through each damage type for this attack
            foreach (AttackDamage atk in this.damageDealt)
            {
                //Int to hold all of the damage for the current attack
                int atkDamage = 0;

                //Adding the base damage
                atkDamage += atk.baseDamage;

                //Looping through each individual die rolled
                for (int d = 0; d < atk.diceRolled; ++d)
                {
                    //Finding the value rolled on the current die
                    atkDamage += Random.Range(1, atk.diceSides);
                }

                //Multiplying the damage by the crit multiplier
                atkDamage = Mathf.RoundToInt(atkDamage * critMultiplier);

                //Looping through the perks of the character that used this ability to see if they have any damage type boost perks
                foreach (Perk charPerk in actingChar.charPerks.allPerks)
                {
                    //If the perk boosts a damage type that's the same as this damage type, we boost it
                    if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && atk.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost)
                    {
                        atkDamage += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(actingChar, isCrit, false, atk.type);
                    }
                }

                //Looping through the defending character's perks to see if they have any spell resist or absorb perks
                foreach (Perk defPerk in defendingChar.charPerks.allPerks)
                {
                    if (defPerk.GetType() == typeof(SpellResistAbsorbPerk))
                    {
                        SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>();

                        //Checking to see if the current damage type is the same as this spell resist perk
                        if (resistPerk.typeToResist == atk.type)
                        {
                            //Checking to see if the damage is negated entirely
                            if (resistPerk.negateAllDamage)
                            {
                                //If the resist type for this spell isn't on absorb, we can negate it. ALWAYS have preference to absorb because it heals
                                if (spellResistDictionary[atk.type] != SpellResistTypes.Absorb)
                                {
                                    spellResistDictionary[atk.type] = SpellResistTypes.Negate;
                                }
                            }
                            //Checking to see if the damage is absorbed to heal the target
                            else if (resistPerk.absorbDamage)
                            {
                                spellResistDictionary[atk.type] = SpellResistTypes.Absorb;
                                //Applying the damage reduction so the defender isn't healed as much
                                damageTypeTotalDamage[atk.type] -= resistPerk.GetSpellResistAmount(defendingChar, isCrit, false);
                            }
                            //Otherwise we just get the amount that it normally resists
                            else
                            {
                                damageTypeTotalDamage[atk.type] -= resistPerk.GetSpellResistAmount(defendingChar, isCrit, false);
                            }
                        }
                    }
                }

                //Adding the current attack's damage to the correct type
                damageTypeTotalDamage[atk.type] += atkDamage;
            }

            //Looping through the attacking character's perks to see if there's any bonus damage to add to this attack
            foreach (Perk charPerk in actingChar.charPerks.allPerks)
            {
                //If the perk is a damage boosting perk, we get the bonus damage from it
                if (charPerk.GetType() == typeof(SkillDamageBoostPerk))
                {
                    int perkDamage = charPerk.GetComponent <SkillDamageBoostPerk>().GetDamageBoostAmount(actingChar, isCrit, false);

                    //Applying the perk's added damage to the correct damage type
                    damageTypeTotalDamage[charPerk.GetComponent <SkillDamageBoostPerk>().damageBoostType] += perkDamage;
                }
            }

            //Subtracting the target's melee and spell damage resistance from our attack damage
            this.SubtractResistances(damageTypeTotalDamage, defendingChar);

            //Dealing damage to the target
            this.DealDamage(damageTypeTotalDamage, spellResistDictionary, defendingChar, targetTile_, isCrit);

            //Dealing threat to the target
            this.DealThreat(damageTypeTotalDamage, actingChar, defendingChar, isCrit);

            //Creating the visual effect at the target tile if it isn't null
            if (this.visualEffectOnHit != null)
            {
                GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform);
            }

            //Looping through each effect that this attack can cause and triggering them
            foreach (AttackEffect effect in this.effectsOnHit)
            {
                this.TriggerEffect(effect, targetTile_, actingChar);
            }
        }
    }
예제 #5
0
    //Overrided function from Effect.cs to trigger this damage effect
    public override void TriggerEffect(Character usingCharacter_, Character targetCharacter_, float timeDelay_ = 0)
    {
        //Setting the character references of who is attacking and who is being attacked
        this.characterToEffect     = targetCharacter_;
        this.characterWhoTriggered = usingCharacter_;

        //Int to hold all of the damage for the attack
        int totalDamage = 0;

        //Adding the base damage
        totalDamage += this.baseDamage;

        //Looping through each individual die rolled
        for (int d = 0; d < this.diceRolled; ++d)
        {
            //Finding the value rolled on the current die
            totalDamage += Random.Range(1, this.diceSides);
        }

        //Rolling to see if this effect crits
        float critRoll = Random.Range(0, 1);
        bool  isCrit   = false;

        if (critRoll < this.critChance)
        {
            totalDamage = totalDamage * this.critMultiplier;
        }

        //Looping through the perks of the character that used this ability to see if they have any damage type boost perks
        foreach (Perk charPerk in usingCharacter_.charPerks.allPerks)
        {
            //If the perk boosts a damage type that's the same as this damage type, we boost it
            if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost)
            {
                totalDamage += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(usingCharacter_, isCrit, false, this.type);
            }
        }

        //Looping through the defending character's perks to see if they have any spell resist or absorb perks
        SpellResistTypes magicResistType = SpellResistTypes.Normal;

        foreach (Perk defPerk in targetCharacter_.charPerks.allPerks)
        {
            if (defPerk.GetType() == typeof(SpellResistAbsorbPerk))
            {
                SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>();

                //Checking to see if the current damage type is the same as this spell resist perk
                if (resistPerk.typeToResist == this.type)
                {
                    //Checking to see if the damage is negated entirely
                    if (resistPerk.negateAllDamage)
                    {
                        //If the resist type for this spell isn't on absorb, we can negate it. ALWAYS have preference to absorb because it heals
                        if (magicResistType != SpellResistTypes.Absorb)
                        {
                            magicResistType = SpellResistTypes.Negate;
                        }
                    }
                    //Checking to see if the damage is absorbed to heal the target
                    else if (resistPerk.absorbDamage)
                    {
                        magicResistType = SpellResistTypes.Absorb;
                        //Applying the damage reduction so the defender isn't healed as much
                        totalDamage -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false);
                    }
                    //Otherwise we just get the amount that it normally resists
                    else
                    {
                        totalDamage -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false);
                    }
                }
            }
        }

        //Subtracting the target character's armor resist and magic resistances
        switch (this.type)
        {
        case CombatManager.DamageType.Slashing:
            if (targetCharacter_.charInventory.totalSlashingArmor > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalSlashingArmor;
            }
            break;

        case CombatManager.DamageType.Stabbing:
            if (targetCharacter_.charInventory.totalStabbingArmor > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalStabbingArmor;
            }
            break;

        case CombatManager.DamageType.Crushing:
            if (targetCharacter_.charInventory.totalCrushingArmor > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalCrushingArmor;
            }
            break;

        case CombatManager.DamageType.Fire:
            if (targetCharacter_.charInventory.totalFireResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalFireResist;
            }
            break;

        case CombatManager.DamageType.Water:
            if (targetCharacter_.charInventory.totalWaterResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalWaterResist;
            }
            break;

        case CombatManager.DamageType.Electric:
            if (targetCharacter_.charInventory.totalElectricResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalElectricResist;
            }
            break;

        case CombatManager.DamageType.Wind:
            if (targetCharacter_.charInventory.totalWindResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalWindResist;
            }
            break;

        case CombatManager.DamageType.Nature:
            if (targetCharacter_.charInventory.totalNatureResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalNatureResist;
            }
            break;

        case CombatManager.DamageType.Arcane:
            if (targetCharacter_.charInventory.totalArcaneResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalArcaneResist;
            }
            break;

        case CombatManager.DamageType.Holy:
            if (targetCharacter_.charInventory.totalHolyResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalHolyResist;
            }
            break;

        case CombatManager.DamageType.Dark:
            if (targetCharacter_.charInventory.totalDarkResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalDarkResist;
            }
            break;

        case CombatManager.DamageType.Bleed:
            if (targetCharacter_.charInventory.totalBleedResist > 0)
            {
                totalDamage -= targetCharacter_.charInventory.totalBleedResist;
            }
            break;
        }

        //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect
        int bonusThreat = 0;

        foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks)
        {
            //If the perk is a threat boosting perk
            if (charPerk.GetType() == typeof(ThreatBoostPerk))
            {
                ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>();

                //If the perk has the same damage type as this effect or it affects all damage types
                if (threatPerk.damageTypeToThreaten == this.type || threatPerk.threatenAllDamageTypes)
                {
                    bonusThreat += threatPerk.GetAddedActionThreat(totalDamage, isCrit, false);
                }
            }
        }

        //Finding the combat tile that the target character is on
        CombatTile targetCharTile = CombatManager.globalReference.FindCharactersTile(targetCharacter_);

        //If the damage was dealt normally
        if (magicResistType == SpellResistTypes.Normal)
        {
            //Dealing damage to the target character and telling the combat manager to display how much was dealt
            targetCharacter_.charPhysState.DamageCharacter(totalDamage);
            CombatManager.globalReference.DisplayDamageDealt(timeDelay_, totalDamage, type, targetCharTile, isCrit);

            //If this character has the EnemyCombatAI component, we increase the threat for the character who put this effect on
            if (this.characterToEffect.GetComponent <EnemyCombatAI_Basic>())
            {
                //If the character who cast this effect is a player character, we increase threat against the caster
                if (!this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
                {
                    //If the attack didn't crit
                    if (!isCrit)
                    {
                        //Applying threat to the targeted character
                        this.characterToEffect.GetComponent <EnemyCombatAI_Basic>().IncreaseThreat(this.characterWhoTriggered, totalDamage + bonusThreat);
                    }
                    //If the attack did crit, we boost threat against all enemies by 25%
                    else
                    {
                        //Finding the bonus amount of threat that's applied to all enemies
                        int boostedThreat = totalDamage + bonusThreat;
                        boostedThreat = Mathf.RoundToInt(boostedThreat * 0.25f);
                        CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, boostedThreat, true);

                        //Applying the rest of the threat to the target character
                        CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, this.characterToEffect, totalDamage + bonusThreat - boostedThreat, false);
                    }
                }
            }
        }
        //If the damage was negated completely
        else if (magicResistType == SpellResistTypes.Negate)
        {
            //Telling the combat manager to display no damage dealt
            CombatManager.globalReference.DisplayDamageDealt(timeDelay_, 0, type, targetCharTile, isCrit);
        }
        //If the damage was abosrbed and healed the character
        else if (magicResistType == SpellResistTypes.Absorb)
        {
            //Telling the combat manager to display the damage healed
            targetCharacter_.charPhysState.HealCharacter(totalDamage);
            CombatManager.globalReference.DisplayDamageDealt(timeDelay_, totalDamage, type, targetCharTile, isCrit, true);

            //If the caster of this effect and the target are player characters, we increase the threat for the character who put this effect on them
            if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>() && !this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>())
            {
                //Applying threat to all enemies for the amount that's healed
                CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, totalDamage + bonusThreat, true);
            }
        }

        //Creating the visual effect for this effect
        CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(targetCharacter_);

        this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform);


        //Increasing the threat to the target based on damage dealt
        //If the attack is a crit, ALL enemies have their threat increased for 25% of the damage
        if (isCrit)
        {
            //Getting 25% of the damage to pass to all enemies
            int threatForAll = (totalDamage + bonusThreat) / 4;
            CombatManager.globalReference.ApplyActionThreat(usingCharacter_, null, threatForAll, true);

            //Applying the rest of the threat to the target character
            CombatManager.globalReference.ApplyActionThreat(usingCharacter_, targetCharacter_, (totalDamage + bonusThreat) - threatForAll, false);
        }
        //If the attack wasn't a crit, only the target character takes threat
        else
        {
            CombatManager.globalReference.ApplyActionThreat(usingCharacter_, targetCharacter_, totalDamage + bonusThreat, false);
        }

        //Destroying this effect once everything is finished up
        Destroy(this.gameObject);
    }