diff --git a/commands/default_cmdsets.py b/commands/default_cmdsets.py index 3450ba9..6d408fc 100644 --- a/commands/default_cmdsets.py +++ b/commands/default_cmdsets.py @@ -23,6 +23,7 @@ from commands.sittables import CmdNoSitStand from commands.everyone import (CmdTake, CmdThink, CmdSay, CmdWhisper, CmdRead, CmdEat, CmdDrink, CmdUse, CmdPush, CmdPull) +from commands.misc import CmdLight from commands.wizards import CmdGM, CmdSpell, CmdGMTrigger, CmdMakeCocktail @@ -46,6 +47,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet): self.add(CmdUse) self.add(CmdPush) self.add(CmdPull) + self.add(CmdLight) self.add(CmdTake) self.add(CmdThink) self.add(SetGender) diff --git a/commands/lighting.py b/commands/lighting.py deleted file mode 100755 index 8130bee..0000000 --- a/commands/lighting.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -from evennia import Command, CmdSet -# from .command import Command - -class CmdLight(Command): - """ - Creates light where there was none. Something to burn. - """ - - key = "light" - # only allow this command if command.obj is carried by caller. - # locks = "cmd:holds()" - - def func(self): - """ - Implements the light command. Since this command is designed - to sit on a "lightable" object, we operate only on self.obj. - """ - if self.obj.light(): - self.caller.msg("You light %s." % self.obj.key) - self.caller.location.msg_contents( - "%s lights %s!" % (self.caller, self.obj.key), exclude=[self.caller]) - else: - self.caller.msg("%s is already burning." % self.obj.key) - - -class CmdSetLight(CmdSet): - """CmdSet for the lightsource commands""" - - def at_cmdset_creation(self): - """called at cmdset creation""" - self.add(CmdLight) diff --git a/commands/misc.py b/commands/misc.py index 6d0acce..65fa256 100755 --- a/commands/misc.py +++ b/commands/misc.py @@ -75,17 +75,34 @@ class CmdSetStick(CmdSet): class CmdLight(Command): """ - Light something on fire, preferably a pipe. + Light something on fire. Usage: - light [ object ] + light + + Want to relax into the old stories, light a pipe. + Want to see in a dungeon, use this to light a + torch or a candle, if you have such an item. """ key = "light" - locks = "cmd:holds()" def func(self): - self.obj.do_light(self.caller) + lighter = self.caller + item = self.args.strip() + if item == "": + lighter.msg("What do you want to light?") + return + + burnables = lighter.search(item, location=lighter, quiet=True) + if burnables and len(burnables) > 0: + try: + burnables[0].do_light() + except Exception: + lighter.msg(f"The {burnables[0].key} isn't flammable.") + else: + lighter.msg(f"Can't find {item}.") + class CmdSmoke(MuxCommand): @@ -122,7 +139,6 @@ class CmdSmoke(MuxCommand): class CmdSetSmoke(CmdSet): def at_cmdset_creation(self): - self.add(CmdLight) self.add(CmdSmoke) diff --git a/typeclasses/lightables.py b/typeclasses/lightables.py index 7620b74..9e1f299 100755 --- a/typeclasses/lightables.py +++ b/typeclasses/lightables.py @@ -1,9 +1,11 @@ #!/usr/bin/env python -from commands.lighting import CmdSetLight +from evennia.utils import delay + +from typeclasses.objects import Object + # ------------------------------------------------------------- -# # LightSource # # This object emits light. Once it has been turned on it @@ -16,7 +18,6 @@ from commands.lighting import CmdSetLight # to use but does not survive a server @reload. Because of # where the light matters (in the Dark Room where you can # find new light sources easily), this is okay here. -# # ------------------------------------------------------------- class LightSource(Object): @@ -47,7 +48,7 @@ class LightSource(Object): # when created. self.db.desc = "A tapered candle." # add the Light command - self.cmdset.add_default(CmdSetLight, persistent=True) + # self.cmdset.add_default(CmdSetLight, persistent=True) def _burnout(self): """ @@ -57,35 +58,38 @@ class LightSource(Object): # delete ourselves from the database self.db.is_giving_light = False try: - self.location.location.msg_contents( - "%s's %s flickers and dies." % (self.location, self.key), exclude=self.location - ) - self.location.msg("Your %s flickers and dies." % self.key) + owner = self.location + owner.announce_action(f"$Your() {self.key} flickers and dies.") self.location.location.check_light_state() except AttributeError: try: - self.location.msg_contents("A %s on the floor flickers and dies." % self.key) + self.location.msg_contents(f"A {self.key} on the floor flickers and dies.") self.location.location.check_light_state() except AttributeError: # Mainly happens if we happen to be in a None location pass self.delete() - def light(self): + def do_light(self): """ Light this object - this is called by Light command. """ + owner = self.location if self.db.is_giving_light: + owner.msg(f"The {self.key} is already lit.") return False + else: + owner.announce_action(f"$You() $conj(light) $pron(your) {self.key}.") + # burn for 3 minutes before calling _burnout self.db.is_giving_light = True # if we are in a dark room, trigger its light check try: - self.location.location.check_light_state() + owner.location.check_light_state() except AttributeError: try: # maybe we are directly in the room - self.location.check_light_state() + owner.check_light_state() except AttributeError: # we are in a None location pass diff --git a/typeclasses/rooms_dark.py b/typeclasses/rooms_dark.py index 39433bd..c6a37f1 100755 --- a/typeclasses/rooms_dark.py +++ b/typeclasses/rooms_dark.py @@ -1,14 +1,38 @@ #!/usr/bin/env python - # ------------------------------------------------------------------------------- # # Dark Room - a room with states # -# This room limits the movemenets of its denizens unless they carry an active +# This room limits the movements of its denizens unless they carry an active # LightSource object (LightSource is defined in objects.LightSource) # # ------------------------------------------------------------------------------- +from random import choice, random + +from evennia import ( + TICKER_HANDLER, + CmdSet, + Command, + DefaultExit, + DefaultRoom, + create_object, + default_cmds, + search_object, + syscmdkeys, + utils, +) +from evennia.commands.default.general import CmdInventory + +# from evennia.utils import dedent, delay, search +from evennia.contrib.rpg.rpsystem import CmdEmote + +# from commands.command import Command +from commands.everyone import CmdSay, CmdWhisper +from commands.misc import CmdLight +from commands.wizards import CmdGM +from typeclasses.lightables import LightSource +from typeclasses.rooms import Room DARK_MESSAGES = ( "It is pitch black. You are likely to be eaten by a grue.", @@ -22,13 +46,14 @@ DARK_MESSAGES = ( ALREADY_LIGHTSOURCE = ( "You don't want to stumble around in blindness anymore. You already " - "found what you need. Let's get the fireplace lit already!" + "found what you need. Let's get |glight|n already!" ) FOUND_LIGHTSOURCE = ( - "Your fingers bump against a candle on a candleabra." + "Your fingers bump against a splinter of wood." + " It smells of resin and seems dry enough to burn! " "You pick it up, holding it firmly. Now you just need to" - " |wlight|n it using the flint and steel you carry with you." + " |glight|n it using the flint and steel you carry with you." ) @@ -62,9 +87,9 @@ class CmdLookDark(Command): nr_searches = 0 caller.ndb.dark_searches = nr_searches - if nr_searches < 4 and random.random() < 0.90: + if nr_searches < 4 and random() < 0.90: # we don't find anything - caller.msg(random.choice(DARK_MESSAGES)) + caller.msg(choice(DARK_MESSAGES)) caller.ndb.dark_searches += 1 else: # we could have found something! @@ -73,7 +98,7 @@ class CmdLookDark(Command): caller.msg(ALREADY_LIGHTSOURCE) else: # don't have a light source, create a new one. - create_object(LightSource, key="candle", location=caller) + create_object(LightSource, key="splinter", location=caller) caller.msg(FOUND_LIGHTSOURCE) @@ -135,7 +160,12 @@ class DarkCmdSet(CmdSet): self.add(CmdLookDark()) self.add(CmdDarkHelp()) self.add(CmdDarkNoMatch()) - self.add(default_cmds.CmdSay()) + self.add(CmdEmote()) + self.add(CmdSay()) + self.add(CmdWhisper()) + self.add(CmdGM()) + self.add(CmdLight()) + self.add(CmdInventory()) self.add(default_cmds.CmdQuit()) self.add(default_cmds.CmdHome()) @@ -213,17 +243,17 @@ class DarkRoom(Room): # put players in darkness char.msg("The room is completely dark.") - def at_object_receive(self, obj, source_location, move_type="move", **kwargs): + def at_object_receive(self, moved_obj, source_location, move_type="move", **kwargs): """ Called when an object enters the room. """ - if obj.has_account: + if moved_obj.has_account: # a puppeted object, that is, a Character - self._heal(obj) + self._heal(moved_obj) # in case the new guy carries light with them self.check_light_state() - def at_object_leave(self, obj, target_location, move_type="move", **kwargs): + def at_object_leave(self, moved_obj, target_location, move_type="move", **kwargs): """ In case people leave with the light, we make sure to clear the DarkCmdSet if necessary. This also works if they are @@ -232,4 +262,4 @@ class DarkRoom(Room): # since this hook is called while the object is still in the room, # we exclude it from the light check, to ignore any light sources # it may be carrying. - self.check_light_state(exclude=obj) + self.check_light_state(exclude=moved_obj) diff --git a/typeclasses/things.py b/typeclasses/things.py index 7052283..f7079b6 100755 --- a/typeclasses/things.py +++ b/typeclasses/things.py @@ -262,7 +262,7 @@ class Pipe(Object): self.cmdset.add_default(CmdSetSmoke) def do_light(self, lighter): - msg = choices(self.db.light_msg or "$You() $conj(pack) and $conj(light) $pron(your) pipe.") + msg = choices(self.db.light_msg or "$You() $conj(pack) and $conj(light) $pron(your) pipe. You can now |Glook|n around.") lighter.announce_action(msg) def do_smoke(self, smoker):