public void SwitchEquipment(EquipmentClass switchNew, int selectedIndex) { if (inventoryList[selectedIndex].isEquipped) { return; } //First check if there is an exist equiped in slot playerCharStateScript = playerObj.GetComponent <CharacterState>(); int newEqpmIndex = BodypartClass.FindBodyPartIndex(switchNew.equipSlot); if (playerCharStateScript.characterBody[newEqpmIndex].bodySlot == switchNew.equipSlot) { // Will need to overwrite the currently equiped with new one EquipmentClass oldEquip = playerCharStateScript.characterBody[newEqpmIndex].secSlot[0]; playerCharStateScript.characterBody[newEqpmIndex].secSlot[0] = switchNew; playerCharStateScript.characterBody[newEqpmIndex].secSlot[0].currStatus = EquipmentClass.equipmentStatus.equipped; playerObj.GetComponent <CharacterAbillity>().AssignEquipAllRandom(true); EquipInventory(switchNew); //Place the old equip into inventory UnequipInventory(oldEquip); } }
bool CheckPickupAutoEquip(EquipmentClass eqpm) { BodypartClass.bodyPartsSlot pickupBodyPart = eqpm.equipSlot; int pickupIndex = BodypartClass.FindBodyPartIndex(eqpm.equipSlot); foreach (EquipmentClass e in playerObj.GetComponent <CharacterState>().characterBody[pickupIndex].secSlot) { if (e == GlobalSettings.DEFAULTEQUIPMENT) { return(true); } } return(false); }
private void EquipIntoSlot(int index, EquipmentClass content, bool isequippedItem) { //Assumed its empty, however will do a check if (inventoryList[index].isEmpty) { inventoryUI = inventoryParent.transform.GetChild(index).gameObject; inventoryList[index].isEmpty = false; inventoryList[index].isEquipped = isequippedItem; inventoryList[index].slotContent = content; inventoryList[index].contentName = content.eName; inventoryUI.transform.GetChild(0).GetComponent <Text>().text = content.eName; inventoryUI.GetComponent <Image>().color = isequippedItem? equippedColor:normalColor; if (isequippedItem) { if (content.currStatus == EquipmentClass.equipmentStatus.dropped) { int pickupIndex = BodypartClass.FindBodyPartIndex(content.equipSlot); int secSlotIndex = -1; for (int e = 0; e < playerObj.GetComponent <CharacterState>().characterBody[pickupIndex].secSlot.Count; e++) { if (playerObj.GetComponent <CharacterState>().characterBody[pickupIndex].secSlot[e] == GlobalSettings.DEFAULTEQUIPMENT) { secSlotIndex = e; } } playerObj.GetComponent <CharacterState>().characterBody[pickupIndex].secSlot[secSlotIndex] = content; playerObj.GetComponent <CharacterState>().characterBody[pickupIndex].secSlot[secSlotIndex].currStatus = EquipmentClass.equipmentStatus.equipped; } //WILL NEED TO CODE ADD BACK TO PLAYER BODY PART playerObj.GetComponent <CharacterAbillity>().AssignEquipAllRandom(true); } } else { Debug.Log("ERROR< SLOT NOT EMPTY"); return; } }
public void DropEquipment(InventoryClass dropSlot) { if (dropSlot.isEmpty) { return; } //Check whether is an equiped item if (dropSlot.slotContent.currStatus == EquipmentClass.equipmentStatus.equipped) { playerCharStateScript = playerObj.GetComponent <CharacterState>(); /////int dropEqpmIndex = System.Array.IndexOf(playerCharStateScript.characterBody, dropSlot.slotContent.equipSlot); int dropEqpmIndex = BodypartClass.FindBodyPartIndex(dropSlot.slotContent.equipSlot); if (dropEqpmIndex != -1) //Comfirm is an equipped item { if (playerCharStateScript.characterBody[dropEqpmIndex].priSlot == dropSlot.slotContent) { playerCharStateScript.characterBody[dropEqpmIndex].priSlot = GlobalSettings.DEFAULTEQUIPMENT; } else if (playerCharStateScript.characterBody[dropEqpmIndex].secSlot.Contains(dropSlot.slotContent)) { int removeIndex = playerCharStateScript.characterBody[dropEqpmIndex].secSlot.IndexOf(dropSlot.slotContent); playerCharStateScript.characterBody[dropEqpmIndex].secSlot[removeIndex] = GlobalSettings.DEFAULTEQUIPMENT; Debug.Log(GlobalSettings.DEFAULTEQUIPMENT); } } } //Now Drop a weapon Pickup GameObject newPickUP = Instantiate(PickUpPrefab, playerObj.transform.position + Vector3.right * 2f, Quaternion.identity); newPickUP.GetComponent <PickUpEquipment>().playerInventory = this; newPickUP.GetComponent <PickUpEquipment>().whichEquipment = dropSlot.slotContent; newPickUP.GetComponent <PickUpEquipment>().whichEquipment.currStatus = EquipmentClass.equipmentStatus.dropped; EmptySlot(dropSlot); }