public void EquipItem(EquipableItem item, int indexFromInventory) { equippedItems.TryGetValue(item.GetAllowedEquipLocation(), out EquipableItem equippedItem); if (equippedItem) { equippedItems.Remove(item.GetAllowedEquipLocation()); } AddItemToEquipmentLocation(item.GetAllowedEquipLocation(), item); Inventory.GetPlayerInventory().FindSlotInInventory(indexFromInventory).RemoveItemFromSlot(1); //equipable items are not stackable, therefore we can remove just one. If this is not called from inventory, the index does not matter if (equippedItem) { Inventory.GetPlayerInventory().FindFirstEmptySlot().AddItemToSlot(equippedItem, 1); } if (equipmentUpdated != null) { Debug.Log("Got here in EquipItem!"); equipmentUpdated(); } }
///<summary> ///Places the parameter item in the location parameter ///<summary> public void AddItemToEquipmentLocation(EquipmentLocation loc, EquipableItem item) { Debug.Assert(item.GetAllowedEquipLocation() == loc); equippedItems[loc] = item; if (equipmentUpdated != null) { Debug.Log("Got here in AddItem in EquipItem!"); equipmentUpdated(); } }
/// <summary> /// Add an item to the given equip location. Do not attempt to equip to /// an incompatible slot. /// </summary> public void AddItem(EquipLocation slot, EquipableItem item) { if (_equippedItems == null || !_equippedItems.ContainsKey(slot)) { return; } Debug.Assert(item.GetAllowedEquipLocation() == slot); _equippedItems[slot] = item; var eventMediator = Object.FindObjectOfType <EventMediator>(); eventMediator.Broadcast(GlobalHelper.EquipmentUpdated, this); }
public int MaxAcceptable(InventoryItem item) { EquipableItem equipableItem = item as EquipableItem; if (equipableItem == null) { return(0); } if (equipableItem.GetAllowedEquipLocation() != equipmentLocation) { return(0); } if (GetItem() != null) { return(0); } return(1); }
private void EquipNewItem(EquipableItem equipableItem) { // Set up correct equipment reference Equipment equipment = null; if (equipableItem.IsPlayerEquipment()) { equipment = playerEquipment; } else { if (followerEquipment == null) { return; } equipment = followerEquipment; } int equipIndex = equipment.TryAddItem(equipableItem); if (equipIndex >= 0) { EquipLocation equipLocation = equipableItem.GetAllowedEquipLocation(); EquipableItem takebackItem = equipment.GetItemInSlot(equipLocation, equipIndex); RemoveItems(1); if (takebackItem != null) { equipment.RemoveItem(equipLocation, equipIndex); AddItems(takebackItem, 1, takebackItem.GetModifiers()); } equipment.AddItem(equipLocation, equipableItem, equipIndex, equipableItem.GetModifiers()); } }
public int MaxAcceptable(InventoryItem item) { //Is this an equippable item EquipableItem equipableItem = item as EquipableItem; if (equipableItem == null) { return(0); } //if the locations are different if (equipableItem.GetAllowedEquipLocation() != _equipLocation) { return(0); } //if we have no item if (GetItem() != null) { return(0); } return(1); }