Ejemplo n.º 1
0
def vipAutoSupplyPerDay(userId):
    """
    vip每日自动补足
    """
    vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0)
    key = GameData.autoSupplyKey % config.CHIP_KINDID
    autoSupplyCount = config.getVipConf(vipLevel).get(key, 0)
    chips = userchip.getUserChipAll(userId)
    if autoSupplyCount >= 10000 and chips < autoSupplyCount and weakdata.getDayFishData(
            userId, key, 0) == 0:
        weakdata.incrDayFishData(userId, key, 1)
        lang = util.getLanguage(userId)
        rewards = [{
            "name": config.CHIP_KINDID,
            "count": (autoSupplyCount - chips)
        }]
        message = config.getMultiLangTextConf(
            "ID_VIP_AUTO_SUPPLY_PER_DAY",
            lang=lang) % (autoSupplyCount / 10000)
        mail_system.sendSystemMail(userId,
                                   mail_system.MailRewardType.SystemReward,
                                   rewards, message)
    if ftlog.is_debug():
        ftlog.debug("vipAutoSupplyPerDay", userId, vipLevel, autoSupplyCount,
                    chips, key, autoSupplyCount - chips)
def accelerateReward(userId):
    """
    前端通知后端看广告加速
    """
    luckyTreeConf = config.getLuckyTreeConf()
    maxAcceleratetimes = luckyTreeConf.get("maxAcceleratetimes")
    accelerateTimes = weakdata.getDayFishData(userId, "accelerateTimes", 0)
    curTime = int(time.time())
    luckyTreeConf = config.getLuckyTreeConf()
    luckyTreeData = getLuckyTreeData(userId)
    rewardTs = luckyTreeData.get("rewardTs")  # 当前的可领奖时间
    if accelerateTimes < maxAcceleratetimes:
        code = 0
    else:
        code = 1
        return luckyTreeData["rewardTs"], code
    # 看一次广告加速的时间,单位 /h
    accelerateTsConf = luckyTreeConf.get("accelerateTime", 1)
    accelerateTs = accelerateTsConf * 60 * 60
    if curTime + accelerateTs < rewardTs:
        rewardTs = rewardTs - accelerateTs
    else:
        rewardTs = curTime
    luckyTreeData["rewardTs"] = rewardTs
    weakdata.incrDayFishData(userId, "accelerateTimes", 1)
    saveLuckyTreeData(userId, luckyTreeData)
    return luckyTreeData["rewardTs"], code
Ejemplo n.º 3
0
def addShareInvitedUserId(shareUserId, invitedUserId, isNewUser=False):
    """
    添加分享邀请人信息
    :param shareUserId: 分享卡片的分享者
    :param invitedUserId: 点击卡片的被邀请者
    :param isNewUser: 是否为新用户
    """
    inviteCount = weakdata.getDayFishData(shareUserId, "inviteCount", 0)
    if inviteCount < config.getCommonValueByKey("inviteLimitCount", 99999):
        if not isNewUser:
            inviteOldUserCount = weakdata.getDayFishData(shareUserId, "inviteOldUserCount", 0)
            if inviteOldUserCount > config.getCommonValueByKey("inviteLimitOldCount", 99999):
                return
            weakdata.incrDayFishData(shareUserId, "inviteOldUserCount", 1)
        inviteList = gamedata.getGameAttrJson(shareUserId, FISH_GAMEID, GameData.inviteList, [])
        inviteId = gamedata.incrGameAttr(shareUserId, FISH_GAMEID, GameData.inviteId, 1)
        inviteData = {
            "inviteId": inviteId,
            "userId": invitedUserId,
            "inviteTime": int(time.time()),
            "isNewUser": isNewUser,
            "isAppUser": 1 if util.isAppClient(invitedUserId) else 0
        }
        inviteList.append(inviteData)
        gamedata.setGameAttr(shareUserId, FISH_GAMEID, GameData.inviteList, json.dumps(inviteList))
        weakdata.incrDayFishData(shareUserId, "inviteCount", 1)
        module_tip.addModuleTipEvent(shareUserId, "invite", inviteId)
        getShareTaskInfo(shareUserId)
        from newfish.game import TGFish
        from newfish.entity.event import InvitedFinishEvent
        event = InvitedFinishEvent(shareUserId, FISH_GAMEID)
        TGFish.getEventBus().publishEvent(event)
