-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathability.py
122 lines (97 loc) · 4.5 KB
/
ability.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
121
122
import pygame
from projectile import *
from vector2 import *
class Ability:
def __init__(self, display_name, cooldown = 1,
stamina_cost_base = 0, stamina_cost_per_level = 0,
mana_cost_base = 0, mana_cost_per_level = 0,
damage_base = 0, damage_per_level = 0,
buffs = []):
self.display_name = display_name
self.cooldown = cooldown
self.stamina_cost_base = stamina_cost_base
self.stamina_cost_per_level = stamina_cost_per_level
self.mana_cost_base = mana_cost_base
self.mana_cost_per_level = mana_cost_per_level
self.damage_base = damage_base
self.damage_per_level = damage_per_level
self.buffs = buffs
def can_execute(self, data, src):
# Check if ability is on cooldown
if (data.cooldown > 0):
return False
# Check costs
if (src.stamina < self.get_stamina_cost(src.level)):
return False
if (src.mp < self.get_mana_cost(src.level)):
return False
return True
def execute(self, data, src):
# Handle cooldown and costs
data.cooldown = self.cooldown
src.modify_stamina(-self.get_stamina_cost(src.level))
src.modify_mp(-self.get_mana_cost(src.level))
def get_damage(self, level):
return self.damage_base + self.damage_per_level * (level - 1)
def get_stamina_cost(self, level):
return self.stamina_cost_base + self.stamina_cost_per_level * (level - 1)
def get_mana_cost(self, level):
return self.mana_cost_base + self.mana_cost_per_level * (level - 1)
def apply_buffs(self, target, src):
for buff in self.buffs:
target.apply_buff(buff, src)
########################################################################################################################################################
class Ability_Melee(Ability):
def can_execute(self, data, src):
if (not super().can_execute(data, src)):
return False
# Check if there is an enemy in the direction we've last moved
enemy = src.gamedata.get_enemy_in_position(src.get_melee_position(), src.faction)
if (enemy == None):
return False
return True
def execute(self, data, src):
# Handle cooldown and costs
super().execute(data, src)
# Check if there is an enemy in the direction we've last moved
enemy = src.gamedata.get_enemy_in_position(src.get_melee_position(), src.faction)
if (enemy != None):
enemy.deal_damage(self.get_damage(src.level), src)
self.apply_buffs(enemy, src)
########################################################################################################################################################
class Ability_Projectile(Ability):
def __init__(self, display_name, cooldown = 1,
stamina_cost_base = 0, stamina_cost_per_level = 0,
mana_cost_base = 0, mana_cost_per_level = 0,
damage_base = 0, damage_per_level = 0,
buffs = [],
filename = None,
duration = 5):
super().__init__(display_name, cooldown, stamina_cost_base, stamina_cost_per_level, mana_cost_base, mana_cost_per_level, damage_base, damage_per_level, buffs)
self.projectile_duration = duration
if (filename != None):
self.image = pygame.image.load(filename)
if (self.image == None):
print(f"Can't load image {filename}!")
else:
self.image_flipx = pygame.transform.flip(self.image, True, False)
self.image_up = pygame.transform.rotate(self.image, 90)
self.image_down = pygame.transform.rotate(self.image, -90)
else:
self.image = None
def can_execute(self, data, src):
if (not super().can_execute(data, src)):
return False
return True
def execute(self, data, src):
# Handle cooldown and costs
super().execute(data, src)
# Create a projectile
projectile = Projectile(src.position, src.get_direction(), data, src)
src.gamedata.add_projectile(projectile)
########################################################################################################################################################
class AbilityData:
def __init__(self, ability):
self.ability = ability
self.cooldown = 0
self.position = Vector2(0, 0)