-
Notifications
You must be signed in to change notification settings - Fork 0
/
fight.cpp
88 lines (66 loc) · 2.31 KB
/
fight.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
#include "fight.h"
#include <iostream>
#include <sstream>
using namespace std;
//Self or enemy target skill?
bool Fight::autoTargetSkill(Creature &player, Creature &enemy, Skill *playerChosenSkill) {
skillReturnType attempt;
if (playerChosenSkill->getTargetType() == TYPE_SELF) {
attempt = playerChosenSkill->Use(player);
} else if (playerChosenSkill->getTargetType() == TYPE_ENEMY) {
attempt = playerChosenSkill->Use(player, enemy);
}
if (attempt == SKILL_SUCCESS ) {
msgBuffer.addMessage(msgSkillUse(playerChosenSkill->getName()));
return true;
} else {
msgBuffer.addMessage(msgSkillFails(playerChosenSkill,attempt));
return false;
}
}
Fight::Fight(PlayerCharacter &pl, Monster &e) {
player = pl;
enemy = e;
}
fightResults Fight::start() {
Skill *playerChosenSkill;
bool skillSuccess;
initInterface();
while ( !player.isDead() && !enemy.isDead()) { //Main fight loop
//4 phases:
//Phase 1: Run player buffs/debuffs
player.clearBuffTurnMultipliers();
runPreBuffs(player);
runPostBuffs(player);
if (player.isDead()) break;
//Phase 2: Player turn
updatePoints(player,enemy);
printAllBuffs(player.buffs, enemy.buffs);
printMessageBuffer(msgBuffer.getBuffer());
showMenu(player);
do {
//Get key, loop until valid
playerChosenSkill = getSkill_fight(player.skillPtrs);
//Self or enemy target skill?
skillSuccess = autoTargetSkill(player, enemy, playerChosenSkill);
} while (skillSuccess == false); //Don't advance turn until player uses a Skill
if (enemy.isDead()) break;
checkExpiry(player.buffs);
//Phase 3: Run enemy buffs/debuffs
enemy.clearBuffTurnMultipliers();
runPreBuffs(enemy);
runPostBuffs(enemy);
if (enemy.isDead()) break;
//Phase 4: Enemy turn
enemy.doTurn(player);
//if (player.isDead()) break;
checkExpiry(enemy.buffs);
}
fightResults results = {false, 0, 0};
if (player.isDead()) {
results = {false, 0, 0};
} else if (enemy.isDead()) {
results = {true, 0, enemy.getXP()};
}
return results;
}