Пример #1
0
    //Function called from EnemyCombatAI_Basic.cs to perform an enemy's action at the given tile
    public void PerformEnemyActionOnTile(CombatTile3D tileClicked_, Action enemyAction_)
    {
        //If the action being performed is a movement action and the tile chosen isn't empty, nothing happens
        if (enemyAction_.GetType() == typeof(MoveAction))
        {
            if (tileClicked_.typeOnTile != TileObjectType.Nothing)
            {
                return;
            }
        }
        //Tells our info display object to show the name of the action used if it isn't a move action
        else
        {
            this.ourInfoDisplay.StartInfoDisplay(enemyAction_.actionName, enemyAction_.timeToCompleteAction);
        }

        //Creating a new instance of the action to use
        GameObject actionInstance = Instantiate(enemyAction_.gameObject);

        //Tells the action to be performed at the tile chosen
        actionInstance.GetComponent <Action>().PerformAction(tileClicked_);

        //Have this combat manager wait a bit before going back because there could be animations
        if (this.stateAfterWait != CombatState.EndCombat)
        {
            this.SetWaitTime(enemyAction_.timeToCompleteAction, CombatState.PlayerInput);
        }
    }
Пример #2
0
    //Function called from CombatTile.cs to perform the selected action in the CombatActionPanelUI
    public void PerformActionAtClickedTile(CombatTile3D tileClicked_)
    {
        //If the action being performed is a movement action and the tile clicked isn't empty, nothing happens
        if (CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>() && tileClicked_.typeOnTile != TileObjectType.Nothing)
        {
            return;
        }

        //Tells our info display object to show the name of the action used if it isn't a move action
        if (!CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>())
        {
            this.ourInfoDisplay.StartInfoDisplay(CombatActionPanelUI.globalReference.selectedAction.actionName, CombatActionPanelUI.globalReference.selectedAction.timeToCompleteAction);
        }

        //Tells the action to be performed at the tile clicked and stops highlighting it
        CombatActionPanelUI.globalReference.selectedAction.PerformAction(tileClicked_);

        //Have this combat manager wait a bit before going back because there could be animations
        if (this.stateAfterWait != CombatState.EndCombat)
        {
            this.SetWaitTime(CombatActionPanelUI.globalReference.selectedAction.timeToCompleteAction, CombatState.PlayerInput);
        }

        //Disables the types of actions that were used
        CombatActionPanelUI.globalReference.DisableUsedActions();

        //Clearing the highlighted area showing the previously used action's range
        this.tileHandler.ClearTileHilights();
    }
Пример #3
0
    //Function called when the player's mouse is no longer over this tile
    private void OnMouseExit()
    {
        //Making sure the pointer isn't over a UI object
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            //If a character is moving right now and this tile is in the movement path, we don't stop highlighting
            if (CombatActionPanelUI.globalReference.selectedAction != null && CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>())
            {
                //If this tile isn't in the movement path, this tile isn't highlighted
                if (!CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>().IsTileInMovementPath(this))
                {
                    this.HighlightTile(false);
                }
            }
            else
            {
                //Stops hilighting this tile's image
                this.HighlightTile(false);

                //Stops highlighting any effect radius if there's a selected attack ability
                this.HighlightEffectRadius(false);
            }

            mouseOverTile = null;
        }
    }
