-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
101 lines (90 loc) · 3.69 KB
/
player.py
File metadata and controls
101 lines (90 loc) · 3.69 KB
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
class Equipment:
def __init__(self):
self.sword = None
self.armor = None
self.charm = None
self.amulet = None
self.ring = None
self.charm_equipped = False
self.amulet_equipped = False
self.ring_equipped = False
def equip_sword(self, sword_item):
self.sword = sword_item
def equip_armor(self, armor_item):
self.armor = armor_item
def equip_trinket(self, trinket_item):
trinket_type = trinket_item["type"]
if trinket_type == "charm" and not self.charm_equipped:
self.charm = trinket_item
self.charm_equipped = True
return True
elif trinket_type == "amulet" and not self.amulet_equipped:
self.amulet = trinket_item
self.amulet_equipped = True
return True
elif trinket_type == "ring" and not self.ring_equipped:
self.ring = trinket_item
self.ring_equipped = True
return True
return False
def get_equipped_names(self):
return {
"sword": self.sword["name"] if self.sword else "Nothing",
"armor": self.armor["name"] if self.armor else "Nothing",
"charm": self.charm["name"] if self.charm else "Nothing",
"amulet": self.amulet["name"] if self.amulet else "Nothing",
"ring": self.ring["name"] if self.ring else "Nothing"
}
class Player:
def __init__(self):
self.base_health = 25
self.base_damage = 10
self.coins = 5
self.level = 1
self.inventory = []
self.equipment = Equipment()
self.bonus_health = 0
self.bonus_damage = 0
self.bonus_agility = 0
self.current_health = self.base_health
self.ap_used = False
self.sp_used = False
self.ap_potent = 0
self.sp_potent = 0
def get_effective_health(self):
armor_mult = self.equipment.armor["defense"] if self.equipment.armor else 1
return round((armor_mult * self.base_health) + self.bonus_health)
def get_effective_damage(self):
sword_mult = self.equipment.sword["damage"] if self.equipment.sword else 1
return round((sword_mult * self.base_damage) + self.bonus_damage)
def update_trinket_bonuses(self):
self.bonus_health = 0
self.bonus_damage = 0
self.bonus_agility = 0
for trinket in [self.equipment.charm, self.equipment.amulet, self.equipment.ring]:
if trinket:
if trinket["power"] == "health":
self.bonus_health += trinket["health"]
elif trinket["power"] == "strength":
self.bonus_damage += trinket["damage"]
elif trinket["power"] == "speed":
self.bonus_agility += trinket["speed"]
def use_potion(self, potion_item):
if potion_item["type"] == "healing":
healed = 5 * potion_item["potentcy"]
self.current_health = min(self.current_health + healed, self.get_effective_health())
elif potion_item["type"] == "agility":
self.bonus_agility += 1 * potion_item["potentcy"]
self.ap_potent = potion_item["potentcy"]
self.ap_used = True
elif potion_item["type"] == "strength":
self.sp_potent = potion_item["potentcy"]
self.bonus_damage += 5 * self.sp_potent
self.sp_used = True
def update_potion_effects(self):
if self.ap_used:
self.bonus_agility -= self.ap_potent
self.ap_used = False
if self.sp_used:
self.bonus_damage -= 5 * self.sp_potent
self.sp_used = False