-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSkill.cpp
More file actions
70 lines (54 loc) · 1.56 KB
/
Skill.cpp
File metadata and controls
70 lines (54 loc) · 1.56 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
#include "Skill.hpp"
#include "Character.hpp"
#include "Battle.hpp"
#include "TargetingRule.hpp"
#include <algorithm>
Skill::Skill(std::string skillName, int manaCost, int skillCooldown,
std::shared_ptr<TargetingRule> targetRule)
: name(std::move(skillName)), cost(manaCost), cooldown(skillCooldown),
currentCooldown(0), rule(std::move(targetRule)) {}
void Skill::resetCooldown() {
currentCooldown = cooldown;
}
void Skill::tickCooldown() {
if (currentCooldown > 0) currentCooldown--;
}
const std::string& Skill::getName() const {
return name;
}
int Skill::getCost() const {
return cost;
}
int Skill::getCooldown() const {
return cooldown;
}
int Skill::getCurrentCooldown() const {
return currentCooldown;
}
void Skill::setCost(int newCost) {
cost = std::max(0, newCost);
}
void Skill::setCooldown(int newCooldown) {
cooldown = std::max(0, newCooldown);
}
bool Skill::canUse(const std::shared_ptr<Character>& actor) const {
return getCurrentCooldown() == 0 && actor->getMana() >= getCost();
}
std::vector<std::shared_ptr<Character>> Skill::validTargets(const std::shared_ptr<Character>& actor, Battle& battle) const {
return rule ? rule->validTargets(actor, battle) : std::vector<std::shared_ptr<Character>>{};
}
void Skill::decrementCooldown() {
tickCooldown();
}
void Skill::putOnCooldown() {
resetCooldown();
}
void Skill::resetCurrentCooldown() {
currentCooldown = 0;
}
bool Skill::isReady() const {
return currentCooldown == 0;
}
std::string Skill::getDescription() const {
return "Skill";
}