Exemple #1
0
    public void Use(string charName) // creates function to handle item use
                                     // requires int of char index to use item on
    {
        //Debug.Log("Item.Use passed item = " + itemName); // prints passed item name to debug log

        CharStats selectedChar = GameMenu.instance.FindPlayerStats(charName);             // pulls reference to selected player stats by name
        int       charToUseOn  = BattleManager.instance.FindPlayerBattlerIndex(charName); // pulls reference to active battler player index by name
        int       charToEquip  = GameMenu.instance.FindPlayerIndex(charName);             // pulls character index in player stats array by name

        if (isItem)                                                                       // checks if item is of type item
        {
            if (affectLife)                                                               // checks if item affects Life status
            {
                if (BattleManager.instance.battleActive)                                  // checks if a battle is active
                {
                    if (BattleManager.instance.activeBattlers[charToUseOn].currentHP > 0) // checks if player is alive
                    {
                        warningText = selectedChar.charName + " is already alive!";       // sets max HP error notification
                        ShowWarning();                                                    // shows warning text
                    }
                    else
                    {
                        BattleManager.instance.activeBattlers[charToUseOn].currentHP += amountToChange;                                              // adds item value to battle char current HP

                        if (BattleManager.instance.activeBattlers[charToUseOn].currentHP > BattleManager.instance.activeBattlers[charToUseOn].maxHP) // checks if battle char current HP > max HP
                        {
                            BattleManager.instance.activeBattlers[charToUseOn].currentHP = BattleManager.instance.activeBattlers[charToUseOn].maxHP; // limits battle char current HP to max HP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
                else // executes if a battle is not active
                {
                    if (selectedChar.currentHP > 0) // checks if player is alive
                    {
                        warningText = selectedChar.charName + " is already alive!"; // sets max HP error notification
                        ShowWarning();                                              // shows warning text
                    }
                    else
                    {
                        // adds item value to selected char HP
                        selectedChar.currentHP += amountToChange;

                        if (selectedChar.currentHP > selectedChar.maxHP) // checks if char current HP has become larger than max HP
                        {
                            selectedChar.currentHP = selectedChar.maxHP; // limits char current HP to max HP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
            }

            else if (affectHP)                                                                                                                    // checks if item affects HP
            {
                if (BattleManager.instance.battleActive)                                                                                          // checks if a battle is active
                {
                    if (BattleManager.instance.activeBattlers[charToUseOn].currentHP == BattleManager.instance.activeBattlers[charToUseOn].maxHP) // checks if active battler current HP = max HP
                    {
                        warningText = selectedChar.charName + " already has maximum HP!";                                                         // sets max HP error notification
                        ShowWarning();                                                                                                            // shows warning text
                    }
                    else if (BattleManager.instance.activeBattlers[charToUseOn].currentHP <= 0)                                                   // checks if player is dead
                    {
                        warningText = selectedChar.charName + " must be revived first!";                                                          // sets dead player notification
                        ShowWarning();                                                                                                            // shows warning text
                    }
                    else
                    {
                        BattleManager.instance.activeBattlers[charToUseOn].currentHP += amountToChange;                                              // adds item value to battle char current HP

                        if (BattleManager.instance.activeBattlers[charToUseOn].currentHP > BattleManager.instance.activeBattlers[charToUseOn].maxHP) // checks if battle char current HP > max HP
                        {
                            BattleManager.instance.activeBattlers[charToUseOn].currentHP = BattleManager.instance.activeBattlers[charToUseOn].maxHP; // limits battle char current HP to max HP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
                else // executes if a battle is not active
                {
                    if (selectedChar.currentHP == selectedChar.maxHP) // checks if the player current HP = max HP
                    {
                        warningText = selectedChar.charName + " already has maximum HP!"; // sets max HP error notification
                        ShowWarning();                                                    // shows warning text
                    }
                    else if (selectedChar.currentHP <= 0)                                 // checks if player is dead
                    {
                        warningText = selectedChar.charName + " must be revived first!";  // sets dead player notification
                        ShowWarning();                                                    // shows warning text
                    }
                    else
                    {
                        // adds item value to selected char HP
                        selectedChar.currentHP += amountToChange;

                        if (selectedChar.currentHP > selectedChar.maxHP) // checks if char current HP has become larger than max HP
                        {
                            selectedChar.currentHP = selectedChar.maxHP; // limits char current HP to max HP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
            }

            else if (affectSP)                                                                                                                    // checks if item affects SP
            {
                if (BattleManager.instance.battleActive)                                                                                          // checks if a battle is active
                {
                    if (BattleManager.instance.activeBattlers[charToUseOn].currentSP == BattleManager.instance.activeBattlers[charToUseOn].maxSP) // checks if active battler current SP = max SP
                    {
                        warningText = selectedChar.charName + " already has maximum SP!";                                                         // sets max SP error notification
                        ShowWarning();                                                                                                            // shows warning text
                    }
                    else
                    {
                        BattleManager.instance.activeBattlers[charToUseOn].currentSP += amountToChange;                                              // adds item value to battle char current SP

                        if (BattleManager.instance.activeBattlers[charToUseOn].currentSP > BattleManager.instance.activeBattlers[charToUseOn].maxSP) // checks if battle char current SP > max SP
                        {
                            BattleManager.instance.activeBattlers[charToUseOn].currentSP = BattleManager.instance.activeBattlers[charToUseOn].maxSP; // limits battle char current SP to max SP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
                else // executes if a battle is not active
                {
                    if (selectedChar.currentSP == selectedChar.maxSP) // checks if the player current SP = max SP
                    {
                        warningText = selectedChar.charName + " already has maximum SP!"; // sets max SP error notification
                        ShowWarning();                                                    // shows warning text
                    }
                    else
                    {
                        // adds item value to selected char SP
                        selectedChar.currentSP += amountToChange;

                        if (selectedChar.currentSP > selectedChar.maxSP) // checks if char current SP has become larger than max SP
                        {
                            selectedChar.currentSP = selectedChar.maxSP; // limits char current SP to max SP
                        }

                        GameManager.instance.RemoveItem(itemName); // removes item from inventory
                    }
                }
            }
        }

        else if (isWeapon)                            // checks if item is of type weapon
        {
            if (selectedChar.equippedWpn == itemName) // checks if same weapon is already equipped
            {
                // displays error message, does not use item
                warningText = selectedChar.charName + " already has " + itemName + " equipped!"; // gives equip weapon warning
                ShowWarning();                                                                   // shows warning text
            }

            // NEED TO UPDATE CHARTOUSEON REFERENCES WITH CHARTOEQUIP
            else // executes if same weapon is not already equipped
            {
                if (selectedChar.equippedWpn != "") // checks if equipped weapon slot is not blank
                {
                    Unequip(selectedChar.equippedWpn, charToEquip);     // calls function to unequip current weapon

                    if (selectedChar.equippedOff != "" && isTwoHanded)  // checks if equipped offhand slot is not blank and weapon to equip is two-handed
                    {
                        Unequip(selectedChar.equippedOff, charToEquip); // calls function to unequip current offhand
                    }
                }
                else if (selectedChar.equippedOff != "")                // checks if equipped weapon is blank but offhand is not blank
                {
                    if (isTwoHanded)                                    // checks if item to equip is two-handed
                    {
                        Unequip(selectedChar.equippedOff, charToEquip); // calls function to unequip current offhand
                    }
                }

                Equip(itemName, charToEquip);         // calls function to equip new weapon

                selectedChar.CalculateDerivedStats(); // re-calculates new derived stats on character after equipping new weapon
            }
        }

        else if (isOffHand)                           // checks if item is of type offhand
        {
            if (selectedChar.equippedOff == itemName) // checks if same offhand item is already equipped
            {
                // displays error message, does not use item
                warningText = selectedChar.charName + " already has " + itemName + " equipped!"; // gives equip offhand warning
                ShowWarning();                                                                   // shows warning text
            }
            else // executes if same offhand is not already equipped
            {
                if (selectedChar.equippedWpn != "" && GameManager.instance.GetItemDetails(selectedChar.equippedWpn).isTwoHanded) // checks if equipped weapon is not blank and is two-handed
                {
                    Unequip(selectedChar.equippedWpn, charToEquip);                                                              // calls function to unequip current weapon
                }
                else if (selectedChar.equippedOff != "")                                                                         // checks if equipped offhand is not blank
                {
                    Unequip(selectedChar.equippedOff, charToEquip);                                                              // calls function to unequip current offhand
                }

                Equip(itemName, charToEquip);         // calls function to equip new offhand

                selectedChar.CalculateDerivedStats(); // re-calculates new derived stats on character after equipping new offhand
            }
        }

        else if (isArmor)                              // checks if item is of type armor
        {
            if (selectedChar.equippedArmr == itemName) // checks if same armor is already equipped
            {
                // displays error message, does not use item
                warningText = selectedChar.charName + " already has " + itemName + " equipped!"; // gives equip armor warning
                ShowWarning();                                                                   // shows warning text
            }
            else // executes if same armor is not already equipped
            {
                if (selectedChar.equippedArmr != "")                 // checks if equipped armor slot on selected character is blank
                {
                    Unequip(selectedChar.equippedArmr, charToEquip); // calls function to unequip current armor
                }

                Equip(itemName, charToEquip);         // calls function to equip new offhand

                selectedChar.CalculateDerivedStats(); // re-calculates new derived stats on character after equipping new armor
            }
        }

        else if (isAccy)                               // checks if item is of type accessory
        {
            if (selectedChar.equippedAccy == itemName) // checks if same accessory is already equipped
            {
                // displays error message, does not use item
                warningText = selectedChar.charName + " already has " + itemName + " equipped!"; // gives equip accessory warning
                ShowWarning();                                                                   // shows warning text
            }
            else // executes if same accessory is not already equipped
            {
                if (selectedChar.equippedAccy != "")                 // checks if equipped accessory slot on selected character is blank
                {
                    Unequip(selectedChar.equippedAccy, charToEquip); // calls function to unequip current accessory
                }

                Equip(itemName, charToEquip);         // calls function to equip new accessory

                selectedChar.CalculateDerivedStats(); // re-calculates new derived stats on character after equipping new accessory
            }
        }
    }