示例#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
    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
 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
 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
    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
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
 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
 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.")