//method to remove an item stack if equipable //remove item stack as equipable and unequiped //call onstorage update for visuals public virtual void RemoveItemStack(Item item) { items.Remove(item); if (item is Equipable) { Equipable itemAsEquipable = item as Equipable; itemAsEquipable.Unequip(); } OnStorageUpdate(); }
void SwitchEquipable(Equipable equipable) { if (currEquip != null) { currEquip.Unequip(); } currEquip = equipable; if (equipable != null) { equipable.Equip(); } }
//method to add item back to inventory that isn't stacked //check if item is equipable, remove as unequiped //remove item from storage //call storage update to apply visuals public virtual void RemoveItem(Item item) { item.currentAmount--; if (item.currentAmount <= 0) { items.Remove(item); } if (item is Equipable) { Equipable itemAsEquipable = item as Equipable; itemAsEquipable.Unequip(); } OnStorageUpdate(); }
//method to handle item trasnfer from storage //declare item to be instantiated and set amount //if item is equipable, transfer item unequiped //call for remove item of item //call for onstorage update for visuals public virtual bool TransferItem(Item item, Storage anotherStorage) { Item itemToTransfer = Object.Instantiate(item); itemToTransfer.currentAmount = 1; bool itemTransferred = anotherStorage.AddItem(itemToTransfer); if (itemTransferred) { if (itemToTransfer is Equipable) { Equipable itemAsEquipable = itemToTransfer as Equipable; itemAsEquipable.Unequip(); } RemoveItem(item); OnStorageUpdate(); anotherStorage.OnStorageUpdate(); } return(itemTransferred); }