Files
Untitled-Cat-Game/untitled/rules.py
2026-06-25 14:17:49 -04:00

55 lines
1.6 KiB
Python

import string
from untitled import content, model
def validate_cat_name(name):
ALLOWED = set(string.ascii_letters + string.digits)
if len(name) < 4 or len(name) > 24:
return "Your cat's name must be 4-24 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 validate_auto_gen_cat_name(name):
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 any(c in "aeiou" for c in name.lower()):
return "Your cat's name must contain a vowel."
def _clamp(value, low=0, high=100):
if value < low:
return low
if value > high:
return high
return value
def reconcile(cat: model.Cat, now):
elapsed_hours = (now - cat.last_updated) / 3600
if elapsed_hours <= 0:
return
cat.fullness -= content.HUNGER_DECAY_PER_HOUR * elapsed_hours
cat.fullness = _clamp(cat.fullness)
cat.happiness -= content.BASE_HAPPINESS_DECAY_PER_HOUR * elapsed_hours
if cat.fullness < content.HUNGER_SADNESS_THRESHOLD:
cat.happiness -= content.HUNGER_SADNESS_PENALTY_PER_HOUR * elapsed_hours
cat.happiness = _clamp(cat.happiness)
cat.last_updated = now
def feed(cat, amount=100):
cat.fullness += amount
cat.fullness = _clamp(cat.fullness)
def excite(cat, amount=100):
cat.happiness += amount
cat.happiness = _clamp(cat.happiness)