public override bool Check(ConditionContext context)
        {
            List <Player> query = Query.Query(context.Game.Players);

            switch (Match)
            {
            case ConditionRequirement.All:
                return(query.Count == context.Game.Players.Count);

            case ConditionRequirement.None:
                return(query.Count == 0);

            case ConditionRequirement.AtLeast:
                return(query.Count >= Amount);

            case ConditionRequirement.AtMost:
                return(query.Count <= Amount);

            case ConditionRequirement.Exactly:
                return(query.Count == Amount);

            default:
                return(false);
            }
        }
示例#2
0
        public override void Execute(EffectContext context)
        {
            ConditionContext cContext = new ConditionContext
            {
                Game    = context.Game,
                Subject = context.ExecutingPlayer,
                Targets = context.Targets,
            };

            bool pass = true;

            foreach (BaseCondition condition in Conditions)
            {
                if (!condition.Check(cContext))
                {
                    pass = false;
                    break;
                }
            }

            if (pass)
            {
                foreach (BaseEffect effect in EffectsIfConditionsPass)
                {
                    effect.Execute(context);
                }
            }
            else
            {
                foreach (BaseEffect effect in EffectsIfConditionsFails)
                {
                    effect.Execute(context);
                }
            }
        }
示例#3
0
        public override bool Check(ConditionContext context)
        {
            switch (Operator)
            {
            case CompoundOperator.AND:
                foreach (BaseCondition condition in Conditions)
                {
                    if (!condition.Check(context))
                    {
                        return(false);
                    }
                }
                return(true);

            case CompoundOperator.OR:
                foreach (BaseCondition condition in Conditions)
                {
                    if (condition.Check(context))
                    {
                        return(true);
                    }
                }
                return(false);

            default:
                return(false);
            }
        }
示例#4
0
 public bool CheckConditions(ConditionContext context)
 {
     foreach (PlayerCondition condition in Conditions)
     {
         if (!condition.Check(context))
         {
             return(false);
         }
     }
     return(true);
 }
        protected override bool Pass(Player player, ConditionContext context)
        {
            int counterValue  = player.GetCounterValue(Counter);
            int comparedValue = 0;

            switch (CompareTo)
            {
            case CompareToType.Value:
                comparedValue = Value;
                break;

            case CompareToType.OtherCounter:
                Player owningPlayer = player;
                foreach (string reference in CounterReferenceChain)
                {
                    owningPlayer = owningPlayer.GetReference(reference);
                    if (owningPlayer == null)
                    {
                        return(false);
                    }
                }
                comparedValue = owningPlayer.GetCounterValue(CompareToCounter);
                break;
            }
            switch (Comparison)
            {
            case Operator.Equal:
                return(counterValue == comparedValue);

            case Operator.NotEqual:
                return(counterValue != comparedValue);

            case Operator.GreaterThan:
                return(counterValue > comparedValue);

            case Operator.GreaterThanOrEqualTo:
                return(counterValue >= comparedValue);

            case Operator.LessThan:
                return(counterValue < comparedValue);

            case Operator.LessThanOrEqualTo:
                return(counterValue <= comparedValue);

            default:
                return(false);
            }
        }
示例#6
0
        public void CheckForVictory()
        {
            List <Player>     winners      = new List <Player>();
            List <Allegiance> winningTeams = new List <Allegiance>();

            foreach (Player player in Players)
            {
                ConditionContext context = new ConditionContext
                {
                    Game    = this,
                    Subject = player,
                    Targets = null,
                };

                if (player.CurrentRole.WinCondition != null && player.CurrentRole.WinCondition.Check(context))
                {
                    winners.Add(player);
                }
                if (player.CurrentAllegiance.WinCondition != null && player.CurrentAllegiance.WinCondition.Check(context))
                {
                    winningTeams.Add(player.CurrentAllegiance);
                }
            }
            if (winners.Count > 0)
            {
                Result result = new Result
                {
                    PlayerWin      = true,
                    Tie            = winners.Count > 1,
                    WinningPlayers = winners,
                };
                EndResults = result;
                Complete   = true;
            }
            else if (winningTeams.Count > 0)
            {
                Result result = new Result
                {
                    AllegianceWin      = true,
                    Tie                = winningTeams.Count > 1,
                    WinningAllegiances = winningTeams,
                };
                EndResults = result;
                Complete   = true;
            }
        }
 protected override bool Pass(Player player, ConditionContext context)
 {
     foreach (string flag in HasFlags)
     {
         if (!player.HasFlag(flag))
         {
             return(false);
         }
     }
     foreach (string flag in DoesNotHaveFlags)
     {
         if (player.HasFlag(flag))
         {
             return(false);
         }
     }
     return(true);
 }
示例#8
0
 public abstract bool Check(ConditionContext context);
示例#9
0
        public override bool Check(ConditionContext context)
        {
            List <Player> playersToApply = new List <Player>();

            switch (AppliesTo)
            {
            // First are single target, we can return right here
            case PlayerApplication.Self:
                return(Pass(context.Subject, context));

            case PlayerApplication.Target:
                if (context.Targets == null)
                {
                    return(false);
                }
                if (context.Targets.Count <= Target)
                {
                    return(false);
                }
                return(Pass(context.Targets[Target], context));

            case PlayerApplication.ReferenceChain:
                Player refPlayer = context.Subject;
                foreach (string reference in ReferenceChain)
                {
                    refPlayer = refPlayer.GetReference(reference);
                    if (refPlayer == null)
                    {
                        return(false);
                    }
                }
                return(Pass(refPlayer, context));

            // Rest are multi target, we need another pass over after so break instead of returning
            case PlayerApplication.PlayerQuery:
                playersToApply.AddRange(context.Game.Players);
                break;

            case PlayerApplication.TargetQuery:
                if (context.Targets == null)
                {
                    return(false);
                }
                playersToApply.AddRange(context.Targets);
                break;

            default:
                return(false);
            }

            List <Player> queried = Query.Query(playersToApply);

            int passCount = 0;

            foreach (Player player in queried)
            {
                if (Pass(player, context))
                {
                    passCount++;
                }
            }

            switch (Requirement)
            {
            case ConditionRequirement.Exactly:
                return(passCount == NumberOfPlayers);

            case ConditionRequirement.AtLeast:
                return(passCount >= NumberOfPlayers);

            case ConditionRequirement.AtMost:
                return(passCount <= NumberOfPlayers);

            case ConditionRequirement.All:
                return(passCount == queried.Count);

            case ConditionRequirement.None:
                return(passCount == 0);

            default:
                return(false);
            }
        }
示例#10
0
 /// <summary>
 /// Checks if the condition passes.
 /// </summary>
 /// <returns>whether or not the condition is currently passing</returns>
 protected abstract bool Pass(Player player, ConditionContext context);