Moved 'drink' command from cups to people
This handles better error messages.
This commit is contained in:
parent
2994ecf255
commit
ddcb0f0306
4 changed files with 55 additions and 32 deletions
|
|
@ -36,19 +36,6 @@ class CmdSetEat(CmdSet):
|
|||
self.add(CmdEat)
|
||||
|
||||
|
||||
class CmdDrink(Command):
|
||||
"""
|
||||
If you are holding a teacup, and it has a liquid, you may drink your tea.
|
||||
|
||||
This doesn't tell others of this particular activity.
|
||||
"""
|
||||
key = "drink"
|
||||
aliases = "sip"
|
||||
|
||||
def func(self):
|
||||
self.obj.do_drink(self.caller)
|
||||
|
||||
|
||||
class CmdMakeTea(Command):
|
||||
"""
|
||||
make [tea-type]
|
||||
|
|
@ -83,11 +70,6 @@ class CmdFillTeacup(Command):
|
|||
self.obj.do_fill(self.caller)
|
||||
|
||||
|
||||
class CmdSetCup(CmdSet):
|
||||
def at_cmdset_creation(self):
|
||||
self.add(CmdDrink)
|
||||
|
||||
|
||||
class CmdSetTeapot(CmdSet):
|
||||
def at_cmdset_creation(self):
|
||||
self.add(CmdMakeTea)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from evennia.contrib.game_systems.gendersub import SetGender
|
|||
from evennia.contrib.rpg.rpsystem import RPSystemCmdSet
|
||||
from evennia.contrib.rpg.character_creator.character_creator import ContribChargenCmdSet
|
||||
from commands.sittables import CmdNoSitStand
|
||||
from commands.everyone import CmdTake, CmdThink, CmdSay, CmdWhisper, CmdRead
|
||||
from commands.everyone import CmdTake, CmdThink, CmdSay, CmdWhisper, CmdRead, CmdDrink
|
||||
from commands.wizards import CmdGM, CmdSpell, CmdGMTrigger, CmdMakeCocktail
|
||||
|
||||
class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
|
|
@ -38,6 +38,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
|||
"""
|
||||
super().at_cmdset_creation()
|
||||
self.add(CmdNoSitStand)
|
||||
self.add(CmdDrink)
|
||||
self.add(CmdTake)
|
||||
self.add(CmdThink)
|
||||
self.add(SetGender)
|
||||
|
|
|
|||
|
|
@ -309,3 +309,52 @@ class CmdTake(Command, NumberedTargetCommand):
|
|||
self.caller.msg(f"You want to take {self.lhs}, but from whom?")
|
||||
else:
|
||||
self.caller.do_take(self.lhs, self.rhs)
|
||||
|
||||
|
||||
class CmdDrink(Command):
|
||||
"""
|
||||
Drink a beverage in your inventory.
|
||||
|
||||
Usage:
|
||||
|
||||
drink [ container ]
|
||||
|
||||
If you are holding a teacup, or cocktail, and it is not empty,
|
||||
you may drink.
|
||||
|
||||
This doesn't tell others of this particular activity.
|
||||
"""
|
||||
key = "drink"
|
||||
aliases = ["sip", "quaff"]
|
||||
|
||||
def drinkable(self, item):
|
||||
return hasattr(item, 'do_drink') and callable(item.do_drink)
|
||||
|
||||
def not_empty(self, item):
|
||||
return (item.db.amount or 0) > 0
|
||||
|
||||
def drink_item(self, name):
|
||||
item = self.caller.search(name, location=self.caller,
|
||||
nofound_string=f"You don't have {name} in your inventory.")
|
||||
if item:
|
||||
if self.drinkable(item):
|
||||
item.do_drink(self.caller)
|
||||
else:
|
||||
self.caller.msg(f"The {item.name} is not drinkable.")
|
||||
|
||||
def drink_anything(self):
|
||||
containers = [item for item in self.caller.contents
|
||||
if self.drinkable(item) and self.not_empty(item)]
|
||||
if len(containers) == 1:
|
||||
containers[0].do_drink(self.caller)
|
||||
elif len(containers) > 1:
|
||||
self.caller.msg("You have two many things you can drink. Which one do you want?")
|
||||
else:
|
||||
self.caller.msg("You have nothing to drink.")
|
||||
|
||||
def func(self):
|
||||
goal = self.args.strip()
|
||||
if goal and goal != "":
|
||||
self.drink_item(goal)
|
||||
else:
|
||||
self.drink_anything()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from evennia.prototypes.spawner import spawn
|
|||
from evennia.utils import logger
|
||||
|
||||
from typeclasses.objects import Object
|
||||
from commands.consumables import CmdSetTeapot, CmdSetCup
|
||||
from commands.consumables import CmdSetTeapot
|
||||
from utils.word_list import routput, choices
|
||||
|
||||
import re
|
||||
|
|
@ -57,9 +57,6 @@ class TeaCup(Object):
|
|||
fill_amount = 4
|
||||
sip_amount = 1
|
||||
|
||||
def at_object_creation(self):
|
||||
self.cmdset.add_default(CmdSetCup)
|
||||
|
||||
def do_drink(self, drinker):
|
||||
amount = self.db.amount or 0
|
||||
tea_type = self.db.tea_type or "tea"
|
||||
|
|
@ -345,12 +342,6 @@ class Cocktail(Object):
|
|||
drink.db.cocktail_type, char)
|
||||
theroom.msg_contents(msg, exclude=owner)
|
||||
|
||||
def at_object_creation(self):
|
||||
"""
|
||||
Add the 'drink' command.
|
||||
"""
|
||||
self.cmdset.add_default(CmdSetCup)
|
||||
|
||||
def do_drink(self, drinker):
|
||||
"""
|
||||
Called when owner calls the 'drink' command.
|
||||
|
|
@ -365,10 +356,10 @@ class Cocktail(Object):
|
|||
elif amount > 0:
|
||||
drinker.msg(choices(self.db.effects, self.key, cocktail_type))
|
||||
else:
|
||||
drinker.msg(choices(EMPTY_COCKTAIL_MSGS, self.key, cocktail_type))
|
||||
self.key = "cocktail glass"
|
||||
self.key = f"{self.db.cocktail_type} glass"
|
||||
self.aliases.add('glass')
|
||||
self.db.desc = "An empty cocktail glass"
|
||||
self.db.desc = f"An empty {self.db.cocktail_type} glass"
|
||||
drinker.msg(choices(EMPTY_COCKTAIL_MSGS, self.key, cocktail_type))
|
||||
|
||||
self.db.amount = self.db.amount - self.sip_amount
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue