Last active
January 31, 2020 19:00
-
-
Save spaghettiSyntax/b85edb4c4dcddb6518ed55d3c596bbfe to your computer and use it in GitHub Desktop.
Item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Item : MonoBehaviour | |
{ | |
[Header("Item Type")] | |
public bool isItem; | |
public bool isWeapon; | |
public bool isArmor; | |
[Header("Item Details")] | |
public string itemName; | |
public string description; | |
public int value; | |
public Sprite itemSprite; | |
[Header("Item Details")] | |
public int amountToChange; | |
public bool affectHP; | |
public bool affectMP; | |
public bool affectStr; | |
public bool affectArm; | |
[Header("Weapon/Armor Details")] | |
public int weaponStrength; | |
public int armorStrength; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
public void Use(int charToUseOn) | |
{ | |
if (BattleManager._instance.battleActive) | |
{ | |
charToUseOn = BattleManager._instance.currentActiveBattler; | |
} | |
CharInfo selectedChar = GameManager._instance.charStats[charToUseOn]; | |
if (isItem) | |
{ | |
if (selectedChar.currentHP != selectedChar.maxHP) | |
{ | |
if (affectHP) | |
{ | |
selectedChar.currentHP += amountToChange; | |
if (selectedChar.currentHP > selectedChar.maxHP) | |
{ | |
selectedChar.currentHP = selectedChar.maxHP; | |
} | |
if (BattleManager._instance.battleActive) | |
{ | |
charToUseOn = BattleManager._instance.currentActiveBattler; | |
BattleManager._instance.activeBattler[charToUseOn].currentHP += amountToChange; | |
if (BattleManager._instance.activeBattler[charToUseOn].currentHP > selectedChar.maxHP) | |
{ | |
BattleManager._instance.activeBattler[charToUseOn].currentHP = selectedChar.maxHP; | |
} | |
} | |
GameManager._instance.RemoveItem(itemName); | |
} | |
} | |
if (selectedChar.currentMP != selectedChar.maxMP) | |
{ | |
if (affectMP) | |
{ | |
selectedChar.currentMP += amountToChange; | |
if (selectedChar.currentMP > selectedChar.maxMP) | |
{ | |
selectedChar.currentMP = selectedChar.maxMP; | |
} | |
if (BattleManager._instance.battleActive) | |
{ | |
charToUseOn = BattleManager._instance.currentActiveBattler; | |
BattleManager._instance.activeBattler[charToUseOn].currentMP += amountToChange; | |
if (BattleManager._instance.activeBattler[charToUseOn].currentMP > selectedChar.maxMP) | |
{ | |
BattleManager._instance.activeBattler[charToUseOn].currentMP = selectedChar.maxMP; | |
} | |
} | |
GameManager._instance.RemoveItem(itemName); | |
} | |
} | |
if (affectStr) | |
{ | |
selectedChar.strength += amountToChange; | |
GameManager._instance.RemoveItem(itemName); | |
} | |
} | |
if (isWeapon) | |
{ | |
if (selectedChar.equippedWeapon != "") | |
{ | |
GameManager._instance.AddItem(selectedChar.equippedWeapon); | |
} | |
selectedChar.equippedWeapon = itemName; | |
selectedChar.weaponPower = weaponStrength; | |
GameManager._instance.RemoveItem(itemName); | |
} | |
if (isArmor) | |
{ | |
if (selectedChar.equippedArmor != "") | |
{ | |
GameManager._instance.AddItem(selectedChar.equippedArmor); | |
} | |
selectedChar.equippedArmor = itemName; | |
selectedChar.armorPower = armorStrength; | |
GameManager._instance.RemoveItem(itemName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment