def _sendRewards(self, status, task, timestamp):
        from hall.game import TGHall

        userAssets = hallitem.itemSystem.loadUserAssets(status.userId)
        assetList = userAssets.sendContent(self.gameId,
                                           task.taskKind.rewardContent, 1,
                                           True, timestamp,
                                           'HALL_RP_TASK_REWARD', task.kindId)
        ftlog.info('RPTaskSystem._sendRewards', 'gameId=', self.gameId,
                   'userId=', status.userId, 'kindId=', task.kindId, 'assets=',
                   [(atup[0].kindId, atup[1]) for atup in assetList])
        changed = TYAssetUtils.getChangeDataNames(assetList)
        datachangenotify.sendDataChangeNotify(self.gameId, status.userId,
                                              changed)

        if task.taskKind.rewardMail:
            contents = TYAssetUtils.buildContentsString(assetList)
            mail = strutil.replaceParams(task.taskKind.rewardMail,
                                         {'rewardContent': contents})
            pkmessage.sendPrivate(HALL_GAMEID, status.userId, 0, mail)

        TGHall.getEventBus().publishEvent(
            UserRedPacketTaskRewardEvent(status.userId, HALL_GAMEID,
                                         task.taskKind, assetList))

        couponCount = TYAssetUtils.getAssetCount(assetList,
                                                 hallitem.ASSET_COUPON_KIND_ID)
        if couponCount > 0:
            TGHall.getEventBus().publishEvent(
                UserReceivedCouponEvent(
                    HALL_GAMEID, status.userId, couponCount,
                    hall_red_packet_const.RP_SOURCE_RP_TASK))
Example #2
0
def sendReward(userId, clientId, timestamp):
    from hall.game import TGHall
    
    for cond, rewardContent in _conf.rewards:
        if cond and not cond.check(HALL_GAMEID, userId, clientId, timestamp):
            continue
        
        userAssets = hallitem.itemSystem.loadUserAssets(userId)
        assetList = userAssets.sendContent(HALL_GAMEID,
                                           rewardContent,
                                           1,
                                           True,
                                           timestamp,
                                           'HALL_RP_REWARD',
                                           0)
        ftlog.info('hall_red_packet_main.sendReward',
                   'userId=', userId,
                   'assets=', [(atup[0].kindId, atup[1]) for atup in assetList])
        changed = TYAssetUtils.getChangeDataNames(assetList)
        datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, changed)
        count = TYAssetUtils.getAssetCount(assetList, hallitem.ASSET_COUPON_KIND_ID)
        if count > 0:
            TGHall.getEventBus().publishEvent(UserReceivedCouponEvent(HALL_GAMEID,
                                                                      userId,
                                                                      count,
                                                                      hall_red_packet_const.RP_SOURCE_RP_MAIN))
        return assetList
    return None
Example #3
0
    def _doNewVipGift(cls, gameId, userId, level):
        try:
            userVip, _giftStates, gotVipGiftResult = hallvip.userVipSystem.gainUserVipGift(gameId, userId, level)
            ftlog.debug('VipTcpHandler._doNewVipGift userId=', userId,
                        'gameId=', gameId,
                        'giftVipLevel=', gotVipGiftResult.vipGiftState.vipLevel.level)
            giftInfo = VipHelper.buildGiftInfo(userVip, gotVipGiftResult.vipGiftState)
            getGiftTodoTask = TodoTaskVipGotGift(gotVipGiftResult.vipGiftState.vipLevel.level,
                                                 gotVipGiftResult.vipGiftState.vipLevel.vipExp,
                                                 gotVipGiftResult.vipGiftState.vipLevel.name,
                                                 gotVipGiftResult.vipGiftState.vipLevel.desc,
                                                 giftInfo)

            todotasks = [getGiftTodoTask]
            needGoldRain = TYAssetUtils.getAssetCount(gotVipGiftResult.giftItemList, hallitem.ASSET_CHIP_KIND_ID) > 0
            if needGoldRain:
                todotasks.append(TodoTaskGoldRain(VipHelper.buildGotGiftDesc(gotVipGiftResult)))
            else:
                todotasks.append(TodoTaskPopTip(VipHelper.buildGotGiftDesc(gotVipGiftResult)))

            mo = TodoTaskHelper.sendTodoTask(gameId, userId, todotasks)
            # 通知客户端变化
            if gotVipGiftResult.giftItemList:
                datachangenotify.sendDataChangeNotify(gameId, userId,
                                                      TYAssetUtils.getChangeDataNames(gotVipGiftResult.giftItemList))
            return mo
        except TYBizException, e:
            return cls.sendErrorResponse(userId, 'newvip', e.errorCode, e.message)
