コード例 #1
0
ファイル: warp.py プロジェクト: ecdavis/spacegame
def do_warp(mobile, destination_uuid):
    destination, position = _find_warp_destination(mobile, destination_uuid)
    if destination is None or position is None:
        raise error.CommandFail("no destination")
    hook.run(hook_types.CELESTIAL_EXIT, mobile)
    mobile.celestial = destination
    mobile.position = position
    return None
コード例 #2
0
ファイル: test_hook.py プロジェクト: ecdavis/pantsmud
    def test_run_catches_exceptions_in_hook_functions(self):
        def raiser(name):
            raise Exception()

        hook.add(self.name, raiser)
        try:
            hook.run(self.name)
        except Exception:
            self.fail("hook.run must catch all exceptions in hook functions.")
コード例 #3
0
ファイル: test_hook.py プロジェクト: ecdavis/pantsmud
 def test_run_does_not_call_functions_of_other_hook_types(self):
     func1 = mock.MagicMock()
     func1.__name__ = "func1"
     func2 = mock.MagicMock()
     func2.__name__ = "func2"
     hook.add(self.name, func1)
     hook.add("other", func2)
     hook.run(self.name)
     func1.assert_called_once_with(self.name)
     self.assertEqual(func2.call_count, 0)
コード例 #4
0
ファイル: test_hook.py プロジェクト: ecdavis/pantsmud
 def test_run_calls_all_functions_for_given_hook_type(self):
     func1 = mock.MagicMock()
     func1.__name__ = "func1"
     func2 = mock.MagicMock()
     func2.__name__ = "func2"
     hook.add(self.name, func1)
     hook.add(self.name, func2)
     hook.run(self.name)
     func1.assert_called_once_with(self.name)
     func2.assert_called_once_with(self.name)
コード例 #5
0
ファイル: jump.py プロジェクト: ecdavis/spacegame
def jump_command(brain, cmd, args):
    params = parser.parse([("system_name", parser.STRING)], args)
    mobile = brain.mobile
    universe = pantsmud.game.environment
    star_system = universe.get_star_system(params["system_name"])
    if not star_system:
        raise error.CommandFail()  # TODO Add error message.
    elif mobile.star_system is star_system:
        raise error.CommandFail()  # TODO Add error message.
    hook.run(hook_types.STAR_SYSTEM_EXIT, mobile)
    mobile.celestial = random.choice(list(star_system.core_celestials))
    message.command_success(mobile, cmd, None)
コード例 #6
0
ファイル: star_system.py プロジェクト: ecdavis/spacegame
    def pulse(self):
        """
        Pulse the StarSystem, i.e. decrement its reset timer.

        When the reset timer reaches zero, the StarSystem will be reset and the reset timer will be set back to the
        reset interval value.
        """
        if self.reset_timer > -1:
            self.reset_timer -= 1
        if self.reset_timer == 0:
            self.reset_timer = self.reset_interval
            hook.run(hook_types.STAR_SYSTEM_RESET, self)
コード例 #7
0
ファイル: handler.py プロジェクト: ecdavis/spacegame
def close_brain_hook(_, brain):
    logging.debug("brain %r closed" % brain)
    if brain.mobile:
        mobile = brain.mobile
        mobile.detach_brain()
        if pantsmud.game.environment:
            pantsmud.game.environment.remove_entity(mobile)
            hook.run(hook_types.REMOVE_MOBILE, mobile)
    if brain.identity:
        identity = brain.identity
        identity.detach_brain()
        if pantsmud.game.environment:
            pantsmud.game.environment.remove_identity(identity)
    if pantsmud.game.environment:
        pantsmud.game.environment.remove_brain(brain)
コード例 #8
0
ファイル: test_hook.py プロジェクト: ecdavis/pantsmud
 def test_run_passes_arguments_to_hook_functions(self):
     func = mock.MagicMock()
     func.__name__ = "hook"
     hook.add(self.name, func)
     hook.run(self.name, "foo", "bar", baz="omg")
     func.assert_called_once_with(self.name, "foo", "bar", baz="omg")
コード例 #9
0
ファイル: test_hook.py プロジェクト: ecdavis/pantsmud
 def test_run_non_existent_hook_does_not_fail(self):
     try:
         hook.run("foobar")
     except Exception:
         self.fail("Running a non-existent hook must not raise an exception.")