示例#1
0
class FishGroup(object):
    """
    鱼群对象
    """
    def __init__(self,
                 conf,
                 enterTime,
                 serverGroupId,
                 startFishId,
                 position=None,
                 gameResolution=None,
                 deadCallback=None):
        """
        :param conf: 鱼阵配置文件 {"id": "autofill_11092_21_3", "fishes": [{"fishType": 11092, "enterTime": 0.0, "exitTime": 25.0}], "totalTime": 25.0}
        :param enterTime: 该鱼群入场时间(渔场运行后的第n秒)
        :param serverGroupId: 鱼群ID(每新增一个鱼群自增加1)
        :param startFishId: 该鱼群第一条鱼的鱼ID
        :param position: 指定出现位置
        :param gameResolution: 召唤该鱼群的玩家的游戏分辨率
        :param deadCallback: 鱼群死亡回调函数
        """
        self.position = position if position else [0, 0]
        self.gameResolution = gameResolution if gameResolution else []
        self.enterTime = enterTime
        self.startFishId = startFishId
        # 鱼群文件名字
        self.id = conf.get("id")
        # 鱼群自增ID
        self.serverGroupId = serverGroupId
        # 鱼群类型
        self.type = self.id.split("_")[1] if self.id.startswith(
            "call_") else self.id.split("_")[0]
        # 鱼群存活时间
        self.totalTime = conf.get("totalTime")
        # 鱼群中的所有鱼
        self.fishes = conf.get("fishes")
        # 鱼群中鱼的数量
        self.fishCount = len(self.fishes)
        # 该鱼群的出场时间
        self.exitTime = self.enterTime + self.totalTime
        # 该鱼群最后一条鱼的鱼ID
        self.endFishId = startFishId + self.fishCount - 1
        self.maxEnterTime = self._getMaxEnterTime()
        # 该鱼群是否已被清除
        self.isClear = False
        # 鱼群被冰冻后延长的存活时间
        self.addTime = 0
        # Boss鱼群延迟出现时间
        self.extendGroupTime = 0
        # 鱼群死亡定时器
        self.deadTimer = None
        # 鱼群死亡回调
        self.deadCallback = deadCallback
        if self.deadCallback:
            self.deadTimer = FTLoopTimer(self.totalTime, 0, self.deadCallback,
                                         self)
            self.deadTimer.start()

    def clear(self):
        """
        清除定时器等数据
        """
        if self.deadTimer:
            self.deadTimer.cancel()
            self.deadTimer = None
        self.isClear = True

    def isExist(self, nowTableTime):
        """
        该鱼群在当前时刻是否存在
        """
        return self.enterTime <= nowTableTime <= self.exitTime + self.addTime

    def fishExist(self, nowTableTime, fishId):
        """
        该鱼群中是否存在某条鱼
        """
        fish = self.fishes[fishId - self.startFishId]
        enterTime = self.enterTime + fish["enterTime"]
        exitTime = self.enterTime + fish["exitTime"] + self.addTime
        return enterTime <= nowTableTime <= exitTime

    def isAlive(self, nowTableTime, table=None):
        """
        该鱼群是否存活(包含特殊鱼及已生成但即将出现的鱼群)
        """
        # 客户端特殊处理的鱼群且鱼群中鱼的数量不多时,判断鱼群是否存活看其中鱼的存活状态
        if table and self.type in SPECIAL_ALIVE_TYPE:
            for fId in xrange(self.startFishId, self.endFishId + 1):
                isOK = table.findFish(fId)
                if isOK:
                    return isOK
            return False
        # 一般鱼群,判断鱼群是否存活看鱼群的整体退出时间,因为其中鱼的数量过多,避免循环查找
        return nowTableTime < self.exitTime + self.addTime

    def isVisible(self, table, userId):
        """
        该鱼群对某玩家是否可见
        """
        # 新手任务期间玩家自己可见的鱼.
        if self.type == "share" or self.type == "newbie" or self.type == "coupon" \
                or self.id.startswith("tuition_44499") or self.id.startswith("autofill_72025"):
            for fId in xrange(self.startFishId, self.endFishId + 1):
                if fId in table.fishMap:
                    if table.fishMap[fId]["owner"] is None or table.fishMap[
                            fId]["owner"] == userId:
                        sendUsersList = table.fishMap[fId].get("sendUsersList")
                        if not sendUsersList or userId in sendUsersList:
                            return True
                        break
            return False
        return True

    def isCleared(self):
        """
        该鱼群是否已被清除
        """
        return self.isClear

    def _getMaxEnterTime(self):
        """
        获得该鱼群最后一条鱼在该鱼阵文件中的入场时间
        """
        fishEnterTimes = []
        for fish in self.fishes:
            fishEnterTimes.append(fish.get("enterTime"))
        fishEnterTimes.sort()
        return fishEnterTimes[-1]

    def getNextGroupTime(self):
        """
        获得下个鱼群的入场时间
        """
        return round(self.maxEnterTime + self.enterTime, 2)

    def desc(self):
        """
        鱼群详情
        """
        info = [
            str(self.id), "enter:",
            str(self.enterTime), "exit:",
            str(self.exitTime), "startfishId:",
            str(self.startFishId), "endFishId:",
            str(self.endFishId), "addTime:",
            str(self.addTime)
        ]
        info = " ".join(info)
        return info

    def adjust(self, addTime):
        """
        调整鱼群存活时间
        """
        self.addTime += addTime
        self.extendGroupTime += addTime
        if self.deadTimer:
            interval = self.deadTimer.getTimeOut() + self.addTime
            if interval > 0:
                self.deadTimer.reset(interval)

    def getFishExitTime(self, fishType):
        """
        获取指定一条鱼的离场时间
        """
        for fish in self.fishes:
            if fishType == fish["fishType"]:
                return fish["exitTime"]
        return 0
