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); }
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); }
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); }
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); }
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; }
//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); // } } } }
public void EndTurn() { RuleStack.Push(new EndTurn()); }
public void SetAttacked(Game game, IAttackEffect attackEffect) { RuleStack.Push(new RespondToAttackRule(attackEffect)); }
public override void Evaluate([CanBeNull] object parameter, [NotNull] RuleStack stack) { Assert.ArgumentNotNull(stack, nameof(stack)); stack.Push(EvaluateCondition(parameter)); }
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())); }