def getConfigForClient(self, gameId, userId, clientId):
        if day1st.isDayFirstLogin(userId, gameId):
            return None
        clientConf = strutil.cloneData(self._clientConf)
        firstChargeHasSent = hallstore.isGetFirstRechargeReward(userId)
        if firstChargeHasSent:
            return None
        tyGame = gdata.getGame(gameId)
        if not tyGame:
            return None
        userGameInnings = tyGame.getPlayGameCount(userId, clientId)
        if userGameInnings < 5:
            return None
        isFirstRecharged = hallstore.isFirstRecharged(userId)
        try:
            if not isFirstRecharged:
                rechargeFactory = TodoTaskFirstRechargeFactory().decodeFromDict(
                    self._serverConf.get("firstCharge", {})
                )
                product = rechargeFactory._getProduct(gameId, userId)
                todoTask = TodoTaskPayOrder(product)
                clientConf["config"]["button"]["todoTask"] = todoTask.toDict()
            else:
                rewardFactory = TodoTaskFirstRechargeRewardFactory.decodeFromDict(
                    self._serverConf.get("firstChargeReward", {})
                )
                clientConf["config"]["button"]["todoTask"] = rewardFactory.newTodoTask(gameId, userId,
                                                                                       clientId).toDict()
        except:
            ftlog.exception("TYActivityFirstCharge.getConfigForClient error")
            return None

        return clientConf
    def getConfigForClient(self, gameId, userId, clientId):
        if day1st.isDayFirstLogin(userId, gameId):
            return None
        clientConf = strutil.cloneData(self._clientConf)
        firstChargeHasSent = hallstore.isGetFirstRechargeReward(userId)
        if firstChargeHasSent:
            return None
        tyGame = gdata.getGame(gameId)
        if not tyGame:
            return None
        userGameInnings = tyGame.getPlayGameCount(userId, clientId)
        if userGameInnings < 5:
            return None
        isFirstRecharged = hallstore.isFirstRecharged(userId)
        try:
            if not isFirstRecharged:
                rechargeFactory = TodoTaskFirstRechargeFactory(
                ).decodeFromDict(self._serverConf.get("firstCharge", {}))
                product = rechargeFactory._getProduct(gameId, userId)
                todoTask = TodoTaskPayOrder(product)
                clientConf["config"]["button"]["todoTask"] = todoTask.toDict()
            else:
                rewardFactory = TodoTaskFirstRechargeRewardFactory.decodeFromDict(
                    self._serverConf.get("firstChargeReward", {}))
                clientConf["config"]["button"][
                    "todoTask"] = rewardFactory.newTodoTask(
                        gameId, userId, clientId).toDict()
        except:
            ftlog.exception("TYActivityFirstCharge.getConfigForClient error")
            return None

        return clientConf
    def buildFlipCardResponse(cls, gameId, userId, roomId, flipIndex,
                              flippedCardList, benefitsSend, userBenefits):
        assert (flipIndex >= 0 and flipIndex <= len(flippedCardList))
        flippedCard = flippedCardList[flipIndex]
        mo = MsgPack()
        mo.setCmd('flip_card_luck')
        mo.setResult('action', 'flip')
        mo.setResult('index', flipIndex)
        mo.setResult('userId', userId)
        mo.setResult('gameId', gameId)

        mo.setResult('cards', cls.encodeFlippedCardList(flippedCardList, flipIndex))
        mo.setResult('desc', cls.getFlippedCardDesc(flippedCard))

        if isinstance(flippedCard, FlippedCardProduct):
            payOrder = TodoTaskPayOrder(flippedCard.product)
            mo.setResult('sub_action', payOrder.toDict())
            mo.setResult('sub_text', hallflipcardluck.getString('product.subText', '立即购买'))

            if benefitsSend:
                mo.setResult('sub_action_ext',
                             TodoTaskHelper.makeTodoTaskBenefitsInfo(benefitsSend, userBenefits).toDict())
            else:
                mo.setResult('sub_action_ext', TodoTaskNoop().toDict())
            mo.setResult('sub_text_ext', hallflipcardluck.getString('product.subTextExt', '取消'))
        elif isinstance(flippedCard, FlippedCardAsset):
            if benefitsSend:
                mo.setResult('sub_action', TodoTaskHelper.makeTodoTaskBenefitsInfo(benefitsSend, userBenefits).toDict())
            else:
                mo.setResult('sub_action', TodoTaskNoop().toStr())
            mo.setResult('sub_text', hallflipcardluck.getString('item.subText', '确定'))
        return mo
Exemple #4
0
def sendMasterGiftTodoTask(userId, gameId, clientId, pic, pay_order, roomId):
    """ 推送高手礼包弹窗
    @param         pay_order        挑选商品模板
    """
    if not TYPlayer.isHuman(userId):
        return
    product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId,
                                                 pay_order)
    if not product:
        ftlog.error('userId =', userId, 'clientId =', clientId, 'pay_order =',
                    pay_order, 'can not find suitable product!')
        return
    todotask = TodoTaskPayOrder(product)
    task = {
        'action': 'cache_wnd_gaoshou',
        'params': {
            'pic': pic,
            'tasks': [todotask.toDict()]
        }
    }
    mo = MsgPack()
    mo.setCmd('majiang_todotasks')
    mo.setResult('gameId', gameId)
    mo.setResult('userId', userId)
    mo.setResult('tasks', [task])
    router.sendToUser(mo, userId)
Exemple #5
0
def sendMasterGiftTodoTask(userId, gameId, clientId, pic, pay_order, roomId):
    """ 推送高手礼包弹窗
    @param         pay_order        挑选商品模板
    """
    if not TYPlayer.isHuman(userId):
        return
    product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, pay_order)
    if not product:
        ftlog.error('userId =', userId, 'clientId =', clientId, 'pay_order =', pay_order,
                    'can not find suitable product!')
        return
    todotask = TodoTaskPayOrder(product)
    task = {
            'action':   'cache_wnd_gaoshou',
            'params':   {
                         'pic':     pic,
                         'tasks':   [todotask.toDict()]
                         }
            }
    mo = MsgPack()
    mo.setCmd('majiang_todotasks')
    mo.setResult('gameId', gameId)
    mo.setResult('userId', userId)
    mo.setResult('tasks', [task])
    router.sendToUser(mo, userId)
Exemple #6
0
 def dict_pay_order(cls, userid, product):
     """ 根据商品信息生成payOrder的字典
     action: pop_pay_order
     Args:
         userid: 玩家userid
         product: 商品信息
     """
     from hall.entity.todotask import TodoTaskPayOrder
     payorder = TodoTaskPayOrder(product)
     payorder = payorder.toDict()
     if not isinstance(payorder, dict):
         raise TYBizConfException(payorder, 'MahjongTodoTaskBuilder.dict_pay_order must be dict!')
     else:
         return payorder
Exemple #7
0
 def dict_pay_order(cls, userid, product):
     """ 根据商品信息生成payOrder的字典
     action: pop_pay_order
     Args:
         userid: 玩家userid
         product: 商品信息
     """
     from hall.entity.todotask import TodoTaskPayOrder
     payorder = TodoTaskPayOrder(product)
     payorder = payorder.toDict()
     if not isinstance(payorder, dict):
         raise TYBizConfException(payorder, 'MahjongTodoTaskBuilder.dict_pay_order must be dict!')
     else:
         return payorder
Exemple #8
0
 def getConfigForClient(self, gameId, userId, clientId):
     """
     预期实现功能。配置中,配置payOrder后台自动生成该商品的todotask
     
     """
     clientConf = strutil.cloneData(self._clientConf)
     payOrder = clientConf["config"]["button"]["payOrder"]
                 
     product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
     ftlog.debug("TYActivitySale product: ", product)
     payOrder = TodoTaskPayOrder(product)
     ftlog.debug("TYActivitySale params: ", payOrder)
     try:
         clientConf["config"]["button"]["todoTask"] = payOrder.toDict()
     except:
         ftlog.exception("getConfigForClient error, can not set todotask, clientId:", clientId)
         return None
     return clientConf
