def sendGrandPrixInfo(self):
     """
     发送大奖赛信息 大奖赛相关信息(进入渔场后服务器主动推送)
     """
     if not grand_prix.isGrandPrixOpenTime():  # 是否为大奖赛开放时段 00:00 —— 23:00
         self._resetGrandPrixData()
         self._freeTimes = 0  # 免费次数
         weakdata.setDayFishData(self.userId,
                                 WeakData.grandPrix_getPointsInfo,
                                 json.dumps([]))
         weakdata.setDayFishData(self.userId, WeakData.grandPrix_freeTimes,
                                 self._freeTimes)
     if ftlog.is_debug():
         ftlog.debug("sendGrandPrixInfo", self.grandPrixStartTS,
                     self.isGrandPrixMode())
     signUpState = 1 if self.isGrandPrixMode() else 0  # 是否已经报名
     remainFreeTimes = config.getVipConf(self.vipLevel).get(
         "grandPrixFreeTimes", 0) - self._freeTimes  # 剩余免费次数
     openTime = "-".join(config.getGrandPrixConf("openTimeRange"))  # 时间范围
     mo = MsgPack()
     mo.setCmd("grand_prix_info")
     mo.setResult("gameId", FISH_GAMEID)
     mo.setResult("userId", self.userId)
     mo.setResult("seatId", self.seatId)
     mo.setResult("remainFreeTimes", remainFreeTimes)
     mo.setResult("fee", config.getGrandPrixConf("fee"))  # 报名费
     mo.setResult("openTime", openTime)  # 00:00 - 23:00
     mo.setResult(
         "isInOpenTime",
         1 if grand_prix.isGrandPrixOpenTime() else 0)  # 大奖在是否在开放时间段
     mo.setResult("signUpState", signUpState)  # 是否已报名大奖赛
     mo.setResult(
         "todayRankType",
         RankType.TodayGrandPrix)  # 今日榜Type,使用fish_ranking获取排行榜数据,下同
     mo.setResult("todayDate", util.timestampToStr(int(time.time()),
                                                   "%m/%d"))  # 今日榜时间
     mo.setResult("yesterdayRankType", RankType.LastGrandPrix)
     mo.setResult("yesterdayDate",
                  util.timestampToStr(int(time.time() - 86400), "%m/%d"))
     mo.setResult(
         "des",
         config.getMultiLangTextConf(
             config.getGrandPrixConf("info").get("des"),
             lang=self.lang))  # 每日积分超过2400送100珍珠,今日榜单每10分钟刷新1次,最终排名00:00公布
     mo.setResult("pointsInfo", grand_prix.getPointInfo(
         self.userId))  # 奖励积分 道具Id、道具数量、是否领取了奖励0|1
     mo.setResult("todayMaxPoints",
                  weakdata.getDayFishData(self.userId,
                                          WeakData.grandPrix_point,
                                          0))  # 今日最高积分
     GameMsg.sendMsg(mo, self.userId)
     if ftlog.is_debug():
         ftlog.debug("FishGrandPrixPlayer, userId =", self.userId, "mo =",
                     mo)
