-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchop.py
43 lines (35 loc) · 1.39 KB
/
chop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from backend import has_item_equipped, update_user_data
from map import occupied_by, owned_by
def chop_forest(user, chop_amount, user_data, usersdb, mapdb):
# Check if the user has an hatchet equipped
item = "hatchet"
if not has_item_equipped(user_data, item):
return f"You have no {item} at hand"
# Check if the forest is under the user's control
under_control = owned_by(
user_data["x_pos"], user_data["y_pos"], control=user, mapdb=mapdb
)
if not under_control:
return "You do not own this forest"
# Check if the user is on a forest tile
proper_tile = occupied_by(
user_data["x_pos"], user_data["y_pos"], what="forest", mapdb=mapdb
)
if not proper_tile:
return "Not on a forest tile"
# Check if the user has enough action points
if user_data["action_points"] < chop_amount:
return "Not enough action points to chop"
# Perform wood chopping
ingredients = user_data.get("ingredients", {})
new_wood = ingredients.get("wood", 0) + chop_amount
ingredients["wood"] = new_wood
new_ap = user_data["action_points"] - chop_amount # Deduct action points
# Update user's data
updated_values = {"action_points": new_ap, "ingredients": ingredients}
update_user_data(
user=user,
updated_values=updated_values,
user_data_dict=usersdb,
)
return "Chopping successful"