Exemple #9
0
    def getConfigForClient(self, gameId, userId, clientId):
        """
        预期实现功能。配置中,配置payOrder后台自动生成该商品的todotask
        
        """
        clientConf = strutil.cloneData(self._clientConf)
        payOrder = clientConf["config"]["button"]["payOrder"]

        product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
        ftlog.debug("TYActivitySale product: ", product)
        payOrder = TodoTaskPayOrder(product)
        ftlog.debug("TYActivitySale params: ", payOrder)
        try:
            clientConf["config"]["button"]["todoTask"] = payOrder.toDict()
        except:
            ftlog.exception("getConfigForClient error, can not set todotask, clientId:", clientId)
            return None
        return clientConf
Exemple #10
0
    def buildFlipCardResponse(cls, gameId, userId, roomId, flipIndex,
                              flippedCardList, benefitsSend, userBenefits):
        assert (flipIndex >= 0 and flipIndex <= len(flippedCardList))
        flippedCard = flippedCardList[flipIndex]
        mo = MsgPack()
        mo.setCmd('flip_card_luck')
        mo.setResult('action', 'flip')
        mo.setResult('index', flipIndex)
        mo.setResult('userId', userId)
        mo.setResult('gameId', gameId)

        mo.setResult('cards',
                     cls.encodeFlippedCardList(flippedCardList, flipIndex))
        mo.setResult('desc', cls.getFlippedCardDesc(flippedCard))

        if isinstance(flippedCard, FlippedCardProduct):
            payOrder = TodoTaskPayOrder(flippedCard.product)
            mo.setResult('sub_action', payOrder.toDict())
            mo.setResult('sub_text',
                         hallflipcardluck.getString('product.subText', '立即购买'))

            if benefitsSend:
                mo.setResult(
                    'sub_action_ext',
                    TodoTaskHelper.makeTodoTaskBenefitsInfo(
                        benefitsSend, userBenefits).toDict())
            else:
                mo.setResult('sub_action_ext', TodoTaskNoop().toDict())
            mo.setResult(
                'sub_text_ext',
                hallflipcardluck.getString('product.subTextExt', '取消'))
        elif isinstance(flippedCard, FlippedCardAsset):
            if benefitsSend:
                mo.setResult(
                    'sub_action',
                    TodoTaskHelper.makeTodoTaskBenefitsInfo(
                        benefitsSend, userBenefits).toDict())
            else:
                mo.setResult('sub_action', TodoTaskNoop().toStr())
            mo.setResult('sub_text',
                         hallflipcardluck.getString('item.subText', '确定'))
        return mo
