def resolveGiveItem(self): '''解析接受任务时给予的物品''' giveItems = [] taskInfo = self.format itemsDes = taskInfo.get('giveItem', u'') try: itemsDataInfo = eval(itemsDes) except Exception: log.err('Task %d `ItemPrize` field Configuration error !' % self._id) return [] if itemsDataInfo: generaldata = itemsDataInfo.get(0, []) professiondata = itemsDataInfo.get(self._profession, []) else: generaldata = [] professiondata = [] for itemId, stack in generaldata: item = Item(itemTemplateId=itemId) item.pack.setStack(stack) giveItems.append(item) for itemId, stack in professiondata: item = Item(itemTemplateId=itemId) item.pack.setStack(stack) giveItems.append(item) return giveItems
def resolveItemPrize(self): '''解析任务奖励 @param profession: int 给予的职业 ''' itemsprize = [] taskInfo = self.format itemsDes = taskInfo.get('ItemPrize', u'') try: itemsDataInfo = eval(itemsDes) except Exception: log.err('Task %d `ItemPrize` field Configuration error !' % self._id) return [] if itemsDataInfo: generaldata = itemsDataInfo.get(0, []) professiondata = itemsDataInfo.get(self._profession, []) else: generaldata = [] professiondata = [] for itemId, stack in generaldata: item = Item(itemTemplateId=itemId) item.pack.setStack(stack) itemsprize.append(item) for itemId, stack in professiondata: item = Item(itemTemplateId=itemId) item.pack.setStack(stack) itemsprize.append(item) return itemsprize
def getMonsterItemByid(instanceid): '''根据副本id获取组队副本需要的信息 @param id: int 副本id ''' result=dbInstance_d.getInstance_dByid(instanceid) ditems=[] #存储掉落物品实例 ms=[] #存储怪物实例 if result: dropitems=result.get('dropitem',None) if dropitems: for itemid in dropitems: itm=Item(itemid) val=[] val.append(itm.baseInfo.getBaseQuality()) #物品品质 val.append(itm.baseInfo.getName()) #物品名称 del itm ditems.append(val) monsters=result.get('moster',None) if monsters: for mosterid in monsters: ms.append( Monster(templateId=mosterid)) result['dropitem']=ditems result['moster']=ms data={"result":True,"message":Lg().g(166),"data":result} return data return None
def sendMessage(_conn, request_proto): '''发送聊天消息''' from app.scense.protoFile.chat import sendMessage1003_pb2 from app.scense.core.Item import Item argument = sendMessage1003_pb2.chatConectingRequest() argument.ParseFromString(request_proto) response = sendMessage1003_pb2.chatConectingResponse() dynamicId = _conn.transport.sessionno characterId = argument.id #当前角色id topic = argument.topic #频道号 tonickname = argument.chatOjbect #角色昵称 content = argument.content #内容 linkData = [] #聊天连接信息 for _item in argument.linkData: item = {} item['chatEquipType'] = _item.chatEquipType item['id'] = _item.id item['name'] = _item.name try: item1 = Item(id=_item.id) except Exception: linkData.append(item) continue item['itemInfo'] = item1 linkData.append(item) del item1 data = chat.sendMessage(dynamicId, characterId, topic, content, linkData, tonickname) response.result = data.get('result', False) response.message = data.get('message', '') return response.SerializeToString()
def getDailyInfo(self, dateindex): '''获取指定日期的目标 @param dateindex: int 日期序号 ''' dailylist = dbdaily.getDailyForDateindex(dateindex) dailylistInfo = [] dailylistInfo for daily in dailylist: info = {} info['dailyId'] = daily['id'] info['name'] = daily['dailyname'] info['desc'] = daily['dailydesc'] info['type'] = daily['type'] info['icon'] = daily['icon'] info['finished'] = self.checkFinished(daily['id']) mydaily = self.dailygoal.get(daily['id']) # info # if daily['dailytype']==2: # if self._owner.guild.getGuildLevel()>=daily['goal']: # info['finished'] = True # else: # if mydaily and mydaily['current']>=daily['goal']: # info['finished'] = True info['received'] = bool(mydaily['received']) info['expbound'] = daily['expbound'] info['coinbound'] = daily['coinbound'] info['goldbound'] = daily['goldbound'] info['itembound'] = [] bounditems = eval('[%s]' % daily('itembound')) for info in bounditems: item = Item(itemTemplateId=info[0]) item.pack.setStack(info[1]) dailylistInfo.append(info) return dailylistInfo
def __F(iam, itemid, pf, data, dt, typeid, tp): if len(iam) < 100: dbTopitem.addTop(itemid, typeid, pf) data['item'] = Item(id=itemid) #物品 data['pf'] = pf #评分 data['tp'] = tp #装备位置 dt.append(data) TopList().updateiaitem(0) TopList().updateiaitem(1) TopList().updateiaitem(2) else: TopList().updateiaitem(0) TopList().updateiaitem(1) TopList().updateiaitem(2) dbTopitem.updateTop(iam[99].get('itemid'), itemid, pf) data['item'] = Item(id=itemid) #物品 data['pf'] = pf data['tp'] = tp #装备位置 dt.append(data)
def initData(self): characterId = self._owner.baseInfo.id itemsPackInfo = db_package.getItemsInstancePackage(characterId) self.clearances = set(dbClearance.getClearanceRecord(characterId)) self.GroupClearances = set(dbClearance.getGroupRecord(characterId)) for itemInfo in itemsPackInfo: if itemInfo['itemId']==-1: continue item = Item(id =itemInfo['itemId']) self.pack.putItemByPosition(itemInfo['position'], item)
def initShopData(self): '''初始化商店信息 ''' self.itemList = dbShop.getShopInfo(self._id) for _item in self.itemList: item = Item(itemTemplateId = _item['item']) item.baseInfo.setItemPrice(_item['coinPrice']) itemInfo = {} itemInfo['item'] = item itemInfo['overTime'] = 0 self.shopitems.append(itemInfo)
def setPackage(self, size=12): '''读取数据库设置角色包裹 @param size: int 包裹的大小 ''' self._package = Package.Package(size) itemsPackInfo = db_package.getPlayerItemsInPackage( self._owner.baseInfo.id) for itemPackInfo in itemsPackInfo: if itemPackInfo['itemId'] == -1: continue item = Item(itemTemplateId=0, id=itemPackInfo['itemId']) self._package.putItemInPackage(itemPackInfo['position'], item, itemPackInfo['category'])
def getByDropOutByid(did): '''根据掉落did获取掉落信息 (适用于副本,返回一个字典,分三个部分,1 items存储掉落物品实例 2 coupon存储绑定钻 3 gold存储游戏币) @param id: int 掉落id ''' tlist = [] #存储副本掉落 try: data = alldrop.get(did, None) for item in data.get('itemid'): dt = {"item": None, "coin": 0, "coupon": 0} abss = random.randint(1, base) if abss >= 1 and abss <= item[2]: #如果随机出来此物品 abss = random.randint(1, item[1]) #物品数量 item1 = Item(item[0]) item1.pack.setStack(abss) dt['item'] = item1 tlist.append(dt) coupon = data.get('coupon') if len(coupon) > 2: dt = {"item": None, "coin": 0, "coupon": 0} cp = eval("[" + coupon + "]") abss = random.randint(1, base) if abss >= 1 and abss <= cp[1]: dt["coupon"] = cp[0] tlist.append(dt) if len(tlist) < fbitemcount: lower = data.get('lower', -1) upper = data.get('upper', -1) if lower > 0 and upper > 0 and upper >= lower: for i in range(fbitemcount - len(tlist)): dt = {"item": None, "coin": 0, "coupon": 0} dt['coin'] = random.randint(lower, upper) tlist.append(dt) del i else: for i in range(fbitemcount - len(tlist)): dt = {"item": None, "coin": 0, "coupon": 0} dt['coin'] = 1 tlist.append(dt) except: for it in range(fbitemcount): dt = {"item": None, "coin": 0, "coupon": 0} dt['coin'] = random.randint(1, 1000) tlist.append(dt) del it if len(tlist) > 0: return random.sample(tlist, fbitemcount) return None
def getRepurchaseInfo(self,characterId): '''获取角色回购的物品的信息''' repurchaseItems = [] data = dbShop.getPlayerRepurchaseInfo(characterId) for _item in data: itemInfo = {} itemInfo['item'] = Item(id = _item[1]) itemInfo['item'].baseInfo.setItemPrice(int(itemInfo['item'].baseInfo.getItemPrice()*1.5)) itemInfo['overTime'] = 10800 - _item[-1].seconds repurchaseItems.append(itemInfo) return repurchaseItems
def getDropByid(did): '''根据怪物id获取掉落物品信息 (适用于 怪物掉落 返回一个掉落物品) @param did: int 怪物掉落表主键id ''' data = alldrop.get(did, None) if not data: log.err(u'掉落表填写错误不存在掉落信息-掉落主键:%d' % did) return None for item in data.get('itemid'): abss = random.randint(1, base) if abss >= 1 and abss <= item[2]: #如果随机出来此物品 abss = random.randint(1, item[1]) #物品数量 item1 = Item(item[0]) item1.pack.setStack(abss) return item1 return None
def setEquipmentSlot(self, size=10): '''设置角色装备栏 @param size: int 装备栏默认为10个部位 ''' playerId = self._owner.baseInfo.id self._equipmentSlot = EquipmentSlot.EquipmentSlot() equipmentsInfo = db_package.getPlayerEquipInEquipmentSlot( self._owner.baseInfo.id) if not equipmentsInfo: db_package.initPlayerEquippack(playerId) equipmentsInfo = {} for equipmentInfo in equipmentsInfo.items(): if equipmentInfo[1] == -1: continue item = Item(itemTemplateId=0, id=equipmentInfo[1]) self._equipmentSlot.putEquipmentInEquipmentSlot( equipmentInfo[0], item)
def getRepurchaseInfo(self, characterId): '''获取角色回购的物品的信息''' repurchaseItems = [] data = dbShop.getPlayerRepurchaseInfo(characterId) for _item in data: itemInfo = {} itemInfo['item'] = Item(id=_item[1]) itemInfo['item'].baseInfo.setItemPrice( int(itemInfo['item'].baseInfo.getItemPrice() / 0.7)) itemInfo['overTime'] = 10800 - _item[-1].seconds repurchaseItems.append(itemInfo) return { 'shopCategory': 1, 'curPage': 1, 'maxPage': 1, 'items': repurchaseItems }
def RepurchaseItem(self, itemId): '''回购物品''' if not dbShop.checkSellItem(itemId, self._owner.baseInfo.id): return {'result': False, 'message': Lg().g(469)} item = Item(id=itemId) price = int(item.baseInfo.getItemPrice() / 0.7) * item.pack.getStack() SurplusCoin = self._owner.finance.getCoin() - price if SurplusCoin < 0: return {'result': False, 'message': Lg().g(88)} result = self._owner.pack.putNewItemInPackage(item) if result == 1: return {'result': False, 'message': Lg().g(377)} self._owner.finance.updateCoin(SurplusCoin) pushUpdatePlayerInfo(self._owner.getDynamicId()) dbShop.delSellItem(itemId) msg = Lg().g(195) pushPromptedMessage(msg, [self._owner.getDynamicId()]) return {'result': True, 'message': Lg().g(195)}
def __init__(self,id=0,count=1,coin=0,coupon=0): ''' @param id: 物品的模板id @param count: int 物品的数量 @param coin: int 游戏币 @param coupon: int 绑定钻 ''' self.item=None #存储一个物品的实例 self.coin=0 #游戏币 self.coupon=0 #绑定钻 if id>0 and count>0: item1=Item(id) item1.pack.setStack(count) self.item=item1 elif coin>0: self.coin=coin elif coupon>0: self.coupon=coupon
def updateShopItems(self, shopType): '''获取商店物品 @param shopType: (int) 商店类型 ''' list = [] shopInfo = loader.get('shop', 'id', shopType, '*') if not shopInfo: return list shopInfo = shopInfo[0] count = shopInfo['count'] for i in range(0, count): item = Item(27) list.append(item) # item = self.getOneShopItem(shopInfo) # while not item: # item = self.getOneShopItem(shopInfo) # if item: # list.append(item) return list
def putNewItemsInPackage(self, itemTemplateId, count): '''添加物品到包裹栏''' item = Item(itemTemplateId=itemTemplateId) packType = 1 if item.baseInfo.getitemPage() == 4: packType = 2 maxstack = item.baseInfo.getItemTemplateInfo().get('maxstack', 1) package = self._package.getPackageByType(packType) itemcndlist = [] while count - maxstack > 0: itemcndlist.append(maxstack) count -= maxstack itemcndlist.append(count) if package.findSparePositionNum() < len(itemcndlist): return False for count in itemcndlist: _item = copy.deepcopy(item) _item.pack.setStack(count) self.putNewItemInPackage(_item) return True
def getTeamDropItem(dropid): '''获取多人副本掉落出的物品 @param dropid: int 多人副本掉落id ''' all = dbTeamInstanceDrop.teamInstanceDropAll #所有掉落信息 # ditem [[物品id,物品数量,1,2],[物品id,物品数量,3,10]] 上限是100 if not all.has_key(dropid): log.err(u"getTeamDropItem(%s) all=%s" % (dropid, all)) ilist = all.get(dropid)['ditem'] sj = random.randint(1, 100) wpobj = None #物品实例 for item in ilist: st = item[2] #较小的内定随机数 en = item[3] #较大的内定随机数 if st <= sj and en >= sj: wpobj = Item(item[0]) wpobj.pack.setStack(item[1]) return wpobj log.err(u"getTeamDropItem(%s) ilist=%s" % (dropid, ilist)) return None
def getInstance_dByid(instanceid): '''根据副本id获取组队副本需要的信息 @param id: int 副本id ''' result=dbInstance_d.getInstance_dByid(instanceid) ditems=[] #存储掉落物品实例 ms=[] #存储怪物实例 if result: dropitems=result.get('dropitem',None) if dropitems: for itemid in dropitems: ditems.append(Item(itemid)) monsters=result.get('moster',None) if monsters: for mosterid in monsters: ms.append( Monster(templateId=mosterid)) result['dropitem']=ditems result['moster']=ms data={"result":True,"message":Lg().g(166),"data":result} return data return None
def buyConsItem(self, tocharacterId, consID, itemCount, itemId, price, buyType): '''购买寄卖物品 @param tocharacterId: int 角色的id @param consID: int 物品寄卖的ID @param itemId: int 物品的id @param price: int 物品的价格 @param itemCount: int 物品的数量 @param buyType: int 购买类型 1 金币 2钻 ''' characterId = self._owner.baseInfo.id package = self._owner.pack._package.getWholePagePack() position = package.findSparePositionForItem() if position == -1: return {'result': False, 'message': Lg().g(16)} if buyType == 1: the_coin = self._owner.finance.getCoin() - price to_coin = int(math.ceil(price * (1 - 0.1))) else: the_coin = self._owner.finance.getGold() - price to_coin = price if the_coin < 0: return {'result': False, 'message': Lg().g(190)} item = Item(id=itemId) item.pack.setStack(itemCount) item.InsertItemIntoDB(characterId=characterId) newitemId = item.baseInfo.getId() result = dbaccess.dbbuyConsItem(characterId, tocharacterId, consID, newitemId, the_coin, to_coin, position, buyType) if not result: return {'result': True, 'message': Lg().g(470)} item = Item(id=newitemId) item.pack.setStack(itemCount) item.InsertItemIntoDB(characterId=characterId) package.putItemByPosition(position, item) if buyType == 1: self._owner.finance.setCoin(the_coin) else: self._owner.finance.setGold(the_coin) return {'result': True, 'message': Lg().g(193)}
def getItemByDropping(self, dropConfigId): ''' 根据掉落配置得到物品 @param dropConfigId: 掉落配置id ''' dropConfig = loader.getById('drop_config', dropConfigId, '*') if not dropConfig or len(dropConfig.items()) == 0: log.err( _why= 'no item for the dropconfig dropConfigId(%d) characterId(%d)'%(dropConfigId,self._owner.baseInfo.id)) return None itemTemplate = self.getDropItemTemplate(dropConfig) # itemTemplate = dbaccess.all_ItemTemplate[1] if itemTemplate: isBound = 0 if itemTemplate['bindType']==1: isBound = 1 itemTemplate['id'] = 27 dropItem = Item(itemTemplateId =itemTemplate['id']) dropItem.attribute.setIsBound(isBound) # itemId = dropItem.InsertItemIntoDB(characterId = self._owner.baseInfo.id) # dropItem.baseInfo.setId(itemId) return dropItem else: return None
def getInfoByitemid(itemid): '''根据角色拥有的物品id获取物品信息 @param itemid: int 物品id ''' Item(id=itemid)
def getNewItemInPackage(self, itemTemplateId): '''获取新的物品''' item = Item(itemTemplateId=itemTemplateId) item.InsertItemIntoDB(characterId=self._owner.baseInfo.id) self.putNewItemInPackage(item)