Example #4
0
def _checkDelivery(self, orderDeliveryResult):
    try:
        order = orderDeliveryResult.order
        if order.orderId.startswith('GO'):
            return
        consumeDiamond = int(order.chargeInfo.getConsume('coin', 0))
        totalPriceDiamond = int(order.product.priceDiamond) * order.count
        if consumeDiamond < totalPriceDiamond:
            ftlog.warn('WARNING checkDelivery err=', 'NotEnoughDiamond',
                       'orderId=', order.orderId,
                       'userId=', order.userId,
                       'gameId=', order.gameId,
                       'productId=', order.productId,
                       'count=', order.count,
                       'price=', order.product.price,
                       'priceDiamond=', order.product.priceDiamond,
                       'totalPriceDiamond=', totalPriceDiamond,
                       'consumeDiamond=', consumeDiamond)
            return
        elif consumeDiamond > totalPriceDiamond:
            ftlog.warn('WARNING checkDelivery err=', 'OverLoadDiamond',
                       'orderId=', order.orderId,
                       'userId=', order.userId,
                       'gameId=', order.gameId,
                       'productId=', order.productId,
                       'count=', order.count,
                       'price=', order.product.price,
                       'priceDiamond=', order.product.priceDiamond,
                       'totalPriceDiamond=', totalPriceDiamond,
                       'consumeDiamond=', consumeDiamond)
            return

        if orderDeliveryResult.itemList:
            # 统计获得了多少金币
            deliveryChip = TYAssetUtils.getAssetCount(orderDeliveryResult.assetItems, hallitem.ASSET_CHIP_KIND_ID)
            maxChip = consumeDiamond * CHECK_DIAMOND_CHIP_RATE
            if deliveryChip > maxChip:
                ftlog.warn('WARNING checkDelivery err=', 'OverMaxChip',
                           'orderId=', order.orderId,
                           'userId=', order.userId,
                           'gameId=', order.gameId,
                           'productId=', order.productId,
                           'count=', order.count,
                           'price=', order.product.price,
                           'priceDiamond=', order.product.priceDiamond,
                           'totalPriceDiamond=', totalPriceDiamond,
                           'consumeDiamond=', consumeDiamond,
                           'deliveryChip=', deliveryChip,
                           'maxChip=', maxChip,
                           'checkRate=', CHECK_DIAMOND_CHIP_RATE)
    except:
        ftlog.exception()
Example #5
0
def _checkDelivery(self, orderDeliveryResult):
    try:
        order = orderDeliveryResult.order
        if order.orderId.startswith('GO'):
            return
        consumeDiamond = int(order.chargeInfo.getConsume('coin', 0))
        totalPriceDiamond = int(order.product.priceDiamond) * order.count
        if consumeDiamond < totalPriceDiamond:
            ftlog.warn('WARNING checkDelivery err=', 'NotEnoughDiamond',
                       'orderId=', order.orderId,
                       'userId=', order.userId,
                       'gameId=', order.gameId,
                       'productId=', order.productId,
                       'count=', order.count,
                       'price=', order.product.price,
                       'priceDiamond=', order.product.priceDiamond,
                       'totalPriceDiamond=', totalPriceDiamond,
                       'consumeDiamond=', consumeDiamond)
            return
        elif consumeDiamond > totalPriceDiamond:
            ftlog.warn('WARNING checkDelivery err=', 'OverLoadDiamond',
                       'orderId=', order.orderId,
                       'userId=', order.userId,
                       'gameId=', order.gameId,
                       'productId=', order.productId,
                       'count=', order.count,
                       'price=', order.product.price,
                       'priceDiamond=', order.product.priceDiamond,
                       'totalPriceDiamond=', totalPriceDiamond,
                       'consumeDiamond=', consumeDiamond)
            return

        if orderDeliveryResult.itemList:
            # 统计获得了多少金币
            deliveryChip = TYAssetUtils.getAssetCount(orderDeliveryResult.assetItems, hallitem.ASSET_CHIP_KIND_ID)
            maxChip = consumeDiamond * CHECK_DIAMOND_CHIP_RATE
            if deliveryChip > maxChip:
                ftlog.warn('WARNING checkDelivery err=', 'OverMaxChip',
                           'orderId=', order.orderId,
                           'userId=', order.userId,
                           'gameId=', order.gameId,
                           'productId=', order.productId,
                           'count=', order.count,
                           'price=', order.product.price,
                           'priceDiamond=', order.product.priceDiamond,
                           'totalPriceDiamond=', totalPriceDiamond,
                           'consumeDiamond=', consumeDiamond,
                           'deliveryChip=', deliveryChip,
                           'maxChip=', maxChip,
                           'checkRate=', CHECK_DIAMOND_CHIP_RATE)
    except:
        ftlog.exception()