Пример #4
0
    //Function inherited from AttackAction.cs and called from CombatManager.cs so we can attack a target
    public override void PerformAction(CombatTile3D targetTile_)
    {
        base.PerformAction(targetTile_);

        //Once the attack is performed, this spell needs to recharge
        Character actingChar = CombatManager.globalReference.initiativeHandler.actingCharacters[0];

        actingChar.charActionList.StartSpellRecharge(this);
    }
    //Function called from InitializeCharactersForCombat to instantiate character models
    private void CreateCharacterModels()
    {
        //Clearing the model lists
        foreach (GameObject pm in this.playerModels)
        {
            Destroy(pm);
        }
        foreach (GameObject em in this.enemyModels)
        {
            Destroy(em);
        }
        this.playerModels = new List <GameObject>();
        this.enemyModels  = new List <GameObject>();

        //Creating each player character model at their tile position
        for (int p = 0; p < this.playerCharacters.Count; p++)
        {
            GameObject charModel = GameObject.Instantiate(this.playerCharacters[p].charModels.charModel);

            CombatTile3D tile = CombatManager.globalReference.tileHandler.FindCharactersTile(this.playerCharacters[p]);

            if (tile == null)
            {
                Debug.Log("Tile null");
            }
            else
            {
                charModel.transform.position = tile.gameObject.transform.position;
                this.playerModels.Add(charModel);
                CombatManager.globalReference.tileHandler.FindCharactersTile(this.playerCharacters[p]).SetObjectOnTile(charModel, TileObjectType.Player);
            }
        }

        //Creating each enemy character model at their tile position
        for (int e = 0; e < this.enemyCharacters.Count; e++)
        {
            GameObject charModel = GameObject.Instantiate(this.enemyCharacters[e].charModels.charModel);

            CombatTile3D tile = CombatManager.globalReference.tileHandler.FindCharactersTile(this.enemyCharacters[e]);

            if (tile == null)
            {
                Debug.Log("Tile null");
            }
            else
            {
                charModel.transform.position = tile.gameObject.transform.position;
                this.enemyModels.Add(charModel);
                CombatManager.globalReference.tileHandler.FindCharactersTile(this.enemyCharacters[e]).SetObjectOnTile(charModel, TileObjectType.Enemy);
            }
        }
    }
Пример #6
0
    //Function called from AttackAction.PerformAction to show that an attack missed
    public void DisplayMissedAttack(float timeDelay_, CombatTile3D attackedCharTile_)
    {
        //Creating an instance of the damage text object prefab
        GameObject newDamageDisplay = GameObject.Instantiate(this.damageTextPrefab.gameObject);

        //Parenting the damage text object to this object's transform
        newDamageDisplay.transform.SetParent(this.transform);
        //Getting the DamageText component reference
        DamageText newDamageText = newDamageDisplay.GetComponent <DamageText>();

        //Setting the info for the text
        newDamageText.DisplayMiss(timeDelay_, attackedCharTile_.transform.position);
    }
Пример #7
0
    //Function called when the player's mouse starts hovering over this tile
    private void OnMouseEnter()
    {
        //Making sure the pointer isn't over a UI object
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            //Hilighting this tile's image
            this.HighlightTile(true);

            mouseOverTile = this;

            //Highlighting any effect radius if there's a selected attack ability
            this.HighlightEffectRadius(true);
        }
    }
Пример #8
0
    //Function called from CombatTile3D.cs to see if a specific tile is in the current movement path
    public bool IsTileInMovementPath(CombatTile3D tileToCheck_)
    {
        //Looping through each tile in the current movement path
        foreach (CombatTile3D ct in this.movementPath)
        {
            //Returns true if the current tile is the one we're looking for
            if (ct == tileToCheck_)
            {
                return(true);
            }
        }

        //If we make it through the loop, the tile we're looking for isn't in the movement path
        return(false);
    }
Пример #9
0
    //Function inherited from Action.cs
    public override void PerformAction(CombatTile3D targetTile_)
    {
        //Calling the base function to start the cooldown time
        base.PerformAction(targetTile_);

        //If the acting character is an enemy, we need to set the movement path since we're not mousing over tiles
        if (CombatManager.globalReference.characterHandler.enemyCharacters.Contains(this.actingCharacter))
        {
            this.movementPath = PathfindingAlgorithms.BreadthFirstSearchCombat(this.movementPath[0], targetTile_, true, true);
        }
        //Otherwise the movement path has already been set by our Update function ("else if" when this.moveCharacter is false)

        //Makes it so that the Update function will now move the character through the movement path
        this.moveCharacter        = true;
        this.currentNumTilesMoved = 0;
    }
