def _checkSetMedal(userId, roomMutil, basebet, basemulti, isGameStart, winchip): winchip = 0 if isGameStart else winchip winrate, oldLevel = gamedata.getGameAttrs(userId, DIZHU_GAMEID, ['winrate', 'level'], False) winrate = strutil.loads(winrate, ignoreException=True, execptionValue={}) if winchip >= 0 or isGameStart: _processGamePlayWinTimes(winrate, isGameStart) oldLevel = strutil.parseInts(oldLevel) detalExp = 0 if winchip > 0 or isGameStart: detalExp = _calUserDetalExp(winchip, roomMutil, basebet, basemulti) exp = userdata.incrExp(userId, detalExp) explevel = dizhuaccount.getExpLevel(exp) gamedata.setGameAttrs(userId, DIZHU_GAMEID, ['winrate', 'level'], [strutil.dumps(winrate), explevel]) if oldLevel != explevel: from dizhu.game import TGDizhu TGDizhu.getEventBus().publishEvent( UserLevelGrowEvent(DIZHU_GAMEID, userId, oldLevel, explevel)) if isGameStart: # 广告商通知 pcount = dizhuconf.getAdNotifyPlayCount() if pcount > 0 and winrate.get('pt', 0) == pcount: sdkclient.adNotifyCallBack(DIZHU_GAMEID, userId) nextExp = dizhuaccount.getGameUserNextExp(explevel) title = dizhuaccount.getGameUserTitle(explevel) return [explevel, exp, detalExp, nextExp, title]
def doWinLose(cls, room, table, seatId, isTimeOutKill=False): # TODO: # 计算春天 dizhuseatId = table.status.diZhu if seatId != dizhuseatId: if table.seats[dizhuseatId - 1].outCardCount == 1: table.status.chuntian = 2 else: s1 = table.seats[(dizhuseatId - 1 + 1) % table.maxSeatN] s2 = table.seats[(dizhuseatId - 1 + 2) % table.maxSeatN] if s1.outCardCount == 0 and s2.outCardCount == 0: table.status.chuntian = 2 # 翻倍计算 叫地主的倍数 windoubles = table.status.callGrade # 炸弹倍数 windoubles *= pow(2, table.status.bomb) # 春天倍数 windoubles *= table.status.chuntian # 底牌倍数 windoubles *= table.status.baseCardMulti # 明牌倍数 windoubles *= table.status.show dizhuwin = 0 if seatId == dizhuseatId: dizhuwin = 1 if seatId == 0 : # 流局 dizhuwin = 0 windoubles = 1 else: windoubles = abs(windoubles) userids = [] detalChips = [] seat_coin = [] baseBetChip = table._match_table_info['baseChip'] robot_card_count = [0] * len(table.seats) # 每个座位 for x in xrange(len(table.seats)): uid = table.seats[x].userId userInfo = table._match_table_info['users'][x] userids.append(uid) if seatId == 0 : # 流局 detalChip = -baseBetChip else: if dizhuwin : if x + 1 == dizhuseatId : detalChip = baseBetChip + baseBetChip else: detalChip = -baseBetChip else: if x + 1 == dizhuseatId : detalChip = -baseBetChip - baseBetChip else: detalChip = baseBetChip detalChip *= windoubles detalChips.append(detalChip) seat_coin.append(userInfo['score'] + detalChip) robot_card_count[x] = table.seats[x].robotCardCount ftlog.info('dizhu.game_win userId=', uid, 'roomId=', room.roomId, 'tableId=', table.tableId, 'delta=', detalChip) ftlog.debug('doWinLose->after room fee->robot_card_count=', robot_card_count) punish.Punish.doWinLosePunish(table.runConfig.punishCardCount, table.runConfig.isMatch, seat_coin, detalChips, robot_card_count) for x in xrange(len(table.seats)): uid = table.seats[x].userId userInfo = table._match_table_info['users'][x] userInfo['score'] = seat_coin[x] # 返回当前Table的game_win moWin = MsgPack() moWin.setCmd('table_call') moWin.setResult('action', 'game_win') moWin.setResult('isMatch', 1) moWin.setResult('gameId', table.gameId) moWin.setResult('roomId', table.roomId) moWin.setResult('tableId', table.tableId) moWin.setResult('stat', table.status.toInfoDictExt()) moWin.setResult('dizhuwin', dizhuwin) if seatId == 0: moWin.setResult('nowin', 1) moWin.setResult('slam', 0) moWin.setResult('cards', [seat.cards for seat in table.seats]) roundId = table.gameRound.number table.clear(userids) for x in xrange(len(userids)): uid = userids[x] mrank = 3 mtableRanking = 3 moWin.setResult('seat' + str(x + 1), [detalChips[x], seat_coin[x], 0, 0, 0, 0, mrank, mtableRanking]) #增加经验 exp = userdata.incrExp(uid, 20) explevel = dizhuaccount.getExpLevel(exp) gamedata.setGameAttr(uid, table.gameId, 'level', explevel) ftlog.debug('AsyncUpgradeHeroMatch.doWinLoseTable add 20 exp, tootle', exp, 'level', explevel) table.gamePlay.sender.sendToAllTableUser(moWin) # 发送给match manager users = [] for x in xrange(len(userids)): user = {} user['userId'] = userids[x] user['deltaScore'] = int(detalChips[x]) user['seatId'] = x + 1 user['score'] = seat_coin[x] users.append(user) mnr_msg = MsgPack() mnr_msg.setCmd('room') mnr_msg.setParam('action', 'm_winlose') mnr_msg.setParam('gameId', table.gameId) mnr_msg.setParam('roomId', table.room.ctrlRoomId) mnr_msg.setParam('tableId', table.tableId) mnr_msg.setParam('users', users) # 记录游戏winlose try: for u in users: table.room.reportBiGameEvent("TABLE_WIN", u['userId'], table.roomId, table.tableId, roundId, u['deltaScore'], 0, 0, [], 'table_win') # cls.report_bi_game_event(TyContext.BIEventId.TABLE_WIN, u['userId'], table._rid, table._id, table._roundId, u['deltaScore'], 0, 0, [], 'table_win') except: if ftlog.is_debug(): ftlog.exception() router.sendRoomServer(mnr_msg, table.room.ctrlRoomId)
def doWinLose(cls, room, table, seatId, isTimeOutKill=False): # TODO: if not table._match_table_info: ftlog.warn('GroupMatch.doWinLoseTable roomId=', room.roomId, 'tableId=', table.tableId, 'seatId=', seatId, 'isTimeOutKill=', isTimeOutKill, 'err=', 'not matchTableInfo') return if ftlog.is_debug(): ftlog.debug('GroupMatch.doWinLose roomId=', room.roomId, 'tableId=', table.tableId, 'seatId=', seatId, 'isTimeOutKill=', isTimeOutKill, 'stageReward=', table.group.stageConf.conf.get('stageReward')) # 计算春天 dizhuseatId = table.status.diZhu if seatId != dizhuseatId: if table.seats[dizhuseatId - 1].outCardCount == 1: table.status.chuntian = 2 else: s1 = table.seats[(dizhuseatId - 1 + 1) % table.maxSeatN] s2 = table.seats[(dizhuseatId - 1 + 2) % table.maxSeatN] if s1.outCardCount == 0 and s2.outCardCount == 0: table.status.chuntian = 2 # 翻倍计算 叫地主的倍数 windoubles = table.status.callGrade # 炸弹倍数 windoubles *= pow(2, table.status.bomb) # 春天倍数 windoubles *= table.status.chuntian # 底牌倍数 windoubles *= table.status.baseCardMulti # 明牌倍数 windoubles *= table.status.show dizhuwin = 0 if seatId == dizhuseatId: dizhuwin = 1 if seatId == 0 : # 流局 dizhuwin = 0 windoubles = 1 else: windoubles = abs(windoubles) userids = [] detalChips = [] seat_coin = [] baseBetChip = table._match_table_info['mInfos']['basescore'] robot_card_count = [0] * len(table.seats) # 每个座位 for x in xrange(len(table.seats)): uid = table.seats[x].userId userids.append(uid) if seatId == 0 : # 流局 detalChip = -baseBetChip else: if dizhuwin : if x + 1 == dizhuseatId : detalChip = baseBetChip + baseBetChip else: detalChip = -baseBetChip else: if x + 1 == dizhuseatId : detalChip = -baseBetChip - baseBetChip else: detalChip = baseBetChip detalChip *= windoubles detalChips.append(detalChip) seat_coin.append(table._match_table_info['mInfos']['scores'][x] + detalChip) robot_card_count[x] = table.seats[x].robotCardCount ftlog.info('dizhu.game_win userId=', uid, 'roomId=', room.roomId, 'tableId=', table.tableId, 'delta=', detalChip) punish.Punish.doWinLosePunish(table.runConfig.punishCardCount, table.runConfig.isMatch, seat_coin, detalChips, robot_card_count) for x in xrange(len(table.seats)): uid = table.seats[x].userId table._match_table_info['mInfos']['scores'][x] = seat_coin[x] # 返回当前Table的game_win moWin = MsgPack() moWin.setCmd('table_call') moWin.setResult('action', 'game_win') moWin.setResult('isMatch', 1) moWin.setResult('gameId', table.gameId) moWin.setResult('roomId', table.roomId) moWin.setResult('tableId', table.tableId) # moWin.setResult('stat', dict(zip(tdz_stat_title, table.status))) moWin.setResult('stat', table.status.toInfoDictExt()) moWin.setResult('dizhuwin', dizhuwin) if seatId == 0: moWin.setResult('nowin', 1) moWin.setResult('slam', 0) moWin.setResult('cards', [seat.cards for seat in table.seats]) roundId = table.gameRound.number table.clear(userids) for x in xrange(len(userids)): uid = userids[x] mrank = 3 mtableRanking = 3 moWin.setResult('seat' + str(x + 1), [detalChips[x], seat_coin[x], 0, 0, 0, 0, mrank, mtableRanking]) if detalChips[x] > 0: stageRewards = table.group.stageConf.conf.get('stageReward', None) if table.group.stageConf else None if stageRewards: contentItems = TYContentItem.decodeList(stageRewards) assetList = dizhu_util.sendRewardItems(uid, contentItems, '', 'DIZHU_STAGE_REWARD', 0) moWin.setResult('stageReward', stageRewards) ftlog.info('stageRewards send. userId=', uid, 'stageRewards=', stageRewards, 'assetList=', assetList) #增加经验 exp = userdata.incrExp(uid, 20) explevel = dizhuaccount.getExpLevel(exp) gamedata.setGameAttr(uid, table.gameId, 'level', explevel) if ftlog.is_debug(): ftlog.debug('BigMatch.doWinLoseTable', 'addExp=', 20, 'curExp=', exp, 'curLevel=', explevel) table.gamePlay.sender.sendToAllTableUser(moWin) # 发送给match manager users = [] for x in xrange(len(userids)): user = {} user['userId'] = userids[x] user['deltaScore'] = int(detalChips[x]) user['seatId'] = x + 1 users.append(user) mnr_msg = MsgPack() mnr_msg.setCmd('room') mnr_msg.setParam('action', 'm_winlose') mnr_msg.setParam('gameId', table.gameId) mnr_msg.setParam('matchId', table.room.bigmatchId) mnr_msg.setParam('roomId', table.room.ctrlRoomId) mnr_msg.setParam('tableId', table.tableId) mnr_msg.setParam('users', users) mnr_msg.setParam('ccrc', table._match_table_info['ccrc']) if cls.WINLOSE_SLEEP > 0: FTTasklet.getCurrentFTTasklet().sleepNb(cls.WINLOSE_SLEEP) # 记录游戏winlose try: for u in users: table.room.reportBiGameEvent('TABLE_WIN', u['userId'], table.roomId, table.tableId, roundId, u['deltaScore'], 0, 0, [], 'table_win') except: if ftlog.is_debug(): ftlog.exception() router.sendRoomServer(mnr_msg, table.room.ctrlRoomId)
def doWinLose(cls, room, table, seatId, isTimeOutKill=False): if not table._match_table_info: ftlog.warn('ErdayiMatch.doWinLoseTable roomId=', room.roomId, 'tableId=', table.tableId, 'seatId=', seatId, 'isTimeOutKill=', isTimeOutKill, 'err=', 'not matchTableInfo') return # 计算春天 dizhuseatId = table.status.diZhu if seatId != dizhuseatId: if table.seats[dizhuseatId - 1].outCardCount == 1: table.status.chuntian = 2 else: s1 = table.seats[(dizhuseatId - 1 + 1) % table.maxSeatN] s2 = table.seats[(dizhuseatId - 1 + 2) % table.maxSeatN] if s1.outCardCount == 0 and s2.outCardCount == 0: table.status.chuntian = 2 # 翻倍计算 叫地主的倍数 windoubles = table.status.callGrade # 炸弹倍数 windoubles *= pow(2, table.status.bomb) # 春天倍数 windoubles *= table.status.chuntian # 底牌倍数 windoubles *= table.status.baseCardMulti # 明牌倍数 windoubles *= table.status.show dizhuwin = 0 if seatId == dizhuseatId: dizhuwin = 1 if seatId == 0: # 流局 dizhuwin = 0 windoubles = 1 else: windoubles = abs(windoubles) userids = [seat.userId for seat in table.seats] seat_coin = [0] * len(table.seats) detalChips = [0] * len(table.seats) baseBetChip = table._match_table_info['step']['basescore'] robot_card_count = [0] * len(table.seats) # 每个座位 # 计算所有农民的输赢 for i, player in enumerate(table.players): userids.append(player.userId) if seatId == 0: detalChips[i] = -baseBetChip if i + 1 == dizhuseatId: continue detalChip = baseBetChip * windoubles # 计算本农民的倍数 seatMulti = max(table.seats[i].seatMulti, 1) * max( table.seats[dizhuseatId - 1].seatMulti, 1) detalChip *= seatMulti if dizhuwin: detalChip *= -1 detalChips[i] = detalChip detalChips[dizhuseatId - 1] -= detalChip if ftlog.is_debug(): ftlog.debug('ErdayiMatch.doWinLoseTable roomId=', room.roomId, 'tableId=', table.tableId, 'seatId=', seatId, 'dizhuseatId=', dizhuseatId, 'detalChip=', detalChip, 'dizhuDetalChip=', detalChips[dizhuseatId - 1]) punish.Punish.doWinLosePunish(table.runConfig.punishCardCount, table.runConfig.isMatch, seat_coin, detalChips, robot_card_count) seat_coin = [0] * len(table.seats) for i, seatInfo in enumerate(table._match_table_info['seats']): seat_coin[i] = seatInfo['score'] # 返回当前Table的game_win moWin = MsgPack() moWin.setCmd('table_call') moWin.setResult('action', 'game_win') moWin.setResult('isMatch', 1) moWin.setResult('gameId', table.gameId) moWin.setResult('roomId', table.roomId) moWin.setResult('tableId', table.tableId) # moWin.setResult('stat', dict(zip(tdz_stat_title, table.status))) moWin.setResult('stat', table.status.toInfoDictExt()) moWin.setResult('dizhuwin', dizhuwin) if seatId == 0: moWin.setResult('nowin', 1) moWin.setResult('slam', 0) moWin.setResult('cards', [seat.cards for seat in table.seats]) roundId = table.gameRound.number table.clear(userids) for i, player in enumerate(table.players): uid = player.userId mrank = 3 mtableRanking = 3 moWin.setResult('seat' + str(player.seatId), [ detalChips[i], seat_coin[i], 0, 0, 0, 0, mrank, mtableRanking ]) if not player.isAI: #增加经验 exp = userdata.incrExp(uid, 20) explevel = dizhuaccount.getExpLevel(exp) gamedata.setGameAttr(uid, table.gameId, 'level', explevel) if ftlog.is_debug(): ftlog.debug('ErdayiMatch.doWinLoseTable', 'addExp=', 20, 'curExp=', exp, 'curLevel=', explevel) table.gamePlay.sender.sendToAllTableUser(moWin) # 发送给match manager users = [] for i, player in enumerate(table.players): if not player.isAI: user = {} user['userId'] = player.userId user['deltaScore'] = int(detalChips[i]) user['seatId'] = player.seatId users.append(user) mnr_msg = MsgPack() mnr_msg.setCmd('room') mnr_msg.setParam('action', 'm_winlose') mnr_msg.setParam('gameId', table.gameId) mnr_msg.setParam('matchId', table.room.bigmatchId) mnr_msg.setParam('roomId', table.room.ctrlRoomId) mnr_msg.setParam('tableId', table.tableId) mnr_msg.setParam('users', users) mnr_msg.setParam('ccrc', table._match_table_info['ccrc']) if cls.WINLOSE_SLEEP > 0: FTTasklet.getCurrentFTTasklet().sleepNb(cls.WINLOSE_SLEEP) # 记录游戏winlose try: for u in users: table.room.reportBiGameEvent('TABLE_WIN', u['userId'], table.roomId, table.tableId, roundId, u['deltaScore'], 0, 0, [], 'table_win') except: if ftlog.is_debug(): ftlog.exception() router.sendRoomServer(mnr_msg, table.room.ctrlRoomId)
def doWinLose(cls, room, table, seatId, isTimeOutKill=False): # TODO: if not table._match_table_info: ftlog.warn('BigMatch.doWinLoseTable roomId=', room.roomId, 'tableId=', table.tableId, 'seatId=', seatId, 'isTimeOutKill=', isTimeOutKill, 'not matchTableInfo') return # 计算春天 dizhuseatId = table.status.diZhu if seatId != dizhuseatId: if table.seats[dizhuseatId - 1].outCardCount == 1: table.status.chuntian = 2 else: s1 = table.seats[(dizhuseatId - 1 + 1) % table.maxSeatN] s2 = table.seats[(dizhuseatId - 1 + 2) % table.maxSeatN] if s1.outCardCount == 0 and s2.outCardCount == 0: table.status.chuntian = 2 # 翻倍计算 叫地主的倍数 windoubles = table.status.callGrade # 炸弹倍数 windoubles *= pow(2, table.status.bomb) # 春天倍数 windoubles *= table.status.chuntian # 底牌倍数 windoubles *= table.status.baseCardMulti # 明牌倍数 windoubles *= table.status.show dizhuwin = 0 if seatId == dizhuseatId: dizhuwin = 1 if seatId == 0: # 流局 dizhuwin = 0 windoubles = 1 else: windoubles = abs(windoubles) # matchlog('Match->doWinLose dizhuwin=', dizhuwin , 'dizhuseatId=', dizhuseatId, 'windoubles=', windoubles) userids = [] detalChips = [] seat_coin = [] baseBetChip = table._match_table_info['mInfos']['basescore'] robot_card_count = [0] * len(table.seats) # 每个座位 for x in xrange(len(table.seats)): uid = table.seats[x].userId userids.append(uid) if seatId == 0: # 流局 detalChip = -baseBetChip else: if dizhuwin: if x + 1 == dizhuseatId: detalChip = baseBetChip + baseBetChip else: detalChip = -baseBetChip else: if x + 1 == dizhuseatId: detalChip = -baseBetChip - baseBetChip else: detalChip = baseBetChip detalChip *= windoubles detalChips.append(detalChip) seat_coin.append(table._match_table_info['mInfos']['scores'][x] + detalChip) robot_card_count[x] = table.seats[x].robotCardCount ftlog.info('dizhu.game_win userId=', uid, 'roomId=', room.roomId, 'tableId=', table.tableId, 'delta=', detalChip) ftlog.debug('doWinLose->after room fee->robot_card_count=', robot_card_count) # table.punishClass().doWinLosePunish(table, seat_coin, detalChips) punish.Punish.doWinLosePunish(table.runConfig.punishCardCount, table.runConfig.isMatch, seat_coin, detalChips, robot_card_count) for x in xrange(len(table.seats)): uid = table.seats[x].userId table._match_table_info['mInfos']['scores'][x] = seat_coin[x] # 返回当前Table的game_win moWin = MsgPack() moWin.setCmd('table_call') moWin.setResult('action', 'game_win') moWin.setResult('isMatch', 1) moWin.setResult('gameId', table.gameId) moWin.setResult('roomId', table.roomId) moWin.setResult('tableId', table.tableId) # moWin.setResult('stat', dict(zip(tdz_stat_title, table.status))) moWin.setResult('stat', table.status.toInfoDictExt()) moWin.setResult('dizhuwin', dizhuwin) if seatId == 0: moWin.setResult('nowin', 1) moWin.setResult('slam', 0) moWin.setResult('cards', [seat.cards for seat in table.seats]) roundId = table.gameRound.number table.clear(userids) for x in xrange(len(table.seats)): uid = table.seats[x].userId mrank = 3 mtableRanking = 3 moWin.setResult('seat' + str(x + 1), [ detalChips[x], seat_coin[x], 0, 0, 0, 0, mrank, mtableRanking ]) #增加经验 exp = userdata.incrExp(uid, 20) explevel = dizhuaccount.getExpLevel(exp) gamedata.setGameAttr(uid, table.gameId, 'level', explevel) ftlog.debug('BigMatch.doWinLoseTable add 20 exp, tootle', exp, 'level', explevel) # nhWin = [] # table.makeBroadCastUsers(nhWin) # tasklet.sendUdpToMainServer(moWin, nhWin) table.gamePlay.sender.sendToAllTableUser(moWin) # 发送给match manager users = [] for x in xrange(len(table.seats)): user = {} user['userId'] = table.seats[x].userId user['deltaScore'] = int(detalChips[x]) user['seatId'] = x + 1 users.append(user) mnr_msg = MsgPack() mnr_msg.setCmd('room') mnr_msg.setParam('action', 'm_winlose') mnr_msg.setParam('gameId', table.gameId) mnr_msg.setParam('matchId', table.room.bigmatchId) mnr_msg.setParam('roomId', table.room.ctrlRoomId) mnr_msg.setParam('tableId', table.tableId) mnr_msg.setParam('users', users) mnr_msg.setParam('ccrc', table._match_table_info['ccrc']) if cls.WINLOSE_SLEEP > 0: FTTasklet.getCurrentFTTasklet().sleepNb(cls.WINLOSE_SLEEP) # 记录游戏winlose try: for u in users: table.room.reportBiGameEvent("TABLE_WIN", u['userId'], table.roomId, table.tableId, roundId, u['deltaScore'], 0, 0, [], 'table_win') # cls.report_bi_game_event(TyContext.BIEventId.TABLE_WIN, u['userId'], table._rid, table._id, table._roundId, u['deltaScore'], 0, 0, [], 'table_win') except: if ftlog.is_debug(): ftlog.exception() # serverids = tasklet.gdata.map_room_servers[table.room.bigmatchId] # mainClient = tasklet.gdata.clientmap[serverids[0]] # mainClient.sendMessage2(None, mnr_msg.pack()) router.sendRoomServer(mnr_msg, table.room.ctrlRoomId)