pet
This commit is contained in:
@@ -17,20 +17,34 @@ def validate_cat_name(name, auto_gen=False):
|
||||
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
|
||||
if cat.fullness < 0:
|
||||
cat.fullness = 0
|
||||
cat.fullness = _clamp(cat.fullness)
|
||||
|
||||
cat.happiness -= content.BASE_HAPPINESS_DECAY_PER_HOUR * elapsed_hours
|
||||
if cat.happiness < 0:
|
||||
cat.happiness = 0
|
||||
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
|
||||
if cat.fullness > 100:
|
||||
cat.fullness = 100
|
||||
cat.fullness = _clamp(cat.fullness)
|
||||
|
||||
|
||||
def excite(cat, amount=100):
|
||||
cat.happiness += amount
|
||||
cat.happiness = _clamp(cat.happiness)
|
||||
|
||||
Reference in New Issue
Block a user