Пример #10
0
    //Function called from AttackAction.PerformAction to show damage dealt to a character at the given tile
    public void DisplayDamageDealt(float timeDelay_, int damage_, DamageType type_, CombatTile3D damagedCharTile_, bool isCrit_, bool isHeal_ = false)
    {
        //If the damage dealt was 0, nothing happens
        if (damage_ <= 0)
        {
            return;
        }

        //Creating an instance of the damage text object prefab
        GameObject newDamageDisplay = GameObject.Instantiate(this.damageTextPrefab.gameObject);

        //Getting the DamageText component reference
        DamageDisplay newDamageText = newDamageDisplay.GetComponent <DamageDisplay>();

        //Setting the info for the text
        newDamageText.SetDamageToDisplay(timeDelay_, damage_, type_, damagedCharTile_.transform.position, isCrit_, isHeal_);

        //Updating the health bars so we can see how much health characters have
        this.uiHandler.UpdateHealthBars();
    }
    //Function called externally from CombatTile3D.cs. Adds a 3D combat tile to our combat tile grid at the row and column given
    public void AddCombatTileToGrid(CombatTile3D tileToAdd_, int row_, int col_)
    {
        //Making sure the row and column values are within bounds
        if (row_ < 0 || row_ > this.numRows)
        {
            return;
        }
        if (col_ < 0 || col_ > this.numCols)
        {
            return;
        }

        //Making sure a tile doesn't already exist in this location
        if (this.combatTileGrid[col_][row_] != null)
        {
            return;
        }

        //Setting the given tile to the correct row and column
        this.combatTileGrid[col_][row_] = tileToAdd_;
    }
Пример #12
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 DamageType.Slashing:
            if (targetCharacter_.charEquipment.totalSlashingArmor > 0)
            {
                totalDamage -= targetCharacter_.charEquipment.totalSlashingArmor;
            }
            break;

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

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

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

        case DamageType.Enchant:
            if (targetCharacter_.charEquipment.totalEnchantResist > 0)
            {
                totalDamage -= targetCharacter_.charEquipment.totalEnchantResist;
            }
            break;

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

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

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

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

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

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

        case DamageType.Stone:
            if (targetCharacter_.charEquipment.totalStoneResist > 0)
            {
                totalDamage -= targetCharacter_.charEquipment.totalStoneResist;
            }
            break;

        case DamageType.Bleed:
            if (targetCharacter_.charEquipment.totalBleedResist > 0)
            {
                totalDamage -= targetCharacter_.charEquipment.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
        CombatTile3D targetCharTile = CombatManager.globalReference.tileHandler.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
        GameObject targetCharModel = CombatManager.globalReference.characterHandler.GetCharacterModel(targetCharacter_);

        this.SpawnVisualAtLocation(targetCharModel.transform.localPosition, targetCharModel.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);
    }