class SwimStage(object):
    """
    冰龙游动阶段
    """
    # 冰龙鱼群
    DRAGON_FISH_TYPE = 75216

    def __init__(self, dragon):
        self.dragon = dragon
        self.table = self.dragon.table
        self.totalRound = 0
        self.currentRound = 0
        self.fishId = 0
        self.catchUserId = 0
        self.timer = None
        self.callDragonFishGroup(self.DRAGON_FISH_TYPE)

    def clearTimer(self):
        if self.timer:
            self.timer.cancel()
            self.timer = None

    def callDragonFishGroup(self, fishType):
        """
        召唤冰龙鱼群
        """
        self.clearTimer()
        groupIds = self.table.runConfig.allSuperBossGroupIds[fishType]
        groupIds = random.choice(groupIds)
        group = self.table.insertFishGroup(groupIds)
        self.fishId = group.startFishId
        self.timer = FTLoopTimer(group.totalTime, 0, self.callDragonFishGroup,
                                 self.DRAGON_FISH_TYPE)
        self.timer.start()
        return group

    def catchDragon(self, userId, stageCount):
        """
        捕获冰龙
        """
        self.catchUserId = userId
        self.totalRound = stageCount
        self.clearTimer()
        # 捕获后延迟出现冰结晶
        self.timer = FTLoopTimer(self.dragon.dragonConf["crystal.appear.time"],
                                 0, self.switchStormRound)
        self.timer.start()

    def switchStormRound(self):
        """
        切换冰冻风暴回合
        """
        self.currentRound += 1
        if self.currentRound <= self.totalRound:
            self.clearTimer()
            self.sendDragonStormMsg()
            # 每回合风暴时间
            self.timer = FTLoopTimer(
                self.dragon.dragonConf["crystal.storm.time"], 0,
                self.switchStormRound)
            self.timer.start()
        else:
            self.timer = FTLoopTimer(
                self.dragon.dragonConf["crystal.leave.time"],
                0,
                self.dragon._doLeave,
                isNow=True)
            self.timer.start()

    def sendDragonStormMsg(self):
        """
        发送冰冻风暴消息
        """
        msg = MsgPack()
        msg.setCmd("dragon_storm")
        msg.setResult("gameId", FISH_GAMEID)
        msg.setResult("roomId", self.table.roomId)
        msg.setResult("tableId", self.table.tableId)
        msg.setResult("rounds", [self.currentRound, self.totalRound])
        msg.setResult("bulletId", self.fishId)
        msg.setResult("catchUserId", self.catchUserId)
        GameMsg.sendMsg(msg, self.table.getBroadcastUids())

    def frozenDragon(self, frozenTime):
        """
        冰龙被冻住
        """
        if not self.catchUserId:
            interval = self.timer.getTimeOut() + frozenTime
            if interval > 0:
                self.timer.reset(interval)
示例#3
0
    ftlog.info('zzzzzz', gdata.allServersMap())


import freetime.util.log as ftlog
from freetime.core.timer import FTLoopTimer
from poker.entity.configure import gdata


def _main1():
    ftlog.info('ssssss')


a = FTLoopTimer(20, -1, _main1)
a.start()
ftlog.info('cccccc', a.getTimeOut())
a.reset(30)
ftlog.info('dddddd', a.getTimeOut())

import freetime.util.log as ftlog
from poker.entity.configure import gdata
# ftlog.info('111111111111', gdata.rooms().keys())
# [441011001, 441021001, 441031001, 441041001, 443011001, 443021001, 444021001, 444031001, 444041001, 444051001, 444111001, 444121001, 444141001, 444151001, 444991001, 445011001, 446011001]
room = gdata.rooms()[444111001]
# ftlog.info('111111111111', room.maptable.keys())
# [4410410010001, 4410410010002, 4410410010003, 4410410010004, 4410410010005, 4410410010006, 4410410010007, 4410410010008, 4410410010009, 4410410010010]
table = room.maptable[4410110010001]
ftlog.info('111111111111', table.runConfig.allSuperBossGroupIds)

import freetime.util.log as ftlog
from freetime.core.timer import FTLoopTimer
from newfish.entity import config, util