51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import string
|
|
|
|
from untitled import content, model
|
|
|
|
|
|
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 _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)
|