Exemplo n.º 1
0
 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");
      *      }
      * }*/
 }
Exemplo n.º 2
0
 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");
     }
 }
 /// <summary>
 /// Crea una nuova istanza di TaskPerformerContext, associandovi l'istanza specificata di ITaskPerformer.
 /// </summary>
 /// <param name="performer">l'istanza di ITaskPerformer da associare a questo nuovo oggetto</param>
 /// <exception cref="ArgumentNullException">performer è null</exception>
 public TaskPerformerContext(ITaskPerformer performer)
 {
     if (performer == null)
     {
         throw new ArgumentNullException("performer");
     }
     m_TaskPerformer = performer;
 }
Exemplo n.º 4
0
    public void TestMatching(ITaskPerformer performer, ITaskAcceptor acceptor)
    {
        List <PerformerTask> matches = TaskMatcher.GetEnabled(performer, acceptor);

        foreach (PerformerTask m in matches)
        {
            Debug.Log(m);
        }
    }
        /// <summary>
        /// Aggiunge l'istanza specificata di ITaskPerformer a questo provider, restituendo true
        /// se l'operazione viene completata con successo, oppure false se in questo provider ne
        /// è già presente una avente stesso nome e stessa versione, o se quella specificata non
        /// è valida. Per poter essere considerata valida, l'istanza specificata non deve essere
        /// null e deve contenere un nome e una versione che non siano vuoti.
        /// </summary>
        /// <param name="classInstance">istanza di ITaskPerformer da aggiungere</param>
        /// <returns>true, se l'istanza è stata aggiunta al provider, false altrimenti</returns>
        public bool Add(ITaskPerformer classInstance)
        {
            bool isValidClass = true;
            isValidClass = isValidClass && classInstance != null;
            isValidClass = isValidClass && !string.IsNullOrEmpty(classInstance.Name);
            isValidClass = isValidClass && !string.IsNullOrEmpty(classInstance.Version);

            if (isValidClass)
            {
                String classId = GetClassIdentifier(classInstance.Name, classInstance.Version);
                if (!m_TaskPerformers.ContainsKey(classId))
                {
                    TaskPerformerContext context = new TaskPerformerContext(classInstance);
                    m_TaskPerformers.Add(classId, context);
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 6
0
    void Set()
    {
        title       = unit.Name;
        description = unit.Description;
        inventory   = unit.Inventory;
        ITaskPerformer performer = unit as ITaskPerformer;

        if (performer != null)
        {
            PerformableTasks = performer.PerformableTasks;
        }
        else
        {
            PerformableTasks = null;
        }
        if (contentUpdated != null)
        {
            contentUpdated();
        }
    }
Exemplo n.º 7
0
        /// <summary>
        /// Aggiunge l'istanza specificata di ITaskPerformer a questo provider, restituendo true
        /// se l'operazione viene completata con successo, oppure false se in questo provider ne
        /// è già presente una avente stesso nome e stessa versione, o se quella specificata non
        /// è valida. Per poter essere considerata valida, l'istanza specificata non deve essere
        /// null e deve contenere un nome e una versione che non siano vuoti.
        /// </summary>
        /// <param name="classInstance">istanza di ITaskPerformer da aggiungere</param>
        /// <returns>true, se l'istanza è stata aggiunta al provider, false altrimenti</returns>
        public bool Add(ITaskPerformer classInstance)
        {
            bool isValidClass = true;

            isValidClass = isValidClass && classInstance != null;
            isValidClass = isValidClass && !string.IsNullOrEmpty(classInstance.Name);
            isValidClass = isValidClass && !string.IsNullOrEmpty(classInstance.Version);

            if (isValidClass)
            {
                String classId = GetClassIdentifier(classInstance.Name, classInstance.Version);
                if (!m_TaskPerformers.ContainsKey(classId))
                {
                    TaskPerformerContext context = new TaskPerformerContext(classInstance);
                    m_TaskPerformers.Add(classId, context);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        // 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)));
        }
Exemplo n.º 9
0
        // 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);
        }
Exemplo n.º 10
0
 public TaskFinder(ITaskPerformer performer)
 {
     this.performer = performer;
 }
Exemplo n.º 11
0
 public PerformableTasks(ITaskPerformer performer)
 {
     this.performer = performer;
 }
Exemplo n.º 12
0
 public static List <PerformerTask> GetActive(ITaskPerformer performer, ITaskAcceptor acceptor)
 {
     return(GetMatching(performer.PerformableTasks.ActiveTasks, acceptor.AcceptableTasks.ActiveTasks));
 }
 /// <summary>
 /// Crea una nuova istanza di TaskPerformerContext, associandovi l'istanza specificata di ITaskPerformer.
 /// </summary>
 /// <param name="performer">l'istanza di ITaskPerformer da associare a questo nuovo oggetto</param>
 /// <exception cref="ArgumentNullException">performer è null</exception>
 public TaskPerformerContext(ITaskPerformer performer)
 {
     if (performer == null) { throw new ArgumentNullException("performer"); }
     m_TaskPerformer = performer;
 }