From 25b38c4b3b624ebd06a6bebba8a7ad2007d8ff8d Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Tue, 22 Jul 2025 22:07:50 -0700 Subject: [PATCH] Objects, like StoryCubes, can gift objects This allows the completion of a puzzle to warrant an actual item to the characters in the room. --- typeclasses/objects.py | 80 ++++++++++++++++++++++++++++++++++++++++-- typeclasses/puppets.py | 76 --------------------------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/typeclasses/objects.py b/typeclasses/objects.py index 87467fd..49de87b 100755 --- a/typeclasses/objects.py +++ b/typeclasses/objects.py @@ -12,6 +12,7 @@ with a location in the game world (like Characters, Rooms, Exits). from re import split, match, sub, IGNORECASE from evennia.contrib.rpg.rpsystem.rpsystem import ContribRPObject +from evennia.prototypes.spawner import spawn from evennia.utils import delay, logger from utils.word_list import routput @@ -432,9 +433,9 @@ class Listener: m = match(r"gift_all ([A-z]+)( *: *([^:]+)( *: *(.*))?)?", cmd) if m: - logger.info(f"Higher Gift: {m.group(1)}") for c in self.characters_here(puppets=True): - self.do_gift(c, m.group(1), m.group(3), m.group(5)) + logger.info(f"Highest Gift: {m.group(1)} to {c.key}") + self.do_gift(c.key, m.group(1), m.group(3), m.group(5)) return m = match(r"gift ([A-z]+) *?( to|=)? *([^:]+)( *: *([^:]+)( *: *(.*))?)?", cmd) @@ -467,3 +468,78 @@ class Listener: else: for obj in objs: move_to_me(obj) + + def do_gift(self, recipient, gift, name=None, desc=None): + """ + Give a 'gift' by name to a 'recipient'. + + This doesn't give the gift if the recipient has already + received the gift. + """ + gifts = { + 'purse': {"typeclass": "typeclasses.things.CoinPurse", + "key": name or gift, + "desc": desc or "Small leather coin purse, with a gold clasp.", + }, + 'ball': {"typeclass": "typeclasses.things.CrystalBall", + "key": name or "crystal ball", + "desc": desc or "Swirling glass ball of colored ectoplasm.", + }, + 'dice': {"typeclass": "typeclasses.things.Dice", + "key": name or "pair of dice", + "desc": desc or "Two bone knuckles with painted dots.", + "attr": { + "number": 2 + } + }, + 'pipe': {"typeclass": "typeclasses.things.Pipe", + "key": name or gift, + "desc": desc or "Smoking pipe carved with esoteric symbols.", + }, + 'wand': {"typeclass": "typeclasses.things.Wand", + "key": name or gift, + "desc": desc or "Curiously crafted wand carved with runes: ᛑ ᛒ ᚱ", + }, + 'bag': {"typeclass": "typeclasses.things.BagofJunk", + "key": name or "sack", + "desc": desc or "Small cloth bag with a leather drawstring.|/You could probably |grummage|n around in that, and maybe |gkeep|n something.", + }, + 'junk': {"typeclass": "typeclasses.things.BagofJunk", + "key": name or "sack", + "desc": desc or "Small cloth bag with a leather drawstring.|/You could probably |grummage|n around in that, and maybe |gkeep|n something.", + "attr": { + "stuff": "human" + }, + }, + 'blue': {"typeclass": "typeclasses.things.Medal", + "key": name or "blue medal", + "desc": desc or "Gold medallion decorated with a trident and conch suspended by a blue ribbon.", + }, + } + + receiver = self.search(recipient, global_search=True) + if not receiver: + logger.info(f"Didn't find {recipient}.") + return None + + if gift in gifts.keys() and \ + not receiver.attributes.get(f"received_{gift}"): + details = gifts[gift] + logger.info(f"Giving {details['key']} to {receiver.key}") + + obj = spawn(details)[0] + for attr, value in enumerate(details.get("attr", {})): + obj.attributes.add(attr, value) + obj.location = receiver + receiver.attributes.add(f"received_{gift}", True) + + their_name = receiver.get_display_name(self) + self.announce_action(f"$You() $conj(give) something to {their_name}.", + exclude=receiver) + + my_name = self.get_display_name(receiver) + receiver.msg(f"{my_name} gives you a {obj.name}.") + return True + + self.msg(f"You can't give '{gift}' to {receiver.key}... {gifts.keys()}") + return None diff --git a/typeclasses/puppets.py b/typeclasses/puppets.py index 32efa02..b2a2c9a 100755 --- a/typeclasses/puppets.py +++ b/typeclasses/puppets.py @@ -6,7 +6,6 @@ from re import split, match, sub, IGNORECASE from shutil import copyfile from evennia import CmdSet -from evennia.prototypes.spawner import spawn from evennia.utils import logger from commands.command import Command @@ -83,81 +82,6 @@ class Puppet(Character, Listener): else: return self.db.desc_unpuppeted if self.db.desc_unpuppeted else self.db.desc - def do_gift(self, recipient, gift, name=None, desc=None): - """ - Give a 'gift' by name to a 'recipient'. - - This doesn't give the gift if the recipient has already - received the gift. - """ - gifts = { - 'purse': {"typeclass": "typeclasses.things.CoinPurse", - "key": name or gift, - "desc": desc or "Small leather coin purse, with a gold clasp.", - }, - 'ball': {"typeclass": "typeclasses.things.CrystalBall", - "key": name or "crystal ball", - "desc": desc or "Swirling glass ball of colored ectoplasm.", - }, - 'dice': {"typeclass": "typeclasses.things.Dice", - "key": name or "pair of dice", - "desc": desc or "Two bone knuckles with painted dots.", - "attr": { - "number": 2 - } - }, - 'pipe': {"typeclass": "typeclasses.things.Pipe", - "key": name or gift, - "desc": desc or "Smoking pipe carved with esoteric symbols.", - }, - 'wand': {"typeclass": "typeclasses.things.Wand", - "key": name or gift, - "desc": desc or "Curiously crafted wand carved with runes: ᛑ ᛒ ᚱ", - }, - 'bag': {"typeclass": "typeclasses.things.BagofJunk", - "key": name or "sack", - "desc": desc or "Small cloth bag with a leather drawstring.|/You could probably |grummage|n around in that, and maybe |gkeep|n something.", - }, - 'junk': {"typeclass": "typeclasses.things.BagofJunk", - "key": name or "sack", - "desc": desc or "Small cloth bag with a leather drawstring.|/You could probably |grummage|n around in that, and maybe |gkeep|n something.", - "attr": { - "stuff": "human" - }, - }, - 'blue': {"typeclass": "typeclasses.things.Medal", - "key": name or "blue medal", - "desc": desc or "Gold medallion decorated with a trident and conch suspended by a blue ribbon.", - }, - } - receiver = self.search(recipient, global_search=True) - if not receiver: - logger.info(f"Didn't find {recipient}.") - return None - - if gift in gifts.keys() and \ - not receiver.attributes.get(f"received_{gift}"): - details = gifts[gift] - logger.info(f"Giving {details['key']} to {receiver.key}") - - obj = spawn(details)[0] - for attr, value in enumerate(details.get("attr", {})): - obj.attributes.add(attr, value) - obj.location = receiver - receiver.attributes.add(f"received_{gift}", True) - - their_name = receiver.get_display_name(self) - self.announce_action(f"$You() $conj(give) something to {their_name}.", - exclude=receiver) - - my_name = self.get_display_name(receiver) - receiver.msg(f"{my_name} gives you a {obj.name}.") - return True - - self.msg(f"You can't give '{gift}' to {receiver.key}... {gifts.keys()}") - return None - - class CmdShrubSay(Command): """Erase and write on the shrub's chalkboard. """