Figured the give and take system

Now the Knocker will only accept the ring, and not berries.
This commit is contained in:
Howard Abrams 2025-04-03 18:54:20 -07:00
parent c50f36bffc
commit 542e140013
5 changed files with 67 additions and 32 deletions

2
.gitignore vendored
View file

@ -56,3 +56,5 @@ nosetests.xml
.vscode
/.venv/
.DS_Store
/server/ssh-private.key
/server/ssh-public.key

View file

@ -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)

View file

@ -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):
"""

View file

@ -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))

View file

@ -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)