Finished the money pickups lecture and Sam mentioned using it for weapons and consumables and I just had to do it.
I found the weapon equipping pretty straightforward as compared to the actionbar stuff which I had to puzzle out but it’s working ok so far. I’m definitely missing something where you pick up several of the same item that aren’t stackable on the action bar but I’m guessing you can just design the game drops to not work like that so that wouldn’t be an issue. Can’t think of anything off the top of my head that wouldn’t be stackable that you’d want multiples of, in that slot at least.
I’m not sure how to have the item you bring in change types other than casting it as a new item so that’s what I did.
Implementation in Equipment.cs for auto equip gear
public int AddItems(InventoryItem item, int number)
{
if (item is EquipableItem)
{
EquipableItem newItem = (EquipableItem)item;
EquipLocation location = newItem.GetAllowedEquipLocation();
if (GetItemInSlot(location) == null)
{
AddItem(location, newItem);
return 1;
}
}
return 0;
}
Implementation in ActionStore.cs for auto adding to action bar
public int AddItems(InventoryItem item, int number)
{
if (item is ActionItem)
{
ActionItem newItem = (ActionItem)item;
foreach (var dockedItem in dockedItems)
{
if (dockedItem.Value.item == newItem && newItem.IsStackable())
{
AddAction(newItem, dockedItem.Key, number);
return number;
}
else if (dockedItem.Value.item == newItem && !newItem.IsStackable())
{
return 0;
}
}
for (int i = 0; i < 5; i++)
{
if (!dockedItems.ContainsKey(i))
{
AddAction(newItem, i, number);
return number;
}
}
}
return 0;
}
I’m still just a beginner but this is the way I figured it out. Foreach the dictionary to see if it contains the item and if it’s stackable, then add the item to the stack. If it’s not stackable but on the bar already, add the extra to the inventory.
Then if it hasn’t found the item, go through each slot looking and add it to the first empty slot. I don’t like having to hardcode the slot limit but I don’t think that limit actually exists other than by the final actionslot item in the UI setting it as 5. So it is what it is I guess.
Anyways, take a look and tell me what you think.