public void Equip(Equippable pItem) { //Try removing the item from inventory if (_inventory.RemoveItem(pItem)) { //Add it to the equipment panel Equippable previousItem; if (_equipmentPanel.AddItem(pItem, out previousItem)) { //If the slot was already taken, return the other item in the inventory if (previousItem != null) { previousItem.Unequip(this); _statsPanel.UpdateStatValues(); _inventory.AddItem(previousItem); } pItem.Equip(this); _statsPanel.UpdateStatValues(); } else { //If for some reason the item couldn't be equipped return it back in the inventory _inventory.AddItem(pItem); } } }
public void UseEquippable(Equippable equippable) { for (int i = 0; i < equippables.Length; i++) { if (equipped[(int)equippable.type] == null) { equipped[(int)equippable.type] = equippable; equippables[i] = null; equippable.Equip(); } else { equipped[(int)equippable.type].Unequip(); equippables[i] = equipped[(int)equippable.type]; equipped[(int)equippable.type] = equippable; equippable.Equip(); } } }
public bool ApplyDrop(Item item) { bool result = false; Equippable equip = item.prefab.GetComponent <Equippable>(); if (equip) { inv.RemoveItem(item); Equippable equipInstance = Instantiate(item.prefab).GetComponent <Equippable>(); equipInstance.Equip(rend); result = true; } return(result); }
private void Drop(ItemSlot pDropItemSlot) { if (_draggedSlot == null || pDropItemSlot == null) { return; } if (pDropItemSlot.CanReceiveItem(_draggedSlot.Item) && _draggedSlot.CanReceiveItem(pDropItemSlot.Item)) { Equippable dragItem = _draggedSlot.Item as Equippable; Equippable dropItem = pDropItemSlot.Item as Equippable; EquipmentSlot esDrag = _draggedSlot as EquipmentSlot; EquipmentSlot esDrop = pDropItemSlot as EquipmentSlot; if (_draggedSlot is EquipmentSlot) { if (dragItem != null) { dragItem.Unequip(this); if (esDrag.EquipmentType == EquipmentType.Gloves) { _equipmentPanel.EquipmentSlots[3].Item = null; _equipmentPanel.EquipmentSlots[3].Amount = 0; } else if (esDrag.EquipmentType == EquipmentType.Gloves1) { _equipmentPanel.EquipmentSlots[2].Item = null; _equipmentPanel.EquipmentSlots[2].Amount = 0; } } if (dropItem != null) { dropItem.Equip(this); if (dropItem.ItemType == EquipmentType.Gloves) { if (esDrag.EquipmentType == EquipmentType.Gloves) { _equipmentPanel.EquipmentSlots[3].Item = dropItem; _equipmentPanel.EquipmentSlots[3].Amount = 1; } else if (esDrag.EquipmentType == EquipmentType.Gloves1) { _equipmentPanel.EquipmentSlots[2].Item = dropItem; _equipmentPanel.EquipmentSlots[2].Amount = 1; } } } } if (pDropItemSlot is EquipmentSlot) { if (!(_draggedSlot is ShopItemSlot)) { if (dropItem != null) { dropItem.Unequip(this); if (esDrop.EquipmentType == EquipmentType.Gloves) { _equipmentPanel.EquipmentSlots[3].Item = null; _equipmentPanel.EquipmentSlots[3].Amount = 0; } else if (esDrop.EquipmentType == EquipmentType.Gloves1) { _equipmentPanel.EquipmentSlots[2].Item = null; _equipmentPanel.EquipmentSlots[2].Amount = 0; } } if (dragItem != null) { dragItem.Equip(this); if (dragItem.ItemType == EquipmentType.Gloves) { if (esDrop.EquipmentType == EquipmentType.Gloves) { _equipmentPanel.EquipmentSlots[3].Item = dragItem; _equipmentPanel.EquipmentSlots[3].Amount = 1; } else if (esDrop.EquipmentType == EquipmentType.Gloves1) { _equipmentPanel.EquipmentSlots[2].Item = dragItem; _equipmentPanel.EquipmentSlots[2].Amount = 1; } } } } else { GameController.errorMessage.AddMessage("Can't do that!"); } } _statsPanel.UpdateStatValues(); if (_draggedSlot is ShopItemSlot) { if (!(pDropItemSlot is ShopItemSlot)) { if (!(pDropItemSlot is EquipmentSlot)) { if (!_shopInventory.IsFull()) { if (DragToBuy(_draggedSlot)) { if (DragToSell(pDropItemSlot.Item, pDropItemSlot)) { SwapItemes(pDropItemSlot); } } } else { if (pDropItemSlot.Item == null && DragToBuy(_draggedSlot)) { SwapItemes(pDropItemSlot); } } } } else { SwapItemes(pDropItemSlot); } } else if (pDropItemSlot is ShopItemSlot) { if (DragToSell(_draggedSlot.Item, _draggedSlot)) { if (DragToBuy(pDropItemSlot)) { SwapItemes(pDropItemSlot); } else if (pDropItemSlot.Item == null) { SwapItemes(pDropItemSlot); } } } else { SwapItemes(pDropItemSlot); } } else { if (pDropItemSlot is EquipmentSlot) { GameController.errorMessage.AddMessage("Item cannot be equipped in this slot!"); } else if (pDropItemSlot is ShopItemSlot) { GameController.errorMessage.AddMessage("Shop is full"); } else { GameController.errorMessage.AddMessage("Inventory is full"); } } }