Exemplo n.º 1
0
        public static ItemCountsAggregate operator -(ItemCountsAggregate value1, ItemCountsAggregate value2)
        {
            VRage.Exceptions.ThrowIf <ArgumentNullException>(value1 == null, "value1");
            VRage.Exceptions.ThrowIf <ArgumentNullException>(value2 == null, "value2");

            ItemCountsAggregate result = value1.Copy();

            foreach (var kvp in value2.Counts)
            {
                result.Counts[kvp.Key] = result.Get(kvp.Key) - kvp.Value;
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Consumes a given selection of items from managed inventories
        /// Adjusts the desired removal amount by how much we actually removed
        /// and returns it.
        /// </summary>
        public void Consume(ref ItemCountsAggregate toRemove, long consumerId = 0)
        {
            VRage.Exceptions.ThrowIf <ArgumentNullException>(toRemove == null, "toRemove");

            Log.Trace("toRemove: " + toRemove.ToString(), "Consume");

            var items = new List <MyDefinitionId>(toRemove.Counts.Keys);

            var inventories = new List <MyInventoryBase>(InventoryTotals.Keys);

            foreach (var item in items)
            {
                //remainingToRemove -= InventoryAggregate.RemoveItemsOfType(remainingToRemove, item);

                MyFixedPoint remainingToRemove = toRemove.Get(item);
                Log.Trace(String.Format("Looking to remove: {0} of {1}", remainingToRemove, item), "Consume");

                foreach (var inventory in inventories)
                {
                    if (remainingToRemove <= 0)
                    {
                        break;
                    }

                    MyFixedPoint amountAvailable = inventory.GetItemAmount(item);
                    if (amountAvailable <= 0)
                    {
                        continue;
                    }

                    MyFixedPoint amountRemoved = amountAvailable < remainingToRemove ?
                                                 amountAvailable : remainingToRemove;

                    Log.Trace(String.Format("Removing: {0} from {1}", amountRemoved, inventory.Entity.EntityId), "Consume");
                    SkipNextNotify = true;
                    inventory.RemoveItemsOfType(amountRemoved, item);
                    remainingToRemove -= amountRemoved;
                }

                toRemove.Set(item, remainingToRemove);
            }

            Log.Trace(String.Format("Remaining after attempted removals: {0}", toRemove.ToString()), "Consume");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Consumes a given selection of items from managed inventories
        /// Adjusts the desired removal amount by how much we actually removed
        /// and returns it.
        /// </summary>
        public void Consume(ref ItemCountsAggregate toRemove, long consumerId = 0)
        {
            VRage.Exceptions.ThrowIf<ArgumentNullException>(toRemove == null, "toRemove");

            Log.Trace("toRemove: " + toRemove.ToString(), "Consume");

            var items = new List<MyDefinitionId>(toRemove.Counts.Keys);

            var inventories = new List<MyInventoryBase>(InventoryTotals.Keys);

            foreach (var item in items) {

                //remainingToRemove -= InventoryAggregate.RemoveItemsOfType(remainingToRemove, item);

                MyFixedPoint remainingToRemove = toRemove.Get(item);
                Log.Trace(String.Format("Looking to remove: {0} of {1}", remainingToRemove, item), "Consume");

                foreach (var inventory in inventories) {
                    if (remainingToRemove <= 0) break;

                    MyFixedPoint amountAvailable = inventory.GetItemAmount(item);
                    if (amountAvailable <= 0) continue;

                    MyFixedPoint amountRemoved = amountAvailable < remainingToRemove ?
                        amountAvailable : remainingToRemove;

                    Log.Trace(String.Format("Removing: {0} from {1}", amountRemoved, inventory.Entity.EntityId), "Consume");
                    SkipNextNotify = true;
                    inventory.RemoveItemsOfType(amountRemoved, item);
                    remainingToRemove -= amountRemoved;
                }

                toRemove.Set(item, remainingToRemove);
            }

            Log.Trace(String.Format("Remaining after attempted removals: {0}", toRemove.ToString()), "Consume");
        }