Example #1
0
 def _isEnoughMoney(cls, price, money):
     if not price.isDefined():
         return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)
     shortage = money.getShortage(price)
     if shortage:
         currency = shortage.getCurrency(byWeight=True)
         return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency))
     return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)
def getMoneyVOWithReason(errorMsg, moneyObj):
    result = []
    for c, v in moneyObj.iteritems():
        if errorMsg == GUI_ITEM_ECONOMY_CODE.getMoneyError(c):
            result.append(('%sError' % c, v))
        result.append((c, v))

    return tuple(result)
Example #3
0
 def _validate(self):
     stats = self.itemsCache.items.stats
     shortage = stats.money.getShortage(self.price)
     if shortage:
         currency = shortage.getCurrency(byWeight=False)
         if currency == Currency.GOLD and not stats.mayConsumeWalletResources:
             error = GUI_ITEM_ECONOMY_CODE.WALLET_NOT_AVAILABLE
         else:
             error = GUI_ITEM_ECONOMY_CODE.getMoneyError(currency)
         return makeError(error)
     return makeSuccess()
Example #4
0
    def _isEnoughMoney(cls, prices, money):
        shortage = MONEY_UNDEFINED
        for itemPrice in prices:
            need = money.getShortage(itemPrice.price)
            if need:
                shortage += need
            return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)

        if shortage:
            currency = shortage.getCurrency(byWeight=True)
            return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency))
        return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)
Example #5
0
def getMoneyVOWithReason(errorMsg, moneyObj):
    """
    Same as getMoneyVO but includes currency reason error
    """
    result = []
    for c, v in moneyObj.iteritems():
        if errorMsg == GUI_ITEM_ECONOMY_CODE.getMoneyError(c):
            result.append(('%sError' % c, v))
        else:
            result.append((c, v))

    return tuple(result)
Example #6
0
 def _isEnoughMoney(cls, price, money):
     """
     Determines if the given money enough for buying/restoring an item with the given price. Note that the method
     should NOT check if the given price is defined and will return (True, '') if the price is undefined (see Money
     class, isDefined method).
     
     :param price: item price represented by Money
     :param money: money for buying, see Money
     :return: tuple(can be installed <bool>, error msg <str>), also see GUI_ITEM_ECONOMY_CODE
     """
     if not price.isDefined():
         return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)
     shortage = money.getShortage(price)
     if shortage:
         currency = shortage.getCurrency(byWeight=True)
         return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency))
     return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)
Example #7
0
    def _isEnoughMoney(cls, prices, money):
        """
        Determines if the given money enough for buying the booster for a price.
        
        :param prices: item prices represented by ItemPrices
        :param money: money for buying, see Money
        :return: tuple(can be installed <bool>, error msg <str>), also see GUI_ITEM_ECONOMY_CODE
        """
        shortage = MONEY_UNDEFINED
        for itemPrice in prices:
            need = money.getShortage(itemPrice.price)
            if need:
                shortage += need
            else:
                return (True, GUI_ITEM_ECONOMY_CODE.UNDEFINED)

        if shortage:
            currency = shortage.getCurrency(byWeight=True)
            return (False, GUI_ITEM_ECONOMY_CODE.getMoneyError(currency))
        return (False, GUI_ITEM_ECONOMY_CODE.ITEM_NO_PRICE)