Exemple #11
0
    def makeClientConf(self, clientconf, gameId, userId, clientId):
        '''
        构造客户端的活动协议配置
        '''
        conf = strutil.cloneData(clientconf)
        activateconf = conf.get("config", {}).get("activate", {})
        subconf = conf.get('config', {})

        task = self._taskWrapper
        
        # New: 要统计的房间列表
        roomid_tocount = activateconf.get('countRoomId', [])
        roomids_tocount = [roomid_tocount] if isstring(roomid_tocount) else roomid_tocount
            
        key_tocount = activateconf.get('countByKey')
        finish_taskcount = task.getFinishTaskCount(gameId, userId, clientconf)
        gain_taskcount = task.getRecvTaskCount(gameId, userId)
        total_tablecount = task.getTablePlayCount(userId)
        
        # New: 统计多个房间的数量
        roomid_tablecount = 0
        for roomid in roomids_tocount:
            roomid_tablecount += task.getRoomTablePlayCount(userId, roomid)
        
        is_activited = ActivityDdzFund.loadFundStatus(userId).isActivated
        ftlog.debug("TYActivityFund.makeClientConf: userId=", userId,
                    "roomids_tocount=",roomids_tocount,
                    "total_tablecount=", total_tablecount,
                    "finish_taskcount=", finish_taskcount,
                    "roomid_tablecount=", roomid_tablecount,
                    "gain_taskcount=", gain_taskcount,
                    "is_activited=",is_activited,
                    'key_tocount=', key_tocount)

        # subconf['overCnt'] = finish_taskcount # 已经完成的任务数量
        if key_tocount:
            subconf['overCnt'] = task.getPlayCountByKey(userId, key_tocount)
        elif len(roomids_tocount) > 0:
            subconf['overCnt'] = roomid_tablecount # 已经完成的局数
        else:
            subconf['overCnt'] = total_tablecount # 已经完成的局数
        subconf['getRewardYetCnt'] = gain_taskcount # 已经领取的任务数量
        subconf['isActive'] = is_activited # 是否已经激活基金活动
        subconf['activeYetHint'] = strutil.replaceParams(subconf.get("activeYetHint",""), {
            "finishcount":subconf['overCnt'],
            "finishcount_room": str(roomid_tablecount),
        })

        reward_btn_map = subconf.get('rewardButton', {})
        normal_tip = reward_btn_map.get('normalTip', '')
        activate_map = subconf.get('activate', {})
        reward_list = activate_map.get('reward', [])

        if len(reward_list)>gain_taskcount:
            desc = reward_list[gain_taskcount].get('desc', '')
            reward_btn_map['normalTip'] = strutil.replaceParams(normal_tip, {"assets":desc})

        # TodoTask
        activatebtn_map = subconf.get("activateButton", {})
        todotask = activatebtn_map.get("todoTask", {})
        payOrder = todotask.get("payOrder")
        ftlog.debug("TYActivityFund.makeClientConf: userId=", userId, "payOrder=", payOrder)

        if payOrder:
            product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
            ftlog.debug("TYActivityFund.makeClientConf: userId=", userId, "product=", product)
            payOrder = TodoTaskPayOrder(product)
            ftlog.debug("TYActivityFund.makeClientConf: userId=", userId, "params=", payOrder)
            activatebtn_map["todoTask"] = payOrder.toDict()

        # 激活日期限制
        ok = self.checkCanActivateDate(conf)
        activateconf['isOutdate'] = not ok
        if ok:
            activateconf['outdateTip'] = None
        ftlog.debug("TYActivityFund.makeClientConf: userId=", userId, "isOutdate", activateconf['isOutdate'])
        ftlog.debug("TYActivityFund.makeClientConf: userId=", userId, "conf=", conf)
        return conf
