コード例 #1
0
        public override void Evaluate(T ruleContext, RuleStack stack)
        {
            var predicate = GetPredicate(ruleContext);

            if (predicate == null)
            {
                this.ApplyFilter(ruleContext, (Expression <Func <IndexedContact, bool> >)(c => false));
                stack.Push(false);
                return;
            }

            this.ApplyFilter(ruleContext, predicate);
            stack.Push(true);
        }
コード例 #2
0
        public override void Evaluate([CanBeNull] object parameter, [NotNull] RuleStack stack)
        {
            Assert.ArgumentNotNull(stack, nameof(stack));

            Operand.Evaluate(parameter, stack);

            var result = (bool)stack.Pop();

            stack.Push(!result);
        }
コード例 #3
0
        public override void Evaluate(T ruleContext, RuleStack stack)
        {
            var condition = GetCondition(ruleContext, stack);

            if (condition == null)
            {
                stack.Push(false);
                return;
            }
            condition.UniqueId = this.UniqueId;
            condition.Evaluate(ruleContext, stack);
        }
コード例 #4
0
        public override void Evaluate([CanBeNull] object parameter, [NotNull] RuleStack stack)
        {
            Assert.ArgumentNotNull(stack, nameof(stack));

            LeftOperand.Evaluate(parameter, stack);

            var left = (bool)stack.Pop();

            if (!left)
            {
                stack.Push(false);
                return;
            }

            RightOperand.Evaluate(parameter, stack);
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: saywordsahn/dominion
        public void StartTurn(Game game)
        {
            foreach (var card in PlayedCards)
            {
                if (card.Card is IDuration d)
                {
                    d.NumberOfTurnsActive++;
                    foreach (var ability in d.GetOnTurnStartAbilities(d.NumberOfTurnsActive))
                    {
                        RuleStack.Push(ability);
                    }
                }
            }
            NumberOfActions = 1;
            NumberOfBuys    = 1;
            MoneyPlayed     = 0;

            PlayStatus = HasActionInHand() ? PlayStatus.ActionPhase : PlayStatus.BuyPhase;
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: saywordsahn/dominion
        //this may need to be updated for future triggered abilities
        //this only works for simple triggered abilities
        public void RunTriggeredAbilities(PlayerAction playerAction, Card card)
        {
            foreach (var triggeredAbility in TriggeredAbilities.ToList())
            {
                if (triggeredAbility.Trigger.IsMet(playerAction, card))
                {
                    if (triggeredAbility.TriggeredAbilityDurationType != TriggeredAbilityDurationType.Once)
                    {
                        triggeredAbility.Ability.Resolved = false;
                    }

                    RuleStack.Push(triggeredAbility.Ability);

                    //we may not need this since resolved abilities won't play 2 times anyway
//                    if (triggeredAbility.TriggeredAbilityDurationType == TriggeredAbilityDurationType.Once)
//                    {
//                        TriggeredAbilities.Remove(triggeredAbility);
//                    }
                }
            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: saywordsahn/dominion
 public void EndTurn()
 {
     RuleStack.Push(new EndTurn());
 }
コード例 #8
0
ファイル: Player.cs プロジェクト: saywordsahn/dominion
 public void SetAttacked(Game game, IAttackEffect attackEffect)
 {
     RuleStack.Push(new RespondToAttackRule(attackEffect));
 }
コード例 #9
0
        public override void Evaluate([CanBeNull] object parameter, [NotNull] RuleStack stack)
        {
            Assert.ArgumentNotNull(stack, nameof(stack));

            stack.Push(EvaluateCondition(parameter));
        }
コード例 #10
0
ファイル: TestRule.cs プロジェクト: sargeles/Sitecore.Rocks
        private void Evaluate(XmlTextWriter output, RuleCondition <RuleContext> condition, RuleContext ruleContext, RuleStack stack, Database database, XElement element)
        {
            var andCondition = condition as AndCondition <RuleContext>;

            if (andCondition != null)
            {
                Evaluate(output, andCondition.LeftOperand, ruleContext, stack, database, element.Element(0));
                if (!(bool)stack.Pop())
                {
                    stack.Push(false);
                }
                else
                {
                    Evaluate(output, andCondition.RightOperand, ruleContext, stack, database, element.Element(1));
                }

                return;
            }

            var orCondition = condition as OrCondition <RuleContext>;

            if (orCondition != null)
            {
                Evaluate(output, orCondition.LeftOperand, ruleContext, stack, database, element.Element(0));
                if ((bool)stack.Pop())
                {
                    stack.Push(true);
                }
                else
                {
                    Evaluate(output, orCondition.RightOperand, ruleContext, stack, database, element.Element(1));
                }

                return;
            }

            var notCondition = condition as NotCondition <RuleContext>;

            if (notCondition != null)
            {
                Evaluate(output, notCondition.Operand, ruleContext, stack, database, element.Element(0));

                var flag = (bool)stack.Pop();
                stack.Push(!flag);

                return;
            }

            condition.Evaluate(ruleContext, stack);

            var text = condition.GetType().Name;

            var conditionItem = database.GetItem(element.GetAttributeValue("id"));

            if (conditionItem != null)
            {
                text = Expand(database, conditionItem["Text"], element);
            }

            var result = stack.Peek();

            output.WriteElementString("entry", string.Format("        Condition \"{0}\" returned \"{1}\".", text, result.ToString()));
        }