Ejemplo n.º 1
0
 def cleanup(self):
     from hall.game import TGHall
     from dizhu.game import TGDizhu
     TGHall.getEventBus().unsubscribe(HallShare3Event, _processActive)
     TGHall.getEventBus().unsubscribe(TYOrderDeliveryEvent, _processActive)
     TGHall.getEventBus().unsubscribe(ChargeNotifyEvent, _processActive)
     TGDizhu.getEventBus().unsubscribe(ActiveEvent, _processActive)
Ejemplo n.º 2
0
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]
Ejemplo n.º 3
0
 def initialize(cls):
     from dizhu.game import TGDizhu
     TGDizhu.getEventBus().subscribe(MatchWinloseEvent, cls.onMatchWinlose)
     TGDizhu.getEventBus().subscribe(UserTableWinloseEvent, cls.onTableWinlose)
     TGHall.getEventBus().subscribe(TYOrderDeliveryEvent, cls.onOrderDelivery)
     pkeventbus.globalEventBus.subscribe(EventConfigure, cls._onConfChanged)
     cls._reloadConf()
Ejemplo n.º 4
0
def initBehaviourReward():
    from dizhu.game import TGDizhu
    TGDizhu.getEventBus().subscribe(UserTablePlayEvent,
                                    _sendUserBehaviourReward)

    from hall.game import TGHall
    TGHall.getEventBus().subscribe(EventUserLogin, _onUnExpectedUserLogin)
Ejemplo n.º 5
0
def _initialize():
    ftlog.info('matchhistory initialize begin')
    from dizhu.game import TGDizhu
    global _inited
    if not _inited:
        _inited = True
        TGDizhu.getEventBus().subscribe(MatchingFinishEvent, onMatchingFinish)
    ftlog.info('matchhistory initialize end')
Ejemplo n.º 6
0
def _initialize():
    from dizhu.game import TGDizhu
    global _inited
    if not _inited:
        _inited = True
        ftlog.debug('dizhuranking._initialize begin')
        TGDizhu.getEventBus().subscribe(EventUserLogin, _onUserLogin)
        ftlog.debug('dizhuranking._initialize end')
Ejemplo n.º 7
0
 def init(self):
     from dizhu.game import TGDizhu
     TGDizhu.getEventBus().subscribe(UserTableWinloseEvent,
                                     self.onTableGameRoundFinish)
     TGDizhu.getEventBus().subscribe(MatchWinloseEvent,
                                     self.onMatchGameRoundFinish)
     TGHall.getEventBus().subscribe(ChargeNotifyEvent, self._onChargeNotify)
     TGHall.getEventBus().subscribe(HallShareEvent, self._onUserShare)
     TGHall.getEventBus().subscribe(HallShare2Event, self._onUserShare)
Ejemplo n.º 8
0
def _initialize():
    ftlog.debug('dizhucoupon initialize begin')
    from dizhu.game import TGDizhu
    global _inited
    global flipCard
    if not _inited:
        _inited = True
        TGDizhu.getEventBus().subscribe(EventUserLogin,
                                        couponService.onUserLogin)
        _reloadConf()
    ftlog.debug('dizhucoupon initialize end')
Ejemplo n.º 9
0
 def init(self):
     from hall.game import TGHall
     from dizhu.game import TGDizhu
     if ftlog.is_debug():
         ftlog.debug('ActivityWxUserActive.init start')
     TGHall.getEventBus().subscribe(HallShare3Event, _processActive)
     TGHall.getEventBus().subscribe(TYOrderDeliveryEvent, _processActive)
     TGHall.getEventBus().subscribe(ChargeNotifyEvent, _processActive)
     TGDizhu.getEventBus().subscribe(ActiveEvent, _processActive)
     if ftlog.is_debug():
         ftlog.debug('ActivityWxUserActive.init end')
Ejemplo n.º 10
0
def _initialize():
    ftlog.info('obsystem initialize begin')
    from dizhu.game import TGDizhu
    global _inited
    if not _inited:
        _inited = True
        TGDizhu.getEventBus().subscribe(MatchingStartEvent, onMatchingStart)
        TGDizhu.getEventBus().subscribe(MatchingFinishEvent, onMatchingFinish)
        _reloadConf()
        pkeventbus.globalEventBus.subscribe(EventConfigure, _onConfChanged)
    ftlog.info('obsystem initialize end')
