59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
import time # first import here!
|
|
import uuid
|
|
|
|
|
|
class Cat:
|
|
def __init__(
|
|
self,
|
|
name,
|
|
traits,
|
|
money=25,
|
|
inventory=None,
|
|
last_login=None,
|
|
fullness=100,
|
|
happiness=100,
|
|
sick=False,
|
|
depressed=False,
|
|
cat_uuid=None,
|
|
):
|
|
self.name = name
|
|
self.traits = traits
|
|
self.last_login = last_login or time.time()
|
|
self.money = money
|
|
self.inventory = inventory if inventory is not None else {}
|
|
self.fullness = fullness # really hunger, but 100 hunger being defualt sounds like its 100% hungry so its fullness.
|
|
self.happiness = happiness
|
|
self.sick = sick
|
|
self.depressed = depressed
|
|
self.cat_uuid = cat_uuid or str(uuid.uuid4())
|
|
|
|
def apply_decay(self): # first neat function! yayyy!
|
|
elapsed_hours = (time.time() - self.last_login) / 3600
|
|
if elapsed_hours <= 0:
|
|
elapsed_hours = 0
|
|
self.fullness -= 5 * elapsed_hours
|
|
if self.fullness <= 0:
|
|
self.fullness = 0
|
|
if not self.sick:
|
|
self.sick = True
|
|
print(
|
|
"Your cat didn't have enough food and got sick while you were away. There is medicine in the shop."
|
|
)
|
|
else:
|
|
print("Your cat is still sick! You can buy medicine in the shop.")
|
|
happiness_decay = 10 if self.sick else 5
|
|
self.happiness -= happiness_decay * elapsed_hours
|
|
if self.happiness <= 0:
|
|
self.happiness = 0
|
|
if not self.depressed:
|
|
self.depressed = True
|
|
print(
|
|
"Your cat didn't get happy enough and got depressed, you can buy catnip in the shop to help."
|
|
)
|
|
else:
|
|
print("Your cat is still depressed! You can get catnip in the shop.")
|
|
# TODO: do what claude said in latest summary
|
|
|
|
def to_dict(self):
|
|
return vars(self)
|