/// <summary> /// Unequips an item and stores it in the inventory. /// </summary> /// <param name="slot"></param> public void Unequip(string slot) { // Hold the prior equipped item EquipmentItem priorEquipment = Slot[slot]; // 2H primary unequips the offhand as well if (Is2H && slot == "MainHand") { Toggle2H(); } // The actual slot unequip if (slot == "MainHand" || slot == "OffHand") { Slot[slot] = ItemDAO.CreateNewEquipmentItem("Bare Hand"); } else if (slot == "Body") { Slot[slot] = ItemDAO.CreateNewEquipmentItem("Naked"); } else if (slot.StartsWith("Charm")) { Slot[slot] = ItemDAO.CreateNewEquipmentItem("Unadorned"); } else { throw new ArgumentException("Tried to unequip an invalid slot."); } // Inventory handling post-unequip if ( // If the slot was empty priorEquipment.ItemName == "Bare Hand" || priorEquipment.ItemName == "Two-handing" || priorEquipment.ItemName == "Naked" || priorEquipment.ItemName == "Unadorned") { // Do nothing; } else { // Add item to the attached inventory. AttachedInventory.AddItem(priorEquipment); } }
/// <summary> /// Equips an item and moves prior equipped item to inventory. /// </summary> /// <param name="slot"></param> /// <param name="item"></param> public bool Equip(string slot, string itemName) { Item item; if (AttachedInventory.Contains(itemName)) { item = AttachedInventory.GetFirstItemInstance(itemName); } else { return(false); // can't equip an item that's not in the inventory } EquipmentItem equipmentItem = (EquipmentItem)item; if (equipmentItem.ValidSlots[slot] == true && MeetsItemReq(equipmentItem)) { EquipmentItem priorEquipment = Slot[slot]; // Hold the prior equipped item, AttachedInventory.RemoveItem(item); Slot[slot] = equipmentItem; // and equip the new item. // If the slot was empty, if (priorEquipment.EquipmentTags.Contains("None")) { RefreshHpSpOnEquip(priorEquipment, equipmentItem); return(true); // return true because the equip succeeded. } else // If the slot had equipment, { AttachedInventory.AddItem(equipmentItem); // add the prior item to the attached inventory RefreshHpSpOnEquip(priorEquipment, equipmentItem); return(true); // and return true because the equip succeeded. } } else // If invalid slot, non-equippable item, or broken equipment, { return(false); // don't equip the item, and return false because the equip failed. } }