public InventorySet Negate() { var Result = new InventorySet(); foreach (var v in this) { Result.Add(v.Key, -v.Value); } return(Result); }
public bool ExactlyEquals(InventorySet other) { foreach (var key in Keys.Union(other.Keys)) { // No match if either set is missing the key // or if the values don't match if (!Keys.Contains(key) || !other.Keys.Contains(key) || this[key] != other[key]) { return(false); } } return(true); }
public static InventorySet operator +(InventorySet left, KeyValuePair <string, int> right) { var Result = new InventorySet(left); if (left.ContainsKey(right.Key)) { Result[right.Key] += right.Value; } else { Result.Add(right.Key, right.Value); } return(Result); }
public static InventorySet operator +(InventorySet left, InventorySet right) { var Result = new InventorySet(); // Join together the set of keys from both and loop over them foreach (var key in left.Keys.Union(right.Keys)) { var lHas = left.ContainsKey(key); var rHas = right.ContainsKey(key); if (lHas) { Result.AddMat(key, left[key]); } if (rHas) { Result.AddMat(key, right[key]); } } return(Result); }