public override void Mutate(State state) { var dump = DumpOperations .GroupBy(m => m.MaterialName) .ToDictionary(m => m.Key, m => m.First().Size); foreach (var item in state.Cargo.Ingredients.Where(item => ResetFilter.Contains(item.Value.Data.Kind)).ToList()) { var currentValue = item.Value.Count; if (dump.TryGetValue(item.Key, out var toSetValue)) { if (currentValue != toSetValue) { state.Cargo.IncrementCargo(item.Key, toSetValue - currentValue); } } else if (currentValue != 0) { state.Cargo.IncrementCargo(item.Key, -1 * currentValue); } } var names = state.Cargo.Ingredients.Keys.ToHashSet(); foreach (var item in DumpOperations.Where(op => !names.Contains(op.MaterialName))) { state.Cargo.IncrementCargo(item.MaterialName, item.Size); } }
public override void Mutate(State state) { var dump = DumpOperations.ToDictionary(m => m.MaterialName, m => m.Size); foreach (var item in state.Cargo.Where(item => ResetFilter.Contains(item.Value.Data.Kind)).ToList()) { var currentValue = item.Value.Count; int toSetValue; if (dump.TryGetValue(item.Key, out toSetValue)) { if (currentValue != toSetValue) { state.IncrementCargo(item.Key, toSetValue - currentValue); } } else if (currentValue != 0) { state.IncrementCargo(item.Key, -1 * currentValue); } } }