Exemple #12
0
    def _doFlipcard(self, userId, gameId, clientId, activityId, coin):
        result = {}
        key = "TYActivity:%d:%d:%s:%s" % (gameId, userId, clientId, activityId)
        ftlog.debug("_doFlipcard key:", key)
        conf = {
            "design": {
                "1": {
                    "name": "豹子A",
                    "payrate": 20,
                    "probability": 0.0001
                },
                "2": {
                    "name": "豹子",
                    "payrate": 20,
                    "probability": 0.0012
                },
                "3": {
                    "name": "同花顺",
                    "payrate": 15,
                    "probability": 0.001
                },
                "4": {
                    "name": "同花",
                    "payrate": 3,
                    "probability": 0.01
                },
                "5": {
                    "name": "顺子",
                    "payrate": 3,
                    "probability": 0.01
                },
                "6": {
                    "name": "对子",
                    "payrate": 1.5,
                    "probability": 0.1
                },
                "7": {
                    "name": "K以上单张",
                    "payrate": 1.2,
                    "probability": 0.3
                },
                "8": {
                    "name": "单张",
                    "payrate": 0,
                    "probability": 0.5777
                }
            }
        }

        # 判断用户金币是否足够
        chipNow = userchip.getChip(userId)
        if coin == 1000 and chipNow < 5000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 20,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 5000 and chipNow < 50000:

            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 80,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 10000 and chipNow < 50000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 80,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 50000 and chipNow < 300000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 300,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        else:
            result = doFlipCard(conf)
            ftlog.debug("_doFlipcard result..cardtype:", result["cardtype"])
            # 减金币操作
            coinDel = 0 - coin
            userchip.incrChip(userId, gameId, coinDel, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'HALL_FLIPCARD', 0,
                              clientId)
            datachangenotify.sendDataChangeNotify(gameId, userId, 'chip')
            ftlog.info("用户名,用户减少了金币,", userId, coinDel)
            if result["cardtype"] != '8':
                design = conf.get('design', {})
                cardTypeNumber = design[result["cardtype"]].get('payrate', 0)

                # 加金币操作
                coinAdd = int(coin * cardTypeNumber)
                cardText = "恭喜你赢得了%d" % coinAdd + "金币"
                ftlog.debug("_doFlipcard get money:", cardText)
                userchip.incrChip(userId, gameId, coinAdd, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'HALL_FLIPCARD',
                                  0, clientId)
                datachangenotify.sendDataChangeNotify(gameId, userId, 'chip')
                ftlog.info("用户名,用户增加了金币,", userId, coinAdd)
                result["todoTask"] = {"action": "pop_tip",
                                      "params": {
                                          "text": cardText,
                                          "duration": 2
                                      }
                                      }
                return result
            else:
                cardText = "再接再厉,下次就会赢哦";
                result["todoTask"] = {"action": "pop_tip",
                                      "params": {
                                          "text": cardText,
                                          "duration": 2
                                      }
                                      }
                ftlog.debug("_doFlipcard key over:", key)
                return result

        '''
Exemple #13
0
    def _doFlipcard(self, userId, gameId, clientId, activityId, coin):
        result = {}
        key = "TYActivity:%d:%d:%s:%s" % (gameId, userId, clientId, activityId)
        ftlog.debug("_doFlipcard key:", key)
        conf = {
            "design": {
                "1": {
                    "name": "豹子A",
                    "payrate": 20,
                    "probability": 0.0001
                },
                "2": {
                    "name": "豹子",
                    "payrate": 20,
                    "probability": 0.0012
                },
                "3": {
                    "name": "同花顺",
                    "payrate": 15,
                    "probability": 0.001
                },
                "4": {
                    "name": "同花",
                    "payrate": 3,
                    "probability": 0.01
                },
                "5": {
                    "name": "顺子",
                    "payrate": 3,
                    "probability": 0.01
                },
                "6": {
                    "name": "对子",
                    "payrate": 1.5,
                    "probability": 0.1
                },
                "7": {
                    "name": "K以上单张",
                    "payrate": 1.2,
                    "probability": 0.3
                },
                "8": {
                    "name": "单张",
                    "payrate": 0,
                    "probability": 0.5777
                }
            }
        }

        # 判断用户金币是否足够
        chipNow = userchip.getChip(userId)
        if coin == 1000 and chipNow < 5000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 20,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(
                gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 5000 and chipNow < 50000:

            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 80,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(
                gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 10000 and chipNow < 50000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 80,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(
                gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        elif coin == 50000 and chipNow < 300000:
            payOrder = {
                "shelves": ["coin"],
                "buyTypes": ["direct"],
                "priceDiamond": {
                    "count": 300,
                    "minCount": 0,
                    "maxCount": -1
                }
            }
            product, _ = hallstore.findProductByPayOrder(
                gameId, userId, clientId, payOrder)
            payOrder = TodoTaskPayOrder(product)
            result["tip"] = payOrder.toDict()
            return result
        else:
            result = doFlipCard(conf)
            ftlog.debug("_doFlipcard result..cardtype:", result["cardtype"])
            # 减金币操作
            coinDel = 0 - coin
            userchip.incrChip(userId, gameId, coinDel,
                              daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO,
                              'HALL_FLIPCARD', 0, clientId)
            datachangenotify.sendDataChangeNotify(gameId, userId, 'chip')
            ftlog.info("用户名,用户减少了金币,", userId, coinDel)
            if result["cardtype"] != '8':
                design = conf.get('design', {})
                cardTypeNumber = design[result["cardtype"]].get('payrate', 0)

                # 加金币操作
                coinAdd = int(coin * cardTypeNumber)
                cardText = "恭喜你赢得了%d" % coinAdd + "金币"
                ftlog.debug("_doFlipcard get money:", cardText)
                userchip.incrChip(userId, gameId, coinAdd,
                                  daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO,
                                  'HALL_FLIPCARD', 0, clientId)
                datachangenotify.sendDataChangeNotify(gameId, userId, 'chip')
                ftlog.info("用户名,用户增加了金币,", userId, coinAdd)
                result["todoTask"] = {
                    "action": "pop_tip",
                    "params": {
                        "text": cardText,
                        "duration": 2
                    }
                }
                return result
            else:
                cardText = "再接再厉,下次就会赢哦"
                result["todoTask"] = {
                    "action": "pop_tip",
                    "params": {
                        "text": cardText,
                        "duration": 2
                    }
                }
                ftlog.debug("_doFlipcard key over:", key)
                return result
        '''