Esempio n. 1
0
        /// <summary>
        /// Add the provided amount to the <see cref="TradeskillMaterial"/> for the given Material ID
        /// </summary>
        /// <returns>Returns the remainder that could not be added.</returns>
        public uint AddAmount(ushort materialId, uint amount)
        {
            if (amount == 0)
            {
                throw new ArgumentException("amount must be more than 0");
            }

            TradeskillMaterialEntry entry = GameTableManager.Instance.TradeskillMaterial.GetEntry(materialId);

            if (entry == null || entry.Item2IdStatRevolution == 0)
            {
                throw new InvalidOperationException("TradeskillMaterialEntry does not exist.");
            }

            uint amountAdded;

            if (tradeskillMaterials.ContainsKey(materialId))
            {
                amountAdded = AddAmountToMaterial(materialId, amount);
            }
            else
            {
                tradeskillMaterials.Add(materialId, new TradeskillMaterial(player.CharacterId, materialId));
                amountAdded = AddAmountToMaterial(materialId, amount);
            }

            return(amountAdded);
        }
Esempio n. 2
0
        /// <summary>
        /// Add the provided amount to the <see cref="TradeskillMaterial"/> that is associated with the provided <see cref="Item"/>
        /// </summary>
        /// <returns>Returns the remainder that could not be added.</returns>
        public uint AddAmount(Item item, uint amount)
        {
            if (amount == 0)
            {
                throw new ArgumentException("amount must be more than 0.");
            }

            TradeskillMaterialEntry entry = GameTableManager.Instance.TradeskillMaterial.Entries.SingleOrDefault(i => i.Item2IdStatRevolution == item.Entry.Id);

            if (entry == null)
            {
                throw new InvalidOperationException("TradeskillMaterialEntry does not exist.");
            }

            ushort materialId  = (ushort)entry.Id;
            uint   amountAdded = 0;

            if (tradeskillMaterials.ContainsKey(materialId))
            {
                amountAdded = AddAmountToMaterial(materialId, amount);
            }
            else
            {
                tradeskillMaterials.Add(materialId, new TradeskillMaterial(player.CharacterId, materialId));
                amountAdded = AddAmountToMaterial(materialId, amount);
            }

            return(amountAdded);
        }
Esempio n. 3
0
        /// <summary>
        /// Remove the provided amount to the <see cref="TradeskillMaterial"/> that is associated with the provided <see cref="Item"/>
        /// </summary>
        public void RemoveAmount(Item item, uint amount)
        {
            TradeskillMaterialEntry entry = GameTableManager.Instance.TradeskillMaterial.Entries.SingleOrDefault(i => i.Item2IdStatRevolution == item.Entry.Id);

            if (entry == null)
            {
                throw new InvalidOperationException("TradeskillMaterialEntry does not exist.");
            }

            ushort materialId = (ushort)entry.Id;

            if (tradeskillMaterials.ContainsKey(materialId))
            {
                if (amount > tradeskillMaterials[materialId].Amount)
                {
                    return; // Swallow the issue for now.
                }
            }
            else
            {
                tradeskillMaterials.Add(materialId, new TradeskillMaterial(player.CharacterId, materialId));
            }

            RemoveAmount(materialId, amount);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns whether the <see cref="TradeskillMaterial"/> associated with the given <see cref="Item"/> is currently at its maximum amount
        /// </summary>
        public bool IsFull(Item item)
        {
            TradeskillMaterialEntry entry = GameTableManager.Instance.TradeskillMaterial.Entries.SingleOrDefault(i => i.Item2IdStatRevolution == item.Entry.Id);

            if (entry == null)
            {
                throw new InvalidOperationException("TradeskillMaterialEntry does not exist.");
            }

            return(IsFull((ushort)entry.Id));
        }