#!/usr/bin/env python from datetime import date import random from evennia import TICKER_HANDLER from evennia.prototypes.spawner import spawn from commands.consumables import CmdSetTrolley, CmdSetMakeConsumable from typeclasses.objects import Object from utils.word_list import routput # , choices class Consumable(Object): """ Create with a command: @create/drop berries;berry : typeclasses.consumables.Consumable @desc berries = Bright red, almost violet, berry. # How many berries are there? @set berries/amount = 10 # How many berries do you eat at a time: @set berries/eat_amount = 3 @set berries/eat_msg = "Sweet and slightly tart. <>." @set berries/finish_msg = "Those were <>." """ amount = 4 eat_amount = 1 def at_object_creation(self): self.db.amount = self.amount self.db.eat_amount = self.eat_amount def do_eat(self, eater): """ Consume (eat) or destroy this object. Indicate this with messages to eater. """ self.db.amount = self.db.amount - self.db.eat_amount if self.db.eat_msgs: msg = random.choice(self.db.eat_msgs) elif self.db.eat_msg: msg = self.db.eat_msg else: msg = "You take a bite." eater.msg(routput(msg)) if self.db.amount <= 0: if self.db.finish_msgs: msg = random.choice(self.db.finish_msgs) elif self.db.finish_msg: msg = self.db.finish_msg else: msg = None if msg: eater.msg(routput(msg)) self.delete() class Producer(Object): """ An object that produces a Consumable object. Use it to create a 'berry bush', for instance: @create/drop berry bush;bush : typeclasses.consumables.Producer @desc bush = A bush laden with bright red brambleberries. # Then describe what to produce: @set bush/make_name = "berries" @set bush/make_aliases = ["berry"] @set bush/make_verb = "pick some" # This one is optional as it defaults to Consumable: @set bush/make_class = "typeclasses.consumables.Consumable" @set bush/make_desc = "Bright red berry with flecks of <>." # How many berries are there when you pick them? @set bush/make_amount = 10 # How many berries do you eat at a time: @set bush/make_eat_amount = 3 # Either a single msg: @set bush/make_eat_msg = "Sweet and slightly tart. <>." # Or many: @set bush/make_eat_msgs = [ "Sweet and slightly tart.", "<>.", "Ooo...that one was sour.", "That was a bit ripe, but still good.", "So sweet with a hint of <>." ] @set bush/make_finish_msg = "Those were <>." """ def at_object_creation(self): self.cmdset.add_default(CmdSetMakeConsumable) def at_pre_get(self, getter, **kwargs): """ Can't get a producer. """ self.do_make(getter) return False def do_make(self, picker, **kwargs): """ Create a configurable consumable, given to picker. """ consumable = spawn({ "typeclass": self.db.make_class or (kwargs['type'] if 'type' in kwargs else "typeclasses.consumables.Consumable"), "key": self.db.make_name, "aliases": self.db.make_aliases, "desc": routput(self.db.make_desc), })[0] consumable.db.amount = self.db.make_amount or 3 consumable.db.eat_amount = self.db.make_eat_amount or 1 if self.db.make_eat_msg: consumable.db.eat_msg = self.db.make_eat_msg if self.db.make_eat_msgs: consumable.db.eat_msgs = self.db.make_eat_msgs if self.db.make_finish_msg: consumable.db.finish_msg = self.db.make_finish_msg if self.db.make_finish_msgs: consumable.db.finish_msgs = self.db.make_finish_msgs consumable.location = picker picker.msg(f"You {self.db.make_verb or 'get'} {self.db.make_name}.") # ---------------------------------------------------------------------- TEACUP_DESCS = [ "A rustic, clay teacup carefully crafted on a wheel. Beautiful <> glaze.", "A fine example of Royal Albert teacup, sporting a design of violet azaleas. Perfect for a black tea.", "A Wings of Grace style teacup with blue butterflies. Perfect for some Earl Grey.", "A dark brown Yixing clay teacup. Perfect for an Oolong tea.", "A light jade green handle-less teacup. A good choice for a green tea.", ] class Trolley(Producer): """ A special producer that has a plate of specific dishes for that day. I need this special because I'm not sure how to populate the database with complex arrays of data. """ scones = [ { "name": "blueberry scone", "taste": "blueberries", }, { "name": "chocolate chip scone", "taste": "chocolate", }, { "name": "lemon poppy seed scone", "taste": "lemon", }, { "name": "cinnamon scone", "taste": "spice", }, { "name": "cranberry orange scone", "tastes": ["tartness of the cranberries", "orange"], }, { "name": "pumpkin scone", "taste": "spices", }, { "name": "cheddar cheese and chive scone", "expression": "cheesy" }, { "name": "cherry almond scone", "expression": "nutty", }, { "name": "apple cinnamon scone", "tastes": ["apple", "cinnamon"], }, ] teacup_prototype = { "typeclass": "typeclasses.drinkables.TeaCup", "key": "teacup", "aliases": "cup", "desc": "A nice teacup.", } def at_object_creation(self): self.cmdset.add_default(CmdSetTrolley) TICKER_HANDLER.add(interval=60 * 60 * 24, callback=self.do_bake) def produce_teacup(self, caller): """ Create and associate with 'caller', a newly created teacup. """ if caller.has("teacup"): caller.msg("You already have a teacup.") else: cuptype = self.teacup_prototype cuptype['desc'] = routput(random.choice(TEACUP_DESCS)) cup = spawn(cuptype)[0] cup.location = caller caller.msg("You pick up a teacup.") def produce_wood(self, caller): """ Create and give to 'caller' a log of wood. """ wood = spawn({ "creator_id": 1, "typeclass": "typeclasses.things.Wood", "key": "log", "aliases": ["wood", "kindling", "logs"], })[0] wood.location = caller caller.msg(routput("You <> " "<> " "<>.")) def do_bake(self): """ Set the scone that we bake today. """ todays_scone = self.scones[date.today().day % len(self.scones)] name = todays_scone.get("name") self.db.make_name = name self.db.make_aliases = ["scone", "scones"] self.db.make_desc = routput("A <>-looking {0}", name) self.db.make_amount = 3 self.db.make_eat_amount = 1 msgs = [ "Delicious.", "So good", "Really good.", 'Mmmmm', ] if todays_scone.get('taste'): msgs += ['You <> <> <> the ' + todays_scone.get('taste') + '.'] if todays_scone.get('tastes'): for taste in todays_scone.get('tastes'): msgs += ['You <> <> <> the ' + taste + '.'] if todays_scone.get('expression'): msgs += [f"<> {todays_scone.get('expression')}."] self.db.make_eat_msgs = msgs self.db.make_finish_msg = "That was <>." self.location.msg_contents(routput("<> scones <> appear <> on the trolley."))