def _incrWinLoseCoupon(userId, deltaCount, roomId, clientId): trueDelta, finalCount = userchip.incrCoupon( userId, DIZHU_GAMEID, deltaCount, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'COUPON_DIZHU_GAME_WIN', roomId, clientId) bireport.gcoin('in.coupon.gamewin', DIZHU_GAMEID, trueDelta) return trueDelta, finalCount
def sendStartChip(userId, gameId, clientId): """发放启动资金 """ global newuser_startchip canGive = False startChip = 0 final = 0 canGivestartChip = getCanGivestartChip(userId, gameId, clientId) try: count = userdata.delAttr(userId, 'sendMeGift') if (count == 1) and (canGivestartChip > 0): canGive = True if ftlog.is_debug(): ftlog.debug('hallstartchip.sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', canGivestartChip, 'canGive=', canGive) if canGive: startChip = canGivestartChip _, final = userchip.incrChip(userId, gameId, startChip, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'USER_STARTUP', 0, clientId) bireport.gcoin('in.chip.newuser.startchip', gameId, startChip) ftlog.debug('hallstartchip.sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', startChip, 'startChip=', startChip, 'final=', final) return canGive, startChip, final except: ftlog.error() return False, 0, 0
def process_interactive_expression(cls, userId, gameId, seatId, chat_msg, target_player_uid, base_chip): """处理消费金币的表情""" config = cls.get_interactive_expression_config(base_chip) emoId = str(chat_msg.get('emoId', -1)) if emoId not in config: ftlog.warn('chat msg illegal', chat_msg, config) return False info = config[emoId] # 底分限制 chip = userchip.getChip(userId) if chip < info['chip_limit'] + info['cost']: ftlog.warn('insufficient', chip, info['chip_limit'], info['cost']) return False if TYPlayer.isHuman(userId): from difang.majiang2.entity.util import Util clientId = Util.getClientId(userId) trueDelta, _ = userchip.incrChip(userId , gameId , -info['cost'] , 0 , "EMOTICON_CONSUME" , chat_msg['emoId'] , clientId ) if trueDelta != -info['cost']: # 失败 ftlog.warn('coin not enougth: ', chip, info['chip_limit'], info['cost']) return False bireport.gcoin('out.interactive_expression', gameId, info['cost']) # 处理魅力值 # charm = incrCharm(userId, info['charm']) # hallranking.rankingSystem.setUserByInputType(gameId # , TYRankingInputTypes.CHARM # , userId # , charm) # if TYPlayer.isHuman(target_player_uid): # charm = incrCharm(target_player_uid, info['ta_charm']) # hallranking.rankingSystem.setUserByInputType(gameId # , TYRankingInputTypes.CHARM # , target_player_uid # , charm) return True
def process_interactive_expression(cls, userId, gameId, seatId, chat_msg, target_player_uid, base_chip): """处理消费金币的表情""" config = cls.get_interactive_expression_config(base_chip) emoId = str(chat_msg.get('emoId', -1)) if emoId not in config: ftlog.warn('chat msg illegal', chat_msg, config) return False info = config[emoId] # 底分限制 chip = userchip.getChip(userId) if chip < info['chip_limit'] + info['cost']: ftlog.warn('insufficient', chip, info['chip_limit'], info['cost']) return False if TYPlayer.isHuman(userId): from difang.majiang2.entity.util import Util clientId = Util.getClientId(userId) trueDelta, _ = userchip.incrChip(userId, gameId, -info['cost'], 0, "EMOTICON_CONSUME", chat_msg['emoId'], clientId) if trueDelta != -info['cost']: # 失败 ftlog.warn('coin not enougth: ', chip, info['chip_limit'], info['cost']) return False bireport.gcoin('out.interactive_expression', gameId, info['cost']) # 处理魅力值 # charm = incrCharm(userId, info['charm']) # hallranking.rankingSystem.setUserByInputType(gameId # , TYRankingInputTypes.CHARM # , userId # , charm) # if TYPlayer.isHuman(target_player_uid): # charm = incrCharm(target_player_uid, info['ta_charm']) # hallranking.rankingSystem.setUserByInputType(gameId # , TYRankingInputTypes.CHARM # , target_player_uid # , charm) return True
def fuzhou_sendStartChip(userId, gameId, clientId): ''' 抚州金币场发放启动资金 :param userId: :param gameId: :param clientId: ''' global fuzhou_startchip canGive = False startChip = 0 final = 0 try: if fuzhou_needSendStartChip(userId, clientId): gamedata.setGameAttr(userId, hallconf.HALL_GAMEID, "start_chip_dfchip", 1) canGive = True if ftlog.is_debug(): ftlog.debug('hallstartchip_fuzhou.fuzhou_sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', startChip, 'canGive=', canGive) if canGive: nowChip = userchip.getChip(userId) startChip = fuzhou_startchip trueDelta, final = userchip.incrChip( userId, gameId, startChip - nowChip, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'FUZHOU_START_CHIP', 0, clientId) datachangenotify.sendDataChangeNotify(gameId, userId, ['chip']) bireport.gcoin('in.chip.newuser.startchip', gameId, startChip) ftlog.debug('hallstartchip_fuzhou.fuzhou_sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', startChip, 'startChip=', startChip, 'trueDelta=', trueDelta, 'final=', final) return canGive, trueDelta, final except: ftlog.error() return False, 0, 0
def doTableSmiliesFrom_v3_775(roomId, bigRoomId, tableId, userId, smilie, minchip, price, self_charm, clientId, wcount=1): ftlog.debug('doTableSmiliesFrom_v3_775:1', 'userId=', userId, 'price=', price, 'smilie=', smilie, 'wcount=', wcount) eventId = 'EMOTICON_' + smilie.upper() + '_CONSUME' trueDelta, final = userchip.incrChipLimit( userId, DIZHU_GAMEID, -price * wcount, -1, -1, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, eventId, roomId, clientId) # 真实的发送个数,金币不足也至少发送一次 rcostchip = abs(trueDelta) rcount = 1 if price > 0: rcount = max(1, int(math.ceil(rcostchip / price))) bireport.gcoin('out.chip.emoticon', DIZHU_GAMEID, rcostchip) ftlog.debug('doTableSmiliesFrom_v3_775:2', 'userId=', userId, 'rcostchip=', rcostchip, 'rcount=', rcount, 'final=', final) # 发送通知 if rcostchip > 0: datachangenotify.sendDataChangeNotify(DIZHU_GAMEID, userId, 'chip') # 魅力值 userdata.incrCharm(userId, self_charm * rcount) bireport.gcoin('out.smilies.' + smilie + '.' + str(bigRoomId), DIZHU_GAMEID, rcostchip) from dizhu.game import TGDizhu for _ in xrange(rcount): TGDizhu.getEventBus().publishEvent( UseTableEmoticonEvent(DIZHU_GAMEID, userId, roomId, tableId, smilie, price)) return rcount, trueDelta, final
def doTableThrowEmojiFrom_3_775(gameId, userId, roomId, bigRoomId, tableId, emojiId, minchip, price, charmDelta, clientId, count, throwWhenChipZero=False): assert (count > 0) if 0 == price: return count, 0, 0 eventId = 'EMOTICON_%s_CONSUME' % (emojiId.upper()) costChip = price * count trueDelta, final = userchip.incrChipLimit( userId, gameId, -costChip, -1, -1, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, eventId, roomId, clientId) # 没有金币则返回0 if trueDelta == 0: return 0, trueDelta, final # 真实的发送个数,金币不足也至少发送一次 realCostChip = abs(trueDelta) realCount = max(1, int(math.ceil(realCostChip / price))) if realCostChip > 0: datachangenotify.sendDataChangeNotify(gameId, userId, 'chip') bireport.gcoin('out.chip.emoticon', gameId, realCostChip) bireport.gcoin('out.smilies.' + emojiId + '.' + str(bigRoomId), gameId, realCostChip) # 魅力值 userdata.incrCharm(userId, charmDelta * realCount) eventBus = gdata.games()[gameId].getEventBus() if eventBus: eventBus.publishEvent( UseTableEmoticonEvent(gameId, userId, roomId, tableId, emojiId, price, realCount)) return realCount, trueDelta, final
def doTableThrowEmojiFrom(gameId, userId, roomId, bigRoomId, tableId, emojiId, minchip, price, charmDelta, clientId): eventId = 'EMOTICON_%s_CONSUME' % (emojiId.upper()) trueDelta, final = userchip.incrChipLimit( userId, gameId, -price, price + minchip, -1, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, eventId, roomId, clientId) # 发送通知 if trueDelta != 0: datachangenotify.sendDataChangeNotify(gameId, userId, 'chip') if trueDelta != -price: return 0, trueDelta, final bireport.gcoin('out.chip.emoticon', gameId, price) # 魅力值 userdata.incrCharm(userId, charmDelta) bireport.gcoin('out.smilies.' + emojiId + '.' + str(bigRoomId), gameId, price) TYGame(gameId).getEventBus().publishEvent( UseTableEmoticonEvent(gameId, userId, roomId, tableId, emojiId, price)) return 1, trueDelta, final
def sendStartChip(userId, gameId, clientId): """发放启动资金 """ global newuser_startchip canGive = False startChip = 0 final = 0 try: count = userdata.delAttr(userId, 'sendMeGift') if (count == 1) and (newuser_startchip > 0): canGive = True if ftlog.is_debug(): ftlog.debug('hallstartchip.sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', startChip, 'canGive=', canGive) if canGive: startChip = newuser_startchip _, final = userchip.incrChip(userId, gameId, startChip, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'USER_STARTUP', 0, clientId) bireport.gcoin('in.chip.newuser.startchip', gameId, startChip) ftlog.debug('hallstartchip.sendStartChip userId=', userId, 'gameId=', gameId, 'clientId=', clientId, 'chip=', startChip, 'startChip=', startChip, 'final=', final) return canGive, startChip, final except: ftlog.error() return False, 0, 0
def doTableSmiliesFrom(roomId, bigRoomId, tableId, userId, smilie, minchip, price, self_charm, clientId): eventId = 'EMOTICON_' + smilie.upper() + '_CONSUME' trueDelta, final = userchip.incrChipLimit( userId, DIZHU_GAMEID, -price, price + minchip, -1, daoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, eventId, roomId, clientId) # 发送通知 if abs(trueDelta) > 0: datachangenotify.sendDataChangeNotify(DIZHU_GAMEID, userId, 'chip') if trueDelta != -price: return 0, trueDelta, final bireport.gcoin('out.chip.emoticon', DIZHU_GAMEID, price) # 魅力值 userdata.incrCharm(userId, self_charm) bireport.gcoin('out.smilies.' + smilie + '.' + str(bigRoomId), DIZHU_GAMEID, price) from dizhu.game import TGDizhu TGDizhu.getEventBus().publishEvent( UseTableEmoticonEvent(DIZHU_GAMEID, userId, roomId, tableId, smilie, price)) return 1, trueDelta, final
def doTableWinLoseGT(roomId, tableId, roundId, winSeatId, gamebase): ftlog.debug('doTableWinLoseGT ->', roomId, tableId, winSeatId, roundId) runConfig = gamebase.table.runConfig state = gamebase.table.status seats = gamebase.table.seats players = gamebase.table.players bigRoomId = gdata.roomIdDefineMap()[roomId].bigRoomId tootle_seat = len(seats) # 座位的个数 dizhuSeatId = state.diZhu # 地主的座位ID winuserid = seats[winSeatId - 1].userId # 出最后一手牌的赢的玩家的ID winUserIds = [winuserid] # 所有赢的玩家的ID集合 dizhuwin = 0 # 是否是地主赢 winslam = 0 # 是否大满贯 # 抢地主倍数 basewinchip = state.callGrade * runConfig.tableMulti # 炸弹倍数 basewinchip *= pow(2, state.bomb) if winSeatId != dizhuSeatId: if seats[dizhuSeatId - 1].outCardCount == 1: state.chuntian = 2 dizhuwin = 0 for ss in xrange(tootle_seat): if (ss + 1) != winSeatId and (ss + 1) != dizhuSeatId: winUserIds.append(seats[ss].userId) else: dizhuwin = 1 chuntian = True for idx in xrange(tootle_seat): if (idx + 1) != dizhuSeatId: if seats[idx].outCardCount > 0: chuntian = False break if chuntian: state.chuntian = 2 ftlog.debug('doTableWinLose dizhuwin=', dizhuwin, 'winuserid=', winuserid, 'winUserIds=', winUserIds) # 让牌倍数(只有二斗有) basewinchip *= state.rangpaiMultiWinLose # 春天倍数 basewinchip *= state.chuntian # 底牌倍数 basewinchip *= state.baseCardMulti # 明牌倍数 basewinchip *= state.show # 翻倍计算 windoubles = int(basewinchip / runConfig.tableMulti) if windoubles >= runConfig.gslam: winslam = 1 basem = windoubles / state.show # 所有玩家的ID列表 allUserIds = [] for seat in seats: allUserIds.append(seat.userId) # 大于5个炸弹局数记录 if state.bomb >= 5: ftlog.info('BombCountRecord: playmode =', runConfig.playMode, 'count = ', state.bomb, 'tableId=', tableId) sfeealls = [DIZHU_GAMEID, roomId, tableId, [], []] winStreak = [{}] * tootle_seat lucky_args = [{}] * tootle_seat skill_score_infos = [{}] * tootle_seat room_fee = [0] * tootle_seat # 每个人的房间服务费 coin_after_sfee = [0] * tootle_seat seat_coin = [0] * tootle_seat seat_delta = [0] * tootle_seat chou_cheng = [0] * tootle_seat detalChip = [0] * tootle_seat # 统计用户总金币变化 addcoupons = [0] * tootle_seat findChips = [0] * tootle_seat finalAccChips = [0] * tootle_seat robot_card_count = [0] * tootle_seat # 每个座位 seat_exps = [0] * tootle_seat seatDeltaAll = 0 cardNoteChip = [0] * tootle_seat # 每个座位的记牌器金币 seat_table_tasks = [0] * tootle_seat tb_infos = [0] * tootle_seat # 服务费抽成调整配置, 扣除玩家的房间服务费 roomFeeConf = dizhuconf.getRoomFeeConf() basic_rate = roomFeeConf.get('basic', 1) winner_rate = roomFeeConf.get('winner_chip', 0) highMulti = roomFeeConf.get('high_multi', 32) feeMulti = roomFeeConf.get('fee_multi', 2.0) for x in xrange(tootle_seat): xp = players[x] userId = allUserIds[x] sfeealls[3].append(userId) sfee = runConfig.roomFee isdizhu = 0 if windoubles >= highMulti: if dizhuwin == 1: if x == dizhuSeatId - 1: isdizhu = 1 sfee *= feeMulti sfee = int(sfee) sfeealls[3].append(feeMulti) else: sfeealls[3].append(1.0) else: if x != dizhuSeatId - 1: isdizhu = 1 sfee *= feeMulti sfee = int(sfee) sfeealls[3].append(feeMulti) else: sfeealls[3].append(1.0) else: sfeealls[3].append(1.0) sfeealls[3].append(sfee) sfee = abs(int(sfee * basic_rate)) # 服务费调整 room_fee[x] = sfee cardNoteChip[ x] = runConfig.cardNoteChip if xp.inningCardNote > 0 else 0 trueDelta, ccoin, winStreak_, lucky_args_, skill_score_infos_ = _doTableWinLoseUT1( userId, bigRoomId, roomId, tableId, sfee, cardNoteChip[x], xp.isSupportBuyin, xp.clientId, winUserIds, winslam, state.chuntian, isdizhu, windoubles) detalChip[x] = detalChip[x] + trueDelta coin_after_sfee[x] = ccoin robot_card_count[x] = seats[x].robotCardCount winStreak[x] = winStreak_ lucky_args[x] = lucky_args_ skill_score_infos[x] = skill_score_infos_ ftlog.debug('doTableWinLosechip->after room fee->allUserIds=', allUserIds) ftlog.debug('doTableWinLosechip->after room fee->room_fee=', room_fee) ftlog.debug('doTableWinLosechip->after room fee->cardNoteChip=', cardNoteChip) ftlog.debug('doTableWinLosechip->after room fee->detalChip=', detalChip) ftlog.debug('doTableWinLosechip->after room fee->coin_after_sfee=', coin_after_sfee) ftlog.debug('doTableWinLosechip->after room fee->robot_card_count=', robot_card_count) if dizhuwin == 1: dzswin = 0 # 先算地主应该赢的钱 dz_abswin = min(basewinchip * (tootle_seat - 1), coin_after_sfee[winSeatId - 1]) # 算农民输的钱 for x in xrange(tootle_seat): if x != winSeatId - 1: nmlose = min(dz_abswin / (tootle_seat - 1), coin_after_sfee[x]) dzswin += nmlose seat_coin[x] = coin_after_sfee[x] - nmlose seat_delta[x] = nmlose * -1 dzwincoin = int(dzswin) seat_coin[winSeatId - 1] = coin_after_sfee[winSeatId - 1] + dzwincoin seat_delta[winSeatId - 1] = dzwincoin if runConfig.sendCoupon and basem >= 64: winseat = seats[winSeatId - 1] addcoupon = winseat.couponCard[0] * 2 + winseat.couponCard[ 1] + winseat.couponCard[2] * 2 if runConfig.roomFee > 220: addcoupon *= (runConfig.roomFee / 220) addcoupons[winSeatId - 1] = abs(int(addcoupon)) else: dzslose = 0 # 地主应该输的钱 dzlosecoin = min(coin_after_sfee[dizhuSeatId - 1], basewinchip * (tootle_seat - 1)) for x in xrange(tootle_seat): if x != dizhuSeatId - 1: if runConfig.sendCoupon and basem >= 64: winseat = seats[x] addcoupon = winseat.couponCard[0] * 2 + winseat.couponCard[ 1] + winseat.couponCard[2] * 2 if runConfig.roomFee > 220: addcoupon *= (runConfig.roomFee / 220) addcoupons[x] = abs(int(addcoupon)) nmwin = min(coin_after_sfee[x], dzlosecoin / (tootle_seat - 1)) dzslose += nmwin seat_coin[x] = coin_after_sfee[x] + nmwin seat_delta[x] = nmwin seat_coin[dizhuSeatId - 1] = coin_after_sfee[dizhuSeatId - 1] - dzslose seat_delta[dizhuSeatId - 1] = dzslose * -1 ftlog.debug('doTableWinLosechip->after cal win->allUserIds=', allUserIds) ftlog.debug('doTableWinLosechip->after cal win->seat_delta=', seat_delta) ftlog.debug('doTableWinLosechip->after cal win->addcoupons=', addcoupons) ftlog.debug('doTableWinLosechip->after cal win->seat_coin=', seat_coin) # 计算托管处罚的调整值 from dizhu.gameplays import punish pfIndex = punish.Punish.doWinLosePunish(runConfig.punishCardCount, runConfig.isMatch, seat_coin, seat_delta, robot_card_count) for x in xrange(tootle_seat): sp = players[x] isdizhu = 0 if x == dizhuSeatId - 1: isdizhu = 1 seatDeltaAll = seatDeltaAll + seat_delta[x] if seat_delta[x] > 0: chou_cheng[x] = -int(seat_delta[x] * winner_rate) seat_coin[x] = seat_coin[x] + chou_cheng[x] skillLevelUp = skill_score_infos[x].get('isLevelUp', False) trueDelta, trueDelta_CC, finalChip, expinfo, tasks, tbplaytimes, tbplaycount = _doTableWinLoseUT2( sp.userId, bigRoomId, roomId, tableId, sp.isSupportBuyin, seat_delta[x], chou_cheng[x], sp.clientId, addcoupons[x], runConfig.isMatch, runConfig.roomMutil, runConfig.basebet, runConfig.basemulti, runConfig.playMode, state.topCardList, roundId, winUserIds, isdizhu, winuserid, windoubles, state.bomb, state.chuntian, winslam, detalChip[x], room_fee[x], skillLevelUp) detalChip[x] = detalChip[x] + trueDelta + trueDelta_CC sfeealls[4].append(sp.userId) sfeealls[4].append(seat_delta[x]) findChips[x] = finalChip seat_exps[x] = expinfo seat_table_tasks[x] = tasks tb_infos[x] = [tbplaytimes, tbplaycount] bireport.tableRoomFee(DIZHU_GAMEID, sfeealls) bireport.tableWinLose(DIZHU_GAMEID, roomId, tableId, roundId, allUserIds) if seatDeltaAll < 0: ftlog.info('doWinLose out.windiff < 0 !! seatDeltaAll=', seatDeltaAll) bireport.gcoin('out.windiff', DIZHU_GAMEID, seatDeltaAll) elif seatDeltaAll > 0: ftlog.warn('doWinLose out.windiff > 0 !! seatDeltaAll=', seatDeltaAll) ftlog.debug('room_fee->', room_fee) ftlog.debug('coin_after_sfee->', coin_after_sfee) ftlog.debug('seat_coin->', seat_coin) ftlog.debug('seat_delta->', seat_delta) ftlog.debug('chou_cheng->', chou_cheng) ftlog.debug('detalChip->', detalChip) ftlog.debug('addcoupons->', addcoupons) ftlog.debug('findChips->', findChips) ftlog.debug('finalAccChips->', finalAccChips) ftlog.debug('tb_infos->', tb_infos) # 独立的陌陌排行榜处理, 此处记录发生变化的userid, 由crontab的脚本发送数据到陌陌服务器 if dizhuconf.isUseMomoRanking(): nowminute = pktimestamp.formatTimeMinuteSort() rkey = 'momo:pushrank:' + nowminute daobase.executeMixCmd('SADD', rkey, *allUserIds) daobase.executeMixCmd('EXPIRE', rkey, 259200) # 3天后自动过期 return { 'dizhuwin': dizhuwin, 'winslam': winslam, 'windoubles': windoubles, 'winStreak': winStreak, 'luckyItemArgs': lucky_args, 'skillScoreInfos': skill_score_infos, 'seat_delta': seat_delta, 'seat_coin': seat_coin, 'addcoupons': addcoupons, 'seat_exps': seat_exps, 'table_task': seat_table_tasks, 'final_acc_chips': finalAccChips, 'chuntian': state.chuntian, 'tb_infos': tb_infos, 'pfIndex': pfIndex }