public void TestBinding(ITaskPerformer performer, ITaskAcceptor acceptor, ITaskAcceptor acceptorPair) { /*MatchResult match = TaskMatcher.GetPerformable (performer, acceptor, acceptorPair); * if (match != null) { * Debug.Log (match.Match); * if (!match.NeedsPair) { * Debug.Log ("starting"); * match.Match.onComplete += (PerformerTask task) => { Debug.Log ("finished"); }; * match.Start (); * } else { * Debug.Log ("Needs pair of type " + match.PairType); * // TODO: Try to find a pair in the world * // if a pair was found, path to it * // else, perform the block below this one * } * } else { * match = TaskMatcher.GetPerformable (performer, acceptorPair, acceptor); * if (match == null) { * // Stop moving * Debug.Log ("stop moving"); * } else { * // Move to the acceptor pair * Debug.Log ("move to other point on path"); * } * }*/ }
public static List <PerformerTask> GetEnabled(ITaskPerformer performer, ITaskAcceptor acceptor) { try { return(GetMatching(performer.PerformableTasks.EnabledTasks, acceptor.AcceptableTasks.EnabledTasks)); } catch { throw new System.Exception("The ITaskPerformer " + performer + " or ITaskAcceptor " + acceptor + " is null"); } }
// Checks if the match exists on the given path element // Finding none, looks for any other matches public bool TaskFromMatch(PathElement elem, MatchResult match, out MatchResult result) { ITaskAcceptor acceptor = elem.Object as ITaskAcceptor; result = (match == null || acceptor == null) ? null : TaskMatcher.GetPerformable(match, performer, acceptor); return(result != null); }
// Finds a match on the given path element // (optional) if mustBeEnabled is false, also searches for disabled tasks public bool TaskFromPathElement(PathElement elem, out MatchResult result, bool mustBeEnabled = true) { ITaskAcceptor acceptor = elem.Object as ITaskAcceptor; result = (acceptor == null) ? null : TaskMatcher.GetPerformable(performer, acceptor, mustBeEnabled); return(result != null); }
public void TestMatching(ITaskPerformer performer, ITaskAcceptor acceptor) { List <PerformerTask> matches = TaskMatcher.GetEnabled(performer, acceptor); foreach (PerformerTask m in matches) { Debug.Log(m); } }
public static AcceptorTask GetAcceptor(PerformerTask task, ITaskAcceptor acceptor) { // TODO: linq foreach (var acceptorTask in acceptor.AcceptableTasks.EnabledTasks) { AcceptorTask a = acceptorTask.Value; if (task.GetType() == a.AcceptedTask) { return(a); } } return(null); }
public static AcceptorTask GetPair(PerformerTask task, ITaskAcceptor acceptor, bool mustBeEnabled = true) { // TODO: linq Dictionary <System.Type, AcceptorTask> tasks = mustBeEnabled ? acceptor.AcceptableTasks.EnabledTasks : acceptor.AcceptableTasks.ActiveTasks; foreach (var acceptorTask in tasks) { AcceptorTask a = acceptorTask.Value; if (a.GetType() == task.Settings.Pair) { return(a); } } return(null); }
// Returns a task for the for the performer to perform public static MatchResult GetPerformable(ITaskPerformer performer, ITaskAcceptor acceptor, bool mustBeEnabled = true) { List <PerformerTask> matches = mustBeEnabled ? GetEnabled(performer, acceptor) : GetActive(performer, acceptor); if (matches.Count == 0) { return(null); } // Prioritizes tasks that don't require a pair, or whose pair exists between the acceptors foreach (PerformerTask task in matches) { AcceptorTask acceptorTask = GetAcceptor(task, acceptor); if (task.Settings.Pair == null) { return(new MatchResult(task, false, acceptorTask)); } } return(new MatchResult(matches[0], true, GetAcceptor(matches[0], acceptor))); }
// Finds the nearest path element with the given task public bool NearestPathElementWithTask(PathElement origin, PerformerTask task, out PathElement destination) { System.Type taskType = task.GetType(); GridPoint point = ConnectionToPoint(origin); destination = Pathfinder.FindNearestPoint( point, (GridPoint p) => { if (TaskMatcher .GetEnabled(performer, p.Object as ITaskAcceptor) .Find(x => x.GetType() == taskType) != null) { return(true); } foreach (Connection c in p.Connections) { ITaskAcceptor acceptor = c.Object as ITaskAcceptor; if (acceptor == null) { continue; } if (TaskMatcher .GetEnabled(performer, acceptor) .Find(x => x.GetType() == taskType) != null) { return(true); } } return(false); } ); return(destination != null); }
public AcceptableTasks(ITaskAcceptor acceptor) { this.acceptor = acceptor; }
public static List <PerformerTask> GetActive(ITaskPerformer performer, ITaskAcceptor acceptor) { return(GetMatching(performer.PerformableTasks.ActiveTasks, acceptor.AcceptableTasks.ActiveTasks)); }
// Tries to find a pair for the provided match public static MatchResult GetPerformable(MatchResult match, ITaskPerformer performer, ITaskAcceptor acceptor) { if (match == null) { return(null); } AcceptorTask pair = GetPair(match.Match, acceptor); if (pair == null) { return(null); } foreach (PerformerTask performerTask in GetEnabled(performer, acceptor)) { if (pair.AcceptedTask == performerTask.GetType()) { return(new MatchResult(performerTask, true, pair)); } } return(null); }