Example #1
0
        public bool TryPay(IReadOnlyTokenCollection price)
        {
            if (!CanPay(price))
            {
                return(false);
            }

            foreach (TokenColor key in TokenUtils.AllTokens)
            {
                var discountedPrice = price.GetCount(key) - Discount(key);

                if (discountedPrice < 1)
                {
                    continue;
                }

                uint goldDiff = (uint)(discountedPrice - TokenCount(key));

                if (goldDiff > 0)
                {
                    _tokensInternal.TryTake(TokenColor.Yellow, goldDiff);
                    _tokensInternal.AddTokens(key, goldDiff);
                }
                else
                {
                    return(false);
                }
            }

            _tokensInternal.TryTake(price);
            return(true);
        }
Example #2
0
 public Development(uint level, uint prestige, TokenColor discounts, IReadOnlyTokenCollection cost)
 {
     Level         = level;
     Prestige      = prestige;
     _costInternal = cost;
     Discounts     = discounts;
 }
Example #3
0
        public bool CanPay(IReadOnlyTokenCollection price)
        {
            uint usableGold = TokenCount(TokenColor.Yellow);

            foreach (TokenColor tokenColor in TokenUtils.AllTokens)
            {
                uint discountedPrice = price.GetCount(tokenColor) - Discount(tokenColor);

                if (discountedPrice < 1)
                {
                    continue;
                }

                uint have = TokenCount(tokenColor);

                if (discountedPrice > usableGold + have)
                {
                    return(false);
                }

                var needGold = discountedPrice - have < 0;

                if (needGold)
                {
                    usableGold -= (discountedPrice - have);
                }
            }

            return(true);
        }
Example #4
0
        public bool TryTake(IReadOnlyTokenCollection tokensToTake)
        {
            foreach (TokenColor key in TokenUtils.AllTokens)
            {
                if (GetCount(key) < tokensToTake.GetCount(key))
                {
                    return(false);
                }
            }

            foreach (TokenColor key in TokenUtils.AllTokens)
            {
                _tokensInternal[key] -= tokensToTake.GetCount(key);
            }

            return(true);
        }