public InventoryItemObject Unequip(Item.EquipmentSlot eSlot, ref Attributes playerAttributes) { InventoryItemObject oldItem = null;// new InventoryItemObject(); // retrieve the slot that takes that type of item int slot = Convert.ToInt32(eSlot); if (_equipmentSlots[slot].GetItem() != null) { oldItem = _equipmentSlots[slot]?.GetInventoryItemObject(); } // retrieve the old stats and remove them from the attributes if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Weapon) { foreach (Weapon.Stat stat in (_equipmentSlots[slot].GetItem() as Weapon).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat); weapStat -= stat; playerAttributes.SetWeaponStat(weapStat); } } _equipmentSlots[slot].SetItemNull(); } else if (_equipmentSlots[slot].GetItem()?.GetItemType() == Item.ItemType.Armor) { foreach (Armor.Stat stat in (_equipmentSlots[slot].GetItem() as Armor).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.DecrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat); armorStat -= stat; playerAttributes.SetArmorStat(armorStat); } } _equipmentSlots[slot].SetItemNull(); } return(oldItem); }
public void Equip(InventoryItemObject item, ref Attributes playerAttributes) { Item.EquipmentSlot eSlot; Item newItem = item.GetItem(); if (newItem is Weapon) { eSlot = Item.EquipmentSlot.Weapon; } else { eSlot = ((Armor)item.GetItem()).GetEquipmentSlot(); } int slot = Convert.ToInt32(eSlot); InventoryItemObject oldItem = Unequip(eSlot, ref playerAttributes); // add the new stats if (item.GetItem()?.GetItemType() == Item.ItemType.Weapon) { foreach (Weapon.Stat stat in (item.GetItem() as Weapon).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Weapon.Stat weapStat = playerAttributes.GetWeaponStats().Find(x => x._stat == stat._stat); if (stat._flatValue) { weapStat += stat; } else { weapStat *= (1 + (stat._value / 100f)); } playerAttributes.SetWeaponStat(weapStat); } } } else if (item.GetItem()?.GetItemType() == Item.ItemType.Armor) { foreach (Armor.Stat stat in (item.GetItem() as Armor).GetStats()) { if (stat._isBasicStat) { string enumString = stat._stat.ToString(); Attributes.StatTypes statType = (Attributes.StatTypes)Enum.Parse(typeof(Attributes.StatTypes), enumString); playerAttributes.IncrementStat(new Attributes.Stat(statType, (int)stat._value)); } else { Armor.Stat armorStat = playerAttributes.GetArmorStats().Find(x => x._stat == stat._stat); if (stat._flatValue) { armorStat += stat; } else { armorStat *= (1 + (stat._value / 100f)); } playerAttributes.SetArmorStat(armorStat); } } } // equip it _equipmentSlots[slot].SetItem(item); item.SetEquipped(true); if (oldItem != null) { oldItem.SetEquipped(false); _player.GetInventory().AddExistingItem(oldItem); // put the old item back into the inventory } }