-
Notifications
You must be signed in to change notification settings - Fork 6
/
unit.cpp
70 lines (56 loc) · 1018 Bytes
/
unit.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
#include "unit.h"
Unit::Unit(int hp, int cost, float walkSpeed, int atk, int attackRange, int attackDelay, int group, Battle *battle, QObject *parent)
: QObject(parent),
MaxHp(hp),
hp(hp),
cost(cost),
walkSpeed(walkSpeed),
atk(atk),
attackRange(attackRange),
attackDelay(attackDelay),
group(group),
battle(battle)
{
previousHpRatio = 100;
}
Unit::~Unit()
{
}
int Unit::getCurrentHp()
{
return hp;
}
int Unit::getMaxHp()
{
return MaxHp;
}
int Unit::getHpRatio()
{
return (hp * 100) / MaxHp;
}
int Unit::getHpChange()
{
if(hp <= 0) return -100;
else return getHpRatio() - previousHpRatio;
}
int Unit::getCost()
{
return cost;
}
void Unit::setTarget(int target)
{
this->target = target;
}
void Unit::onhit(int enemyATK)
{
hp -= enemyATK;
/* friend healer will not to overheal */
if(hp >= MaxHp) hp = MaxHp;
}
void Unit::active()
{
}
void Unit::setPreviousHpRatio()
{
previousHpRatio = getHpRatio();
}