def initRandomLoot(): #to do, better randomProtos = Loot.randomItemProtos = [] spellScrolls = Loot.spellScrolls = {} protos = {} con = ItemProto._connection.getConnection() for id, spell_proto_id in con.execute( "SELECT id,spell_proto_id FROM item_proto WHERE spell_proto_id OR (rating = 1 AND NOT flags & ?);", (RPG_ITEM_SOULBOUND, )): ip = protos.setdefault(id, ItemProto.get(id)) if spell_proto_id: for classname, level in con.execute( "SELECT classname,level FROM spell_class WHERE spell_proto_id = ?;", (spell_proto_id, )): spellScrolls.setdefault(classname, {}).setdefault(level, []).append(ip) else: randomProtos.append(ip) # 'unique' variant loot uloot = {} for itemid, freq in con.execute( "SELECT DISTINCT item_proto_id,freq FROM loot_item WHERE freq >= ? AND loot_proto_id IN (SELECT DISTINCT loot_proto_id FROM spawn WHERE NOT flags & ?);", (RPG_FREQ_COMMON, RPG_SPAWN_UNIQUE)): if con.execute( "SELECT id FROM item_slot WHERE item_proto_id = ? LIMIT 1;", (itemid, )).fetchone(): # equippable if freq > uloot.get(itemid, 0): uloot[itemid] = freq # level -> list of item protos uniqueProtos = Loot.uniqueItemProtos = {} for itemid, freq in uloot.iteritems(): ip = protos.setdefault(itemid, ItemProto.get(itemid)) level = ip.level for cl in ip.classes: if cl.level > level: level = cl.level if level == 1: continue uniqueProtos.setdefault(level, []).append((freq, ip))
def initRandomLoot(): #to do, better randomProtos = Loot.randomItemProtos = [] spellScrolls = Loot.spellScrolls = {} protos = {} con = ItemProto._connection.getConnection() for id,spell_proto_id in con.execute("SELECT id,spell_proto_id FROM item_proto WHERE spell_proto_id OR (rating = 1 AND NOT flags & ?);",(RPG_ITEM_SOULBOUND,)): ip = protos.setdefault(id,ItemProto.get(id)) if spell_proto_id: for classname,level in con.execute("SELECT classname,level FROM spell_class WHERE spell_proto_id = ?;",(spell_proto_id,)): spellScrolls.setdefault(classname,{}).setdefault(level,[]).append(ip) else: randomProtos.append(ip) # 'unique' variant loot uloot = {} for itemid,freq in con.execute("SELECT DISTINCT item_proto_id,freq FROM loot_item WHERE freq >= ? AND loot_proto_id IN (SELECT DISTINCT loot_proto_id FROM spawn WHERE NOT flags & ?);",(RPG_FREQ_COMMON,RPG_SPAWN_UNIQUE)): if con.execute("SELECT id FROM item_slot WHERE item_proto_id = ? LIMIT 1;",(itemid,)).fetchone(): # equippable if freq > uloot.get(itemid,0): uloot[itemid] = freq # level -> list of item protos uniqueProtos = Loot.uniqueItemProtos = {} for itemid,freq in uloot.iteritems(): ip = protos.setdefault(itemid,ItemProto.get(itemid)) level = ip.level for cl in ip.classes: if cl.level > level: level = cl.level if level == 1: continue uniqueProtos.setdefault(level,[]).append((freq,ip))
def giveItem(self,itemname,fullStack=False,caseInsensitive=False): try: if caseInsensitive: con = ItemProto._connection.getConnection() ip = ItemProto.get(con.execute("SELECT id FROM item_proto WHERE lower(name)=lower(\"%s\") LIMIT 1;"%itemname).fetchone()[0]) else: ip = ItemProto.byName(itemname) except: return None item = ip.createInstance() if fullStack: item.stackCount = ip.stackMax if not self.curChar.giveItemInstance(item): item.destroySelf() return None return item
def giveItem(self, itemname, fullStack=False, caseInsensitive=False): try: if caseInsensitive: con = ItemProto._connection.getConnection() ip = ItemProto.get( con.execute( "SELECT id FROM item_proto WHERE lower(name)=lower(\"%s\") LIMIT 1;" % itemname).fetchone()[0]) else: ip = ItemProto.byName(itemname) except: return None item = ip.createInstance() if fullStack: item.stackCount = ip.stackMax if not self.curChar.giveItemInstance(item): item.destroySelf() return None return item