def getDescriptionForLookAt(self, keyword): if keyword in ['products', 'display']: text = "In the products display you see:" i = 0 curr = self.getRoom()._zone._currency for id, price, qty in self._products: i = i+1 if i % 2 == 1: text = text + "\r\n" obj = self._world.getObject(id) descr = obj.getTheName() p = utils.convertCurrency(price, CUR_DOLLAR, curr) money = utils.getMoneyText(p, curr) if self._quantities[i-1] > 0: text = text+' ['+`i`+'] '+string.ljust(string.ljust(descr, 22)+money, 32) else: text = text+' ['+`i`+'] '+string.ljust(string.ljust(descr, 22)+'sold out', 36) return text else: return Object.getDescriptionForLookAt(self, keyword)
def performList(self, ch): currency = self.getLocation()._zone._currency ch.writeToSelf(string.capitalize( utils.substNames(self._shopMessages["showList"], self, ch, None))+"\r\n") ch.writeToSelf(string.center("#", 4) +string.ljust("Description",46) +string.rjust("Stock",5) +string.rjust("Price",15) +"\r\n"+"-"*70+"\r\n") idx = 0 for id, qty in self._products: p = self._world.getObject(id) if not p: self.warning("shopkeeper with invalid product "+id) continue price = utils.convertCurrency(p._value, CUR_DOLLAR, currency) price = utils.getMoneyText(price, currency) if qty == 0: qty = "-" else: qty = str(qty) idx = idx + 1 ch.writeToSelf(string.ljust('#'+`idx`, 4) +string.ljust(p.getName(),46) +string.rjust(qty, 5) +string.rjust(price, 15)+"\r\n")
def doPush(self, performer, item): if item > len(self._products) or item < 1: performer.writeToSelf("There's no such button in this machine.\r\n") return id, price, qty = self._products[item-1] if self._quantities[item-1] < 1: performer.writeToSelf("Nothing happens.\r\n") return curr = self.getRoom()._zone._currency total = 0.0 for i in range(len(self._contains)-1, -1, -1): c = self._contains[i] if isinstance(c, Money) and c._currency == curr: total = total+c._amount self.removeThing(c) c.destroy() price = utils.convertCurrency(price, CUR_DOLLAR, curr) if price > total: performer.writeToSelf("Nothing happens.\r\n") if total > 0: change = Money(self._world, total, curr) self.putThing(change) return obj = self._world.makeObject(id) self.putThing(obj) if total > price: change = Money(self._world, total - price, curr) self.putThing(change) performer.writeToSelf(self._buyMessage+"\r\n") performer.writeToOthers(self._buyMessage+"\r\n")
def convertTo(self, currency): amount = utils.convertCurrency(self._amount, self._currency, currency) return Money(self._world, amount, currency)
def performBuy(self, ch, args): currency = self.getLocation()._zone._currency argL = utils.splitArgs(args) if len(argL) == 0: ch.writeToSelf("What do you want to buy?\r\n") return 1 if utils.isnumber(argL[0]): n = int(argL[0]) i = 1 if n <= 0: ch.writeToSelf("Heh heh.. sure.. why don't you try that in some alternative universe?\r\n") return 1 else: n = 1 i = 0 if len(argL)-1 < i: ch.writeToSelf("What do you want to buy?\r\n") return # # Get the product to be bought # what = argL[i] if what[0] == '#': i = abs(int(what[1:])) else: i = -1 idx = 0 found = 0 for id, qty in self._products: p = self._world.makeObject(id) if not p: continue price = utils.convertCurrency(p._value, CUR_DOLLAR, currency) i = i - 1 if p.matchAlias(what): found = 1 break p.destroy() if i == 0: found = 1 break idx = idx + 1 if not found: text = utils.substNames(self._shopMessages['notFound'], self, ch, None) self._world.execute(self, "say "+text) return if qty <= 0: text = utils.substNames(self._shopMessages['outOfStock'], self, ch, None) self._world.execute(self, "say "+text) return n = min(qty, n) money = ch.findCarriedObjects(currency, price*n) if not money: text = utils.substNames(self._shopMessages['youCantPay'], self, ch, None) self._world.execute(self, "say "+text) return money = money[0] count = 0 for j in range(n): obj = self._world.makeObject(id) if not obj: self.warning("shopkeeper could not make product "+id) continue if not ch.canCarryThing(obj): text = utils.substNames(self._shopMessages['cantCarry'], self, ch, obj) self._world.execute(self, "say "+text) break # # Finish the transaction. # ch.carryThing(obj) count = count + 1 self._products[idx] = (self._products[idx][0], self._products[idx][1]-1) if count == 0: return money = ch.findCarriedObjects(currency, price*count) ch.uncarryThing(money[0]) text = utils.substNames(self._shopMessages['bought'], self, ch, obj) self._world.execute(self, "say "+text) if n == 1: ch.writeToSelf("You buy "+obj.getName()+".\r\n") ch.writeToOthers(ch.getName()+" buys "+obj.getName()+".\r\n") else: ch.writeToSelf("You buy "+`count`+" "+obj.getTheName()+".\r\n") ch.writeToOthers(ch.getName()+" buys "+`count`+" "+obj.getTheName() +".\r\n")