-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magic.cpp
96 lines (91 loc) · 2.03 KB
/
Magic.cpp
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
#include "Magic.h"
#include "Character.h"
Magic::Magic(std::string newName, int dmg, int sp, DamageType dmgType, Element elem, bool req, Effect eff)
:baseDamage{ dmg }, element {elem}, spCost {sp}
{
name = newName;
type = dmgType;
requiresTarget = req;
effect = eff;
}
int Magic::getSPcost()
{
return spCost;
}
void Magic::useAction(Character* user, Character* target)
{
int damage = baseDamage;
if (baseDamage != 0)
{
damage += user->getMagicAttack(); //only adds magic attack to damage to spells that are supposed to deal damage or heal.
}
std::cout << user->getName() << " used " << name << "!\n";
user->loseSP(spCost);
if (element == healing || element == revival)
{
if (effect == normal)
{
if (element == revival)
{
target->revive();
}
else
{
target->clearStatuses();
}
}
if (damage != 0 || element == revival)
{
if (element == revival || target->condition != Character::KO)
{
if (element == revival && damage == 0)
{
damage = 1; // always revive with at least 1 hp.
}
target->recover(damage);
}
else
{
std::cout << target->getName() << " can't be healed while dead.\n";
}
}
}
else
{
target->takeDamage(damage, Character::magic, user, static_cast<Character::Element>(element));
}
if (effect != nothing)
{
//target->applyStatus(static_cast<Character::Effect>(effect));
CreateStatusEffects(target);
}
}
void Magic::useAction(Character* user, std::vector<Character*> targets)
{
int damage = user->getMagicAttack() + baseDamage;
std::cout << user->getName() << " used " << name << "!\n";
user->loseSP(spCost);
for (auto t : targets)
{
if (element == healing)
{
if (t->condition != Character::KO)
{
t->recover(damage);
}
else
{
std::cout << t->getName() << " can't be healed while dead.\n";
}
}
else
{
t->takeDamage(damage, Character::magic, user, static_cast<Character::Element>(element));
}
if (effect != nothing)
{
//t->applyStatus(static_cast<Character::Effect>(effect));
CreateStatusEffects(t);
}
}
}