Пример #13
0
    //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 DamageType.Slashing:
            if (targetCharacter_.charEquipment.totalSlashingArmor > 0)
            {
                totalHeal -= targetCharacter_.charEquipment.totalSlashingArmor;
            }
            break;

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

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

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

        case DamageType.Enchant:
            if (targetCharacter_.charEquipment.totalEnchantResist > 0)
            {
                totalHeal -= targetCharacter_.charEquipment.totalEnchantResist;
            }
            break;

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

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

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

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

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

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

        case DamageType.Stone:
            if (targetCharacter_.charEquipment.totalStoneResist > 0)
            {
                totalHeal -= targetCharacter_.charEquipment.totalStoneResist;
            }
            break;

        case DamageType.Bleed:
            if (targetCharacter_.charEquipment.totalBleedResist > 0)
            {
                totalHeal -= targetCharacter_.charEquipment.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
        CombatTile3D targetCharTile = CombatManager.globalReference.tileHandler.FindCharactersTile(targetCharacter_);

        //If the heal was negated completely
        if (magicResistType == SpellResistTypes.Negate)
        {
            //Telling the combat manager to display that no damage was healed
            CombatTile3D healedCharTile = CombatManager.globalReference.tileHandler.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
            CombatTile3D healedCharTile = CombatManager.globalReference.tileHandler.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
        GameObject targetCharModel = CombatManager.globalReference.characterHandler.GetCharacterModel(targetCharacter_);

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

        //Destroying this effect once everything is finished up
        Destroy(this.gameObject);
    }
Пример #14
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);
            }
        }
    }
 //Constructor function for this class
 public EnemyActionAndTile(Action enemyAct_, CombatTile3D targetTile_)
 {
     this.enemyActionToUse = enemyAct_;
     this.targetTile       = targetTile_;
 }
    //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();
            }
        }
    }
    //Pathfinding algorithm that uses Breadth First Search to check all directions equally. Returns the tile path taken to get to the target tile.
    public static List <CombatTile3D> BreadthFirstSearchCombat(CombatTile3D startingPoint_, CombatTile3D targetPoint_, bool avoidObjects_ = true, bool avoidCharacters_ = true)
    {
        //Creating the 2D list of tiles that will be returned
        List <CombatTile3D> tilePath = new List <CombatTile3D>();

        //The list of path points that make up the frontier
        List <CombatTile3D> frontier = new List <CombatTile3D>();

        //Adding the starting tile to the fronteir and making sure its previous point is cleared
        frontier.Add(startingPoint_);

        //The list of path points that have already been visited
        List <CombatTile3D> visitedPoints = new List <CombatTile3D>();

        visitedPoints.Add(startingPoint_);

        startingPoint_.prevTile       = null;
        startingPoint_.hasBeenChecked = true;

        //Loop through each path point until the frontier is empty
        while (frontier.Count != 0)
        {
            //Getting the reference to the next path point to check
            CombatTile3D currentPoint = frontier[0];

            //If the current point is the path point we're looking for
            if (currentPoint == targetPoint_)
            {
                //If the target tile has nothing on it
                if (currentPoint.typeOnTile == TileObjectType.Nothing)
                {
                    //Adding the current point's tile to the list of returned objects
                    tilePath.Add(currentPoint);
                }

                //Creating a variable to hold the reference to the previous point
                CombatTile3D prev = currentPoint.prevTile;

                //Looping through the trail of points back to the starting point
                while (true)
                {
                    //Adding the point's game object to the list of returned objects
                    tilePath.Add(prev);

                    //If the point isn't the starting point
                    if (prev != startingPoint_)
                    {
                        //Setting the previous point to the next point in the path
                        prev = prev.prevTile;
                    }
                    //If the point is the starting point
                    else
                    {
                        //We break out of the loop
                        break;
                    }
                }

                //Reversing the list of path points since it's currently backward
                tilePath.Reverse();

                //Exiting early since there's no reason to continue
                break;
            }
            //If the current point isn't the point we're looking for
            else
            {
                List <CombatTile3D> connectedTiles = new List <CombatTile3D>(4)
                {
                    currentPoint.left, currentPoint.right, currentPoint.up, currentPoint.down
                };
                //Looping through each path point that's connected to the current point
                foreach (CombatTile3D connection in connectedTiles)
                {
                    if (connection != null)
                    {
                        //If the connected point hasn't been visited yet
                        if (!connection.hasBeenChecked)
                        {
                            //Telling the connected point came from the current point we're checking
                            connection.prevTile = currentPoint;

                            CombatTile3D connectedCombatTile = connection.GetComponent <CombatTile3D>();
                            //If the connected tile isn't empty, we have to check it first
                            if (connectedCombatTile.typeOnTile != TileObjectType.Nothing)
                            {
                                //Making sure that this type of movement can safely travel across the type of object on the tile
                                if (connectedCombatTile == targetPoint_ ||
                                    (connectedCombatTile.typeOnTile == TileObjectType.Object && !avoidObjects_) ||
                                    (connectedCombatTile.typeOnTile == TileObjectType.Enemy && !avoidCharacters_) ||
                                    (connectedCombatTile.typeOnTile == TileObjectType.Player && !avoidCharacters_))
                                {
                                    //Adding the connected point to the frontier and list of visited tiles
                                    frontier.Add(connectedCombatTile);
                                }
                                else
                                {
                                    connectedCombatTile.prevTile       = null;
                                    connectedCombatTile.hasBeenChecked = true;
                                }
                            }
                            else
                            {
                                //Adding the connected point to the frontier and list of visited tiles
                                frontier.Add(connectedCombatTile);
                            }
                            visitedPoints.Add(connectedCombatTile);
                            //Marking the tile as already checked so that it isn't added again
                            connection.hasBeenChecked = true;
                        }
                    }
                }

                //Adding the current point to the list of visited points and removing it from the frontier
                frontier.Remove(currentPoint);
            }
        }

        //Looping through all path points in the list of visited points to clear their data
        foreach (CombatTile3D point in visitedPoints)
        {
            point.ClearPathfinding();
        }

        //Returning the completed list of tiles
        return(tilePath);
    }
    //Function called from CombatActionPanelUI.cs. Returns all combat tiles within the given range of the starting tile
    public static List <CombatTile3D> FindTilesInActionRange(CombatTile3D startingTile_, int actionRange_, bool includeObstacleTiles_ = true, bool includeCharacterTiles_ = true)
    {
        //The list of combat tiles that are returned
        List <CombatTile3D> allTilesInRange = new List <CombatTile3D>();

        //The list of each group of tiles in every range incriment. The index is the range
        List <List <CombatTile3D> > tilesInEachIncriment = new List <List <CombatTile3D> >();
        //Creating the first range incriment which always includes the starting tile
        List <CombatTile3D> range0 = new List <CombatTile3D>()
        {
            startingTile_
        };

        range0[0].hasBeenChecked = true;
        tilesInEachIncriment.Add(range0);

        for (int r = 1; r <= actionRange_; ++r)
        {
            //Creating a new list of tiles for this range incriment
            List <CombatTile3D> newRange = new List <CombatTile3D>();

            //Looping through each tile in the previous range
            foreach (CombatTile3D tile in tilesInEachIncriment[r - 1])
            {
                List <CombatTile3D> connectedTiles = new List <CombatTile3D>()
                {
                    tile.left, tile.right, tile.up, tile.down
                };

                //Looping through each tile connected to the one we're checking
                foreach (CombatTile3D connection in connectedTiles)
                {
                    //If the connected tile hasn't already been checked
                    if (connection != null && !connection.hasBeenChecked)
                    {
                        //If we ignore obstacles OR if the the tile doesn't have obstacles on it
                        if (connection.typeOnTile == TileObjectType.Nothing ||
                            (connection.typeOnTile == TileObjectType.Object && includeObstacleTiles_) ||
                            (connection.typeOnTile == TileObjectType.Player && includeCharacterTiles_) ||
                            (connection.typeOnTile == TileObjectType.Enemy && includeCharacterTiles_))
                        {
                            //Adding the connected tile to this new range and marking it as checked
                            newRange.Add(connection.GetComponent <CombatTile3D>());
                        }

                        connection.hasBeenChecked = true;
                    }
                }
            }

            //Adding this range incriment to the list
            tilesInEachIncriment.Add(newRange);
        }

        //Grouping all of the tiles into the list that is returned
        foreach (List <CombatTile3D> rangeList in tilesInEachIncriment)
        {
            foreach (CombatTile3D tile in rangeList)
            {
                allTilesInRange.Add(tile);
                //Resetting the tile to say it hasn't been checked
                tile.hasBeenChecked = false;
            }
        }

        return(allTilesInRange);
    }
