93 lines
2.5 KiB
Python
93 lines
2.5 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)
|
|
|
|
if cat.happiness == 0:
|
|
cat.depressed = True
|
|
if cat.fullness == 0:
|
|
cat.sick = True
|
|
|
|
cat.last_updated = now
|
|
|
|
|
|
def feed(player, cat, amount=content.FOOD_RESTORE):
|
|
if player.inventory["food"] <= 0:
|
|
return False
|
|
player.inventory["food"] -= 1
|
|
cat.fullness = _clamp(cat.fullness + amount)
|
|
return True
|
|
|
|
|
|
def cure_sick(save, restore=content.MEDICINE_RESTORE):
|
|
if save.player.inventory["medicine"] <= 0:
|
|
return False
|
|
save.cat.fullness = restore
|
|
save.cat.sick = False
|
|
save.player.inventory["medicine"] -= 1
|
|
return True
|
|
|
|
|
|
def cure_depressed(save, restore=content.CATNIP_RESTORE):
|
|
if save.player.inventory["catnip"] <= 0:
|
|
return False
|
|
save.cat.happiness = restore
|
|
save.cat.depressed = False
|
|
save.player.inventory["catnip"] -= 1
|
|
return True
|
|
|
|
|
|
def excite(cat, amount=100):
|
|
cat.happiness += amount
|
|
cat.happiness = _clamp(cat.happiness)
|
|
|
|
|
|
def buy(player, item, price):
|
|
if price > player.money:
|
|
return False
|
|
player.money -= price
|
|
player.inventory[item] += 1
|
|
return True
|
|
|
|
|
|
def earn(player, amount):
|
|
player.money += amount
|