public void Equip(sEquippableItem _item) { if (inventory.RemoveItem(_item)) // if the item is able to be removed from the inventory { sEquippableItem previousItem; // reference for the previous item if (equipPanel.AddItem(_item, out previousItem)) // if we can add the item to the equipment panel { if (previousItem != null) // if there was an item in the equipment slot before adding this one { inventory.AddItem(previousItem); // add the previous item in the slot back in to the inventory previousItem.Unequip(this); statPanel.UpdateStatValues(); } _item.Equip(this); statPanel.UpdateStatValues(); } else { Debug.Log("Can not equip this item here!"); inventory.AddItem(_item); // if we can't add the item to an equipment slot, return it to the inventory } } }
private void Drop(ItemSlot _dropItemSlot) { if (draggedSlot == null) { return; } // Can the slot that we are dropping the item, recieve the item from the slot that started the drag // AND // Can the slot that started the drag recieve the item from the slot that we are dropping the item if (_dropItemSlot.CanRecieveItem(draggedSlot.Item) && draggedSlot.CanRecieveItem(_dropItemSlot.Item)) { sEquippableItem dragItem = draggedSlot.Item as sEquippableItem; sEquippableItem dropItem = _dropItemSlot.Item as sEquippableItem; // If we are dragging an item out of an equipment slot if (draggedSlot is EquipmentSlot) { // Unequip the drag item and equip the item in the drop slot if (dragItem != null) { dragItem.Unequip(this); } if (dropItem != null) { dropItem.Equip(this); } } if (_dropItemSlot is EquipmentSlot) { // Unequip the drop item and equip the item in the drag item if (dragItem != null) { dragItem.Equip(this); } if (dropItem != null) { dropItem.Unequip(this); } } // Update the stat panel //statPanel.UpdateStatValues(); sScrapItem draggedItem = draggedSlot.Item; draggedSlot.Item = _dropItemSlot.Item; if (draggedSlot as LootBoxSlot) { print("slot looted!"); } _dropItemSlot.Item = draggedItem; } }
private void Equip(ItemSlot _itemSlot) { // if the item in the selected equipment slot is an equippable item, equip it! sEquippableItem equippableItem = _itemSlot.Item as sEquippableItem; if (equippableItem != null) { Equip(equippableItem); itemTooltip.HideToolTip(); } }
public override bool CanRecieveItem(sScrapItem _item) { if (_item == null) { return(true); } // Check if the item we are trying to equip is an equippable item sEquippableItem equippableItem = _item as sEquippableItem; // And if it is an equippable item, check if the items equipment type corresponds to the slot equipment type return(equippableItem != null && equippableItem.equipType == equipType); }
public bool RemoveItem(sEquippableItem _item) { for (int i = 0; i < equipmentSlots.Length; i++) { if (equipmentSlots[i].equipType == _item.equipType) { equipmentSlots[i].Item = null; return(true); } } Debug.Log("No item to be removed!"); return(false); }
public void Unequip(sEquippableItem _item) { if (!inventory.IsFull() && equipPanel.RemoveItem(_item)) { _item.Unequip(this); statPanel.UpdateStatValues(); inventory.AddItem(_item); print("unequipped"); } else { Debug.Log("Can not unequip item! - inventory full!"); } }
private void HideTooltip(ItemSlot _itemSlot) { // if the item in the selected equipment slot is an equippable item, hide the tooltip! sEquippableItem equippableItem = _itemSlot.Item as sEquippableItem; sScrapItem scrapItem = _itemSlot.Item; if (equippableItem != null) { itemTooltip.HideToolTip(); } else if (scrapItem != null) { itemTooltip.HideToolTip(); } }
public bool AddItem(sEquippableItem _item, out sEquippableItem _previousItem) // out sends a reference out of the method { for (int i = 0; i < equipmentSlots.Length; i++) { if (equipmentSlots[i].equipType == _item.equipType) { _previousItem = (sEquippableItem)equipmentSlots[i].Item; equipmentSlots[i].Item = _item; return(true); } } Debug.Log("Item can not be equiped!"); _previousItem = null; return(false); }
private void ShowTooltip(ItemSlot _itemSlot) { Toolbox.GetInstance().GetAudioManager().PlayConsistentOneShot(hoverSound, hoverVolume); // if the item in the selected equipment slot is an equippable item, display the tooltip! sEquippableItem equippableItem = _itemSlot.Item as sEquippableItem; sScrapItem scrapItem = _itemSlot.Item; if (equippableItem != null) { itemTooltip.ShowEquipmentToolTip(equippableItem); } else if (scrapItem != null) { itemTooltip.ShowScrapToolTip(scrapItem); } }
private string GetStatModifiersText(CharacterStat _stat) { sb.Length = 0; foreach (StatModifier mod in _stat.StatModifiers) { if (sb.Length > 0) { sb.AppendLine(); } if (mod.Value > 0) { sb.Append("+"); } if (mod.Type == StatModType.Flat) { sb.Append(mod.Value); } else { sb.Append(mod.Value * 100); sb.Append("%"); } // Access the source variable // "as" keyword checks if the source variable is of type sEquippableItem, // if source IS an equippable item, convert it and assign it to the item variable, // if source is NOT an equippable item, it will assign a null to the item variable sEquippableItem item = mod.Source as sEquippableItem; if (item != null) // if item is of type sEquippableItem { sb.Append(" "); sb.Append(item.itemName); } else { Debug.LogError("Modifier is not an equippable item!"); } } return(sb.ToString()); }
private void Unequip(ItemSlot _itemSlot) { // if the item in the selected equipment slot is an equippable item, unequip it! sEquippableItem equippableItem = _itemSlot.Item as sEquippableItem; if (equippableItem != null) { Unequip(equippableItem); itemTooltip.HideToolTip(); // if the item is from a loot box, remove the item from inside it if (_itemSlot as LootBoxSlot) { _itemSlot.Item = null; } } }
public void ShowEquipmentToolTip(sEquippableItem _item) { itemNameText.text = _item.itemName; itemSlotText.text = _item.equipType.ToString(); sb.Length = 0; // Stat normal AddStat(_item.strengthBonus, "Strength", false); AddStat(_item.agilityBonus, "Agility", false); AddStat(_item.intellectBonus, "Intellect", false); AddStat(_item.vitalityBonus, "Vitality", false); // Stat percentages AddStat(_item.strengthPercentBonus, "Strength", true); AddStat(_item.agilityPercentBonus, "Agility", true); AddStat(_item.intellectPercentBonus, "Intellect", true); AddStat(_item.vitalityPercentBonus, "Vitality", true); itemStatsText.text = sb.ToString(); gameObject.SetActive(true); }