diff --git a/setup.py b/setup.py index 58936a5..8851db9 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ author_email="me@ezdwt.com", url="http://github.com/ecdavis/spacegame", download_url="https://github.com/ecdavis/spacegame/tarball/master", - packages=["spacegame", "spacegame.core", "spacegame.modules", "spacegame.universe"], + packages=["spacegame", "spacegame.commands", "spacegame.core", "spacegame.modules", "spacegame.universe"], test_suite="tests.get_all_tests", install_requires=["pants >= 1.0", "pantsmud >= 0.5.0"], tests_require=['mock'], diff --git a/spacegame/__init__.py b/spacegame/__init__.py index 8d8eaa7..1eb63ae 100644 --- a/spacegame/__init__.py +++ b/spacegame/__init__.py @@ -1,9 +1,11 @@ +import spacegame.commands import spacegame.core import spacegame.modules def init(): spacegame.core.init() - spacegame.modules.init() + spacegame.modules.init() # Init modules after core + spacegame.commands.init() # Init commands after modules def start(): diff --git a/spacegame/commands/__init__.py b/spacegame/commands/__init__.py new file mode 100644 index 0000000..484e304 --- /dev/null +++ b/spacegame/commands/__init__.py @@ -0,0 +1,5 @@ +from spacegame.commands import warp + + +def init(): + warp.init() diff --git a/spacegame/commands/warp.py b/spacegame/commands/warp.py new file mode 100644 index 0000000..3bdd985 --- /dev/null +++ b/spacegame/commands/warp.py @@ -0,0 +1,34 @@ +from pantsmud.driver import command, parser +from pantsmud.util import message +from spacegame.modules import warp + + +def warp_command(brain, cmd, args): + params = parser.parse([("destination_uuid", parser.UUID)], args) + result = warp.do_warp(brain.mobile, params["destination_uuid"]) + message.command_success(brain, cmd, result) + + +def warp_beacon_command(brain, cmd, args): + parser.parse([], args) + result = warp.do_warp_beacon(brain.mobile) + message.command_success(brain, cmd, result) + + +def warp_scan_command(brain, cmd, args): + parser.parse([], args) + result = warp.do_warp_scan(brain.mobile) + message.command_success(brain, cmd, result) + + +def warp_scan_activate_command(brain, cmd, args): + parser.parse([], args) + result = warp.do_warp_scan_activate(brain.mobile) + message.command_success(brain, cmd, result) + + +def init(): + command.add_command("warp", warp_command) + command.add_command("warp.beacon", warp_beacon_command) + command.add_command("warp.scan", warp_scan_command) + command.add_command("warp.scan.activate", warp_scan_activate_command) diff --git a/spacegame/modules/warp.py b/spacegame/modules/warp.py index aa21f73..c426911 100644 --- a/spacegame/modules/warp.py +++ b/spacegame/modules/warp.py @@ -1,7 +1,7 @@ import random import pantsmud.game -from pantsmud.driver import auxiliary, command, hook, parser -from pantsmud.util import error, message +from pantsmud.driver import auxiliary, hook +from pantsmud.util import error from spacegame.core import aux_types, hook_types from spacegame.universe import entity @@ -17,16 +17,14 @@ def save_data(self): return {} -def warp_command(brain, cmd, args): - params = parser.parse([("destination_uuid", parser.UUID)], args) - mobile = brain.mobile - destination, position = _find_warp_destination(mobile, params["destination_uuid"]) +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 - message.command_success(mobile, cmd) + return None def _find_warp_destination(mobile, destination_uuid): @@ -37,7 +35,7 @@ def _find_warp_destination(mobile, destination_uuid): celestials = mobile.star_system.get_celestials(uuids=mobile.aux["warp"].scanner) for celestial in celestials: if celestial.uuid == destination_uuid: - return celestial, _random_position_around((0, 0, 0)) + return celestial, _random_position_around((0+celestial.warp_radius, 0, 0)) return None, None @@ -50,35 +48,36 @@ def _random_position_around(position): ) -def warp_beacon_command(brain, cmd, args): - parser.parse([], args) - mobile = brain.mobile +def do_warp_beacon(mobile): beacon = entity.Entity(is_warp_beacon=True) beacon.celestial = mobile.celestial beacon.position = mobile.position pantsmud.game.environment.add_entity(beacon) - message.command_success(mobile, cmd, {"beacon_uuid": str(beacon.uuid)}) + return { + "beacon_uuid": str(beacon.uuid) + } -def warp_scan_command(brain, cmd, args): - parser.parse([], args) - mobile = brain.mobile +def do_warp_scan(mobile): beacons = mobile.star_system.get_entities(is_warp_beacon=True) beacon_data = {b.name: str(b.uuid) for b in beacons if b.celestial is not mobile.celestial} celestials = mobile.star_system.get_celestials(uuids=mobile.aux["warp"].scanner) celestial_data = {c.name: str(c.uuid) for c in celestials if c is not mobile.celestial} - message.command_success(mobile, cmd, {"beacons": beacon_data, "celestials": celestial_data}) + return { + "beacons": beacon_data, + "celestials": celestial_data + } -def warp_scan_activate_command(brain, cmd, args): - parser.parse([], args) - mobile = brain.mobile +def do_warp_scan_activate(mobile): celestials = mobile.star_system.get_celestials() celestial_data = {c.name: c.uuid for c in celestials if c is not mobile.celestial} mobile.aux["warp"].scanner = celestial_data.values()[:] for k, v in celestial_data.items(): # TODO ugh celestial_data[k] = str(v) - message.command_success(mobile, cmd, {"celestials": celestial_data}) + return { + "celestials": celestial_data + } def clear_warp_scanner(_, mobile): @@ -87,9 +86,5 @@ def clear_warp_scanner(_, mobile): def init(): auxiliary.install(aux_types.AUX_TYPE_ENTITY, "warp", WarpAux) - command.add_command("warp", warp_command) - command.add_command("warp.beacon", warp_beacon_command) - command.add_command("warp.scan", warp_scan_command) - command.add_command("warp.scan.activate", warp_scan_activate_command) hook.add(hook_types.CELESTIAL_EXIT, clear_warp_scanner) hook.add(hook_types.STAR_SYSTEM_EXIT, clear_warp_scanner)