Ejemplo n.º 11
0
 def _doShareLogin(cls, userId, shareUserId):
     # 广播事件
     from dizhu.game import TGDizhu
     TGDizhu.getEventBus().publishEvent(
         UserShareLoginEvent(DIZHU_GAMEID, userId, shareUserId))
     mo = MsgPack()
     mo.setCmd('dizhu')
     mo.setResult('action', 'share_login')
     mo.setResult('gameId', DIZHU_GAMEID)
     mo.setResult('userId', userId)
     mo.setResult('success', 1)
     router.sendToUser(mo, userId)
Ejemplo n.º 12
0
def _doTableGameStartUT1(userId, roomId, tableId, dizhuUserId, baseCardType,
                         roomMutil, basebet, basemulti):
    # 触发游戏开始的事件, 在此事件监听中处理用户的winrate以及其他任务或属性的调整和设定
    # 更新宝箱的状态
    bigRoomId = gdata.roomIdDefineMap()[roomId].bigRoomId
    tbinfos = treasurebox.updateTreasureBoxStart([userId], bigRoomId)
    # 更新每个人的winrate
    _checkSetMedal(userId, roomMutil, basebet, basemulti, True, 0)
    # 触发每个人的游戏开始事件
    from dizhu.game import TGDizhu
    TGDizhu.getEventBus().publishEvent(
        UserTablePlayEvent(DIZHU_GAMEID, userId, roomId, tableId, baseCardType,
                           dizhuUserId))
    return tbinfos
Ejemplo n.º 13
0
def _publishWinLoseEvent(roomId, tableId, seatUid, roundId, winUserIds,
                         isDizhu, winuserid, seat_delta, detalChipAll,
                         findChips, windoubles, bomb, chuntian, winslam,
                         clientId, topValidCard, skillLevelUp):
    from dizhu.game import TGDizhu
    ebus = TGDizhu.getEventBus()
    hallebus = TGHall.getEventBus()
    isWin = True if seatUid in winUserIds else False
    winlose = Winlose(winuserid, topValidCard, isWin, isDizhu, seat_delta,
                      findChips, windoubles, bomb, chuntian > 1, winslam)
    ebus.publishEvent(
        UserTableWinloseEvent(DIZHU_GAMEID, seatUid, roomId, tableId, winlose,
                              skillLevelUp))

    isWinNum = 0
    if isWin:
        isWinNum = 1
    roomLevel = gdata.roomIdDefineMap()[roomId].configure.get('roomLevel', 1)
    ftlog.debug('hallebus push gameoverevent userId=', seatUid)
    hallebus.publishEvent(
        GameOverEvent(seatUid, DIZHU_GAMEID, clientId, roomId, tableId,
                      isWinNum, roomLevel))

    finalUserChip = userchip.getChip(seatUid)
    finalTableChip = userchip.getTableChip(seatUid, DIZHU_GAMEID, tableId)
    bireport.reportGameEvent('TABLE_WIN', seatUid, DIZHU_GAMEID, roomId,
                             tableId, roundId, detalChipAll, 0, 0, [],
                             clientId, finalTableChip, finalUserChip)
    return finalUserChip
Ejemplo n.º 14
0
def _processUserRewardAsync(evt):
    rewardInfo = {
        'type': evt.rewardType,
        'rewards': evt.rewards,
        'rewardId': evt.rewardId,
        'timestamp': evt.timestamp,
        'params': evt.params
    }
    if ftlog.is_debug():
        ftlog.debug('reward_async._processUserRewardAsync userId=', evt.userId,
                    'evt=', rewardInfo)
    if evt.rewardType == REWARD_ASYNC_TYPE_AS_ARENA_MATCH:
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        TGDizhu.getEventBus().publishEvent(
            ActiveEvent(6, evt.userId, 'redEnvelope'))
    RewardAsyncHelper.addUserRewards(evt.userId, rewardInfo)
Ejemplo n.º 15
0
def publishUserTableBomb(userId, roomId, tableId, userIds, **kwargs):
    try:
        mixRoomId = kwargs.get('mixRoomId')
        roomName = kwargs.get('roomName', '')
        from dizhu.game import TGDizhu
        TGDizhu.getEventBus().publishEvent(
            UserTableOutCardBombEvent(DIZHU_GAMEID,
                                      userId,
                                      roomId,
                                      tableId,
                                      userIds,
                                      mixConfRoomId=mixRoomId,
                                      roomName=roomName))
    except:
        ftlog.error('new_table_remote.publishUserTableBomb gameId=',
                    DIZHU_GAMEID, 'userId=', userId, 'roomId=', roomId,
                    'tableId=', tableId, 'mixRoomId=', kwargs.get('mixRoomId'))
Ejemplo n.º 16
0
    def _segment_recover(cls, userId, gameId, clientId):
        # 段位复活数据
        errmsg = '你的保段复活费用不足'
        success = 0
        userRecoverData = SegmentMatchHelper.getUserSegmentRecoverData(userId)
        if userRecoverData.active:
            totalRecoverCount = userRecoverData.totalRecoverCount
            recoverConf = getSegmentConf().segmentRecover
            others = recoverConf.get('buy', {}).get('itemCount', {}).get('others', 10)
            needCount = recoverConf.get('buy', {}).get('itemCount', {}).get(str(totalRecoverCount), others)
            itemId = recoverConf.get('buy', {}).get('itemId')
            # 判断用户参赛券否够
            contentItemList = [{'itemId': itemId, 'count': needCount}]
            assetKindId, count = user_remote.consumeAssets(DIZHU_GAMEID, userId, contentItemList,
                                                           'SEGMENT_MATCH_RECOVER_FEE', 0)

            ftlog.info('SegmentMatchHandler.collectFee',
                       'userId=', userId,
                       'fees=', contentItemList,
                       'assetKindId=', assetKindId,
                       'count=', count)

            if not assetKindId:
                errmsg = 'ok'
                success = 1
                # 广播事件
                TGDizhu.getEventBus().publishEvent(SegmentRecoverEvent(userId, gameId))

        msg = MsgPack()
        msg.setCmd('dizhu')
        msg.setResult('action', 'segment_recover')
        msg.setResult('gameId', gameId)
        msg.setResult('userId', userId)
        msg.setResult('success', success)
        msg.setResult('errmsg', errmsg)

        if ftlog.is_debug():
            ftlog.debug('SegmentMatchHandler._segment_recover'
                        'userId=', userId,
                        'gameId=', gameId,
                        'clientId=', clientId,
                        'userRecoverData=', userRecoverData.toDict(),
                        'msg=', msg._ht)

        return msg
Ejemplo n.º 17
0
 def _onGameStart(self, event):
     super(DizhuTableProtoFriend, self)._onGameStart(event)
     userIds = [s.player.userId for s in event.table.seats]
     from dizhu.game import TGDizhu
     from dizhu.entity.common.events import ActiveEvent
     for userId in userIds:
         TGDizhu.getEventBus().publishEvent(ActiveEvent(6, userId, 'friendGame'))
     # 朋友桌第一局启动, 默认加好有
     if ftlog.is_debug():
         ftlog.debug('DizhuTableProtoFriend._onGameStart',
                     'tableId=', self.table.tableId,
                     'userIds=', userIds,
                     'nRound=', self.tableCtrl.nRound,
                     )
     if self.tableCtrl.nRound == 0:
         for seat in event.table.seats:
             # 加好友, 转到UT服执行
             new_table_remote.addWechatFriend(seat.player.userId, userIds)
Ejemplo n.º 18
0
    def registerEvents(cls):
        eventbus = TGDizhu.getEventBus()
        ftlog.debug('YouKu register events')
        for event in cls.eventset:
            eventbus.subscribe(event, cls.handleEvent)

        hallEventBus = TGHall.getEventBus()
        hallEventBus.subscribe(TYDailyCheckinRewardEvent,
                               cls.handleDailyCheckinEvent)
Ejemplo n.º 19
0
 def getDashiFenLevel(cls, userId):
     '''
     获取用户的大师分等级
     '''
     from dizhu.game import TGDizhu
     info = TGDizhu.getDaShiFen(userId, None)
     if info:
         return info.get('level', 0)
     return 0
Ejemplo n.º 20
0
    def _canQuickEnterRoom(cls, userId, gameId, roomId, isOnly):
        ret = cls._canQuickEnterRoomBase(userId, gameId, roomId, isOnly)
        if ret != TYRoom.ENTER_ROOM_REASON_OK:
            return ret

        roomConfig = gdata.roomIdDefineMap()[roomId].configure

        # 检测准入情况,配置中若没有准入时间(openTimeList),则默认准许全天进入
        if not cls._checkOpenTime(roomConfig, datetime.now().time()):
            return TYRoom.ENTER_ROOM_REASON_NOT_OPEN

        if roomConfig.get('typeName') in ('dizhuFT', 'dizhu_friend'):
            return TYRoom.ENTER_ROOM_REASON_NOT_OPEN

        clientId = sessiondata.getClientId(userId)
        if not dizhuhallinfo.canDisplayRoom(gameId, userId, clientId, roomId,
                                            roomConfig):
            if ftlog.is_debug():
                ftlog.debug(
                    'DizhuQuickStartV4_0._canQuickEnterMatchRoom NotCanDisplayRoom',
                    'gameId=', gameId, 'userId=', userId, 'clientId=',
                    clientId, 'roomId=', roomId)
            return TYRoom.ENTER_ROOM_REASON_NOT_OPEN

        # 大师分和vip准入筛选
        # 两个条件是`或者`的关系
        dashifenLevel = roomConfig.get('dashifenLevel', 0)
        vipLevel = roomConfig.get('vipLevel', 0)
        ftlog.debug('_canQuickEnterRoom->', userId, gameId, roomId,
                    'dashifenLevel=', dashifenLevel, 'vipLevel=', vipLevel)
        if dashifenLevel <= 0 and vipLevel <= 0:
            return TYRoom.ENTER_ROOM_REASON_OK

        # 若大师分不满足情况,则再检测VIP,不能直接返回大师分不满足的错误
        if dashifenLevel > 0:
            dashifen = 0
            from dizhu.game import TGDizhu
            info = TGDizhu.getDaShiFen(userId, None)
            ftlog.debug('_canQuickEnterRoom->', userId, gameId, roomId,
                        'dashifenInfo=', info)
            if info:
                dashifen = info.get('level', 0)
            if dashifen >= dashifenLevel:
                return TYRoom.ENTER_ROOM_REASON_OK

        if vipLevel > 0:
            vip = 0
            vipInfo = hallvip.userVipSystem.getUserVip(userId)
            ftlog.debug('_canQuickEnterRoom->', userId, gameId, roomId,
                        'vipInfo=', vipInfo)
            if vipInfo:
                vip = vipInfo.vipLevel.level
            if vip >= vipLevel:
                return TYRoom.ENTER_ROOM_REASON_OK

        return TYRoom.ENTER_ROOM_REASON_DASHIFEI_LEVEL
Ejemplo n.º 21
0
def incrSkillScore(userId, add_score):
    assert (add_score >= 0)
    tootle = gamedata.incrGameAttr(userId, DIZHU_GAMEID, 'skillscore',
                                   add_score)

    # 大师分增量榜
    ftlog.debug('setUserByInputType userId=', userId, 'add_score=', add_score,
                TYRankingInputTypes.DASHIFEN_INCR)
    hallranking.rankingSystem.setUserByInputType(
        6, TYRankingInputTypes.DASHIFEN_INCR, userId, add_score,
        timestamp.getCurrentTimestamp())

    oldScore = tootle - add_score
    level_old = get_skill_level(oldScore)
    level_new = get_skill_level(tootle)
    sinfo = score_info(userId)
    sinfo['userId'] = userId
    sinfo['addScore'] = add_score  # add by wuyangwei
    if level_old != level_new:
        # 修改昵称
        change_name = False
        need_level = dizhuconf.getChangeNickNameLevel()
        if need_level == level_new:
            set_name_sum = hallrename.getRenameSum(DIZHU_GAMEID, userId)
            if set_name_sum <= 0:
                sinfo['changename'] = 1  #服务器修改此标记,客户端识别弹出改昵称界面
                change_name = True
        # 升级奖励
        up_info = get_skill_level_reward(userId, level_old, level_new)
        if (not change_name) and up_info:
            sinfo['rewards'] = up_info
        # 是否升级, 以前通过升级奖励配置, 配置去掉后会有问题
        sinfo['isLevelUp'] = True

    from dizhu.game import TGDizhu
    TGDizhu.getEventBus().publishEvent(
        SkillScoreIncrEvent(DIZHU_GAMEID, userId, oldScore, level_old, tootle,
                            level_new))
    ftlog.debug('SkillScore.incrSkillScore gameId=', DIZHU_GAMEID, 'userId=',
                userId, 'addScore=', add_score, 'newScore=', tootle,
                'oldLevel=', level_old, 'newLevel=', level_new, 'skillInfo=',
                sinfo)
    return sinfo
