internal InventoryItemInstance(InventoryItemModel model, float condition, int quantity, bool equipped) { ItemModel = model; Condition = condition; Equipped = equipped; Quantity = quantity; }
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 InventoryItemInstance(InventoryItemModel model) { ItemModel = model; Condition = model.MaxCondition; Equipped = false; Quantity = 1; }
public InventoryItemInstance(InventoryItemModel model, long id, float condition, int quantity, bool equipped) { InstanceUID = id; ItemModel = model; Condition = condition; Equipped = equipped; Quantity = quantity; }
/// <summary> /// Gets the nice name of an item, or its plain name if the nice name isn't available /// </summary> public static string GetNiceName(InventoryItemModel item) { var def = GetDef(item.Name); if (def != null) { return(def.NiceName); } return(item.Name); }
//returns found instance public InventoryItemInstance TakeItem(InventoryItemModel item) { InventoryItemInstance foundInstance = FindItem(item); if (foundInstance == null) { return(null); } Items.Remove(foundInstance); return(foundInstance); }
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(); } int oldQuantity = Items[foundIndex].Quantity; Items[foundIndex].Quantity -= quantity; CallOnQuantityChanged(Items[foundIndex], oldQuantity); if (Items[foundIndex].Quantity == 0) { CallOnRemove(Items[foundIndex]); Items.RemoveAt(foundIndex); } } else { if (quantity > 1) { //TODO f**k this is horrible for (int j = 0; j < quantity; j++) { UseItem(item); } } else { CallOnRemove(Items[foundIndex]); Items.RemoveAt(foundIndex); } } } return(foundModel); }
/// <summary> /// Adds an inventory item model /// </summary> public static void AddModel(InventoryItemModel model, bool overwrite = false) { string name = model.Name; if (overwrite || !Models.ContainsKey(name)) { Models[name] = model; } else { throw new InvalidOperationException("A model by that name already exists"); } }
//this is arguably useless actually but I'm drunk and tired private InventoryItemInstance FindItem(InventoryItemModel item) { InventoryItemInstance foundInstance = null; foreach (InventoryItemInstance i in Items) { if (i.ItemModel == item) { foundInstance = i; break; } } return(foundInstance); }
public static InventoryItemInstance MakeItemInstance(SerializableItemInstance sItemInstance) { InventoryItemModel model = InventoryModel.GetModel(sItemInstance.ItemModel); if (model == null) { CDebug.LogEx(string.Format("Couldn't find model {0} for SerializableItemInstance", sItemInstance.ItemModel), LogLevel.Error, sItemInstance); return(null); } InventoryItemInstance rItemInstance = new InventoryItemInstance(model, sItemInstance.Condition, sItemInstance.Quantity, false); return(rItemInstance); }
public static EquipSlot GetItemSlot(InventoryItemModel item) { //LeftWeapon isn't actually supported if (item is WeaponItemModel) { return(EquipSlot.RightWeapon); } else if (item is ArmorItemModel aim) { return(aim.Slot); } else { return(EquipSlot.None); } }
public InventoryItemInstance(InventoryItemModel model, float condition, int quantity, bool equipped) : this(model, 0, condition, quantity, equipped) { var gameState = GameState.Instance; if (gameState != null) { //use GameState id counter InstanceUID = gameState.NextUID; } else { //use Time based id counter byte[] idBytes = BitConverter.GetBytes((ulong)DateTime.UtcNow.Ticks); idBytes[0] = (byte)(CoreUtils.Random.Next(byte.MinValue, byte.MaxValue)); InstanceUID = (long)BitConverter.ToUInt64(idBytes, 0); } }
private void AddItem(string item, int quantity, bool enforceQuantityLimit, out int quantityRemaining) { quantityRemaining = 0; if (quantity <= 0) { return; } InventoryItemModel mdl = Models[item]; enforceQuantityLimit &= mdl.MaxQuantity > 0; if (enforceQuantityLimit) { int quantityToAdd = Math.Min(quantity, mdl.MaxQuantity); quantityRemaining = quantity - quantityToAdd; quantity = quantityToAdd; } if (mdl.Stackable) { InventoryItemInstance instance = FindFirstItem(mdl.Name); if (instance == null) { instance = new InventoryItemInstance(mdl); Items.Add(instance); CallOnAdd(instance); instance.Quantity = 0; } int oldQuantity = instance.Quantity; instance.Quantity += quantity; CallOnQuantityChanged(instance, oldQuantity); } else { for (int i = 0; i < quantity; i++) { var instance = new InventoryItemInstance(mdl); Items.Add(instance); CallOnAdd(instance); } } }
public void AddItem(string item, int quantity) { if (quantity <= 0) { return; } 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 InventoryItemInstance(InventoryItemModel model) : this(model, model.MaxCondition, 1, false) { }
public InventoryItemInstance(InventoryItemModel model, float condition, int quantity, bool equipped) : this(model, 0, condition, quantity, equipped) { ResetUID(); }