Пример #19
0
 //Function that is overrided by inheriting classes and called from the CombatManager to use this ability
 public virtual void PerformAction(CombatTile3D targetTile_)
 {
     //Nothing here because the inheriting classes act differently
 }
Пример #20
0
    //Function called every frame
    private void Update()
    {
        //If we should be animating this character moving from tile to tile
        if (this.moveCharacter)
        {
            //Increasing the total time that's passed
            this.currentTimePassed += Time.deltaTime;

            GameObject charModel = CombatManager.globalReference.characterHandler.GetCharacterModel(this.actingCharacter);

            //If enough time has passed that we've moved one more tile further. We progress the acting character one more tile along the movement path
            if (this.currentTimePassed >= this.timeToCompleteAction)
            {
                //Increasing the index for the number of tiles moved
                this.currentNumTilesMoved += 1;

                //Resetting the current movement time
                this.currentTimePassed = 0;

                //Moving the character sprite to the new tile position
                charModel.transform.position = this.movementPath[this.currentNumTilesMoved].transform.position;

                //Removing the acting character from the tile they're on
                CombatManager.globalReference.tileHandler.combatTileGrid[this.actingCharacter.charCombatStats.gridPositionCol][this.actingCharacter.charCombatStats.gridPositionRow].SetObjectOnTile(null, TileObjectType.Nothing);

                //Once the time has passed for this tile, the selected character's position is updated
                this.actingCharacter.charCombatStats.gridPositionCol = this.movementPath[this.currentNumTilesMoved].col;
                this.actingCharacter.charCombatStats.gridPositionRow = this.movementPath[this.currentNumTilesMoved].row;
                CombatManager.globalReference.tileHandler.combatTileGrid[this.actingCharacter.charCombatStats.gridPositionCol][this.actingCharacter.charCombatStats.gridPositionRow].SetObjectOnTile(this.actingCharacter.gameObject, TileObjectType.Player);

                //Looping through and triggering all effects on the moving character that happen during movement
                foreach (Effect e in this.actingCharacter.charCombatStats.combatEffects)
                {
                    e.EffectOnMove();

                    //Checking to see if the acting character has died due to some effect
                    if (this.actingCharacter.GetComponent <PhysicalState>().currentHealth <= 0)
                    {
                        //Clearing the movement path tiles
                        for (int t = this.currentNumTilesMoved; t < this.movementPath.Count; ++t)
                        {
                            this.movementPath[t].SetTileColor(this.movementPath[t].unusedColor);
                        }
                        //This game object is destroyed
                        Destroy(this.gameObject);
                        break;
                    }
                }

                //If we've moved through all of the tiles on the movement path, this object is destroyed
                if (this.currentNumTilesMoved + 1 == this.movementPath.Count)
                {
                    //Setting the character's combat sprite to a stationary position directly on the last tile in our movement path
                    CombatManager.globalReference.characterHandler.GetCharacterModel(this.actingCharacter).transform.position = this.movementPath[this.movementPath.Count - 1].transform.position;

                    Destroy(this.gameObject);
                }
            }
            //Otherwise we interpolate the character's model to move between tiles
            else
            {
                //Interpolating this character model between the tiles they're moving from and moving to
                Vector3 startPos = this.movementPath[this.currentNumTilesMoved].transform.position;
                Vector3 endPos   = this.movementPath[this.currentNumTilesMoved + 1].transform.position;

                float   interpPercent = this.currentTimePassed / this.timeToCompleteAction;
                Vector3 interpPos     = (endPos - startPos) * interpPercent;
                interpPos += startPos;

                charModel.transform.position = interpPos;

                //Rotating the model to face the tile they're moving to
                Vector3 targetPos = this.movementPath[this.currentNumTilesMoved + 1].transform.position;
                targetPos.y = charModel.transform.position.y;
                charModel.transform.LookAt(targetPos);
            }
        }
        //If there are tiles in the movement path and the mouse is hovering over a combat tile
        else if (this.movementPath.Count > 0 && CombatTile3D.mouseOverTile != null)
        {
            CombatTile3D        lastPathTile   = this.movementPath[this.movementPath.Count - 1];
            List <CombatTile3D> connectedTiles = new List <CombatTile3D>()
            {
                lastPathTile.left, lastPathTile.right, lastPathTile.up, lastPathTile.down
            };

            //If the tile that the mouse is over is connected to the last tile in the current movement path
            if (connectedTiles.Contains(CombatTile3D.mouseOverTile) && this.movementPath.Count <= this.range)
            {
                //If the tile that the mouse is over isn't already in the movement path and this type of movement allows the user to ignore obstacles
                if (!this.movementPath.Contains(CombatTile3D.mouseOverTile))
                {
                    //If the tile has no object on it OR if there is an object and the movement action ignores objects
                    if (CombatTile3D.mouseOverTile.typeOnTile == TileObjectType.Nothing ||
                        (CombatTile3D.mouseOverTile.typeOnTile == TileObjectType.Object && this.ignoreObstacles) ||
                        ((CombatTile3D.mouseOverTile.typeOnTile == TileObjectType.Enemy || CombatTile3D.mouseOverTile.typeOnTile == TileObjectType.Player) && this.ignoreEnemies))
                    {
                        this.movementPath.Add(CombatTile3D.mouseOverTile);
                        CombatTile3D.mouseOverTile.HighlightTile(true, true);
                    }
                }
                //If the tile that the mouse is over IS already in the movement path and isn't the most recent tile
                else
                {
                    //Removing all tiles in the movement path that come after this one
                    int indexOfPrevTile = this.movementPath.IndexOf(CombatTile3D.mouseOverTile) + 1;
                    for (int t = indexOfPrevTile; t < this.movementPath.Count;)
                    {
                        this.movementPath[t].HighlightTile(false);
                        this.movementPath[t].SetTileColor(Color.white);

                        this.movementPath.RemoveAt(t);
                    }
                }
            }
            //If the tile that the mouse is over is NOT connected to the last tile in the current movement path but is still in the path
            else if (this.movementPath.Contains(CombatTile3D.mouseOverTile))
            {
                //Removing all tiles in the movement path that come after this one
                int indexOfPrevTile = this.movementPath.IndexOf(CombatTile3D.mouseOverTile) + 1;
                for (int t = indexOfPrevTile; t < this.movementPath.Count;)
                {
                    this.movementPath[t].HighlightTile(false);
                    this.movementPath[t].SetTileColor(Color.white);

                    this.movementPath.RemoveAt(t);
                }
            }
            //If the tile that the mouse is over is neither on the movement path or on a tile connected to it
            else
            {
                //Making sure the tile that the mouse is over is within this action's range
                if (CombatTile3D.mouseOverTile.inActionRange)
                {
                    //Looping through all of the tiles currently in the movement path and clearing them
                    for (int p = 1; p < this.movementPath.Count; ++p)
                    {
                        this.movementPath[p].HighlightTile(false);
                        this.movementPath[p].SetTileColor(Color.white);
                    }

                    //Use the breadth first search algorithm to find the path to this tile from the player
                    List <CombatTile3D> newPath = PathfindingAlgorithms.BreadthFirstSearchCombat(this.movementPath[0], CombatTile3D.mouseOverTile, this.ignoreObstacles, this.ignoreEnemies);
                    if (newPath.Count > 0)
                    {
                        this.movementPath = newPath;
                    }

                    //Looping through each tile that's now in the movement path and coloring it in
                    for (int t = 1; t < this.movementPath.Count; ++t)
                    {
                        this.movementPath[t].HighlightTile(true, true);
                    }
                }
            }
        }
    }
    //Function called externally from the buttons on the action panel. Tells the combat manager to hilight an action's range
    public void SelectActionAtIndex(int actionIndex_)
    {
        //Clearing all tile highlights before we highlight different ones
        CombatManager.globalReference.tileHandler.ClearTileHilights();

        //Getting a reference to the character that's currently acting
        Character actingCharacter = CombatManager.globalReference.initiativeHandler.actingCharacters[0];
        //Finding out which tile the acting character is on
        CombatTile3D actingCharsTile = CombatManager.globalReference.tileHandler.FindCharactersTile(actingCharacter);

        //If the currently selected action is a move action, we need to clear tile highlights along its movement path
        if (this.selectedAction != null && this.selectedAction.GetComponent <MoveAction>())
        {
            this.selectedAction.GetComponent <MoveAction>().ClearMovePathHighlights();
        }

        //Destroying the game object that holds the currently selected action
        if (this.selectedAction != null)
        {
            Destroy(this.selectedAction.gameObject);
        }

        //Creating an instance of the newly selected action prefab object
        GameObject actionObj = null;

        //Finding the range of the action based on the button hit
        int actionRange = 0;

        switch (this.actionTypeShown)
        {
        case ActionType.Major:
            actionRange = actingCharacter.charActionList.majorActions[actionIndex_].range;
            actionObj   = GameObject.Instantiate(actingCharacter.charActionList.majorActions[actionIndex_].gameObject);
            //this.selectedAction = actingCharacter.charActionList.standardActions[actionIndex_];
            break;

        case ActionType.Minor:
            actionRange = actingCharacter.charActionList.minorActions[actionIndex_].range;
            actionObj   = GameObject.Instantiate(actingCharacter.charActionList.minorActions[actionIndex_].gameObject);
            break;

        case ActionType.Fast:
            actionRange = actingCharacter.charActionList.fastActions[actionIndex_].range;
            actionObj   = GameObject.Instantiate(actingCharacter.charActionList.fastActions[actionIndex_].gameObject);
            break;

        case ActionType.Massive:
            actionRange = actingCharacter.charActionList.massiveActions[actionIndex_].range;
            actionObj   = GameObject.Instantiate(actingCharacter.charActionList.massiveActions[actionIndex_].gameObject);
            break;
        }

        //Getting the action component reference from the created action object
        this.selectedAction = actionObj.GetComponent <Action>();

        //Finding out which tiles need to be hilighted if this action isn't a move action
        List <CombatTile3D> tilesToHighlight;

        //List<CombatTile3D> tilesToCheckForCharacters = new List<CombatTile3D>();
        if (!this.selectedAction.GetComponent <MoveAction>())
        {
            tilesToHighlight = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange, false, true);
            //tilesToCheckForCharacters = tilesToHighlight;
        }
        //If this action is a move action, we have to find the selected tiles based on environment obstacles
        else
        {
            MoveAction ourMoveAct = this.selectedAction.GetComponent <MoveAction>();

            //Looping through all of the acting character's perks to see if there are any movement boost perks
            int rangeModifier = 0;
            foreach (Perk charPerk in actingCharacter.charPerks.allPerks)
            {
                //If the current perk is a movement boost perk that applies to this movement's action type, we apply the number of added spaces
                if (charPerk.GetType() == typeof(MovementBoostPerk) && ourMoveAct.type == charPerk.GetComponent <MovementBoostPerk>().actionTypeToBoost)
                {
                    rangeModifier += charPerk.GetComponent <MovementBoostPerk>().addedMovementSpaces;
                }
            }

            //Highlighting all tiles in range
            tilesToHighlight = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange + rangeModifier, ourMoveAct.ignoreObstacles, false);
            //Debug.Log("Getting tiles to check for characters");
            //tilesToCheckForCharacters = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange + rangeModifier + 1);
        }

        //Looping through all tiles in range and hilighting them
        foreach (CombatTile3D tile in tilesToHighlight)
        {
            tile.inActionRange = true;
            tile.HighlightTile(false);
        }

        //Displays the action's details
        this.UpdateActionDetailsPanel();
    }
Пример #22
0
 //Function called from PathfindingAlgorithms to clear the variables used in this class
 public void ClearPathfinding()
 {
     this.prevTile       = null;
     this.hasBeenChecked = false;
 }