-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassassin.cpp
More file actions
41 lines (38 loc) · 1.16 KB
/
assassin.cpp
File metadata and controls
41 lines (38 loc) · 1.16 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
#include "assassin.h"
Assassin::Assassin() // Uses base Character to set stats
{
stats[currHP] = stats[HP] -= 2;
stats[ATK] += 2;
stats[DEF] -= 5;
name = "Assassin";
}
int Assassin::attack() const
{
int roll = rand() % 100 + 1; // When Assassin attacks, a number is rolled from 1 to 100
if (roll <= critChance)
{
std::cout << "A critical hit!" << std::endl;
return stats[ATK] * critDamage; // If the number is the critChance, the Assassin crits and does damage
} //based on his critDamage
else
{
return stats[ATK]; // If he doesn't "crit", he just does the normal amount of damage
}
}
bool Assassin::takeDamage(int dmg)
{
if (dmg == 0)
return true;
int roll = rand() % 100 + 1; // When the Assassin is to be attacked, a number is rolled from 1 to 100
if (roll <= evadeChance)
{
std::cout << "You evaded the attack!" << std::endl;
}
else
{
int reducedDmg = dmg - stats[DEF]; // Otherwise, the damage taken by the assassin is calculated normally
reducedDmg = reducedDmg <= 0 ? 1 : reducedDmg;
stats[currHP] -= (reducedDmg);
}
return stats[currHP] <= 0 ? false : true;
}