def get_item_by_name(self, partialname): """Return first item (object) from inventory matching given partialname""" for item in self.inventory: itemobj=globalitemloader.get_item(item) if partialname.lower() in itemobj.name.lower(): return itemobj return None
def get_item_by_name(self, partialname): """Return first item(obj) from ground matching partial name""" for item in self.items: itemobj=globalitemloader.get_item(item) if partialname.lower() in itemobj.name.lower(): return itemobj return None
def give_drop(self, actor): """give drop items""" if len(self.drop)==0:return drop=random.choice(self.drop) count=random.randint(1, drop[2]) #if chance if random.randint(0, 100)<=drop[0]: for coun in range(count): actor.inventory.append(drop[1]) item=globalitemloader.get_item(drop[1]) actor.send("^y\rOtrzymujesz %s x %s.^~\n" % (item.name, count))
def showinventory(actor, args): """Show actor inventory""" if len(actor.inventory)==0: actor.client.send_cc("\r^gNic nie masz w plecaku.^~\n") return actor.client.send_cc("^Y\rZawartosc twojego plecaka:^~\n") tmpinv=[] for item in actor.inventory[:]: if item in tmpinv:continue itemobj=globalitemloader.get_item(item) actor.client.send_cc("\r "+str(itemobj.name)+" x %s\n" % actor.inventory.count(item)) tmpinv.append(item)
def search(actor): """Search for item on the ground""" room=actor.get_room() if len(room.searchitems)>0: item=random.choice(room.searchitems) # get random item else:item=["", -1] # 0% chance to find (if cant find any item in this loc) number=random.randint(0, 100) if number<=item[1] and not actor.found_item: actor.found_item=True # Actor found item in this area #create object itemobj=globalitemloader.get_item(item[0]) actor.client.send_cc("^G\rZnalazles %s^~\n" % itemobj.name) actor.inventory.append(item[0]) else:actor.client.send_cc("^R\rNic nie znalazles^~\n")
def look(actor, args=[]): """Show informations about room""" room=actor.get_room() #If argument given then search for matching item/place and show desc if len(args)>0: args=" ".join(args) #Check items on the ground item=room.get_item_by_name(args) if item: actor.send("\r^y%s^~\n" % item.name) actor.send("\r %s\n" % item.desc) return #check items from inventory item=actor.get_item_by_name(args) if item: actor.send("\r^y%s^~\n" % item.name) actor.send("\r %s\n" % item.desc) return #Check monsters in room monster=room.get_monster_by_name(args) if monster: actor.send("\r^y%s^~\n" % monster.name) actor.send("\r %s\n" % monster.desc) return return ######################### #show information about location ######################### actor.client.send_cc("\r^c%s^~\n" % str(room.name)) #Show exits actor.client.send_cc("\r[ Wyjscia: ^Y") for exit in room.exits: if exit=="n":actor.client.send_cc("polnoc ") elif exit=="e":actor.client.send_cc("wschod ") elif exit=="w":actor.client.send_cc("zachod ") elif exit=="s":actor.client.send_cc("poludnie ") actor.client.send_cc("^~ ]\n") #show desc about location actor.client.send_cc("%s\n" % str(room.desc)) #show items on the ground if len(room.items)>0: if len(room.items)>1: actor.send("\r^G Tu leza ") else: actor.send("\r^G Tu lezy ") #enumarate items for item in room.items: itemobj=globalitemloader.get_item(item) actor.send(str(itemobj.name)+" ") actor.send("^~\n") #Show information about players in actor room if len(room.players)>1: actor.send("\r^wSa tutaj inni gracze: ") for player in room.players: if player!=actor: actor.send("^Y%s^~ " % player.name) actor.send("^~\n") #Show information about monsters in actor room if len(room.monsters)>0: actor.send("\r^RTutaj sa wrogie potwory. Badz ostrozny: ") for monster in room.monsters: # for each monster object in room #if last dont add comma if monster==room.monsters[-1]: actor.send("%s" % str(monster.name)) else: actor.send("%s, " % str(monster.name)) actor.send("^~\n")