Пример #1
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        assert (isinstance(item, TYMemberCardItem))
        if item.isExpires(timestamp):
            return items.TYItemActionResult(None, None, -30, '道具已经过期', None)

        if not item.canCheckin(timestamp):
            return items.TYItemActionResult(None, None, -31, '道具已经签到过', None)

        # 保存item
        item.checkinTime = timestamp
        userBag = userAssets.getUserBag()
        userBag.updateItem(item, timestamp)

        # 发放开出的奖品
        # 检查是否是订阅会员
        ct = datetime.fromtimestamp(timestamp)
        eventId = 'ITEM_USE' if pluginCross.hallsubmember.isSubExpires(
            userAssets.userId, ct) else 'ITEM_SUB_MEMBER_CHECKIN'
        assetItemList = userAssets.sendContentItemList(gameId,
                                                       self.content.getItems(),
                                                       1, True, timestamp,
                                                       eventId, item.kindId)
        gotContent = assetutils.buildContentsString(assetItemList)
        replaceParams = {'gotContent': gotContent}
        _mail, message, _changed = _action._handleMailAndMessageAndChanged(
            gameId, userAssets, self, assetItemList, replaceParams)

        ftlog.info('TYItemActionCheckin._doActionImpl gameId=', gameId,
                   'userId=', userAssets.userId, 'itemId=', item.itemId,
                   'itemKindId=', item.kindId, 'gotContent=', gotContent,
                   'mail=', _mail, 'message=', message, 'changed=', _changed)
        # TGHall.getEventBus().publishEvent(TYCheckinItemEvent(gameId, userBag.userId, item, assetItemList))
        return TYItemActionCheckinResult(self, item, message, assetItemList)
Пример #2
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        assert (isinstance(item, TYExchangeItem))
        if item.isDied(timestamp):
            if item.itemKind.units.isTiming():
                return items.TYItemActionResult(None, None, -30, '道具已经过期',
                                                None)
            else:
                return items.TYItemActionResult(None, None, -31, '道具数量不足',
                                                None)

        if item.state != TYExchangeItem.STATE_NORMAL:
            return items.TYItemActionResult(None, None, -32, '道具审核中', None)

        wechat_red_pack = self.isWechatRedPack()  # 微信红包,无需手机号、地址
        msg = MsgPack()
        msg.setKey('apiVersion', 5.0)
        msg.setCmdAction('exchange5', 'exchange')
        msg.updateParam(self.auditParams)
        msg.setParam(
            'phone',
            str(
                params.get('phoneNumber'
                           ) if not wechat_red_pack else '11111111111'))
        msg.setParam('uName', params.get('uName', ''))
        msg.setParam('bindPhone', params.get('bindPhone', ''))
        msg.setParam('phoneNumber', params.get('phoneNumber', ''))
        msg.setParam('uAddres', params.get('uAddres', ''))
        msg.setParam('gameId', gameId)
        msg.setParam('itemId', item.itemId)
        msg.setParam('userId', userAssets.userId)
        msg.setParam('extabName', '_item_')
        msg.setParam('clientId', clientId)
        msg.setParam('wxappid',
                     hallconf.getWeiXinAppId(userAssets.userId, clientId))
        msg.setParam('proviceId', params.get('proviceId', ''))
        msg.setParam('cityId', params.get('cityId', ''))
        msg.setParam('countyId', params.get('countyId', ''))
        msg.setParam('townId', params.get('townId', ''))
        msg.setParam('proviceName', params.get('proviceName', ''))
        msg.setParam('cityName', params.get('cityName', ''))
        msg.setParam('countyName', params.get('countyName', ''))
        msg.setParam('townName', params.get('townName', ''))

        ftlog.info('TYItemActionExchange->doAction', msg)
        exchangeId, errMsg = pluginCross.hallexchange.doExchangeRequest(
            userAssets.userId, msg)
        if not exchangeId or errMsg:
            return items.TYItemActionResult(None, None, -33, errMsg, None)

        # 兑换开始,成功,转换道具状态
        item.state = TYExchangeItem.STATE_AUDIT
        item.original = 0
        userAssets.getUserBag().updateItem(item, timestamp)

        replaceParams = {'item': item.itemKind.displayName}
        _mail, message, _changed = _action._handleMailAndMessageAndChanged(
            gameId, userAssets, self, None, replaceParams)
        # TGHall.getEventBus().publishEventent(TYItemExchangeEvent(gameId, userAssets.userId, item))
        return TYItemActionExchangeResult(self, item, message, exchangeId)
