MaximilianPs

QuestCondition (Condition.cs)

Sep 5th, 2022
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. [System.Serializable]
  2.     public class Condition
  3.     {
  4.         [SerializeField]
  5.         Disjunction[] and;
  6.  
  7.         public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
  8.         {
  9.             foreach (Disjunction dis in and)
  10.             {
  11.                 if (!dis.Check(evaluators))
  12.                 {
  13.                     return false;
  14.                 }
  15.             }
  16.             return true;
  17.         }
  18.  
  19.         [System.Serializable]
  20.         public class Disjunction
  21.         {
  22.             [SerializeField]
  23.             Predicate[] or;
  24.  
  25.             public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
  26.             {
  27.                 foreach (Predicate pred in or)
  28.                 {
  29.                     if (pred.Check(evaluators))
  30.                     {
  31.                         return true;
  32.                     }
  33.                 }
  34.                 return false;
  35.             }
  36.         }
  37.  
  38.         [System.Serializable]
  39.         public class Predicate
  40.         {
  41.             [SerializeField] EPredicate predicate;
  42.             [SerializeField] string[] parameters;
  43.             [SerializeField] bool negate = false;
  44.  
  45.             public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
  46.             {
  47.                 foreach (var evaluator in evaluators)
  48.                 {
  49.                     bool? result = evaluator.Evaluate(predicate, parameters);
  50.                    
  51.                     if (result == null) continue;
  52.                     if (result == negate) return false;
  53.                 }
  54.  
  55.                 return true;
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment