def delTime(self): self.flag = True if None == self.getBrotherExtra().pop('delTime', None): return False DbService.getGuildService().updateBrotherExtra(self.bid, json.dumps(self.extra)) return
def init(self): def brotherInfo(ret): ffext.dump('brother init', ret.result) if ret.flag == False or len(ret.result) == 0: self.allBrotherList = {} return for i in range(0, len(ret.result)): brotherID = long(ret.result[i][0]) if None == self.getBrotherById(brotherID): brotherCtrl = BrotherCtrl() brotherCtrl.bid = brotherID brotherCtrl.allBrothers = {} brotherCtrl.flag = True extra = str(ret.result[i][1]) if extra != '': extra = json.loads(extra) if extra: brotherCtrl.extra = extra brotherCtrl.ranking = 0 self.allBrotherList[brotherCtrl.bid] = brotherCtrl brotherCtrl = self.getBrotherById(brotherID) playerBrotherInfo = PlayerBrotherInfo() playerBrotherInfo.setPlayerBrother(long(ret.result[i][2]), str(ret.result[i][3]), long(ret.result[i][4]), long(ret.result[i][5]), long(ret.result[i][6])) brotherCtrl.allBrothers[ playerBrotherInfo.uid] = playerBrotherInfo return DbService.getGuildService().syncGetBrotherMemberInfoList(brotherInfo) return True
def cbEnd(): rankWarInfo = self.allGuildRankWarVSInfo.pop(rankWarId, None) if not rankWarInfo: return rankWarInfo.tmRankWarStart = 0 retMsg = MsgDef.GuildRankWarOpsRet( MsgDef.GuildRankWarOpsCmd.RANKWAR_END, rankWarInfo.tmRankWarStart) retMsg.winGuildId = 0 if rankWarInfo.guildWin: retMsg.winGuildId = rankWarInfo.guildWin elif rankWarInfo.guildScore1 > rankWarInfo.guildScore2: rankWarInfo.guildWin = rankWarInfo.guild1.guildID retMsg.winGuildId = rankWarInfo.guild1.guildID elif rankWarInfo.guildScore1 < rankWarInfo.guildScore2: rankWarInfo.guildWin = rankWarInfo.guild2.guildID retMsg.winGuildId = rankWarInfo.guild2.guildID elif rankWarInfo.guildScore1 == rankWarInfo.guildScore2: allHp1 = 0 allHp2 = 0 for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) if memberSession: member = memberSession.player allHp1 += member.hp for k, v in rankWarInfo.guildTeam2.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) if memberSession: member = memberSession.player allHp2 += member.hp if allHp1 > allHp2: rankWarInfo.guildWin = rankWarInfo.guild1.guildID retMsg.winGuildId = rankWarInfo.guild1.guildID elif allHp1 < allHp2: rankWarInfo.guildWin = rankWarInfo.guild2.guildID retMsg.winGuildId = rankWarInfo.guild2.guildID if not retMsg.winGuildId: DbService.getGuildService().updateRankWarWin( 0, rankWarInfo.guildId1, rankWarInfo.guildId2) for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) for k, v in rankWarInfo.guildTeam2.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) else: DbService.getGuildService().updateRankWarWin( 0, rankWarInfo.getAnotherGuild(retMsg.winGuildId)) if retMsg.winGuildId == rankWarInfo.guild1.guildID: for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) elif retMsg.winGuildId == rankWarInfo.guild2.guildID: for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg)
def addBrotherInfo(self, brotherInfo): brotherid = idtool.allocId() brotherInfo.bid = brotherid self.allBrotherList[brotherInfo.bid] = brotherInfo playerInfo = brotherInfo.getPlayerInfo() DbService.getGuildService().addBrother(brotherid, playerInfo[0].uid, playerInfo[1].uid, playerInfo[2].uid)
def addBrotherList(self, player1, player2, player3): brotherid = idtool.allocId() brother = BrotherCtrl() brother.bid = brotherid brother.addBrotherMember(player1, player2, player3) #brother.extra = '' self.allBrotherList[brother.bid] = brother DbService.getGuildService().addBrother(brotherid, player1.uid, player2.uid, player3.uid) return brotherid
def addTime(self, time): self.flag = False self.extra['delTime'] = time DbService.getGuildService().updateBrotherExtra(self.bid, json.dumps(self.extra)) return
def delBrother(self, bid): brotherCtrl = self.allBrotherList.pop(bid) if None == brotherCtrl: return False DbService.getGuildService().delBrother(brotherCtrl) return True
def init(self): db = ffext.allocDbConnection('cfg', ffext.getConfig('-cfg')) ret = db.queryResult( 'select guildLevel,guildExp,guildNum, guildDayExp, playerDayExp from guild' ) self.guildLevelCfg = {} for row in ret.result: levelCfg = guildLevelCfg() levelCfg.setGuildLevelCfg(long(row[0]), long(row[1]), long(row[2]), long(row[3]), long(row[4])) self.guildLevelCfg[levelCfg.guildLevel] = levelCfg def guildInfo(ret): if ret.flag == False or len(ret.result) == 0: self.allGuild = {} return for i in range(0, len(ret.result)): guildID = long(ret.result[i][0]) if None == self.getGuildById(guildID): guildInfo = GuildInfo() guildLevel = long(ret.result[i][8]) guildExp = long(ret.result[i][9]) #行会剩余资源 levelRanking = 1 #遍历现有字典,获取该行会现有排名,并插入 for uid, val in self.allGuild.iteritems(): if val.guildLevel < guildLevel or ( val.guildLevel == guildLevel and val.guildExp < guildExp): val.levelRanking = val.levelRanking + 1 else: levelRanking = levelRanking + 1 guildInfo.allGuildMemberTemp = {} #申请加入行会成员列表 guildInfo.guildID = long(ret.result[i][0]) #行会ID guildInfo.guildName = str(ret.result[i][5]) #行会名称 guildInfo.guildImage = str(ret.result[i][6]) #行会名称 guildInfo.guildNotice = str(ret.result[i][7]) #行会名称 guildInfo.guildLevel = guildLevel #行会等级 guildInfo.levelRanking = levelRanking #行会经验 guildInfo.guildExp = guildExp guildInfo.guildLeaderName = str(ret.result[i][10]) #行会名称 guildInfo.lastDateContribution = long( ret.result[i][11]) #行会经验 guildInfo.lastDate = str(ret.result[i][12]) #行会名称 self.allGuild[guildInfo.guildID] = guildInfo else: guildInfo = self.getGuildById(guildID) playerGuildInfo = PlayerGuildInfo() ranking = 1 contribute = ret.result[i][4] #遍历现有字典,获取该行会现有排名,并插入 for uid, val in guildInfo.allGuildMember.iteritems(): if val.contribute > contribute: ranking = ranking + 1 else: val.ranking = val.ranking + 1 #ffext.dump('ret is!!!!!!!!!!!!!!!!!!!!!!!!! ', ret) playerGuildInfo.setPlayerGuildInfo(long(ret.result[i][1]), str(ret.result[i][2]), long(ret.result[i][3]), contribute, ranking) guildInfo.allGuildMember[playerGuildInfo.uid] = playerGuildInfo return #DbService.getGuildService().syncGetGuildMemberInfoList(guildInfo) def loadAllGuild(ret): if ret.flag == False or len(ret.result) == 0: self.allGuild = {} return for i in range(0, len(ret.result)): guildInfo = GuildInfo() levelRanking = i + 1 #sql = "select guildid, guildname, guildimage, guildnotice, guildlevel, guildExp, guildchiefname, lastdatecontribution, lastdate from guildinfo order by guildlevel desc, guildExp desc" guildInfo.guildID = long(ret.result[i][0]) # 行会ID guildInfo.guildName = str(ret.result[i][1]) # 行会名称 guildInfo.guildImage = str(ret.result[i][2]) # 行会名称 guildInfo.guildNotice = str(ret.result[i][3]) # 行会名称 guildInfo.guildLevel = long(ret.result[i][4]) # 行会等级 guildInfo.levelRanking = levelRanking guildInfo.guildExp = long(ret.result[i][5]) # 行会经验 guildInfo.guildLeaderName = str(ret.result[i][6]) # 行会名称 guildInfo.lastDateContribution = long(ret.result[i][7]) # 行会经验 guildInfo.lastDate = ffext.str2timestamp( ret.result[i][8]) # 行会名称 #ffext.dump('loadAllGuild', guildInfo) self.allGuild[guildInfo.guildID] = guildInfo return def loadAllGuildMember(ret): for i in range(0, len(ret.result)): playerGuildInfo = PlayerGuildInfo() row = ret.result[i] guildID = long(row[0]) guildInfo = self.getGuildById(guildID) if not guildInfo: return #sql = "select guildid, guildmemberinfo.uid as uid1, name2,memberpost3, contribute4 daycontribute5, lastdate6, level7 from guildmemberinfo, player where player.uid = guildmemberinfo.uid and player.delflag = 0" playerGuildInfo.setPlayerGuildInfo(long(row[1]), str(row[2]), long(row[3]), long(row[4]), 1, int(row[7]), int(row[8])) playerGuildInfo.daycontribute = long(row[5]) playerGuildInfo.lastdate = ffext.str2timestamp(row[6]) guildInfo.allGuildMember[playerGuildInfo.uid] = playerGuildInfo #ffext.dump('loadAllGuildMember!!!!!!!!!!!!!!!!!!!!!!!!', row, playerGuildInfo) return DbService.getGuildService().syncGetAllGuildInfo(loadAllGuild) DbService.getGuildService().syncGetAllGuildMember(loadAllGuildMember) for k, v in self.allGuild.iteritems(): v.calMemberRank() return True
def addRankWarVsInfo(self, guildId1, guildId2, mapxy): rankWarInfo = GuildRankWarVSInfo() rankWarId = idtool.allocTmpId() rankWarInfo.warId = rankWarId rankWarInfo.guildId1 = guildId1 rankWarInfo.guildId2 = guildId2 rankWarInfo.guildTeam1 = {} rankWarInfo.guildTeam2 = {} rankWarInfo.tmRankWarStart = ffext.getTime() + RANK_WAR_SEC_START retMsg = MsgDef.GuildRankWarOpsRet() cmd = MsgDef.ClientCmd.GUILD_RANKWAR_OPS def cb(ret): for row in ret.result: memberUid = int(row[0]) guildId = int(row[1]) memberSession = ffext.getSessionMgr().findByUid(memberUid) if memberSession: member = memberSession.player #询问是否进入地图 retMsg.guildId = guildId retMsg.mapname = mapxy[0] retMsg.x = mapxy[1] retMsg.y = mapxy[2] memberSession.sendMsg(cmd, retMsg) import time time.sleep(10) if guildId == rankWarInfo.guildId1 and member.mapname == mapxy[ 0]: member.modeAttack = MsgDef.EATTACK_MODE.PEACE rankWarInfo.guildTeam1[memberUid] = member elif guildId == rankWarInfo.guildId2 and member.mapname == mapxy[ 0]: member.modeAttack = MsgDef.EATTACK_MODE.PEACE rankWarInfo.guildTeam2[memberUid] = member self.allGuildRankWarVSInfo[rankWarInfo.warId] = rankWarInfo DbService.getGuildService().queryRankWarTeamMember( 1, rankWarInfo.guildId1, rankWarInfo.guildId2, cb) #self.allGuildWarVSInfo[rankWarInfo.warId] = rankWarInfo def cbStart(): retMsg = MsgDef.GuildWarOpsRet( MsgDef.GuildRankWarOpsCmd.RANKWAR_START, rankWarInfo.tmRankWarStart) for k, v in rankWarInfo.guildTeam1.iteritems(): v.modeAttack = MsgDef.EATTACK_MODE.GUILD for k, v in rankWarInfo.guildTeam2.iteritems(): v.modeAttack = MsgDef.EATTACK_MODE.GUILD pass def cbEnd(): rankWarInfo = self.allGuildRankWarVSInfo.pop(rankWarId, None) if not rankWarInfo: return rankWarInfo.tmRankWarStart = 0 retMsg = MsgDef.GuildRankWarOpsRet( MsgDef.GuildRankWarOpsCmd.RANKWAR_END, rankWarInfo.tmRankWarStart) retMsg.winGuildId = 0 if rankWarInfo.guildWin: retMsg.winGuildId = rankWarInfo.guildWin elif rankWarInfo.guildScore1 > rankWarInfo.guildScore2: rankWarInfo.guildWin = rankWarInfo.guild1.guildID retMsg.winGuildId = rankWarInfo.guild1.guildID elif rankWarInfo.guildScore1 < rankWarInfo.guildScore2: rankWarInfo.guildWin = rankWarInfo.guild2.guildID retMsg.winGuildId = rankWarInfo.guild2.guildID elif rankWarInfo.guildScore1 == rankWarInfo.guildScore2: allHp1 = 0 allHp2 = 0 for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) if memberSession: member = memberSession.player allHp1 += member.hp for k, v in rankWarInfo.guildTeam2.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) if memberSession: member = memberSession.player allHp2 += member.hp if allHp1 > allHp2: rankWarInfo.guildWin = rankWarInfo.guild1.guildID retMsg.winGuildId = rankWarInfo.guild1.guildID elif allHp1 < allHp2: rankWarInfo.guildWin = rankWarInfo.guild2.guildID retMsg.winGuildId = rankWarInfo.guild2.guildID if not retMsg.winGuildId: DbService.getGuildService().updateRankWarWin( 0, rankWarInfo.guildId1, rankWarInfo.guildId2) for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) for k, v in rankWarInfo.guildTeam2.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) else: DbService.getGuildService().updateRankWarWin( 0, rankWarInfo.getAnotherGuild(retMsg.winGuildId)) if retMsg.winGuildId == rankWarInfo.guild1.guildID: for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) elif retMsg.winGuildId == rankWarInfo.guild2.guildID: for k, v in rankWarInfo.guildTeam1.iteritems(): memberSession = ffext.getSessionMgr().findByUid(k) memberSession.sendMsg(cmd, retMsg) ffext.timer(WAR_SEC_START * 1000, cbStart) ffext.timer((WAR_SEC_START + WAR_SEC_END) * 1000, cbEnd) return rankWarInfo