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);
            }
        }
Пример #2
0
        // Private because API so not clear. Instead use Query, then check if the results
        // contain the player you want.
        private bool MatchPlayer(Player player, IEnumerable <Player> players)
        {
            if (Status != Player.Status.Any && player.CurrentStatus != Status)
            {
                return(false);
            }
            if (RequiredAllegiance != null && player.CurrentAllegiance != RequiredAllegiance)
            {
                return(false);
            }
            if (RequiredRole != null && player.CurrentRole != RequiredRole)
            {
                return(false);
            }
            foreach (string flag in RequiredFlags)
            {
                if (!player.HasFlag(flag))
                {
                    return(false);
                }
            }
            foreach (string flag in ForbiddenFlags)
            {
                if (player.HasFlag(flag))
                {
                    return(false);
                }
            }

            foreach (CounterQuery cq in CounterRequirements)
            {
                int  value = player.GetCounterValue(cq.Counter);
                bool pass  = true;

                // We need a list ordered by counter value
                List <Player> counterSorted = null;
                if (cq.Comparison == CounterQuery.Operator.InTop ||
                    cq.Comparison == CounterQuery.Operator.InBottom)
                {
                    if (sortedByCounterCache != null && sortedByCounterCache.ContainsKey(cq.Counter))
                    {
                        counterSorted = sortedByCounterCache[cq.Counter];
                    }
                    else
                    {
                        counterSorted = new List <Player>(players);
                        counterSorted.Sort((Player p1, Player p2) => {
                            return(p1.GetCounterValue(cq.Counter).CompareTo(p2.GetCounterValue(cq.Counter)));
                        });
                        if (sortedByCounterCache != null)
                        {
                            sortedByCounterCache[cq.Counter] = counterSorted;
                        }
                    }
                }

                int index = -1; // used in top/bottom
                switch (cq.Comparison)
                {
                case CounterQuery.Operator.Equal:
                    pass = value == cq.Value;
                    break;

                case CounterQuery.Operator.NotEqual:
                    pass = value != cq.Value;
                    break;

                case CounterQuery.Operator.GreaterThan:
                    pass = value > cq.Value;
                    break;

                case CounterQuery.Operator.GreaterThanOrEqualTo:
                    pass = value >= cq.Value;
                    break;

                case CounterQuery.Operator.LessThan:
                    pass = value < cq.Value;
                    break;

                case CounterQuery.Operator.LessThanOrEqualTo:
                    pass = value <= cq.Value;
                    break;

                case CounterQuery.Operator.InTop:
                    index = counterSorted.IndexOf(player);
                    if (index < 0 || index >= counterSorted.Count)
                    {
                        pass = false;
                        break;
                    }
                    pass = index >= counterSorted.Count - cq.Value;
                    break;

                case CounterQuery.Operator.InBottom:
                    index = counterSorted.IndexOf(player);
                    if (index < 0 || index >= counterSorted.Count)
                    {
                        pass = false;
                        break;
                    }
                    pass = index < cq.Value;
                    break;

                default:
                    pass = false;
                    break;
                }
                if (!pass)
                {
                    return(false);
                }
            }
            return(true);
        }