Ejemplo n.º 4
0
def updateInvitedState(userId, shareUserId, isNewUser=False):
    """
    更新邀请状态
    :param userId: 被邀请者
    :param shareUserId: 分享者
    :param isNewUser: 是否为新用户
    """
    isInvited = weakdata.getDayFishData(userId, "isInvited", 0)
    if not isInvited:
        user_rpc.addShareInvitedUserId(shareUserId, userId, isNewUser)
    weakdata.incrDayFishData(userId, "isInvited", 1)
Ejemplo n.º 5
0
def getReturnerMission(userId, clientId):
    """
    获取回归豪礼
    """
    timeLeft = 0
    currTime = int(time.time())
    returnerMission = getReturnerMissionData(userId)
    returnerMissionConf = config.getReturnerMissionConf()
    if returnerMission:
        # 获取回归豪礼结束倒计时
        expireDays = returnerMissionConf["expireDays"] * 24 * 3600
        endTime = returnerMission["lastActiveTime"] + expireDays
        timeLeft = max(endTime - currTime, 0)
    mo = MsgPack()
    mo.setCmd("returner_mission")
    mo.setResult("gameId", FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("timeLeft", timeLeft)
    if timeLeft > 0:
        # 是否首次登录弹出
        dayFirst = weakdata.incrDayFishData(userId, WeakData.returnerMission, 1)
        # 当前是激活后的第几个任务(按天处理)
        lastActiveTime = util.getDayStartTimestamp(returnerMission["lastActiveTime"])
        fewDays = (datetime.fromtimestamp(currTime) - datetime.fromtimestamp(lastActiveTime)).days + 1
        fewDays = max(1, min(fewDays, len(returnerMission["tasks"])))
        currentTaskId = returnerMissionConf["tasks"][fewDays - 1]["taskId"]
        lang = util.getLanguage(userId, clientId)
        # 任务数据
        tasks = buildTaskData(returnerMission, lang)
        mo.setResult("dayFirst", 1 if dayFirst == 1 else 0)
        mo.setResult("currentTaskId", currentTaskId)
        mo.setResult("rule", config.getMultiLangTextConf(returnerMissionConf["rule"], lang=lang))
        mo.setResult("tasks", tasks)
    router.sendToUser(mo, userId)
Ejemplo n.º 6
0
    def startGrandPrix(self):
        """
        大奖赛开始 grandPrixStartTS=0 报名大奖赛/ grandPrixStartTS > 0 直接进入渔场
        """
        curTime = int(time.time())
        dayStartTimestamp = util.getDayStartTimestamp(curTime)
        remainGrandPrixTimeSeconds = util.timeStrToInt(
            config.getGrandPrixConf("openTimeRange")[1]) - (
                curTime - dayStartTimestamp)  # 大奖赛剩余时间
        # 当局进入大奖赛
        if self.grandPrixStartTS == 0:
            event = JoinGrandPrixEvent(self.userId, FISH_GAMEID,
                                       self.table.bigRoomId)  # 参加大奖赛事件
            TGFish.getEventBus().publishEvent(event)
            # 距离大奖赛结束不足10秒不可参赛
            if not grand_prix.isGrandPrixOpenTime(
            ) or remainGrandPrixTimeSeconds < 10:
                code = SignupCode.SC_NOT_OPEN
            elif config.getVipConf(self.vipLevel).get(
                    "grandPrixFreeTimes", 0) > self._freeTimes:  # 用免费次数报名
                self._freeTimes = weakdata.incrDayFishData(
                    self.userId, WeakData.grandPrix_freeTimes, 1)
                code = SignupCode.SC_SUCC
            else:
                # 扣除报名费
                fee = config.getGrandPrixConf("fee")[0]
                _consume = [{
                    "name": fee.get("name"),
                    "count": fee.get("count")
                }]
                _ret = util.consumeItems(self.userId, _consume, "ITEM_USE",
                                         self.table.roomId)
                if _ret:
                    code = SignupCode.SC_SUCC
                else:
                    code = SignupCode.SC_FEE_NOT_ENOUGH
            if code == SignupCode.SC_SUCC:
                # 选择目标鱼
                for _val in config.getGrandPrixConf(
                        "group").values():  # 1、2、3个组
                    idx = random.randint(0, len(_val) - 1)  # 一组鱼
                    _cnt = config.getGrandPrixConf("target").get(
                        str(_val[idx]), {}).get("count", 999)  # 某一种鱼 捕获数量
                    _point = config.getGrandPrixConf("target").get(
                        str(_val[idx]), {}).get("point", 0)  # 某一种鱼 获得的积分
                    self.grandPrixTargetFish[str(
                        _val[idx])] = [0, _cnt, _point]

                # 备份技能数据.
                self.grandPrixUseSkillTimes = []
                for i in range(skill_system.MAX_INSTALL_NUM - 1):
                    self.grandPrixUseSkillTimes.append({
                        "skillId":
                        0,
                        "state":
                        0,
                        "star":
                        0,
                        "grade":
                        0,
                        "count":
                        config.getGrandPrixConf("fireCount")[1],  # 技能使用次数3
                        "skillType":
                        0 if i < skill_system.MAX_INSTALL_NUM else
                        1  # 0主技能 1辅助技能
                    })

                for idx, _skillId in enumerate(self.skillSlots):
                    _skill = self.getSkill(_skillId, 0)
                    self.grandPrixUseSkillTimes[idx]["skillId"] = _skillId
                    self.grandPrixUseSkillTimes[idx][
                        "state"] = _skill.skillState
                    self.grandPrixUseSkillTimes[idx]["star"] = _skill.skillStar
                    self.grandPrixUseSkillTimes[idx][
                        "grade"] = _skill.skillGrade

                if self.inGameTimes:
                    bireport.reportGameEvent("BI_NFISH_GRAND_PRIX_INGAMETIMES",
                                             self.userId, FISH_GAMEID, 0, 0,
                                             self.grandPrixStartTS,
                                             self.inGameTimes, 0, 0, [],
                                             util.getClientId(self.userId))
                    self.inGameTimes = 0

                self.grandPrixFishPoint = 0
                self.grandPrixSurpassCount = 0
                self.grandPrixStartTS = curTime  # 大奖赛开始的时间戳
                self.grandPrixFireCount = config.getGrandPrixConf(
                    "fireCount")[0]
                self._saveGrandPrixData()  # 保存大奖赛数据
        else:
            if not grand_prix.isGrandPrixOpenTime():  # 现在不可参赛
                code = SignupCode.SC_NOT_OPEN
            elif not self.isGrandPrixMode():
                code = SignupCode.SC_SUCC
            else:
                code = SignupCode.SC_UNFINISH

        if code in [SignupCode.SC_SUCC, SignupCode.SC_UNFINISH]:
            interval = max(0.1, remainGrandPrixTimeSeconds)
            if self.grandPrixFireCount == 0:  # 3秒之后结束大奖赛
                interval = 0.1
            if self.grandPrixEndTimer:
                self.grandPrixEndTimer.cancel()
                self.grandPrixEndTimer = None
            self.grandPrixEndTimer = FTLoopTimer(interval, 0,
                                                 self.endGrandPrix)  # 启动结束定时器
            self.grandPrixEndTimer.start()
            # 取消处于使用中的技能,以免干扰技能使用次数计数
            if self.offline == 0:  # 玩家在线
                self.cancelUsingSkills()
                self.unloadSkills()
                self.loadAllSkillData()
                self.syncSkillSlots()
        elif code == SignupCode.SC_NOT_OPEN:  # 没开启
            self._resetGrandPrixData()  # 重置大奖赛相关数据

        self._getSurpassTarget()  # 获取要超越的玩家数据
        mo = MsgPack()
        mo.setCmd("start_grand_prix")
        mo.setResult("gameId", FISH_GAMEID)
        mo.setResult("userId", self.userId)
        mo.setResult("seatId", self.seatId)
        mo.setResult("fireCount", self.grandPrixFireCount)
        mo.setResult("fishPoint", self.grandPrixFishPoint)
        mo.setResult("targetFish", self.grandPrixTargetFish)
        mo.setResult(
            "useSkillTimes", {
                val.get("skillId", 0): val.get("count", 0)
                for val in self.grandPrixUseSkillTimes
            })
        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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def doGetFishGiftReward(userId, clientId, giftId):
    """
    领取礼包
    """
    giftConf = getGiftConf(clientId, giftId)
    if not giftConf:
        return
    code = 1
    chestId = 0
    commonRewards = []
    chestRewards = []
    availableGift = gamedata.getGameAttrJson(userId, FISH_GAMEID,
                                             GameData.availableGift, [])
    canGetRewards = False
    if giftConf["giftType"] == GiftType.MONTHCARD:
        userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag()
        itemId = giftConf["monthCard"]["name"]
        item = userBag.getItemByKindId(itemId)
        if item and not item.isDied(int(time.time())):
            if itemId == config.MONTH_CARD_KINDID:
                canGetRewards = weakdata.getDayFishData(
                    userId, WeakData.getMonthCardGift, 0) == 0
            else:
                canGetRewards = weakdata.getDayFishData(
                    userId, WeakData.getPermanentMonthCardGift, 0) == 0
    else:
        canGetRewards = giftId in availableGift

    if not canGetRewards:
        return

    eventId = "BI_NFISH_BUY_ITEM_GAIN"
    for item in giftConf.get("items", []):
        if item["type"] == 1:  # 宝箱
            chestId = item["itemId"]
            rewards = chest_system.getChestRewards(userId, chestId)
            code = chest_system.deliveryChestRewards(userId, chestId, rewards,
                                                     eventId)
            chestRewards.extend(rewards)
        elif item["type"] == 2:  # 等级
            _makeUserLevelUp(userId, item["count"])
            code = 0
        elif item["type"] == 3:  # 资产/道具
            rewards = [{"name": item["itemId"], "count": item["count"]}]
            code = util.addRewards(userId,
                                   rewards,
                                   eventId,
                                   int(giftId),
                                   param01=int(giftId))
            commonRewards.extend(rewards)
        elif item["type"] == 5:  # 皮肤炮皮肤
            skinId = item["itemId"]
            ret = gun_system.addEquipGunSkinSkin(userId, skinId, clientId)
            if ret:
                code = 0
                rewards = [{
                    "name": item["itemId"],
                    "count": item["count"],
                    "type": item["type"]
                }]
                commonRewards.extend(rewards)
        elif item["type"] == 6:  # 直升炮台
            upToLevel = item["count"]
            success = gun_system.upgradeGun(userId,
                                            False,
                                            MULTIPLE_MODE,
                                            byGift=True,
                                            upToLevel=upToLevel)
            if success:
                code = 0

    message = MsgPack()
    if giftConf["giftType"] == GiftType.MONTHCARD:
        message.setCmd("monthGiftGet")
    else:
        message.setCmd("fishGiftReward")
    message.setResult("gameId", FISH_GAMEID)
    message.setResult("userId", userId)
    message.setResult("giftId", giftId)
    message.setResult("chestId", chestId)
    if code == 0 and (commonRewards or chestRewards):
        if giftConf["giftType"] == GiftType.MONTHCARD:
            itemId = giftConf["monthCard"]["name"]
            if itemId == config.MONTH_CARD_KINDID:
                weakdata.incrDayFishData(userId, WeakData.getMonthCardGift, 1)
            else:
                weakdata.incrDayFishData(userId,
                                         WeakData.getPermanentMonthCardGift, 1)
        else:
            availableGift.remove(giftId)
            gamedata.setGameAttr(userId, FISH_GAMEID, GameData.availableGift,
                                 json.dumps(availableGift))
        message.setResult("commonRewards", commonRewards)
        message.setResult("chestRewards", chestRewards)
    message.setResult("code", code)
    router.sendToUser(message, userId)

    productId = giftConf.get("productId", "")
    isIn, roomId, tableId, seatId = util.isInFishTable(userId)
    if isIn:
        mo = MsgPack()
        mo.setCmd("table_call")
        mo.setParam("action", "take_gift_reward")
        mo.setParam("gameId", FISH_GAMEID)
        mo.setParam("clientId", util.getClientId(userId))
        mo.setParam("userId", userId)
        mo.setParam("roomId", roomId)
        mo.setParam("tableId", tableId)
        mo.setParam("seatId", seatId)
        mo.setParam("productId", productId)
        router.sendTableServer(mo, roomId)