예제 #1
0
 def coinage(self, tab: dict, elecplat: str) -> 'Money':
     '''Return a random Money object based to tab probabilities.
     
     tab has to be as following:
     {coin_type: (prob_coin, dice_string, multiplier), ...}
     coin_type: copper, silver, gold, electrum, platinum
     prob_coin: probability (0-100) that coin type is present in the hoard
     dice_string: string to build the dice to random create
     multiplier: the number to multiply the result of dice_string
     
     elecplat: 'electrum' or 'platinum'. Whatever else to choose randomly
     
     >>> m = Mint()
     >>> g = m.coinage({'copper': (100, '1d10', 1000), 'silver': (100, '1d6', 1000), 'gold':   (25,  '1d6', 100), 'electrum': (25, '1d4', 10), 'platinum': (25, '1d4', 10)}, elecplat='platinum')
     >>> type(g)
     <class 'items.treasure.Money'>
     '''
     m = {}
     for c in DD_CURRENCIES:
         if self.throw() < tab[c][0]: # if 1d100 < prob_coin
             m[c] = self.throw_this(tab[c][1]) * tab[c][2]
         else:
             m[c] = 0
     
     if elecplat == 'electrum':
         m['platinum'] = 0
     elif elecplat == 'platinum':
         m['electrum'] = 0
     else:
         if self.throw_this('1d2') == 1:
             m['platinum'] = 0
         else:
             m['electrum'] = 0
         
     return Money(m)
예제 #2
0
    def setUp(self):

        self.m1 = Money()  # empty constructor
        self.m2 = Money(WALLET1)  # complete dict
        self.m3 = Money({'gold': 28})  # partial dict
        self.m4 = Money(TUPLE_COINS)  # tuple
        self.m5 = Money(LIST_COINS)  # list
        self.m6 = Money(**WALLET2)  # complete kwargs
        self.m7 = Money(copper=50, gold=8)  # partial kwargs