Example #6
0
 def doGainNSLoginReward(self, userId, gameId, clientId):
     checkinOk, rewardAssetList, _checkinDays = \
         halldailycheckin.dailyCheckin.gainCheckinReward(gameId, userId)
     rewardChipCount = 0
     if checkinOk:
         datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(rewardAssetList))
         rewardChipCount = TYAssetUtils.getAssetCount(rewardAssetList, hallitem.ASSET_CHIP_KIND_ID)
     states = halldailycheckin.dailyCheckin.getStates(gameId, userId, pktimestamp.getCurrentTimestamp())
     mo = MsgPack()
     mo.setCmd('gain_nslogin_reward')
     mo.setResult('gameId', gameId)
     mo.setResult('userId', userId)
     mo.setResult('rewardstate', TodoTaskHelper.translateDailyCheckinStates(states))
     mo.setResult('success', True)
     mo.setResult('chip', userchip.getChip(userId))
     mo.setResult('rewardchip', rewardChipCount)
     router.sendToUser(mo, userId)
Example #7
0
 def doGainNSLoginReward(self, userId, gameId, clientId):
     checkinOk, rewardAssetList, _checkinDays = \
         halldailycheckin.dailyCheckin.gainCheckinReward(gameId, userId)
     rewardChipCount = 0
     if checkinOk:
         datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(rewardAssetList))
         rewardChipCount = TYAssetUtils.getAssetCount(rewardAssetList, hallitem.ASSET_CHIP_KIND_ID)
     states = halldailycheckin.dailyCheckin.getStates(gameId, userId, pktimestamp.getCurrentTimestamp())
     mo = MsgPack()
     mo.setCmd('gain_nslogin_reward')
     mo.setResult('gameId', gameId)
     mo.setResult('userId', userId)
     mo.setResult('rewardstate', TodoTaskHelper.translateDailyCheckinStates(states))
     mo.setResult('success', True)
     mo.setResult('chip', userchip.getChip(userId))
     mo.setResult('rewardchip', rewardChipCount)
     router.sendToUser(mo, userId)
Example #8
0
    def _doNewVipGift(cls, gameId, userId, level):
        try:
            userVip, _giftStates, gotVipGiftResult = hallvip.userVipSystem.gainUserVipGift(
                gameId, userId, level)
            ftlog.debug('VipTcpHandler._doNewVipGift userId=', userId,
                        'gameId=', gameId, 'giftVipLevel=',
                        gotVipGiftResult.vipGiftState.vipLevel.level)
            giftInfo = VipHelper.buildGiftInfo(userVip,
                                               gotVipGiftResult.vipGiftState)
            getGiftTodoTask = TodoTaskVipGotGift(
                gotVipGiftResult.vipGiftState.vipLevel.level,
                gotVipGiftResult.vipGiftState.vipLevel.vipExp,
                gotVipGiftResult.vipGiftState.vipLevel.name,
                gotVipGiftResult.vipGiftState.vipLevel.desc, giftInfo)

            todotasks = [getGiftTodoTask]
            needGoldRain = TYAssetUtils.getAssetCount(
                gotVipGiftResult.giftItemList, hallitem.ASSET_CHIP_KIND_ID) > 0
            if needGoldRain:
                todotasks.append(
                    TodoTaskGoldRain(
                        VipHelper.buildGotGiftDesc(gotVipGiftResult)))
            else:
                todotasks.append(
                    TodoTaskPopTip(
                        VipHelper.buildGotGiftDesc(gotVipGiftResult)))

            mo = TodoTaskHelper.sendTodoTask(gameId, userId, todotasks)
            # 通知客户端变化
            if gotVipGiftResult.giftItemList:
                datachangenotify.sendDataChangeNotify(
                    gameId, userId,
                    TYAssetUtils.getChangeDataNames(
                        gotVipGiftResult.giftItemList))
            return mo
        except TYBizException, e:
            return cls.sendErrorResponse(userId, 'newvip', e.errorCode,
                                         e.message)