Beispiel #1
0
def isGrandPrixOpenTime():
    """
    是否为大奖赛开放时段 00:00 -- 23:00
    """
    curTime = int(time.time())
    dayStartTS = util.getDayStartTimestamp(curTime)
    openTimeRange = config.getGrandPrixConf("openTimeRange")
    return util.timeStrToInt(
        openTimeRange[0]) < (curTime - dayStartTS) < util.timeStrToInt(
            openTimeRange[1])
 def setTipTimer(self):
     """
     设置比赛开始和结束的通知消息
     """
     if self.grandPrixTipTimer:
         self.grandPrixTipTimer.cancel()
         self.grandPrixTipTimer = None
         self.sendGrandPrixInfo()  # 发送大奖赛信息
     curTime = int(time.time())
     dayStartTS = util.getDayStartTimestamp(curTime)
     openTimeRange = config.getGrandPrixConf("openTimeRange")
     pastTime = curTime - dayStartTS  # 03:00|23:10
     beginTime = util.timeStrToInt(openTimeRange[0])  # 00:00
     endTime = util.timeStrToInt(openTimeRange[1])  # 23:00
     if pastTime < beginTime:
         interval = beginTime - pastTime + 5  # 开始的通知
     elif beginTime <= pastTime <= endTime:
         interval = endTime - pastTime + 5  # 结束的通知
     else:
         interval = 86400 + beginTime - pastTime + 5  # 开始的通知
     self.grandPrixTipTimer = FTLoopTimer(interval, 0,
                                          self.setTipTimer)  # 死循环
     self.grandPrixTipTimer.start()
Beispiel #3
0
 def grandPrixEnterRoom(cls, userId):
     """
     大奖赛房间能否进入
     """
     startDay = config.getGrandPrixConf("info").get("startDay")
     currentTime = int(time.time())
     if startDay and currentTime < util.getTimestampFromStr(startDay):
         return cls.ENTER_ROOM_REASON_NOT_OPEN
     if weakdata.getDayFishData(userId, WeakData.grandPrix_startTS, 0) == 0:
         dayStartTimestamp = util.getDayStartTimestamp(currentTime)
         remainGrandPrixTimeSeconds = util.timeStrToInt(
             config.getGrandPrixConf("openTimeRange")[1]) - (
                 currentTime - dayStartTimestamp)  # 大奖赛剩余时间
         if not grand_prix.isGrandPrixOpenTime(
         ) or remainGrandPrixTimeSeconds < 10:
             return cls.ENTER_ROOM_REASON_GRAND_PRIX_NOE_OPEN
         vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level
         if config.getVipConf(vipLevel).get("grandPrixFreeTimes", 0) <= \
                 weakdata.getDayFishData(userId, WeakData.grandPrix_freeTimes, 0):  # 用免费次数已经用完
             fee = config.getGrandPrixConf("fee")[0]
             surplusCount = util.balanceItem(userId, fee["name"])
             if surplusCount < fee["count"]:
                 return cls.ENTER_ROOM_REASON_GRAND_PRIX_LESS_FEES
     return cls.ENTER_ROOM_REASON_OK
    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)
def addRobotToGrandPrix():
    """
    机器人进入大奖赛排行榜 "robot": [1, 30, [2, 2]]
    """
    global _addRobotToGrandPrixRankTimestamp
    curTime = int(time.time())
    startDay = config.getGrandPrixConf("info").get("startDay")
    if startDay and curTime < util.getTimestampFromStr(startDay):
        return
    if curTime < _addRobotToGrandPrixRankTimestamp:
        return
    robotConf = config.getGrandPrixConf("info").get("robot", [])
    if len(robotConf) < 3 or len(robotConf[2]) < 2:
        _addRobotToGrandPrixRankTimestamp = curTime + 10 * 60  # 10分钟
        return
    # 不启用机器人
    if robotConf[0] == 0:
        _addRobotToGrandPrixRankTimestamp = curTime + 10 * 60
        return
    startInterval = robotConf[1] * 60
    dayStartTS = util.getDayStartTimestamp(curTime)
    openTimeRange = config.getGrandPrixConf("openTimeRange")
    if util.timeStrToInt(openTimeRange[0]) + startInterval >= (
            curTime - dayStartTS) or (
                curTime - dayStartTS) >= util.timeStrToInt(openTimeRange[1]):
        _addRobotToGrandPrixRankTimestamp = curTime
        return
    nextAddInterval = random.randint(robotConf[2][0] * 60,
                                     robotConf[2][1] * 60)
    _addRobotToGrandPrixRankTimestamp = curTime + nextAddInterval

    rdKey = redis_keys.MixData.grandPrixRobotData % config.FISH_GAMEID
    robotDatas = config.getGrandPrixConf("robotData")
    maxCount = sum([val["count"] for val in robotDatas
                    ])  # {"count": 1, "points": [58001, 60000]},
    dayStartTS = util.getDayStartTimestamp(int(time.time()))
    robotDatas = daobase.executeMixCmd("HGET", rdKey, str(dayStartTS))
    if robotDatas:
        robotDatas = json.loads(robotDatas)
    else:
        robotDatas = {}
    robotDatas.setdefault("uids", [])
    robotDatas.setdefault("ranks", [])
    uidList = robotDatas.get("uids")
    rankList = robotDatas.get("ranks")
    if len(uidList) >= maxCount:
        _addRobotToGrandPrixRankTimestamp = curTime + 10 * 60
        return

    datas = daobase.executeMixCmd("HGETALL", rdKey)
    if datas:
        for ts in datas[0::2]:
            if int(ts) < dayStartTS:
                daobase.executeMixCmd("HDEL", rdKey, ts)

    startRobotUid = 0
    ruid = random.randint(startRobotUid + 1, startRobotUid + maxCount)
    while ruid in uidList:
        ruid = random.randint(startRobotUid + 1, startRobotUid + maxCount)
    rrank = random.randint(1, maxCount)
    while rrank in rankList:
        rrank = random.randint(1, maxCount)
    uidList.append(ruid)
    rankList.append(rrank)
    daobase.executeMixCmd("HSET", rdKey, str(dayStartTS),
                          json.dumps(robotDatas))
    robotDatas = config.getGrandPrixConf("robotData")
    for val in robotDatas:
        if rrank > val["count"]:
            rrank -= val["count"]
        else:
            fishPoint = random.randint(val["points"][0], val["points"][1])
            if userdata.checkUserData(ruid):
                refreshGrandPrixPoint(ruid, fishPoint)
            # else:
            #     ftlog.error("addRobotToGrandPrix, error", "uid =", ruid)
            # if ftlog.is_debug():
            #     ftlog.debug("addRobotToGrandPrix", "uid =", ruid, "rank =", rrank, "point =", fishPoint, maxCount)
            break