Beispiel #2
0
def sendGrandPrixInfo(userId):
    """
    发送大奖赛信息
    """
    if not isGrandPrixOpenTime():
        grandPrixStartTS = 0
        grandPrixFireCount = 0
        grandPrixTargetFish = {}
        grandPrixUseSkillTimes = []
        grandPrixFishPoint = 0
        # grandPrixLevelFpMultiple = []
        getPointsInfo = []
        todayMaxPoints = 0
        freeTimes = 0
        saveGrandPrixData(userId, grandPrixStartTS, grandPrixFireCount,
                          grandPrixFishPoint, grandPrixUseSkillTimes,
                          grandPrixTargetFish, getPointsInfo, todayMaxPoints,
                          freeTimes)

    vipLevel = util.getVipRealLevel(userId)
    # 大奖赛剩余免费次数
    remainFreeTimes = config.getVipConf(vipLevel).get(
        "grandPrixFreeTimes", 0) - weakdata.getDayFishData(
            userId, WeakData.grandPrix_freeTimes, 0)
    mo = MsgPack()
    mo.setCmd("grand_prix_info")
    mo.setResult("gameId", FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("remainFreeTimes", remainFreeTimes)
    mo.setResult("fee", config.getGrandPrixConf("fee"))
    mo.setResult("openTime",
                 "-".join(config.getGrandPrixConf("openTimeRange")))
    mo.setResult("isInOpenTime", 1 if isGrandPrixOpenTime() else 0)
    mo.setResult(
        "signUpState",
        1 if weakdata.getDayFishData(userId, WeakData.grandPrix_startTS, 0) > 0
        else 0)
    mo.setResult("todayRankType", RankType.TodayGrandPrix)
    mo.setResult("todayDate", util.timestampToStr(int(time.time()), "%m/%d"))
    mo.setResult("yesterdayRankType", RankType.LastGrandPrix)
    mo.setResult("yesterdayDate",
                 util.timestampToStr(int(time.time() - 86400), "%m/%d"))
    mo.setResult("pointsInfo",
                 getPointInfo(userId))  # 奖励积分 道具Id、道具数量、是否领取了奖励0|1
    mo.setResult("todayMaxPoints",
                 weakdata.getDayFishData(userId, WeakData.grandPrix_point,
                                         0))  # 今日最高积分
    router.sendToUser(mo, userId)
Beispiel #3
0
 def getTimeDescStr(self, timeStr):
     """
     获取活动时间描述文本
     """
     intTime = util.getTimestampFromStr(timeStr)
     return util.timestampToStr(
         intTime,
         config.getMultiLangTextConf("ID_FORMAT_DATE", lang=self.lang))
Beispiel #4
0
def buyPiggyBank(userId, clientId, productId, buyType=None, itemId=0):
    """
    购买存钱罐
    """
    code = 3
    rewards = []
    product = config.getPiggyBankProduct(clientId, productId)
    if product is None:
        mo = MsgPack()
        mo.setCmd("piggyBankBuy")
        mo.setResult("gameId", config.FISH_GAMEID)
        mo.setResult("userId", userId)
        mo.setResult("productId", productId)
        mo.setResult("code", code)
        router.sendToUser(mo, userId)
        ftlog.warn("piggy_bank, userId =", userId, "productId =", productId,
                   "buyType =", buyType, "code =", code)
        return
    # if buyType:
    #     if buyType not in product.get("otherBuyType", {}):
    #         return
    # else:
    #     buyType = product.get("buyType")
    type = product.get("type")
    key = UserData.piggyBankData % (FISH_GAMEID, userId)
    piggyBankData = daobase.executeUserCmd(userId, "HGET", key, type)
    dailyMaxTimes = product.get("dailyTimes", 0)
    if piggyBankData:
        piggyBankData = json.loads(piggyBankData)
    else:
        piggyBankData = {}
    ts = int(time.time()) / 60 * 60
    if piggyBankData.get(GameData.pb_enable,
                         0) == 0 and weakdata.getDayFishData(
                             userId, "pb_buyTimes", 0) < dailyMaxTimes:
        isSucc = False
        if buyType in product.get("otherBuyType", {}):
            price = product["otherBuyType"].get(buyType, 0)
            if buyType == config.BT_VOUCHER and price > 0:
                _consume = [{
                    "name": config.VOUCHER_KINDID,
                    "count": abs(price)
                }]
                _ret = util.consumeItems(
                    userId,
                    _consume,
                    "BI_NFISH_BUY_ITEM_CONSUME",
                    pokerconf.productIdToNumber(productId),
                    param01=productId)
                vip_system.addUserVipExp(
                    config.FISH_GAMEID,
                    userId,
                    abs(price) * 10,
                    "BUY_PRODUCT",
                    pokerconf.productIdToNumber(productId),
                    productId,
                    rmbs=abs(price))
                if _ret:
                    isSucc = True
                else:
                    code = 2
            else:
                isSucc = True
        elif buyType == config.BT_DIRECT or config.isThirdBuyType(buyType):
            isSucc = True
        elif buyType == config.BT_DIAMOND:
            price = product.get("price_diamond", 0)
            price, _ret = store.getUseRebateItemPrice(userId, itemId, price,
                                                      buyType, productId,
                                                      clientId)  # 满减券之后的钻石 满减券
            if price > 0:
                consumeCount = 0
                if _ret:
                    store.autoConvertVoucherToDiamond(userId, price)  # 代购券
                    consumeCount, final = userchip.incrDiamond(
                        userId,
                        FISH_GAMEID,
                        -abs(price),
                        0,
                        "BI_NFISH_BUY_ITEM_CONSUME",
                        int(config.DIAMOND_KINDID),
                        util.getClientId(userId),
                        param01=productId)
                if not _ret or abs(consumeCount) != price:
                    code = 2
                else:
                    isSucc = True
        if isSucc:
            piggyBankData[GameData.pb_enable] = 1
            # piggyBankData[GameData.pb_saveMoneyTS] = ts
            piggyBankData[GameData.pb_getMoneyTS] = 0
            # piggyBankData[GameData.pb_moneyCount] = conf.get("initVal", 0)
            pb_buyTimes = weakdata.incrDayFishData(userId, "pb_buyTimes", 1)
            # piggyBankData[GameData.pb_buyTimes] = piggyBankData.get(GameData.pb_buyTimes, 0) + 1
            daobase.executeUserCmd(userId, "HSET", key, type,
                                   json.dumps(piggyBankData))
            code, rewards = getMoney(userId, clientId, productId)

    mo = MsgPack()
    mo.setCmd("piggyBankBuy")
    mo.setResult("gameId", config.FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("productId", productId)
    mo.setResult("code", code)
    if code == 0:
        util.addProductBuyEvent(userId, productId, clientId)
        mo.setResult("reward", rewards)
    router.sendToUser(mo, userId)
    vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0)
    ftlog.debug("piggy_bank, userId =", userId, "vip =", vipLevel, "type =",
                type, "code =", code, "piggyBankData =", piggyBankData,
                util.timestampToStr(ts), product)

    getPiggyBankInfo(userId, clientId)
Beispiel #5
0
def getMoney(userId, clientId, productId):
    """
    取钱
    """
    key = UserData.piggyBankData % (FISH_GAMEID, userId)
    vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0)
    conf = config.getPiggyBankProduct(clientId, productId)
    type = conf.get("type")
    iscooling = conf.get("iscooling", 0)
    ts = int(time.time()) / 60 * 60
    endcoolingTS = 0
    if iscooling:
        endcoolingTime = conf.get("endcoolingTime", 0)
        endcoolingTS = util.getDayStartTimestamp(ts) + endcoolingTime * 60 * 60
        if ts >= endcoolingTS:
            endcoolingTS += 86400
    piggyBankData = daobase.executeUserCmd(userId, "HGET", key, type)
    if piggyBankData:
        piggyBankData = json.loads(piggyBankData)
    else:
        piggyBankData = {}
    code = 4
    totalMoney = 0
    getMoneyCount = 0
    rewards = []
    if piggyBankData.get(
            GameData.pb_enable,
            0) == 1 and piggyBankData.get(GameData.pb_getMoneyTS, 0) <= ts:
        code = 0
        resetTime = _getResetTime(conf.get("resetTime", -1))
        _resetKey = _getDataKey(
            ts, resetTime)  # str(util.getDayStartTimestamp(ts))
        if resetTime == -1:
            totalMoney = int(piggyBankData.get(GameData.pb_moneyCount, 0))
        else:
            totalMoney = int(
                piggyBankData.get(GameData.pb_moneyCountDict,
                                  {}).get(_resetKey, 0))
        getMoneyCount = min(totalMoney, conf.get("maxCount", 0))
        if getMoneyCount > 0:
            piggyBankData[GameData.pb_savedMoneyCount].setdefault(_resetKey, 0)
            piggyBankData[GameData.pb_savedMoneyCount][_resetKey] = 0
            # piggyBankData[GameData.pb_moneyCount] -= getMoneyCount
            if type == "free":
                piggyBankData[
                    GameData.
                    pb_getMoneyTS] = ts + FREE_PIGGY_BANK_COOLDOWN_INTERVAL
            else:
                if iscooling:
                    piggyBankData[GameData.pb_endcoolingTS] = endcoolingTS
                    piggyBankData[GameData.pb_getMoneyTS] = piggyBankData[
                        GameData.pb_endcoolingTS]
                else:
                    piggyBankData[GameData.pb_getMoneyTS] = 0
                piggyBankData[GameData.pb_enable] = 0
                piggyBankData[GameData.pb_saveMoneyTS] = ts
            conf = config.getPiggyBankConf(clientId, vipLevel).get(type, {})
            if resetTime == -1:
                piggyBankData[GameData.pb_moneyCount] = conf.get("initVal", 0)
            else:
                piggyBankData.setdefault(GameData.pb_moneyCountDict, {})
                piggyBankData[
                    GameData.pb_moneyCountDict][_resetKey] = conf.get(
                        "initVal", 0)
                piggyBankData[GameData.pb_moneyCount] = piggyBankData[
                    GameData.pb_moneyCountDict][_resetKey]

            daobase.executeUserCmd(userId, "HSET", key, type,
                                   json.dumps(piggyBankData))
            rewards = [{"name": config.CHIP_KINDID, "count": getMoneyCount}]
            util.addRewards(userId, rewards, "BI_NFISH_GET_PIGGY_BANK",
                            vipLevel)
    ftlog.debug("piggy_bank, userId =", userId, "type =", type, "totalMoney =",
                totalMoney, "getMoneyCount =", getMoneyCount, "code =", code,
                "piggyBankData =", piggyBankData, util.timestampToStr(ts))
    return code, rewards
