当前位置: 首页>>代码示例>>Python>>正文


Python ScriptManager.get方法代码示例

本文整理汇总了Python中cuwo.script.ScriptManager.get方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptManager.get方法的具体用法?Python ScriptManager.get怎么用?Python ScriptManager.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cuwo.script.ScriptManager的用法示例。


在下文中一共展示了ScriptManager.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import get [as 别名]
class CubeWorldServer:
    exit_code = None
    world = None
    old_time = None
    skip_index = 0

    def __init__(self, loop, config):
        self.loop = loop
        self.config = config
        base = config.base

        # game-related
        self.update_packet = packets.ServerUpdate()
        self.update_packet.reset()

        self.connections = set()
        self.players = MultikeyDict()

        self.updated_chunks = set()

        use_same_loop = base.update_fps == base.network_fps
        if use_same_loop:
            def update_callback():
                self.update()
                self.send_update()
        else:
            update_callback = self.update
        self.update_loop = LoopingCall(update_callback)
        self.update_loop.start(1.0 / base.update_fps, now=False)

        if use_same_loop:
            self.send_loop = self.update_loop
        else:
            self.send_loop = LoopingCall(self.send_update)
            self.send_loop.start(1.0 / base.network_fps, now=False)

        self.mission_loop = LoopingCall(self.update_missions)
        self.mission_loop.start(base.mission_update_rate, now=False)

        # world
        self.world = World(self, self.loop, base.seed,
                           use_tgen=base.use_tgen,
                           use_entities=base.use_entities,
                           chunk_retire_time=base.chunk_retire_time,
                           debug=base.world_debug_info)
        if base.world_debug_file is not None:
            debug_fp = open(base.world_debug_file, 'wb')
            self.world.set_debug(debug_fp)

        # server-related
        self.git_rev = base.get('git_rev', None)

        self.passwords = {}
        for k, v in base.passwords.items():
            self.passwords[k.lower()] = v

        self.scripts = ScriptManager()
        for script in base.scripts:
            self.load_script(script)

        # time
        self.extra_elapsed_time = 0.0
        self.start_time = loop.time()
        self.set_clock('12:00')

        # start listening
        self.loop.set_exception_handler(self.exception_handler)
        self.loop.create_task(self.create_server(self.build_protocol,
                                                 port=base.port,
                                                 family=socket.AF_INET))

    def exception_handler(self, loop, context):
        exception = context.get('exception')
        if isinstance(exception, TimeoutError):
            pass
        else:
            loop.default_exception_handler(context)

    def build_protocol(self):
        return CubeWorldConnection(self)

    def drop_item(self, item_data, pos):
        item = packets.ChunkItemData()
        item.drop_time = 750
        # XXX provide sane values for these
        item.scale = 0.1
        item.rotation = 185.0
        item.something3 = item.something5 = item.something6 = 0
        item.pos = pos
        item.item_data = item_data
        self.world.get_chunk(get_chunk(pos)).add_item(item)

    def add_packet_list(self, items, l, size):
        for item in iterate_packet_list(l):
            items.append(item.data.copy())

    def handle_tgen_packets(self, in_queue):
        if in_queue is None:
            return

#.........这里部分代码省略.........
开发者ID:matpow2,项目名称:cuwo,代码行数:103,代码来源:server.py

示例2: __init__

# 需要导入模块: from cuwo.script import ScriptManager [as 别名]
# 或者: from cuwo.script.ScriptManager import get [as 别名]
class CubeWorldServer:
    exit_code = None
    world = None

    def __init__(self, loop, config):
        self.loop = loop
        self.config = config
        base = config.base

        # game-related
        self.update_packet = packets.ServerUpdate()
        self.update_packet.reset()

        self.connections = set()
        self.players = MultikeyDict()

        self.chunks = {}
        self.updated_chunks = set()

        self.update_loop = LoopingCall(self.update)
        self.update_loop.start(1.0 / base.update_fps, now=False)

        # world
        self.world = World(self, self.loop, base.seed, base.use_tgen,
                           base.use_entities)

        # server-related
        self.git_rev = base.get('git_rev', None)

        self.passwords = {}
        for k, v in base.passwords.items():
            self.passwords[k.lower()] = v

        self.scripts = ScriptManager()
        for script in base.scripts:
            self.load_script(script)

        # time
        self.extra_elapsed_time = 0.0
        self.start_time = loop.time()
        self.set_clock('12:00')

        # start listening
        asyncio.Task(self.create_server(self.build_protocol,
                                        port=base.port))

    def build_protocol(self):
        return CubeWorldConnection(self)

    def drop_item(self, item_data, pos):
        item = packets.ChunkItemData()
        item.drop_time = 750
        # XXX provide sane values for these
        item.scale = 0.1
        item.rotation = 185.0
        item.something3 = item.something5 = item.something6 = 0
        item.pos = pos
        item.item_data = item_data
        self.world.get_chunk(get_chunk(pos)).add_item(item)

    def update(self):
        self.scripts.call('update')

        # entity updates
        for entity_id, entity in self.world.entities.items():
            entity_packet.set_entity(entity, entity_id, entity.mask)
            entity.mask = 0
            self.broadcast_packet(entity_packet)
        self.broadcast_packet(update_finished_packet)

        # other updates
        update_packet = self.update_packet
        for chunk in self.updated_chunks:
            chunk.on_update(update_packet)
        self.broadcast_packet(update_packet)
        update_packet.reset()

        # reset drop times
        for chunk in self.updated_chunks:
            chunk.on_post_update()

        self.updated_chunks.clear()

        # time update
        time_packet.time = self.get_time()
        time_packet.day = self.get_day()
        self.broadcast_packet(time_packet)

    def send_chat(self, value):
        chat_packet.entity_id = 0
        chat_packet.value = value
        self.broadcast_packet(chat_packet)

    def play_sound(self, name, pos=None, pitch=1.0, volume=1.0):
        sound = packets.SoundAction()
        sound.set_name(name)
        sound.pitch = pitch
        sound.volume = volume

        if pos is not None:
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:cuwo,代码行数:103,代码来源:server.py


注:本文中的cuwo.script.ScriptManager.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。