Пример #3
0
 def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
     product, _ = pluginCross.hallstore.findProductByPayOrder(
         HALL_GAMEID, userAssets.userId, clientId, self.payOrder)
     if product:
         todotask = pluginCross.halltodotask.makeTodoTaskPayOrder(
             gameId, userAssets.userId, clientId, product)
         if todotask:
             return items.TYItemActionResult(self, item, 0, '', todotask)
     return items.TYItemActionResult(self, item, -30, 'product not found !',
                                     None)
Пример #4
0
def _makeTodoWithPayOrder(provider, gameId, userId, clientId):
    payOrder = provider.getParam('payOrder')
    if not payOrder:
        todotaskId = provider.getParam('todotask')
        if todotaskId:
            todotask = pluginCross.halltodotask.makeTodoTaskByConfId(todotaskId, gameId, userId, clientId)
            return items.TYItemActionResult(None, None, -20, provider.failure, todotask)
        else:
            todotask = _makeTodoTaskShowInfo(provider.failure, None, False)
            return items.TYItemActionResult(None, None, -21, provider.failure, todotask)
    else:
        product, shelves = pluginCross.store.findProductByPayOrder(gameId, userId, clientId, payOrder)
        goShelvesName = shelves.name if product and shelves else ''
        todotask = _makeTodoTaskShowInfo(provider.failure, goShelvesName, False)
        return items.TYItemActionResult(None, None, -22, provider.failure, todotask)
Пример #5
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        userBag = userAssets.getUserBag()

        if item.isDied(timestamp):
            return items.TYItemActionResult(None, None, -30, '道具已经过期', None)

        if item.itemKind.singleMode:
            unitsCount = int(params.get('count'))
            consumeCount = userBag.consumeItemUnits(gameId, item, unitsCount,
                                                    timestamp, 'SALE_ITEM',
                                                    item.kindId)
            if consumeCount < unitsCount:
                return items.TYItemActionResult(None, None, -31, '道具数量不足',
                                                None)

            assetItem = userAssets.addAsset(
                gameId, self.contentItem.assetKindId,
                self.contentItem.count * unitsCount, timestamp, 'SALE_ITEM',
                item.kindId)
            saleItem = assetutils.buildItemContent(
                (item.itemKind, unitsCount, 0))
        else:
            userBag.removeItem(gameId, item, timestamp, 'SALE_ITEM',
                               item.kindId)
            assetItem = userAssets.addAsset(gameId,
                                            self.contentItem.assetKindId,
                                            self.contentItem.count, timestamp,
                                            'SALE_ITEM', item.kindId)
            saleItem = item.itemKind.displayName

        # 生成打开生成的列表
        rewardsList = [{
            'name': assetItem[0].displayName,
            'pic': assetItem[0].pic,
            'count': assetItem[1],
            'kindId': assetItem[0].kindId
        }]
        rewardTodotask = pluginCross.halltodotask.makeTodoTaskShowRewards(
            rewardsList)

        assetList = [assetItem]
        gotContent = assetutils.buildContent(assetItem)
        replaceParams = {'saleItem': saleItem, 'gotContent': gotContent}
        _mail, message, _changed = _action._handleMailAndMessageAndChanged(
            gameId, userAssets, self, assetList, replaceParams)
        # TGHall.getEventBus().publishEvent(TYSaleItemEvent(gameId, userBag.userId, item, assetList))
        return TYItemActionSaleResult(self, item, message, assetList,
                                      rewardTodotask)
