Objects, like StoryCubes, can gift objects
This allows the completion of a puzzle to warrant an actual item to the characters in the room.
This commit is contained in:
parent
8e2918564b
commit
25b38c4b3b
2 changed files with 78 additions and 78 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue