/* * public Dictionary<MyDefinitionId, MyFixedPoint> GetCounts() { * VRage.Exceptions.ThrowIf<FieldAccessException>(this.Counts == null, "this.Counts"); * * return new Dictionary<MyDefinitionId, MyFixedPoint>(Counts); * } */ public ItemCountsAggregate Copy() { //Log.Trace(String.Format("Copying {0}", this.ToString()), "Copy"); ItemCountsAggregate result = new ItemCountsAggregate(); foreach (var kvp in this.Counts) { result.Set(kvp.Key, kvp.Value); } //Log.Trace("Returning result", "Copy"); return(result); }
/// <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"); }
/// <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"); }
/* public Dictionary<MyDefinitionId, MyFixedPoint> GetCounts() { VRage.Exceptions.ThrowIf<FieldAccessException>(this.Counts == null, "this.Counts"); return new Dictionary<MyDefinitionId, MyFixedPoint>(Counts); } */ public ItemCountsAggregate Copy() { //Log.Trace(String.Format("Copying {0}", this.ToString()), "Copy"); ItemCountsAggregate result = new ItemCountsAggregate(); foreach (var kvp in this.Counts) result.Set(kvp.Key, kvp.Value); //Log.Trace("Returning result", "Copy"); return result; }