Ejemplo n.º 22
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
Ejemplo n.º 23
0
    def testEvent(self):
        #         winlose = Winlose(winuserid, topValidCard, isWin, isDizhu, seat_delta, findChips,
        #                       windoubles, bomb, chuntian > 1, winslam)
        timestamp = int(time.time())
        cardRule = CardDiZhuLaizi3Player()
        winCard = cardRule.validateCards([0])
        event = UserTableWinloseEvent(
            self.gameId, self.userId, 6001, 600101,
            Winlose(self.userId, winCard, 1, 1, 100, 100, 1, 1, 2, 1))
        TGDizhu.getEventBus().publishEvent(event)

        act = activitysystemnew.findActivity('act1')
        status = act.loadStatus(self.userId, int(time.time()))
        act.gainReward(status, 5001, timestamp)

        self.assertRaises(TYBizException, act.refresh, status, timestamp)

        userAssets = hallitem.itemSystem.loadUserAssets(self.userId)
        userAssets.addAsset(self.gameId, 'user:chip', 1000, timestamp, 'TEST',
                            0)
        act.refresh(status, timestamp)
Ejemplo n.º 24
0
def _processRecover(userId, burialId):
    userRecoverData = SegmentMatchHelper.getUserSegmentRecoverData(userId)
    leftCount = 0
    if userRecoverData.active:
        dataStr = loadUserBehaviorData(userId)
        if dataStr:
            userData = UserShareBehaviorData(userId).fromDict(
                json.loads(dataStr))
            userData.increaseBurialWatchCount(burialId)
            saveUserBehaviorData(userId, json.dumps(userData.toDict()))
            burialConf = getBurialConf(burialId)
            leftCount = userData.getBurialLeftCount(burialConf)

            userRecoverData.shareRecoverCount += 1
            SegmentMatchHelper.saveUserSegmentRecoverData(
                userId, userRecoverData)

            # 广播事件
            TGDizhu.getEventBus().publishEvent(
                SegmentRecoverEvent(userId, DIZHU_GAMEID))
    return leftCount
Ejemplo n.º 25
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
Ejemplo n.º 26
0
def _initialize():
    from dizhu.game import TGDizhu
    ftlog.debug('dizhuredenvelope._initialize')
    TGDizhu.getEventBus().subscribe(UserTableWinloseEvent, _onTableWinlose)
