def giveItemById(obj, retMsg, itemCfgId, num): if itemCfgId == 0: # 金币 obj.addGold(num, True) return item = obj.itemCtrl.addItemByCfgId(itemCfgId, num) if item: ffext.dump('whenDie itemEnterMap', item.itemCfg.name, num) # self.mapObj.itemEnterMap(item, self.x + 1, self.y + 1) if item.__class__ == list: for k in item: retItem = MsgDef.Item() ItemHandler.buildItem(retItem, k) retMsg.items.append(retItem) else: retItem = MsgDef.Item() ItemHandler.buildItem(retItem, item) retMsg.items.append(retItem) return
def genmsg(): onlineSec = player.getGameTime() dailyInfo = MsgDef.DailyLoginInfo( player.loginActCtrl.seven_login_days, player.loginActCtrl.seven_login_mask, onlineSec, player.loginActCtrl.online_reward_mask, player.loginActCtrl.invite_reward) retMsg = MsgDef.DailyLoginOpsRet(opstype, dailyInfo, [], 0) if opstype == MsgDef.DailyLoginOpsCmd.DAILY_OP_ALL_INFO: #from handler import ItemHandler for i in range(0, 32): item = MsgDef.Item() #ItemHandler.buildItem(retItem, k) #item.uid = itemObj.uid #itemCfg = itemObj.itemCfg item.itemCfgId = getDailyAwardId(i) item.name = DAILY_AWARD_CFG[i] #item.strengthenLevel = itemObj.strengthenLevel item.lefttimes = 1 #item.propExt = itemObj.propExt #item.propStrengthen = itemObj.toStrenthenPropData() retMsg.items.append(item) for i in range(0, len(LoginRewardModel.ONLINE_AWARD_CFG)): item = MsgDef.Item() # ItemHandler.buildItem(retItem, k) needSec = LoginRewardModel.ONLINE_AWARD_CFG[i][0] item.uid = int(needSec / 60) # itemCfg = itemObj.itemCfg item.itemCfgId = 1020101 item.name = '血瓶(小)' # item.strengthenLevel = itemObj.strengthenLevel item.lefttimes = i + 1 # item.propExt = itemObj.propExt # item.propStrengthen = itemObj.toStrenthenPropData() retMsg.items.append(item) return retMsg
def processMarriageItem(itemObj, num): ret_msg = MsgDef.Item() from handler import ItemHandler ItemHandler.buildItem(ret_msg, itemObj) return ret_msg
def processArenaReq(session, msg=None): player = session.player arenaCtrl = player.arenaCtrl if msg.opstype == 0 or msg.opstype == 1: #0表示显示竞技场数据 retMsg = MsgDef.ArenaOpsRet( msg.opstype, arenaCtrl.leftChallengeTimes, arenaCtrl.score, ArenaModel.getArenaMgr().getRankByUid(player.uid), []) retMsg.listPlayers = ArenaModel.getArenaMgr().allRank session.sendMsg(MsgDef.ServerCmd.ARENA_OPS, retMsg) elif msg.opstype == 2: #显示积分兑换 retMsg = MsgDef.ArenaOpsRet(msg.opstype, arenaCtrl.leftChallengeTimes, arenaCtrl.score, arenaCtrl.rank, [], []) for k, itemCfgPair in ItemModel.getItemMgr().arenaScoreItem.iteritems( ): item = MsgDef.Item() itemCfg = itemCfgPair[0] ItemModel.tmpBuildItem(item, itemCfg) retMsg.listItems.append( MsgDef.ArenaScore2Item(itemCfgPair[1], item)) session.sendMsg(MsgDef.ServerCmd.ARENA_OPS, retMsg) return elif msg.opstype == 3: #积分兑换 cfgid = msg.idArg destCfg = None if msg.numArg < 0: msg.numArg = 1 for k, itemCfgPair in ItemModel.getItemMgr().arenaScoreItem.iteritems( ): itemCfg = itemCfgPair[0] if itemCfg.cfgId == cfgid: destCfg = itemCfgPair break if None == destCfg: session.sendMsg(MsgDef.ServerCmd.ERROR_MSG, buildErrMsg(MsgDef.ClientCmd.ARENA_OPS, '参数有误')) return score = destCfg[1] * msg.numArg if player.arenaCtrl.score < score: session.sendMsg(MsgDef.ServerCmd.ERROR_MSG, buildErrMsg(MsgDef.ClientCmd.ARENA_OPS, '积分不足')) return needPkgNum = msg.numArg if destCfg[0].flagDieJia: needPkgNum = 1 if player.itemCtrl.getFreePkgSize() < needPkgNum: session.sendMsg(MsgDef.ServerCmd.ERROR_MSG, buildErrMsg(MsgDef.ClientCmd.ARENA_OPS, '包裹不足')) return player.AddScoreArena(-1 * score) itemObj = player.itemCtrl.addItemByCfgId(cfgid) from handler import ItemHandler ItemHandler.processQueryPkg(session) retMsg = MsgDef.ArenaOpsRet(msg.opstype, arenaCtrl.leftChallengeTimes, arenaCtrl.score, arenaCtrl.rank, [], []) session.sendMsg(MsgDef.ServerCmd.ARENA_OPS, retMsg) return elif msg.opstype == 4: #挑战某人 if player.arenaCtrl.leftChallengeTimes <= 0: session.sendMsg( MsgDef.ServerCmd.ERROR_MSG, buildErrMsg(MsgDef.ClientCmd.ARENA_OPS, '每天最多挑战10次')) return ArenaModel.getArenaMgr().createArena(session.player, msg.destuid) return
def handleDrop(self, objAttackKill): if objAttackKill.getType() != Base.PLAYER: return objAttack = objAttackKill #击杀血量最多的人,给装备奖励 maxObj = objAttackKill maxHurt = 0 for uid, data in self.allHurtCount.iteritems(): player = self.mapObj.getPlayerById(uid) if not player: continue if data.hurt > maxHurt: maxObj = player maxHurt = data.hurt maxTeam = None maxTeamHurt = 0 for uid, data in self.allTeamHurtCount.iteritems(): from model import TeamModel team = TeamModel.getTeamMgr().getTeamById(uid) if not team: continue if data.hurt > maxTeamHurt: maxTeam = team maxTeamHurt = data.hurt #初始化数据,方便复活 self.allHurtCount = {} self.allTeamHurtCount = {} objAttack.addExp(self.propCfg.expval, True) burstItemList = [] from handler import ItemHandler def burstItemCallBack(itemCfgId, num): burstItemList.append((itemCfgId, num)) def giveItemById(obj, retMsg, itemCfgId, num): if itemCfgId == 0: # 金币 obj.addGold(num, True) return item = obj.itemCtrl.addItemByCfgId(itemCfgId, num) if item: ffext.dump('whenDie itemEnterMap', item.itemCfg.name, num) # self.mapObj.itemEnterMap(item, self.x + 1, self.y + 1) if item.__class__ == list: for k in item: retItem = MsgDef.Item() ItemHandler.buildItem(retItem, k) retMsg.items.append(retItem) else: retItem = MsgDef.Item() ItemHandler.buildItem(retItem, item) retMsg.items.append(retItem) return def burstItemCallBackName(name, num): from model import ItemModel itemCfg = ItemModel.getItemMgr().getCfgByName(name) if itemCfg: burstItemCallBack(itemCfg.cfgId, num) else: ffext.error('burstItemCallBackName %s %d' % (name, num)) return for k in self.propCfg.allBurstCfg: k.genBurst(burstItemCallBackName) burstBagCfg = getMonsterMgr().cfgLevel2Drop.get(self.propCfg.level) if burstBagCfg: ffext.dump('burstBagCfg', burstBagCfg) # 1 根据表【怪物掉落包个数】获得该等级怪物的掉落物品的个数 # 2 每个包掉落概率:根据怪物的等级和类型,获得是否该包是否掉落 # 3 金币数目:怪物实际掉落金币=怪物等级金币*怪物的金币倍数 # 4 物品:每一个掉落包从【金币/物品1/物品2/物品3/物品4】中随机一个 # 5 若随机到【/物品1/物品2/物品3/物品4】,寻找制定的掉落包ID内物品 monType = self.propCfg.getMonDifficultyType() num = burstBagCfg.numList[monType] rate = burstBagCfg.rateList[monType] dropBagList = burstBagCfg.bagIdList for k in range(num): rand = random.randint(1, 100) ffext.dump('rate trace', rate, rand, len(dropBagList)) if rate >= rand and len(dropBagList) > 0: # 爆落 destBagId = dropBagList[rand % len(dropBagList)] ffext.dump('rate trace', rate, rand, len(dropBagList), destBagId) if destBagId == 0: # 金币 gold = random.randint(burstBagCfg.goldMin, burstBagCfg.goldMax) burstItemCallBack( destBagId, gold * self.propCfg.expgoldtimes) # *怪物的金币倍数 continue destBagCfg = getMonsterMgr().bagid2cfg.get(destBagId) if destBagCfg: for itemCfgId in destBagCfg.itemIdList: burstItemCallBack(itemCfgId, 1) ffext.dump('handledrop', burstItemList, objAttack.name, maxHurt, maxTeamHurt) if maxHurt >= maxTeamHurt: #个人获得道具 objAttack = maxObj retMsg = MsgDef.MonserBurstItemsRet(self.uid, objAttack.uid, [], self.propCfg.expval, 0) for k in burstItemList: giveItemById(objAttack, retMsg, k[0], k[1]) if len(retMsg.items) > 0: ItemHandler.processQueryPkg(objAttack.session) objAttack.sendMsg(MsgDef.ServerCmd.MONSTER_BURST_ITEMS, retMsg) return else: #团队获得道具 allPlayers = [] for k, v in maxTeam.getTeamMember().iteritems(): p = self.mapObj.getPlayerById(k) if p: allPlayers.append(p) if not allPlayers: return objPrize = allPlayers[random.randint(0, len(allPlayers) - 1)] retMsg = MsgDef.MonserBurstItemsRet(self.uid, objPrize.uid, [], 0, 0) objPrizeRef = weakref.ref(objPrize) def tmpPrizeCallBack(): objPrize = objPrizeRef() if not objPrize: return for k in burstItemList: giveItemById(objPrize, retMsg, k[0], k[1]) if len(retMsg.items) > 0: ItemHandler.processQueryPkg(objPrize.session) retMsg.teamBurstInfo = [] callbackArg = {'players': {}, 'prizecallback': tmpPrizeCallBack} for arg in allPlayers: randNum = 1 if arg == objPrize: randNum = 6 else: randNum = random.randint(1, 5) retMsg.teamBurstInfo.append( MsgDef.BurstRandInfo(arg.uid, arg.name, randNum)) callbackArg[arg.uid] = arg.name for k in burstItemList: ffext.dump('busrt info', k) from model import ItemModel itemCfg = ItemModel.getItemMgr().getCfgByCfgId(k[0]) if itemCfg: retItem = MsgDef.Item() ItemModel.tmpBuildItem(retItem, itemCfg) retMsg.items.append(retItem) def timercb(): ffext.dump("timercb teamburst...") cb = callbackArg['prizecallback'] if cb: callbackArg['prizecallback'] = None cb() return ffext.timer(5 * 1000, timercb) ffext.dump('monter burst items', retMsg) for objAttack in allPlayers: retMsg.callbackId = objPrize.addCallBack( burstCallBack, callbackArg) objAttack.sendMsg(MsgDef.ServerCmd.MONSTER_BURST_ITEMS, retMsg) return