Dabbler's room will produce a tea cup for each person. A teapot can make different types of teas, or even just a random one.
62 lines
1.6 KiB
Python
Executable file
62 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import random
|
|
import re
|
|
import string
|
|
|
|
class Token():
|
|
def __init__(self, string):
|
|
cleaned_words = re.sub(r"[\.,\?!'\"=:;#\&\*\(\)\[\]\{\}]*", "", string)
|
|
self.words = cleaned_words.split()
|
|
|
|
def empty(self):
|
|
if len(self.words) == 0:
|
|
return True
|
|
|
|
def contains(self, word):
|
|
if len(self.words) > 0:
|
|
result = [True for w in self.words if w == word]
|
|
if len(result) > 0:
|
|
return result[0]
|
|
|
|
def character_has(holder, item):
|
|
"""
|
|
Return true if character, holder, has an item.
|
|
Where item is probably a string name to match an item's key.
|
|
It can also be a type, for instance:
|
|
|
|
character_has(character, typeclasses.drinkables.TeaCup)
|
|
"""
|
|
for i in holder.contents:
|
|
if isinstance(item, str) and i.key == item:
|
|
return i
|
|
elif type(i) == item:
|
|
return i
|
|
elif i == item:
|
|
return i
|
|
|
|
def squish(text):
|
|
"Remove series of spaces from the text."
|
|
return re.sub(' *', ' ', text)
|
|
|
|
def routput(string):
|
|
"""
|
|
Return string with internal word choices replaced randomly.
|
|
For instance, the string:
|
|
|
|
'This feels [|very|quite] [nice|cozy|comfortable].'
|
|
|
|
Could return any of the following strings:
|
|
|
|
'This feels quite nice.'
|
|
'This feels cozy.'
|
|
'This feels very comfortable.'
|
|
"""
|
|
# string =
|
|
acc = []
|
|
for s in string.split("["):
|
|
choices, *rest = s.split("]")
|
|
choice = random.choice(choices.split('|'))
|
|
acc = acc + [choice] + rest
|
|
return squish(''.join(acc))
|