Пример #1
0
 internal InventoryItemInstance(InventoryItemModel model, float condition, int quantity, bool equipped)
 {
     ItemModel = model;
     Condition = condition;
     Equipped  = equipped;
     Quantity  = quantity;
 }
Пример #2
0
        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);
        }
Пример #3
0
 public InventoryItemInstance(InventoryItemModel model)
 {
     ItemModel = model;
     Condition = model.MaxCondition;
     Equipped  = false;
     Quantity  = 1;
 }
Пример #4
0
 public InventoryItemInstance(InventoryItemModel model, long id, float condition, int quantity, bool equipped)
 {
     InstanceUID = id;
     ItemModel   = model;
     Condition   = condition;
     Equipped    = equipped;
     Quantity    = quantity;
 }
Пример #5
0
        /// <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);
        }
Пример #6
0
        //returns found instance
        public InventoryItemInstance TakeItem(InventoryItemModel item)
        {
            InventoryItemInstance foundInstance = FindItem(item);

            if (foundInstance == null)
            {
                return(null);
            }

            Items.Remove(foundInstance);
            return(foundInstance);
        }
Пример #7
0
        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);
        }
Пример #8
0
        /// <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");
            }
        }
Пример #9
0
        //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);
        }
Пример #10
0
        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);
        }
Пример #11
0
 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);
     }
 }
Пример #12
0
        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);
            }
        }
Пример #13
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);
                }
            }
        }
Пример #14
0
        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));
                }
            }
        }
Пример #15
0
 public InventoryItemInstance(InventoryItemModel model) : this(model, model.MaxCondition, 1, false)
 {
 }
Пример #16
0
 public InventoryItemInstance(InventoryItemModel model, float condition, int quantity, bool equipped) : this(model, 0, condition, quantity, equipped)
 {
     ResetUID();
 }