Пример #6
0
def doActionByItemId(userId, gameId, itemId, actionName, timestamp, params, clientId=None):
    """
    GDSS接口在用
    """
    if _DEBUG:
        debug('doActionByItemId IN', userId, gameId, itemId, actionName, timestamp, params, clientId)

    try:
        userAssets = itemsys.itemSystem.loadUserAssets(userId)
        if not userAssets:
            return items.TYItemActionResult(None, None, -1, '用户ID资产错误', None)

        userBag = userAssets.getUserBag()
        if not userBag:
            return items.TYItemActionResult(None, None, -2, '用户ID背包错误', None)

        item = userBag.findItem(itemId)
        if not item:
            return items.TYItemActionResult(None, None, -3, '不能识别的道具ID', None)

        action = item.itemKind.findActionByName(actionName)
        if not action:
            return items.TYItemActionResult(None, None, -4, '不能执行该动作', None)

        clientId = clientId or tysessiondata.getClientId(userId)

        # 基本参数类型检查 10
        result = action.checkParams(gameId, userId, timestamp, params)
        if result.code != 0:
            return result

        # 前提条件检查 20
        result = action.checkCondition(gameId, clientId, userId, item, timestamp, params)
        if result.code != 0:
            return result

        # 执行动作 30
        result = action.doAction(gameId, clientId, userAssets, item, timestamp, params)
    except Exception, e:
        ftlog.error()
        result = items.TYItemActionResult(None, None, -6, '系统错误' + str(e), None)
Пример #7
0
 def checkParams(self, gameId, userId, timestamp, params):
     ftlog.info('exchange.checkParams->', params)
     if self.isWechatRedPack():  # 微信红包,无需手机号
         return items.ACT_RESULT_OK
     useBindPhone = params.get('bindPhone', 0)
     if not useBindPhone:
         # 如果没有bindPhone,则需要检查phoneNumber
         phoneNumber = params.get('phoneNumber')
         if not phoneNumber:
             return items.TYItemActionResult(None, None, -10, '请输入手机号码',
                                             None)
     return items.ACT_RESULT_OK
Пример #8
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        if item.isDied(timestamp):
            return items.TYItemActionResult(None, None, -30, '道具已经过期', None)
        # 消耗道具
        userBag = userAssets.getUserBag()
        count = userBag.consumeItemUnits(gameId, item, 1, timestamp,
                                         'ITEM_USE', item.kindId)
        if count != 1:
            return items.TYItemActionResult(None, None, -31, '道具数量不足', None)

        return items.TYItemActionResult(None, None, 0, 'ok, not implement',
                                        None)

        rpcproxy = typlugin.getRpcProxy(self.gameId, typlugin.RPC_CALL_SAFE,
                                        typlugin.RPC_TARGET_MOD_ONE)
        rfc = rpcproxy.gamemgr.setGameData(userBag.userId, self.gameId,
                                           self.field, self.value)
        if not rfc:
            return items.TYItemActionResult(None, None, -32, '系统错误,目标游戏服务不存在',
                                            None)
        if rfc.getException():
            return items.TYItemActionResult(
                None, None, -33, '系统错误,目标游戏服务异常:' + str(rfc.getException()),
                None)
        code, info = rfc.getResult()
        return items.TYItemActionResult(None, None, code, info, None)
Пример #9
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):

        if item.isDied(timestamp):
            return items.TYItemActionResult(None, None, -30, '道具已经过期', None)

        # 手机号码的处理
        useBindPhone = params.get('bindPhone', 0)
        if not useBindPhone:
            # 如果没有bindPhone,则需要检查phoneNumber
            phoneNumber = params.get('phoneNumber')
            if not phoneNumber:
                return items.TYItemActionResult(None, None, -31, '请输入手机号码', None)
        else:
            # 获取绑定的手机号
            phoneNumber = pluginCross.halldata.getUserDataList(userAssets.userId, UserKeys.ATT_BIND_MOBILE)
            if not phoneNumber:
                return items.TYItemActionResult(None, None, -32, '您绑定的手机号状态有误,请联系客服电话4008098000', None)

        # 获取库存
        exCode = DaoMixExCodeList.getFreeExCode(userAssets.userId, item.kindId, phoneNumber, timestamp)
        if not exCode:
            return items.TYItemActionResult(None, None, -33, '非常抱歉的通知您,兑换码已无库存,请联系客服电话4008098000', None)

        # 短信发送
        replaceParams = {'item': item.itemKind.displayName}
        mail, message, _ = _action._buildMailAndMessageAndChanged(gameId, userAssets, self, None, replaceParams)
        content = mail + exCode + message
        code = tyrpcsdk.sendSmsToUser(userAssets.userId, content, phoneNumber)
        if code == 0:
            # 消耗item
            userBag = userAssets.getUserBag()
            userBag.removeItem(gameId, item, timestamp, 'ITEM_USE', 0)
            return items.ACT_RESULT_OK
        else:
            # 将消息下发到用户的消息列表中
            # pluginCross.hallmessage.sendMessageSystem(userAssets.userId, gameId, sendToMsg, None, None)
            return items.TYItemActionResult(None, None, -34, '非常抱歉,短信发送失败,请联系客服电话4008098000', None)
