diff --git a/typeclasses/exits.py b/typeclasses/exits.py index a8fae8f..cdde5d9 100644 --- a/typeclasses/exits.py +++ b/typeclasses/exits.py @@ -8,10 +8,17 @@ for allowing Characters to traverse the exit to its destination. """ from evennia.objects.objects import DefaultExit +from evennia.commands.cmdset import CmdSet +from evennia.commands.command import Command +from evennia.utils import utils from .objects import ObjectParent from commands.misc import CmdSetKnock +MOVE_DELAY = {"stroll": 6, "walk": 4, "run": 2, "sprint": 1} + +SPEED_DESCS = {"stroll": "strolling", "walk": "walking", "run": "running", "sprint": "sprinting"} + class Exit(ObjectParent, DefaultExit): """ @@ -21,13 +28,123 @@ class Exit(ObjectParent, DefaultExit): See mygame/typeclasses/objects.py for a list of properties and methods available on all Objects child classes like this. - """ + def at_traverse(self, traveler, destination): + """ + Implements the actual traversal, using utils.delay to delay the move_to. + """ + # if the traverser has an Attribute move_speed, use that, + # otherwise default to "walk" speed + move_speed = traveler.db.move_speed or "walk" + move_delay = MOVE_DELAY.get(move_speed, 4) pre_check = traveler.at_pre_move(destination) + + def move_callback(): + "This callback will be called by utils.delay after move_delay seconds." + source_location = traveler.location + if traveler.move_to(destination, move_type="traverse"): + self.at_post_traverse(traveler, source_location) + else: + if self.db.err_traverse: + # if exit has a better error message, let's use it. + self.caller.msg(self.db.err_traverse) + else: + # No shorthand error message. Call hook. + self.at_failed_traverse(traveler) + if pre_check: + moving = SPEED_DESCS[move_speed] if self.db.traverse_msg: - traveler.msg(f"\n{self.db.traverse_msg}\n") - return super().at_traverse(traveler, destination) + msg = f"\n{self.db.traverse_msg}\n".format(move_speed, moving) + else: + if self.key in ['north', 'south', 'east', 'west']: + msg = f"You start {moving} {self.key}." + else: + msg = f"You start {moving} on {self.key}." + + traveler.msg(msg) else: + if self.db.err_traverse: + # if exit has a better error message, let's use it. + self.caller.msg(self.db.err_traverse) return False + + # create a delayed movement + t = utils.delay(move_delay, move_callback) + + # we store the deferred on the character, this will allow us + # to abort the movement. We must use an ndb here since + # deferreds cannot be pickled. + traveler.ndb.currently_moving = t + + +# +# set speed - command +# + + +class CmdSetSpeed(Command): + """ + set your movement speed + + Usage: + setspeed stroll|walk|run|sprint + + This will set your movement speed, determining how long time + it takes to traverse exits. If no speed is set, 'walk' speed + is assumed. + """ + + key = "setspeed" + + def func(self): + """ + Simply sets an Attribute used by the SlowExit above. + """ + speed = self.args.lower().strip() + if speed not in SPEED_DESCS: + self.caller.msg("Usage: setspeed stroll||walk||run||sprint") + elif self.caller.db.move_speed == speed: + self.caller.msg("You are already %s." % SPEED_DESCS[speed]) + else: + self.caller.db.move_speed = speed + self.caller.msg("You are now %s." % SPEED_DESCS[speed]) + + +# +# stop moving - command +# + + +class CmdStop(Command): + """ + stop moving + + Usage: + stop + + Stops the current movement, if any. + """ + + key = "stop" + + def func(self): + """ + This is a very simple command, using the + stored deferred from the exit traversal above. + """ + currently_moving = self.caller.ndb.currently_moving + if currently_moving and not currently_moving.called: + currently_moving.cancel() + self.caller.msg("You stop moving.") + for observer in self.caller.location.contents_get(self.caller): + observer.msg("%s stops." % self.caller.get_display_name(observer)) + else: + self.caller.msg("You are not moving.") + + +class SlowExitCmdSet(CmdSet): + def at_cmdset_creation(self): + self.add(CmdSetSpeed()) + self.add(CmdStop()) diff --git a/web/static/webclient/css/custom.css b/web/static/webclient/css/custom.css index a60de12..b66c706 100644 --- a/web/static/webclient/css/custom.css +++ b/web/static/webclient/css/custom.css @@ -81,6 +81,11 @@ textarea.inputfield:focus { color: #008020; } +/* Color for the help commands: */ +.color-002 { + font-family: monospace, monospace; +} + .color-014 { font-weight: bold; font-size: 24px;