-
Notifications
You must be signed in to change notification settings - Fork 0
/
use_functions.py
120 lines (108 loc) · 3.87 KB
/
use_functions.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def add_arrows(entity, args):
"""
Add arrows to the entities equipment
"""
arrow_count = args.get("arrow_count")
equipment_component = entity.components.get("equipment")
if equipment_component:
equipment_component.equipment["arrows"] += arrow_count
return True
else:
return False
def toggle_equip(entity, args):
"""
Toggle whether an equipment piece is equipped
"""
equipment_component = entity.components.get("equipment")
slot = args.get("slot")
item = args.get("item")
if equipment_component:
was_equipped = dequip(equipment_component.equipment, slot, item)
if not was_equipped:
equip(equipment_component.equipment, slot, item)
return True
return False
def equip(equipment_list, slot, item):
"""
Equip an equipment piece
"""
equipment_list[slot] = item
return True
def dequip(equipment_list, slot, item):
"""
Dequip an equipment piece
"""
if equipment_list[slot] == item:
equipment_list[slot] = None
return True
else:
return False
def decrease_hunger(entity, args):
hunger_decrease_ratio = args.get("hunger_decrease_ratio")
hunger_component = entity.components.get("hunger")
if hunger_component is not None:
hunger_component.turns -= hunger_component.turns_to_starve * hunger_decrease_ratio
return True
else:
return False
def heal_entity(entity, args):
heal_amount = args.get("heal_amount")
if heal_amount is not None and entity.components.get("fighter") and entity.components["fighter"].hp < entity.components["fighter"].max_hp:
fighter = entity.components["fighter"]
fighter.hp += heal_amount
if fighter.hp > fighter.max_hp:
fighter.hp = fighter.max_hp
return True
else:
return False
def damage_entity(entity, args):
args = {"heal_amount": args.get("damage_amount")}
return heal_entity(entity, args)
def increase_strength(entity, args):
increase_amount = args.get("strength_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.strength += increase_amount
return True
else:
return False
def increase_defense(entity, args):
increase_amount = args.get("defense_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.defense += increase_amount
return True
else:
return False
def increase_accuracy(entity, args):
increase_amount = args.get("accuracy_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.accuracy += increase_amount
return True
else:
return False
def increase_dexterity(entity, args):
increase_amount = args.get("dexterity_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.dexterity += increase_amount
return True
else:
return False
def increase_intelligence(entity, args):
increase_amount = args.get("intelligence_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.intelligence += increase_amount
return True
else:
return False
def increase_max_hp(entity, args):
increase_amount = args.get("max_hp_increase")
if increase_amount is not None and entity.components.get("fighter"):
fighter = entity.components["fighter"]
fighter.max_hp += increase_amount
return True
else:
return False