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 cmdSocial(ch, cmd, args): """ Perform the social given by the command. """ # # Find the wanted social in the Social table # for item in Social: if item[0] == cmd: break cmd, toSelfNoVictim, toOtherNoVictim, toSelfNotFound, toOtherNotFound,\ toSelf, toVictim, toOthers, toSelfFromSelf, toOtherFromSelf = item argL = utils.splitArgs(args) selfMsg = None otherMsg = None victimMsg = None if len(argL) > 0: # has a victim victim = ch.findVictim(argL[0]) # victim is ourself if victim == ch: selfMsg = toSelfFromSelf otherMsg = toOtherFromSelf # victim was not found elif victim == None: selfMsg = toSelfNotFound otherMsg = toOtherNotFound else: selfMsg = toSelf otherMsg = toOthers victimMsg = toVictim else: victim = None # no victim selfMsg = toSelfNoVictim otherMsg = toOtherNoVictim room = ch.getPlace() if selfMsg: ch.writeToSelf(string.capitalize(utils.substNames(selfMsg, ch, victim, None))+"\r\n") if otherMsg: room.writeToRoom(string.capitalize(utils.substNames(otherMsg, ch, victim, None))+"\r\n", [ch, victim]) if victimMsg: victim.writeToSelf(string.capitalize(utils.substNames(victimMsg, ch, victim, None))+"\r\n", WRI_DEAD) event = Event(EVN_SOCIAL, ch) event.command = cmd event.victim = victim room.handleEvent(event) return 1
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")