//Change the equipment based on index, called when changing the equipment in the menu public void ChangeEquipment(EquipmentScriptable equipment, int playerIndex, int equipmentIndex) { //First of all find the player switch (playerIndex) { case 0: //Find it's current equipment and unequip it inventory.FindAndSetEquipped(player1Equipment.GetType(equipmentIndex), false); player1Equipment.SetType(equipment, equipmentIndex); //Equip the new equipment break; case 1: //Same for all players inventory.FindAndSetEquipped(player2Equipment.GetType(equipmentIndex), false); player2Equipment.SetType(equipment, equipmentIndex); break; case 2: inventory.FindAndSetEquipped(player3Equipment.GetType(equipmentIndex), false); player3Equipment.SetType(equipment, equipmentIndex); break; case 3: inventory.FindAndSetEquipped(player4Equipment.GetType(equipmentIndex), false); player4Equipment.SetType(equipment, equipmentIndex); break; } //Recalculate the total equipment status CalculateEquipmentStatus(); ChangePlayerStatus(); ChangePlayerHealth(); //Change the players health inventory.FindAndSetEquipped(equipment, true); //Set the new equipment as equipped statusMenu.UpdateUI(); }
//Called by EquipmentHolder to set the equipped item, also called when changing equipment public void FindAndSetEquipped(EquipmentScriptable equipment, bool value) { for (int index = 0; index < equipments.Count; index++) { if (equipments[index].first == equipment) { equipments[index].second = value; } } }
//Used to set an equipment based on an index public void SetType(EquipmentScriptable equipment, int index) { switch (index) { case 0: weapon = equipment; break; case 1: head = equipment; break; case 2: chest = equipment; break; case 3: shoulder = equipment; break; case 4: arms = equipment; break; case 5: waist = equipment; break; case 6: legs = equipment; break; } }
//Update the UI that will show how much the currently focused equipment has (middle text in the status menu) private void UpdateEquipmentValue() { EquipmentScriptable aux = equipmentHolder.GetEquipment(selectedPlayerIndex, selectedEquipmentIndex); if (aux == null) { equipmentValueText[0].text = "(0)"; equipmentValueText[1].text = "(0)"; equipmentValueText[2].text = "(0)"; equipmentValueText[3].text = "(0)"; equipmentValueText[4].text = "(0)"; equipmentValueText[5].text = "(0)"; } else { equipmentValueText[0].text = "(" + aux.health + ")"; equipmentValueText[1].text = "(" + aux.defense + ")"; equipmentValueText[2].text = "(" + aux.speed + ")"; equipmentValueText[3].text = "(" + aux.strength + ")"; equipmentValueText[4].text = "(" + aux.intelligence + ")"; equipmentValueText[5].text = "(" + aux.dexterity + ")"; } }
//Add the equipment picked up on the map to the list public void AddEquipment(EquipmentScriptable equipment) { equipments.Add(new Pair <EquipmentScriptable, bool>(equipment, false)); }
//Update values for the change that the equipment that we are trying to change into will bring public void UpdateEquipmentSelectValueText(bool cond) { if (cond == false || eventSys.currentSelectedGameObject == null || eventSys.currentSelectedGameObject.GetComponent <EquipmentSlotHolder>() == null) { //Disable the text when closing the select equipment menu and on a few other cases equipmentSelectValueText[0].text = ""; equipmentSelectValueText[1].text = ""; equipmentSelectValueText[2].text = ""; equipmentSelectValueText[3].text = ""; equipmentSelectValueText[4].text = ""; equipmentSelectValueText[5].text = ""; } else if (eventSys.currentSelectedGameObject.GetComponent <EquipmentSlotHolder>().equipment == null) { EquipmentScriptable oldEquip = equipmentHolder.GetEquipment(selectedPlayerIndex, selectedEquipmentIndex); //If we are selecting the "none" option we will unequip the equipment so the status change will be 0 for everything equipmentSelectValueText[0].text = "(0)"; equipmentSelectValueText[1].text = "(0)"; equipmentSelectValueText[2].text = "(0)"; equipmentSelectValueText[3].text = "(0)"; equipmentSelectValueText[4].text = "(0)"; equipmentSelectValueText[5].text = "(0)"; if (oldEquip != null) { //This will make the text blue in case we had something equipped before ChangeEquipSelectColor(ref equipmentSelectValueText[0], 0, oldEquip.health); ChangeEquipSelectColor(ref equipmentSelectValueText[1], 0, oldEquip.defense); ChangeEquipSelectColor(ref equipmentSelectValueText[2], 0, oldEquip.speed); ChangeEquipSelectColor(ref equipmentSelectValueText[3], 0, oldEquip.strength); ChangeEquipSelectColor(ref equipmentSelectValueText[4], 0, oldEquip.intelligence); ChangeEquipSelectColor(ref equipmentSelectValueText[5], 0, oldEquip.dexterity); } else { //This will make the text it's default color in case we didn't have anything equipped before ChangeEquipSelectColor(ref equipmentSelectValueText[0], 0, 0); ChangeEquipSelectColor(ref equipmentSelectValueText[1], 0, 0); ChangeEquipSelectColor(ref equipmentSelectValueText[2], 0, 0); ChangeEquipSelectColor(ref equipmentSelectValueText[3], 0, 0); ChangeEquipSelectColor(ref equipmentSelectValueText[4], 0, 0); ChangeEquipSelectColor(ref equipmentSelectValueText[5], 0, 0); } } else { EquipmentScriptable newEquip = eventSys.currentSelectedGameObject.GetComponent <EquipmentSlotHolder>().equipment; EquipmentScriptable oldEquip = equipmentHolder.GetEquipment(selectedPlayerIndex, selectedEquipmentIndex); //Otherwise show the status change equipmentSelectValueText[0].text = "(" + newEquip.health + ")"; equipmentSelectValueText[1].text = "(" + newEquip.defense + ")"; equipmentSelectValueText[2].text = "(" + newEquip.speed + ")"; equipmentSelectValueText[3].text = "(" + newEquip.strength + ")"; equipmentSelectValueText[4].text = "(" + newEquip.intelligence + ")"; equipmentSelectValueText[5].text = "(" + newEquip.dexterity + ")"; //Based on the status change, change the color of the text to represent the change for every status int aux = 0; if (oldEquip != null) { aux = oldEquip.health; } ChangeEquipSelectColor(ref equipmentSelectValueText[0], newEquip.health, aux); aux = 0; if (oldEquip != null) { aux = oldEquip.defense; } ChangeEquipSelectColor(ref equipmentSelectValueText[1], newEquip.defense, aux); aux = 0; if (oldEquip != null) { aux = oldEquip.speed; } ChangeEquipSelectColor(ref equipmentSelectValueText[2], newEquip.speed, aux); aux = 0; if (oldEquip != null) { aux = oldEquip.strength; } ChangeEquipSelectColor(ref equipmentSelectValueText[3], newEquip.strength, aux); aux = 0; if (oldEquip != null) { aux = oldEquip.intelligence; } ChangeEquipSelectColor(ref equipmentSelectValueText[4], newEquip.intelligence, aux); aux = 0; if (oldEquip != null) { aux = oldEquip.dexterity; } ChangeEquipSelectColor(ref equipmentSelectValueText[5], newEquip.dexterity, aux); } }