-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHero.cpp
More file actions
119 lines (112 loc) · 3.28 KB
/
Hero.cpp
File metadata and controls
119 lines (112 loc) · 3.28 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "Hero.h"
#include "game.h"
Hero::Hero() {
strength = startSkill + rand() % startSkillRandom;
dexterity = startSkill + rand() % startSkillRandom;
intelligence = startSkill + rand() % startSkillRandom;
level = 1;
killed = 0;
cpoints = 0;
maxhp = startHp + strength;
hp = maxhp;
xp = 0;
maxxp = XP_table[level - 1];
visDistance = heroStartVisDistance + intelligence;
cweapon = Items[0];
carmor = Items[1];
x = 0;
y = 0;
}
void Hero::GetHero(GameMap &dMap) {
SetSymbol((short)(x + 1 - dMap.curX), (short)(y + 1 - dMap.curY), 'X', Black, Red);
}
void Hero::SetVisibleCells(GameMap &dMap) {
for (int mx = x - visDistance; mx <= x + visDistance; mx++)
for (int my = y - visDistance; my <= y + visDistance; my++)
if (mx >= 0 && my >= 0 && mx <= dMap.Width && my <= dMap.Height && Distance(mx, my, x, y) <= visDistance) {
if (dMap.MainMap[mx][my].type >= minTrap && dMap.MainMap[mx][my].type < trapKnown && dMap.MainMap[mx][my].isVisible == false && (rand() % 100 < intelligence)) {
AddLog(sSeeTrap);
dMap.MainMap[mx][my] = Tiles[trapKnown];
}
dMap.MainMap[mx][my].isVisible = true;
}
}
void Hero::HeroStep(short dx, short dy, GameMap &dMap) {
dx += x;
dy += y;
if (dx >= 0 && dy >= 0 && dx <= dMap.Width && dy <= dMap.Height && dMap.IsFree(dx, dy)) {
x = dx;
y = dy;
if (((dMap.curX + mapVisX - x) <= scrollDist) && (dMap.curX <= (dMap.Width - mapVisX)))
dMap.curX++;
else if (((dMap.curY + mapVisY - y) <= scrollDist) && (dMap.curY <= (dMap.Height - mapVisY)))
dMap.curY++;
else if (((x - dMap.curX) < scrollDist) && (dMap.curX > 0))
dMap.curX--;
else if (((y - dMap.curY) < scrollDist) && (dMap.curY > 0))
dMap.curY--;
SetVisibleCells(dMap);
if (dMap.MainMap[x][y].type >= minTrap && dMap.MainMap[x][y].type <= trapKnown)
if (rand() % 100 < (dexterity + intelligence) * trapDisarmpc) {
AddLog(sDisarmTrap);
dMap.MainMap[x][y] = Tiles[trapUsed];
}
else {
AddLog(sFallTrap);
dMap.MainMap[x][y] = Tiles[trapUsed];
int damage = (int)(hp * trapHPpc);
if (hp > 1 && damage >= hp)
damage = hp - 1;
else if (damage >= hp)
damage = hp;
if (damage == 0) damage = 1;
hp -= damage;
AddLog(sReceived + to_wstring(damage) + sDamageToHero2);
if (hp <= 0) {
hp = 0;
AddLog(sDeath);
}
}
}
}
int Hero::GetDamage() {
if (cweapon.type == blank)
return strength;
else
return strength + cweapon.damage;
}
int Hero::GetDefense() {
if (carmor.type == blank)
return 0;
else
return carmor.defense;
}
void Hero::ExpInc(float dxp) {
if (dxp > 0) {
killed++;
dxp += (dxp*intelligence) / 100;
xp += dxp;
AddLog(sReceived + FloatToWstring(dxp) + sIncExp);
if (xp >= XP_table[level - 1] && level < maxLevel) {
level++;
maxxp = XP_table[level - 1];
AddLog(sNewLevel);
cpoints += newLevelPoints;
}
int chance = rand() % 100;
if (chance < 34) {
if (chance < 11)
invertory[invertory.size()] = poultices[chance % poulticeNum];
else {
int min = 2 * (level - 2);
int max = level * 2 + 1;
if (max > itemsNum) max = itemsNum;
if (min < 0) min = 0;
if (min > max) min = max - 1;
int random = rand() % (max - min + 1) + min;
invertory[invertory.size()] = Items[random];
}
AddLog(sReceived + sItems[invertory[invertory.size() - 1].id]);
}
}
}