Пример #10
0
    def checkCondition(self, gameId, clientId, userId, item, timestamp, params):

        if not self.conditionList:
            return items.ACT_RESULT_OK

        for conditionId in self.conditionList:
            if not pluginCross.condition.checkCondition(gameId,
                                                        userId,
                                                        clientId,
                                                        conditionId,
                                                        item=item,
                                                        params=params):
                condition = pluginCross.condition.getConditionInstanceById(conditionId, True)
                if isinstance(condition, TYItemActionCondition):
                    return _makeTodoWithPayOrder(condition, gameId, userId, clientId)
                else:
                    return items.TYItemActionResult(None, None, -23, '条件检查失败', None)
        return items.ACT_RESULT_OK
Пример #11
0
    def doAction(self, gameId, clientId, userAssets, item, timestamp, params):
        assert (isinstance(item, TYBoxItem))
        userBag = userAssets.getUserBag()

        if item.isDied(timestamp):
            return items.TYItemActionResult(None, None, -30, '道具已经过期', None)

        if self.itemBindings:
            ok, _assetTuple = self.itemBindings.consume(
                gameId, item, userAssets, timestamp, 'ITEM_USE', item.kindId)
            if not ok:
                return _action._makeTodoWithPayOrder(self.itemBindings, gameId,
                                                     userAssets.userId,
                                                     clientId)
        if not item.itemKind.singleMode:
            # 互斥型道具打开时直接删除
            userBag.removeItem(gameId, item, timestamp, 'ITEM_USE',
                               item.kindId)
        else:
            # 保存item
            item.openTimes += 1
            item.original = 0
            userBag.consumeItemUnits(gameId, item, 1, timestamp, 'ITEM_USE',
                                     item.kindId)

        sendItems = self._getContent(item).getItems()
        assetItemList = userAssets.sendContentItemList(gameId, sendItems, 1,
                                                       True, timestamp,
                                                       'ITEM_USE', item.kindId)
        # 如果需要生成下一个道具
        if self.nextItemKind:
            userBag.addItemUnitsByKind(gameId, self.nextItemKind, 1, timestamp,
                                       0, 'ITEM_USE', item.kindId)
        # 生成打开生成的列表
        rewardsList = []
        for assetItemTuple in assetItemList:
            '''
            0 - assetItem
            1 - count
            2 - final
            '''
            assetItem = assetItemTuple[0]
            reward = {
                'name': assetItem.displayName,
                'pic': assetItem.pic,
                'count': assetItemTuple[1],
                'kindId': assetItem.kindId
            }
            rewardsList.append(reward)
        rewardTodotask = pluginCross.halltodotask.makeTodoTaskShowRewards(
            rewardsList)

        # 提示文案
        gotContent = assetutils.buildContentsString(assetItemList)
        # 提示消息替换参数
        replaceParams = {
            'item': item.itemKind.displayName,
            'gotContent': gotContent
        }
        _mail, message, _changed = _action._handleMailAndMessageAndChanged(
            gameId, userAssets, self, assetItemList, replaceParams)
        # TGHall.getEventBus().publishEvent(TYOpenItemEvent(gameId, userBag.userId, item, assetItemList))
        return TYItemActionBoxOpenResult(self, item, message, assetItemList,
                                         rewardTodotask)