Ejemplo n.º 27
0
    def sendWinloseRes(self, result):
        details = self.buildResultDetails(result)
        mp = self.buildWinloseRes(result, details, 1)
        # 免费场开关
        freeFeeSwitch = self.table.room.roomConf.get('freeFeeSwitch', 0)
        mp.setResult('free', freeFeeSwitch)
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        crossPlayCount = configure.getGameJson(DIZHU_GAMEID, 'wx.cross',
                                               {}).get('crossPlayCount', 10)
        crossDelaySeconds = configure.getGameJson(DIZHU_GAMEID, 'wx.cross',
                                                  {}).get(
                                                      'crossDelaySeconds', 10)
        authPlayCount = configure.getGameJson(DIZHU_GAMEID, 'authorization',
                                              {}).get('authPlayCount', 5)
        rewards = configure.getGameJson(DIZHU_GAMEID, 'authorization',
                                        {}).get('rewards', {})
        for index, seat in enumerate(self.table.seats):
            isKickOutCoin = 0

            # 每次进来需要重新初始化
            realSeats = []
            seatIndexes = []
            for i, seatDetails in enumerate(details.get('seatDetails', [])):
                copyDetail = copy.copy(seatDetails)
                realSeats.append(copyDetail)
                seatIndexes.append(i)
                mp.setResult('seat%s' % (i + 1), copyDetail)
            seatIndexes.remove(index)

            if self.table.room.roomConf.get('zeroSumFlag', 0) == 1:
                currentBaseScore = result.gameRound.baseScores[index]
                for seatIndex in seatIndexes:
                    otherBaseScore = result.gameRound.baseScores[seatIndex]
                    realSeats[seatIndex][0] = int(
                        float(currentBaseScore) / otherBaseScore *
                        realSeats[seatIndex][0])
                    realSeats[seatIndex][1] = int(
                        float(currentBaseScore) / otherBaseScore *
                        realSeats[seatIndex][1])
            else:
                # 显示以当前seat为基准做假数据
                dizhuIndex = mp.getResult('stat').get('dizhu')
                currentSeat = realSeats[index]
                windoubles = mp.getResult('windoubles')
                currentBaseScore = self.table.gameRound.baseScores[index]
                currentIsDizhu = dizhuIndex == index + 1
                dizhuwin = mp.getResult('dizhuwin')
                realDeltas = [realSeat[0] for realSeat in realSeats]
                if ftlog.is_debug():
                    ftlog.debug(
                        'DizhuTableProtoMix.sendWinloseRes realDeltas=',
                        realDeltas, 'userId=', seat.player.userId, 'mixId=',
                        seat.player.mixConf.get('mixId'), 'index=', index)

                if len(realDeltas) == 2:
                    for index2, realSeat in enumerate(realSeats):
                        if index != index2:
                            realSeat[0] = abs(currentSeat[0]) * (
                                realSeat[0] / abs(realSeat[0]))
                else:
                    if realDeltas.count(0) == 0:
                        for index2, realSeat in enumerate(realSeats):
                            if index != index2:
                                if currentIsDizhu:
                                    realSeat[0] = abs(currentSeat[0] / 2) * (
                                        realSeat[0] / abs(realSeat[0]))
                                else:
                                    if dizhuIndex == index2 + 1:
                                        realSeat[0] = abs(
                                            currentSeat[0] * 2) * (
                                                realSeat[0] / abs(realSeat[0]))
                                    else:
                                        realSeat[0] = abs(currentSeat[0]) * (
                                            realSeat[0] / abs(realSeat[0]))

                    elif realDeltas.count(0) == 1:  # 一个人托管
                        for index2, realSeat in enumerate(realSeats):
                            if index != index2:
                                if currentIsDizhu:  # 地主肯定有值
                                    if realSeat[0] != 0:
                                        if dizhuwin:
                                            realSeat[0] = abs(
                                                currentSeat[0]) * (
                                                    realSeat[0] /
                                                    abs(realSeat[0]))
                                        else:
                                            realSeat[0] = abs(
                                                currentSeat[0] /
                                                2) * (realSeat[0] /
                                                      abs(realSeat[0]))
                                else:
                                    if currentSeat[0] == 0:
                                        if dizhuIndex == index2 + 1:
                                            realSeat[0] = abs(
                                                windoubles * 2 *
                                                currentBaseScore) * (
                                                    realSeat[0] /
                                                    abs(realSeat[0]))
                                        else:
                                            if dizhuwin:
                                                realSeat[0] = abs(
                                                    windoubles * 2 *
                                                    currentBaseScore) * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                            else:
                                                realSeat[0] = abs(
                                                    windoubles *
                                                    currentBaseScore) * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                    else:
                                        if dizhuIndex == index2 + 1:
                                            if dizhuwin:
                                                realSeat[0] = abs(
                                                    currentSeat[0]) * 1 * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                                            else:
                                                realSeat[0] = abs(
                                                    currentSeat[0]) * 2 * (
                                                        realSeat[0] /
                                                        abs(realSeat[0]))
                    else:
                        for index2, realSeat in enumerate(realSeats):
                            if realSeat[0]:
                                realSeat[0] = abs(
                                    windoubles * 2 * currentBaseScore) * (
                                        realSeat[0] / abs(realSeat[0]))

                if ftlog.is_debug():
                    fakeDeltas = []
                    for i, seatDetails in enumerate(
                            details.get('seatDetails', [])):
                        fakeDeltas.append(mp.getResult('seat%s' % (i + 1))[0])
                    ftlog.debug(
                        'DizhuTableProtoMix.sendWinloseRes fakeDeltas=',
                        fakeDeltas, 'userId=', seat.player.userId, 'mixId=',
                        seat.player.mixConf.get('mixId'), 'index=', index)

            if seat.player and not seat.isGiveup:
                ssts = result.seatStatements

                # 是否达到踢出值
                isLowerKickOutCoin = True if ssts[
                    index].final < seat.player.mixConf.get('kickOutCoin',
                                                           0) else False

                # 不踢出
                if isLowerKickOutCoin and seat.player.chip < seat.player.mixConf.get(
                        'buyinchip', 0):
                    isKickOutCoin = 1

                mp.setResult('kickOutCoinTip', '')
                if isLowerKickOutCoin and seat.player.chip >= seat.player.mixConf.get(
                        'buyinchip', 0):
                    mp.setResult(
                        'kickOutCoinTip', '点击继续,将自动将您\n桌面金币补充至%s。\n继续努力吧!' %
                        seat.player.mixConf.get('buyinchip'))

                # 是否达到踢出值
                mp.setResult('isKickOutCoin', isKickOutCoin)
                # 破产埋点Id
                kickOutBurialId = seat.player.mixConf.get('kickOutBurialId')
                mp.setResult('kickOutBurialId', kickOutBurialId)
                # 首败分享埋点
                mp.rmResult('firstLoseBurialId')
                if seat.player.isFirstLose(ssts[index].isWin):
                    firstLoseBurialId = self.table.room.roomConf.get(
                        'firstLoseBurialId')
                    mp.setResult('firstLoseBurialId', firstLoseBurialId)

                # 是否展示交叉导流
                dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(
                    seat.userId, DIZHU_GAMEID)
                mp.setResult('dailyPlay', dailyPlayCount)
                mp.rmResult('showCross')
                mp.setResult('showCross', dailyPlayCount > crossPlayCount)
                mp.setResult('crossDelaySeconds', crossDelaySeconds)
                if ftlog.is_debug():
                    ftlog.debug('sendWinloseRes userId=', seat.userId,
                                'dailyPlayCount=', dailyPlayCount,
                                'showCross=', dailyPlayCount > crossPlayCount,
                                'crossDelaySeconds=', crossDelaySeconds)
                if dailyPlayCount == 3:
                    TGDizhu.getEventBus().publishEvent(
                        ActiveEvent(6, seat.userId, 'playTimes3'))

                mp.rmResult('auth')
                if dailyPlayCount == authPlayCount:
                    mp.setResult('auth', {'auth': 1, 'rewards': rewards})

                # 服务费字段
                mp.setResult('room_fee',
                             ssts[index].fee + ssts[index].fixedFee)

                # 每日首胜
                if seat.player.isFirstWin(ssts[index].isWin):
                    from dizhu.game import TGDizhu
                    from dizhu.entity.common.events import ActiveEvent
                    import poker.util.timestamp as pktimestamp
                    TGDizhu.getEventBus().publishEvent(
                        ActiveEvent(6, seat.userId, 'dailyFirstWin'))
                    today = pktimestamp.formatTimeDayInt()
                    firstWin = {str(today): 1}
                    gamedata.setGameAttrs(seat.userId, DIZHU_GAMEID,
                                          ['firstWin'],
                                          [strutil.dumps(firstWin)])
                router.sendToUser(mp, seat.userId)
