public InventoryItemInstance(InventoryItemModel model) { ItemModel = model; Condition = model.MaxCondition; Equipped = false; Quantity = model.Stackable ? 1 : UnstackableQuantity; }
internal InventoryItemInstance(InventoryItemModel model, float condition, int quantity) { ItemModel = model; Condition = condition; Equipped = false; Quantity = quantity; }
public void AddItem(string item, int quantity) { InventoryItemModel mdl = Models[item]; if (mdl.Stackable) { InventoryItemInstance instance = null; foreach (InventoryItemInstance i in Items) { if (i.ItemModel.Name == mdl.Name) { instance = i; break; } } if (instance == null) { instance = new InventoryItemInstance(mdl); Items.Add(instance); instance.Quantity = 0; } instance.Quantity += quantity; } else { for (int i = 0; i < quantity; i++) { Items.Add(new InventoryItemInstance(mdl)); } } }
public InventoryItemModel UseItem(string item) { //search list for first instance int foundIndex = -1; InventoryItemModel foundModel = null; for (int i = 0; i < Items.Count; i++) { if (Items[i].ItemModel.Name == item) { foundIndex = i; foundModel = Items[i].ItemModel; break; } } if (foundIndex >= 0) { if (foundModel.Stackable) { Items[foundIndex].Quantity -= 1; if (Items[foundIndex].Quantity == 0) { Items.RemoveAt(foundIndex); } } else { Items.RemoveAt(foundIndex); } } return(foundModel); }
public InventoryItemModel UseItem(string item, int quantity) { int foundIndex = -1; InventoryItemModel foundModel = null; for (int i = 0; i < Items.Count; i++) { if (Items[i].ItemModel.Name == item) { foundIndex = i; foundModel = Items[i].ItemModel; break; } } if (foundIndex >= 0) { if (foundModel.Stackable) { if (Items[foundIndex].Quantity < quantity) { throw new InvalidOperationException(); } Items[foundIndex].Quantity -= quantity; if (Items[foundIndex].Quantity == 0) { Items.RemoveAt(foundIndex); } } else { if (quantity > 1) { //TODO f**k this is horrible for (int j = 0; j < quantity; j++) { UseItem(item); } } else { Items.RemoveAt(foundIndex); } } } return(foundModel); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return(null); } JObject jsonObject = JObject.Load(reader); float condition = jsonObject["Condition"].Value <float>(); string modelName = jsonObject["$ItemModel"].Value <string>(); int quantity = jsonObject["Quantity"].Value <int>(); InventoryItemModel model = InventoryModel.GetModel(modelName); return(new InventoryItemInstance(model, condition, quantity)); }