-
Notifications
You must be signed in to change notification settings - Fork 0
/
skill.cc
40 lines (33 loc) · 844 Bytes
/
skill.cc
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
#include <vector>
#include <unordered_map>
#include "skill.h"
Skill::~Skill() {}
void Skill::notifyObservers() {
for (Skill* skill : observers) {
skill->notify(this);
}
}
void Skill::setResources(Resources* resources) {
this->resources = resources;
}
void Skill::addObserver(Skill* skill) {
observers.emplace_back(skill);
}
void Skill::use() {
if (!isReady()) {throw std::terminate;}
useSkill();
notifyObservers();
notifyResources();
}
Skill* Skill::deepCopy(std::unordered_map<Skill*, Skill*>& copied) {
if (copied.find(this) == copied.end()) {
Skill* newSkill = copy();
copied[this] = newSkill;
for (Skill* ob : observers) {
newSkill->addObserver(ob->deepCopy(copied));
}
return newSkill;
} else {
return copied[this];
}
}