From 542e1400136561c3a01509bd588ba6d830f8bc8c Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 3 Apr 2025 18:54:20 -0700 Subject: [PATCH] Figured the give and take system Now the Knocker will only accept the ring, and not berries. --- .gitignore | 2 ++ commands/take.py | 15 +++++++++------ typeclasses/characters.py | 36 ++++++++++++++---------------------- typeclasses/things.py | 39 ++++++++++++++++++++++++++++++++++++--- utils/support.py | 7 ++++++- 5 files changed, 67 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 5a87007..308031e 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ nosetests.xml .vscode /.venv/ .DS_Store +/server/ssh-private.key +/server/ssh-public.key diff --git a/commands/take.py b/commands/take.py index ce9bd61..350bcde 100755 --- a/commands/take.py +++ b/commands/take.py @@ -1,22 +1,25 @@ #!/usr/bin/env python from commands.command import Command +from evennia.commands.default.general import NumberedTargetCommand - -class CmdTake(Command): +class CmdTake(Command, NumberedTargetCommand): """ Steals an object from another. Added to the default_cmdsets. """ key = "take" aliases = ["steal"] - # only allow this command if command.obj is carried by caller. - # locks = "cmd:holds()" + rhs_split = ("=", " from ") def func(self): """ Implements the take command. Since this command is designed to work on the object, we operate only on self.obj. """ - # logger.log_info(f"Dealing with {self.caller.key}") - self.caller.do_take(self.args) + if not self.args: + self.msg("What do you want to take?") + elif not self.rhs: + self.msg(f"You want to take {self.lhs}, but from whom?") + else: + self.caller.do_take(self.lhs, self.rhs) diff --git a/typeclasses/characters.py b/typeclasses/characters.py index 3cfefc2..348325f 100644 --- a/typeclasses/characters.py +++ b/typeclasses/characters.py @@ -72,32 +72,24 @@ class Character(Object, DefaultCharacter): letter.db.inside = READ_LETTER.format(self.name.capitalize()) letter.location = self - def do_take(self, args): + def do_take(self, to_take, from_whom): """ A character has a _steal_command. What are the limitations? """ - args = Token(args) - if args.empty(): - self.msg("What do you want to take?") - elif len(args.words) == 1: - self.msg(f"You want to take {args.words[0]}, but from whom?") - else: - to_take = args.words[0] - from_whom = args.words[-1] - victim = self.search(from_whom) - if victim: - thing = victim.has(to_take) - if thing and thing.db.can_take: - self.msg(f"You take {thing.key} from {victim.key}.") - self.location.msg_contents( - f"{self.key} takes {thing.key} from {victim.key}!", - exclude=self) - thing.move_to(self, quiet=True, use_destination=True) - return + victim = self.search(from_whom) + if victim: + thing = victim.has(to_take) + if thing and thing.db.can_take: + self.msg(f"You take {thing.key} from {victim.key}.") + self.location.msg_contents( + f"{self.key} takes {thing.key} from {victim.key}!", + exclude=self) + thing.move_to(self, quiet=True, use_destination=True) + return - self.msg(f"{victim.key} doesn't have a {to_take} you can take.") - else: - self.msg(f"You don't see {from_whom}.") + self.msg(f"{victim.key} doesn't have a {to_take} you can take.") + else: + self.msg(f"You don't see {from_whom}.") def at_pre_move(self, destination, **kwargs): """ diff --git a/typeclasses/things.py b/typeclasses/things.py index 0843e71..cfab9fc 100755 --- a/typeclasses/things.py +++ b/typeclasses/things.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from evennia import create_script -from evennia.utils import logger +from evennia.utils import logger, delay from .scripts import KnockScript from .objects import Object @@ -11,6 +11,17 @@ from utils.word_list import routput from random import choice, random import re +class Ring(Object): + def move_to(self, destination, *args, **kwargs): + """ + The ring should only go to the door knocker... + """ + if destination.is_typeclass("typeclasses.things.Knocker") or \ + destination.is_typeclass("typeclasses.characters.Character"): + super().move_to(destination) + return True + return False + class Stick(Object): def at_object_creation(self): @@ -309,8 +320,30 @@ class Knocker(Object): super().msg(text=text, from_obj=from_obj, **kwargs) def at_object_leave(self, obj, target_location, **kwargs): + """ + If the ring is removed, we make a comment. + """ if obj.key == "brass ring" and target_location != self: self.at_say("Oh my, that feels better.") - else: - self.at_say("Umph") + + def at_pre_object_receive(self, arriving_object, + source_location, **kwargs): + """ + The knocker only accepts the ring as a gift. + """ + return True if arriving_object.key == "brass ring" else False + + def at_object_receive(self, obj, source_location, + move_type, **kwargs): + """ + If the ring is returned, we make a comment. + """ + if obj.key == "brass ring": + delay(2, self.chewing) return True + + def chewing(self): + """ + Make a muffled comment. + """ + self.at_say(choice(self.muffled_responses)) diff --git a/utils/support.py b/utils/support.py index 211990e..129db2b 100755 --- a/utils/support.py +++ b/utils/support.py @@ -21,8 +21,13 @@ def character_has(holder, item): return i def god_msg(msg, sender=None, location=None): + """ + Bit of a debugging tool that allows messages to my character. + """ dabbler = Character.objects.search_object("#1")[0] - dabbler.msg(f"{msg} {'from ' + sender if sender else ''} {'at ' + location if location else ''}") + send_msg = ('from ' + sender.name) if sender else '' + loc_msg = ('at ' + location.name) if location else '' + dabbler.msg(f"{msg} {send_msg} {loc_msg}") def debug(msg, sender=None, location=None): god_msg(f"DEBUG: {msg}", sender, location)