-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.py
More file actions
51 lines (44 loc) · 1.8 KB
/
enemy.py
File metadata and controls
51 lines (44 loc) · 1.8 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
import random
class Enemy:
def __init__(self, enemy_data, player_level, player_bonus_agility):
self.name = enemy_data["name"]
self.base_health = enemy_data["health"]
self.base_damage = enemy_data["damage"]
self.base_agility = enemy_data["agility"]
self.coin_value = enemy_data["coin_value"]
self.detectable = enemy_data["detectable"]
self.aggressive = enemy_data["aggressive"]
# Apply level scaling
level_mult = 1 + (player_level - 1) / 10
self.health = round(level_mult * self.base_health, 3)
self.damage = round(level_mult * self.base_damage, 3)
self.agility = self.base_agility + (player_bonus_agility / 4)
self.next_action = None
def get_aggressive_text(self):
if self.aggressive == True:
return "aggressive"
elif self.aggressive == False:
return "defensive"
else:
return "neutral"
def update_agility(self, player_bonus_agility):
base_agilities = {
"Goblin": 1.5,
"Zombie": 1.75,
"Skeleton": 1.25,
"Orc": 2,
"Ghost": 1.25
}
base = base_agilities.get(self.name, 1.0)
self.agility = base + (player_bonus_agility / 4)
def choose_next_action(self):
choices = [1, 2]
if self.aggressive == True:
action_num = random.choices(choices, weights=[2, 1])[0]
elif self.aggressive == False:
action_num = random.choices(choices, weights=[1, 2])[0]
elif self.aggressive == "Neutral":
action_num = random.choices(choices, weights=[1, 1])[0]
else:
action_num = random.choice([1, 2])
self.next_action = "attack" if action_num == 1 else "defend"