public void Execute(UnitActionCollection actionCollection) { foreach (var entry in actionCollection.Actions) { var guid = entry.Key; var action = entry.Value; var unit = State.FindObject(guid) as Unit; if (unit == null) { return; } //If the Unit is technically dead, we will skip it and it should be cleaned up for next round if (unit.ShouldRemove()) { continue; } if (!unit.CanAttemptAction(action)) { action = new NoopAction(); //Defaults to no-op } try { AttemptAction(unit, action); } catch (BadActionException ex) { Log.Error("Failed to execute action due to the following error: ", ex); throw; //TODO: Do we really want to throw errors here? Testing is easier, but that is all } } }
/// <summary> /// Add in the actions from the other collection to this collection. /// </summary> /// <param name="other"></param> /// <exception cref="ArgumentException">If there are any conflicting GUIDs /// (no check is made to determine if the action is the same)</exception> public void Merge(UnitActionCollection other) { foreach (var item in other.Actions) { var guid = item.Key; var action = item.Value; try { AddAction(guid, action); } catch (ArgumentException ex) { throw new ArgumentException($"Action already exists for {guid}", ex); } } }