34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
import string
|
|
|
|
from untitled import content
|
|
|
|
|
|
def validate_cat_name(name, auto_gen=False):
|
|
ALLOWED = set(string.ascii_letters + string.digits)
|
|
if not auto_gen:
|
|
if len(name) < 4 or len(name) > 24:
|
|
return "Your cat's name must be 4-24 characters long."
|
|
else:
|
|
if len(name) < 4 or len(name) > 9:
|
|
return "Your cat's name must be greater than 3 characters and below 9 characters long."
|
|
if not all(c in ALLOWED for c in name):
|
|
return "Your cat's name can only have letters and numbers."
|
|
if not any(c in string.ascii_letters for c in name):
|
|
return "Your cat's name needs at least 1 letter."
|
|
|
|
|
|
def reconcile(cat, now):
|
|
elapsed_hours = (now - cat.last_updated) / 3600
|
|
if elapsed_hours <= 0:
|
|
return
|
|
cat.fullness -= content.HUNGER_DECAY_PER_HOUR * elapsed_hours
|
|
if cat.fullness < 0:
|
|
cat.fullness = 0
|
|
cat.last_updated = now
|
|
|
|
|
|
def feed(cat, amount=100):
|
|
cat.fullness += amount
|
|
if cat.fullness > 100:
|
|
cat.fullnesss = 100
|