/* * Creator: Yunzheng Zhou * Insert new potion into slot and interact with GUI * Parameter: slot - UIEquipSlot variable, * id - an int variable indicating the item id * testslot - Test_UIEquipSlot_Assign variable */ public void fillinPotionslot(UIEquipSlot slot, int id, Test_UIEquipSlot_Assign testslot) { for (int i = 0; i < 40; i++) { if (Inventory.instance.items[i].itemID == id) { Inventory.instance.setdefault(i); slot.Assign(itemdatabase.GetByID(id)); testslot.assignItem = id; InventoryGUI.instance.items[i] = id; InventoryGUI.instance.gameslot[i].GetComponent <UIItemSlot>().Assign(itemdatabase.GetByID(0)); InventoryGUI.instance.gameslot[i].GetComponent <Test_UIItemSlot_Assign>().assignItem = 0; return; } } testslot.assignItem = 0; slot.Assign(itemdatabase.GetByID(0)); for (int i = 0; i < 5; i++) { if (EquipmentManager.instance.potionSlot[i].GetComponent <Test_UIEquipSlot_Assign>().assignItem == 0) { EquipmentManager.instance.Potions[i] = null; } } }
/* * Creator: Yunzheng Zhou * Retrieve and use item from inventary slot. * Parameter: item - RaycastResult variable referencing mouse postion and action */ public void UseItem(RaycastResult item) // right click. Use this! { if (this is UIEquipSlot && (int)(this as UIEquipSlot).equipType != 9) { return; } UIItemSlot inventorySlot = item.gameObject.GetComponent <UIItemSlot>(); UIEquipSlot equipSlot = item.gameObject.GetComponent <UIEquipSlot>(); Test_UIItemSlot_Assign tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); Test_UIEquipSlot_Assign equipItem = item.gameObject.GetComponent <Test_UIEquipSlot_Assign>(); if (equipItem != null) { if (equipItem.assignItem == 0) { return; } } UIItemInfo inven; Item consumable; if (inventorySlot == null) { //equipSlot = item.gameObject.GetComponent<UIEquipSlot>(); //equipItem = item.gameObject.GetComponent<Test_UIEquipSlot_Assign>(); if (equipItem == null) { return; } consumable = backupitemDataBase.GetItem(equipItem.assignItem); inven = equipSlot.GetItemInfo(); } else //consumable { if (inventorySlot.isVendor) { return; } tmpItem = item.gameObject.GetComponent <Test_UIItemSlot_Assign>(); inven = inventorySlot.GetItemInfo(); consumable = backupitemDataBase.GetItem(tmpItem.assignItem); } if (consumable.isconsumable) { playSFX(onConsumeSFX); consumable.Use(); if (inventorySlot == null) { equipSlot.Assign(itemdatabase.GetByID(0)); fillinPotionslot(equipSlot, equipItem.assignItem, equipItem); return; } inventorySlot.Assign(itemdatabase.GetByID(0)); tmpItem.assignItem = 0; } else //equip { int i = (int)(itemdatabase.GetByID(tmpItem.assignItem).EquipType); if (i > 6 || i < 1) { //Debug.Log("find gem"); return; } //this.InternalHideTooltip(); UIEquipSlot EquipedSlot = EquipmentManager.instance.equipmentSlot[i].GetComponent <UIEquipSlot>(); //Debug.Log(EquipedSlot); UIItemInfo currentEquiped = EquipedSlot.GetItemInfo(); if (currentEquiped.EquipType == 0) { //tmpItem.assignItem = 10; playSFX(onEquipSFX); inventorySlot.Assign(EquipedSlot); if ((int)EquipedSlot.equipType == 1) { Player.instance.playerController.WeaponState = 1; } } else { playSFX(onEquipSFX); inventorySlot.Assign(currentEquiped); } int tmpID = currentEquiped.ID; Test_UIEquipSlot_Assign equipedItem = EquipmentManager.instance.equipmentSlot[i].GetComponent <Test_UIEquipSlot_Assign>(); equipedItem.assignItem = tmpItem.assignItem; equipedItem.itemDatabase = itemdatabase; //equipedItem.slot = EquipedSlot; EquipedSlot.Assign(inven); //equipedItem.slot.Assign(inven); //EquipedSlot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); //equipedItem.slot.Assign(itemdatabase.GetByID(equipedItem.assignItem)); tmpItem.assignItem = tmpID; Test_UIItemSlot_Assign inventoryitem = inventorySlot.GetComponent <Test_UIItemSlot_Assign>(); inventoryitem.assignItem = tmpID; //Inventory.instance.UpdateInventory(); for (int k = 4; k < 8; k++) { EquipmentManager.instance.EquipmentUpdate(k); } } }