I’ve gone over the videos, and I’m still not grasping how to weald this code.
I’m trying to equip a weapon on pickup if we are unarmed. Or any equipment slot for that matter, auto equip empty equipment slots.
I’ve narrowed the process down to this function with the pseudo code that I want to do… this is in the inventory.cs… I have TODO in the summaries as well…
/// <summary> //TODO this is where it first looks for an inv slot, but if equip slot is null, don't bother
/// Attempt to add the items to the first available slot.
/// </summary> // TODO this is where we check if it is quippable and if so is that slot empty.. equip it
/// <param name="item">The item to add.</param>
/// <param name="number">The number to add.</param>
/// <returns>Whether or not the item could be added.</returns>
public bool AddToFirstEmptySlot(InventoryItem item, int number)
{
// TODO
// if this is an equippable item
// check if that equipment slot is null
// if so equip item
int i = FindSlot(item);
if (i < 0)
{
return false;
}
slots[i].item = item;
slots[i].number += number;
if (inventoryUpdated != null)
{
inventoryUpdated();
}
return true;
}
I’m fairly certain this is where I want to do this, but I’m open to suggestions if there is a better way…
I don’t know what to actually check to see if this is an equippable item… or how to gather if it’s a weapon or helm.
but I think I’ve also narrowed down where to do the checking and equipping from the Equipment.cs script…TODOs in the summaries
/// <summary>
/// Return the item in the given equip location. // TODO this is where we can check to equip on pickup
/// </summary>
public EquipableItem GetItemInSlot(EquipLocation equipLocation)
{
if (!equippedItems.ContainsKey(equipLocation))
{
return null;
}
return equippedItems[equipLocation];
}
/// <summary> // TODO this is where we can eqiup it on pickup if check is empty slot
/// 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)
{
Debug.Assert(item.GetAllowedEquipLocation() == slot);
equippedItems[slot] = item;
if (equipmentUpdated != null)
{
equipmentUpdated();
}
}
How do I check if an inventory item is equippable? I need to start there…