Ejemplo n.º 1
0
        public static bool isPlayRuleOK(HREngine.Private.Rule rule, Playfield p)
        {
            bool       retval = true;
            RuleEntity entity = (RuleEntity)rule.Entity;
            RuleMethod method = (RuleMethod)rule.Method;

            // wrong target
            if (entity == RuleEntity.PlayerMinionField)
            {
                List <int> values = new List <int>();
                foreach (Minion m in p.ownMinions)
                {
                    if (method == RuleMethod.GetAttack)
                    {
                        values.Add(m.Angr);
                    }
                    if (method == RuleMethod.GetHealth)
                    {
                        values.Add(m.Hp);
                    }
                    if (method == RuleMethod.GetMana)
                    {
                        values.Add(m.Hp);
                    }
                }
            }

            if (entity == RuleEntity.EnemyMinionField)
            {
                return(false);
            }
            return(retval);
        }
Ejemplo n.º 2
0
 /**
  * To make it simple for the user, we can figure out the rule name
  * from the calling method or class
  */
 private string setMethodName(RuleMethod method, string ruleName)
 {
     /**
      * A Rule method may not be set in constructor, so it can be null
      */
     if (method != null)
     {
         // If no rule name, set the method name itself as the rule name
         if (ruleName == null)
         {
             return(method.GetMethodInfo().Name);
         }
     }
     else
     {
         /**
          * For classes implementing Rule, their ctor will call the Rule constructor
          * In which case the method will not be null, but .ctor
          *
          * In that case, find out the class name of the constructor and set it as ruleName
          */
         if (ruleName == null)
         {
             string name;
             int    m = 1;
             name = new StackFrame(1).GetMethod().DeclaringType.Name;
             while (name == "Rule")
             {
                 name = new StackFrame(++m).GetMethod().DeclaringType.Name;
             }
             return(name);
         }
     }
     return(ruleName);
 }
Ejemplo n.º 3
0
 internal void Add(RuleMethod rule)
 {
     Remove(rule);
     IsReadOnly = false;
     Add(new BrokenRule(rule));
     IsReadOnly = true;
 }
Ejemplo n.º 4
0
 internal void Remove(RuleMethod rule)
 {
     // we loop through using a numeric counter because
     // removing items within a foreach isn't reliable
     IsReadOnly = false;
     for (int index = 0; index < Count; index++)
     {
         if (this[index].RuleName == rule.RuleName)
         {
             RemoveAt(index);
             break;
         }
     }
     IsReadOnly = true;
 }
Ejemplo n.º 5
0
 /**
  * Remove Rule by method from the RulesList
  */
 public bool RemoveRule(RuleMethod ruleMethod)
 {
     return(1 == RulesList.RemoveAll(rule => rule.RuleMethod == ruleMethod));
 }
Ejemplo n.º 6
0
 /**
  * Spread parametrize constructor, making it easy for caller
  * so that they don't have to create an object of RuleAttributes just to create a rule
  */
 public Rule(RuleMethod ruleMethod = null, string ruleName = null, string ruleGroupName = "default", bool ruleEnabled = true, bool stopOnException = true, bool stopOnRuleFailure = false)
     : this(ruleMethod, new RuleAttributes(ruleName, ruleGroupName, ruleEnabled, stopOnException, stopOnRuleFailure))
 {
 }
Ejemplo n.º 7
0
 /**
  * Core constructor which takes method and attributes
  * Other constructors will call this
  */
 public Rule(RuleMethod method, RuleAttributes ruleAttributes)
 {
     RuleMethod          = method;
     ruleAttributes.Name = setMethodName(RuleMethod, ruleAttributes.Name);
     RuleAttributes      = ruleAttributes;
 }