Beispiel #6
0
def saveMoneyToPiggyBank(userId, clientId):
    """
    向存钱罐存钱
    """
    vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0)
    conf = config.getPiggyBankConf(clientId, vipLevel)
    key = UserData.piggyBankData % (FISH_GAMEID, userId)
    ts = int(time.time()) / 60 * 60
    curDayStartTS = util.getDayStartTimestamp(ts)
    # 初始化存档.
    _initSaveLoad(userId, clientId)

    for k, v in conf.iteritems():
        piggyBankData = daobase.executeUserCmd(userId, "HGET", key, k)
        if piggyBankData:
            piggyBankData = json.loads(piggyBankData)
        else:
            piggyBankData = {}
        # ftlog.debug("piggy_bank, userId =", userId, piggyBankData)
        lastTS = piggyBankData.get(GameData.pb_saveMoneyTS, 0)
        if lastTS == 0:
            continue
        endcoolingTs = piggyBankData.get(GameData.pb_endcoolingTS, 0)
        unitCount = v.get("outroom", 0)
        resetTime = _getResetTime(v.get("resetTime", -1))
        # 处理跨天逻辑.
        while lastTS < curDayStartTS:
            if resetTime != -1:
                resetTS = util.getDayStartTimestamp(lastTS) + resetTime * 3600
                if lastTS < endcoolingTs < resetTS:
                    lastTS = endcoolingTs
                elif resetTS < endcoolingTs:
                    lastTS = resetTS
                if lastTS < resetTS:
                    interval = (resetTS - lastTS) / 60
                    addCount = interval * unitCount
                    if interval > 0:
                        ftlog.debug("piggy_bank, userId =", userId, "type =",
                                    k, "interval =", interval, "vip =",
                                    vipLevel, "addCount =", addCount,
                                    piggyBankData, util.timestampToStr(lastTS),
                                    util.timestampToStr(resetTS))
                        addMoneyToPiggyBank(userId, clientId, k, addCount,
                                            resetTS - 1)
                    lastTS = resetTS
            nextStartDayTS = util.getDayStartTimestamp(lastTS) + 86400
            if lastTS < endcoolingTs < nextStartDayTS:
                lastTS = endcoolingTs
            elif nextStartDayTS < endcoolingTs:
                lastTS = nextStartDayTS
            interval = (nextStartDayTS - lastTS) / 60
            addCount = interval * unitCount
            if interval > 0:
                ftlog.debug("piggy_bank, userId =", userId, "type =", k,
                            "interval =", interval, "vip =", vipLevel,
                            "addCount =", addCount, piggyBankData,
                            util.timestampToStr(lastTS),
                            util.timestampToStr(nextStartDayTS))
                addMoneyToPiggyBank(userId, clientId, k, addCount,
                                    nextStartDayTS - 1)
            lastTS = nextStartDayTS
        if resetTime != -1:
            resetTS = util.getDayStartTimestamp(lastTS) + resetTime * 3600
            if lastTS < resetTS < ts:
                if lastTS < endcoolingTs < resetTS:
                    lastTS = endcoolingTs
                elif resetTS < endcoolingTs:
                    lastTS = resetTS
                interval = (resetTS - lastTS) / 60
                addCount = interval * unitCount
                if interval > 0:
                    ftlog.debug("piggy_bank, userId =", userId, "type =", k,
                                "interval =", interval, "vip =", vipLevel,
                                "addCount =", addCount, piggyBankData,
                                util.timestampToStr(lastTS),
                                util.timestampToStr(resetTS))
                    addMoneyToPiggyBank(userId, clientId, k, addCount,
                                        resetTS - 1)
                lastTS = resetTS
        if lastTS < endcoolingTs < ts:
            lastTS = endcoolingTs
        elif ts < endcoolingTs:
            lastTS = ts
        interval = (ts - lastTS) / 60
        addCount = interval * unitCount
        if interval > 0:
            ftlog.debug("piggy_bank, userId =", userId, "type =", k,
                        "interval =", interval, "vip =", vipLevel,
                        "addCount =", addCount, piggyBankData,
                        util.timestampToStr(lastTS), util.timestampToStr(ts))
            addMoneyToPiggyBank(userId, clientId, k, addCount, ts)

    # 清理过期的每日积累上线key
    for k, v in conf.iteritems():
        piggyBankData = daobase.executeUserCmd(userId, "HGET", key, k)
        if piggyBankData:
            piggyBankData = json.loads(piggyBankData)
        else:
            piggyBankData = {}
        isChanged = False
        resetTime = _getResetTime(v.get("resetTime", -1))
        _resetTS = int(_getDataKey(int(time.time()), resetTime))
        ts_keys = piggyBankData[GameData.pb_savedMoneyCount].keys()
        for ts in ts_keys:
            if int(ts) < _resetTS:
                ftlog.debug(
                    "piggy_bank, delete pb_savedMoneyCount expired ts key, userId =",
                    userId, "type =", k, "ts =", util.timestampToStr(int(ts)),
                    "val =", piggyBankData[GameData.pb_savedMoneyCount][ts])
                del piggyBankData[GameData.pb_savedMoneyCount][ts]
                isChanged = True
        if resetTime != -1:
            ts_keys = piggyBankData.get(GameData.pb_moneyCountDict, {}).keys()
            for ts in ts_keys:
                if int(ts) < _resetTS:
                    ftlog.debug(
                        "piggy_bank, delete pb_moneyCountDict expired ts key, userId =",
                        userId, "type =", k, "ts =",
                        util.timestampToStr(int(ts)), "val =",
                        piggyBankData[GameData.pb_moneyCountDict][ts])
                    del piggyBankData[GameData.pb_moneyCountDict][ts]
                    isChanged = True
        if isChanged:
            # ftlog.debug("piggy_bank, piggyBankData changed, userId =", userId, piggyBankData)
            daobase.executeUserCmd(userId, "HSET", key, k,
                                   json.dumps(piggyBankData))