Ejemplo n.º 28
0
def doTreasureBox(userId, bigRoomId):
    ftlog.debug('doTreasureBox userId=', userId, 'bigRoomId=', bigRoomId)
    # 判定房间配置
    tbconfiger = dizhuconf.getTreasureBoxInfo(bigRoomId)
    if not tbconfiger or not tbconfiger.get('reward', None):
        ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId,
                    'not tbox room !')
        return {'ok': 0, 'info': '本房间不支持宝箱,请进入高倍房再使用'}
    # 判定是否可以领取
    tbplaytimes, tblasttime, datas = getUserTbInfo(userId, bigRoomId)
    tbplaycount = tbconfiger['playCount']
    if tblasttime <= 0 or tbplaytimes < tbplaycount:
        ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId,
                    'can not tbox !')
        return {
            'ok': 0,
            'tbt': min(tbplaytimes, tbplaycount),
            'tbc': tbplaycount,
            'info': tbconfiger['desc']
        }
    # 更新宝箱状态
    datas['tblasttime'] = int(time.time())
    datas['tbplaytimes'] = 0
    _setTbData(userId, datas)

    rewards = tbconfiger['reward']
    content = TYContentRegister.decodeFromDict(rewards)
    sitems = content.getItems()
    # 活动加成
    ditems = _getDoubleInfos(bigRoomId)
    if ditems:
        for si in sitems:
            kindId = si.assetKindId
            mutil = ditems.get(kindId, 0)
            if mutil and mutil > 0:
                si.count = int(si.count * mutil)
    # 发送道具
    # ua = hallitem.itemSystem.loadUserAssets(userId)
    # aslist = ua.sendContentItemList(DIZHU_GAMEID, sitems, 1, True,
    #                                 timestamp.getCurrentTimestamp(), 'TASK_OPEN_TBOX_REWARD', bigRoomId)
    aslist = dizhu_util.sendRewardItems(userId, sitems, '',
                                        'TASK_OPEN_TBOX_REWARD', bigRoomId)
    addmsg = TYAssetUtils.buildContentsString(aslist)
    items = []
    for x in aslist:
        kindId = hallconf.translateAssetKindIdToOld(x[0].kindId)
        items.append({'item': kindId, 'count': x[1], 'total': x[2]})
        if kindId in ['user:coupon', 'COUPON']:
            # 广播事件
            from hall.game import TGHall
            TGHall.getEventBus().publishEvent(
                UserCouponReceiveEvent(
                    HALL_GAMEID, userId, x[1],
                    user_coupon_details.USER_COUPON_TABLE_TBBOX))

    from dizhu.game import TGDizhu
    TGDizhu.getEventBus().publishEvent(
        UserTBoxLotteryEvent(DIZHU_GAMEID, userId))
    datas = {
        'ok': 1,
        'tbt': 0,
        'tbc': tbplaycount,
        'info': '开启宝箱,获得' + addmsg,
        'items': items
    }
    ftlog.debug('doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId,
                datas)
    return datas
