public void Remove(ClothingItem item) { Backpack.Remove(item); var slot = GetSlot(item); if (slot.Value == item) slot.Value = null; item.OnToggle -= Toggle; }
private EZData.VariableContext<ClothingItem> GetSlot(ClothingItem item) { switch(item.Slot) { case Slot.Shoulders: return ShouldersEzVariableContext; case Slot.Bracers: return BracersEzVariableContext; case Slot.Boots: return BootsEzVariableContext; } return null; }
public void Add(ClothingItem item) { item.OnToggle += Toggle; Backpack.Add(item); }
private void Toggle(ClothingItem item) { var slot = GetSlot(item); // find a slot corresponding to the item if (slot.Value == item) // if item is equipped { slot.Value = null; // remove it from slot Backpack.Add(item); // and put to backpack } else // otherwise if item is not equipped { if (slot.Value != null) Backpack.Add(slot.Value); // clear the slot if it was used Backpack.Remove(item); // take item from backpack slot.Value = item; // and put to the slot } }