Ejemplo n.º 29
0
def subscribeUserRewardAsyncEvent():
    from dizhu.game import TGDizhu
    TGDizhu.getEventBus().subscribe(UserRewardAsyncEvent,
                                    _processUserRewardAsync)
Ejemplo n.º 30
0
    def sendWinloseRes(self, result):
        details = self.buildResultDetails(result)
        mp = self.buildWinloseRes(result, details, 1)
        # 免费场开关
        freeFeeSwitch = self.table.room.roomConf.get('freeFeeSwitch', 0)
        mp.setResult('free', freeFeeSwitch)
        from dizhu.game import TGDizhu
        from dizhu.entity.common.events import ActiveEvent
        crossPlayCount = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossPlayCount', 10)
        crossDelaySeconds = configure.getGameJson(DIZHU_GAMEID, 'wx.cross', {}).get('crossDelaySeconds', 10)
        authPlayCount = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('authPlayCount', 5)
        rewards = configure.getGameJson(DIZHU_GAMEID, 'authorization', {}).get('rewards', {})
        for index, seat in enumerate(self.table.seats):
            isKickOutCoin = 0
            if seat.player and not seat.isGiveup:
                if self.table.room.roomConf.get('isAI') and seat.player.isAI:
                    continue
                ssts = result.seatStatements
                # 是否达到踢出值
                isLowerKickOutCoin = True if ssts[index].final < self.table.room.roomConf.get('kickOutCoin', 0) else False

                # 不踢出
                if isLowerKickOutCoin and seat.player.chip < self.table.room.roomConf['buyinchip']:
                    isKickOutCoin = 1

                # 点击继续的提醒
                mp.rmResult('kickOutCoinTip')
                if isLowerKickOutCoin and seat.player.chip >= self.table.room.roomConf['buyinchip']:
                    mp.setResult('kickOutCoinTip', details.get('kickOutCoinTip'))

                # 是否达到踢出值
                mp.setResult('isKickOutCoin', isKickOutCoin)
                # 破产埋点Id
                kickOutBurialId = self.table.room.roomConf.get('kickOutBurialId')
                mp.setResult('kickOutBurialId', kickOutBurialId)
                # 首败分享埋点
                mp.rmResult('firstLoseBurialId')
                if seat.player.isFirstLose(ssts[index].isWin):
                    firstLoseBurialId = self.table.room.roomConf.get('firstLoseBurialId')
                    mp.setResult('firstLoseBurialId', firstLoseBurialId)

                # 是否展示交叉导流
                dailyPlayCount = new_table_remote.doGetUserDailyPlayCount(seat.userId, DIZHU_GAMEID)
                mp.setResult('dailyPlay', dailyPlayCount)
                mp.rmResult('showCross')
                mp.setResult('showCross', dailyPlayCount > crossPlayCount)
                mp.setResult('crossDelaySeconds', crossDelaySeconds)

                if dailyPlayCount == 3:
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'playTimes3'))

                mp.rmResult('auth')
                if dailyPlayCount == authPlayCount:
                    mp.setResult('auth', {'auth': 1, 'rewards': rewards})

                # 服务费字段
                mp.setResult('room_fee', ssts[index].fee + ssts[index].fixedFee)

                # 每日首胜
                if seat.player.isFirstWin(ssts[index].isWin):
                    from dizhu.game import TGDizhu
                    from dizhu.entity.common.events import ActiveEvent
                    import poker.util.timestamp as pktimestamp
                    TGDizhu.getEventBus().publishEvent(ActiveEvent(6, seat.userId, 'dailyFirstWin'))
                    today = pktimestamp.formatTimeDayInt()
                    firstWin = {str(today): 1}
                    gamedata.setGameAttrs(seat.userId, DIZHU_GAMEID, ['firstWin'], [strutil.dumps(firstWin)])

                if ftlog.is_debug():
                    ftlog.debug('sendWinloseRes userId=', seat.userId,
                                'dailyPlayCount=', dailyPlayCount,
                                'showCross=', dailyPlayCount > crossPlayCount,
                                'crossDelaySeconds=', crossDelaySeconds,
                                'msg=', mp)
                router.sendToUser(mp, seat.userId)