forked from QwandriXCI/Conjure_Animals_Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConjure.cpp
More file actions
213 lines (200 loc) · 3.28 KB
/
Copy pathConjure.cpp
File metadata and controls
213 lines (200 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <string>
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <sstream>
using Stats = std::unordered_map<std::string, std::vector<int>>;
Stats getstats()
{
std::ifstream f("statblocks.txt");
if (f.bad())
{
std::cout << "failed to open file\n";
exit(1);
}
Stats stats;
std::string line;
while (getline(f, line))
{
std::istringstream linestrm(line);
std::string name;
linestrm >> name;
if (name.empty())
{
std::cout << "empty name\n";
exit(1);
}
if (name[0] == '#')
{
continue;
}
std::vector<int> statline;
while (linestrm.good())
{
int i;
linestrm >> i;
statline.push_back(i);
}
if (statline.size() != 12)
{
std::cout << "wrong number of stats: " << line << "\n";
exit(1);
}
stats[name] = std::move(statline);
}
return stats;
}
static auto stats = getstats();
enum class Reference
{
MAX_HP = 0,
HP,
THP,
HIT,
STR,
DEX,
CON,
INTEL,
WIS,
CHA,
DICE,
SIZE,
END
};
enum class Conditions
{
PRONE = 0,
EXHAUSTION,
STUNNED,
BLIND,
DEAF,
PARALYSED,
FRIGHTENED,
CHARMED,
GRAPPLED,
INCAPACITATED,
INVISIBLE,
PETRIFIED,
POISONED,
RESTRAINED,
UNCONSCIOUS,
END
};
class Animal
{
private:
std::string name;
int max_hp;
int hp;
int thp;
int hit;
int str;
int dex;
int con;
int intel;
int wis;
int cha;
int dice;
int size;
static std::vector<Animal> gfield;
public:
Animal(std::string creature)
{
const auto& s = stats[creature];
if (s.size() != static_cast<size_t>(Reference::END))
{
std::cout << "Could not create animal from " << creature << "\n";
exit(1);
}
name = creature;
max_hp = s[static_cast<size_t>(Reference::MAX_HP)];
hp = s[static_cast<size_t>(Reference::HP)];
thp = s[static_cast<size_t>(Reference::THP)];
hit = s[static_cast<size_t>(Reference::HIT)];
str = s[static_cast<size_t>(Reference::STR)];
dex = s[static_cast<size_t>(Reference::DEX)];
con = s[static_cast<size_t>(Reference::CON)];
intel = s[static_cast<size_t>(Reference::INTEL)];
wis = s[static_cast<size_t>(Reference::WIS)];
cha = s[static_cast<size_t>(Reference::CHA)];
dice = s[static_cast<size_t>(Reference::DICE)];
size = s[static_cast<size_t>(Reference::SIZE)];
}
void damage(std::vector<int> choices, int dmg)
{
for (int i = 0; i < choices.size(); i++)
{
Animal& ref = gfield[choices[i]];
if (ref.thp < dmg)
{
ref.thp = 0;
ref.hp -= (dmg - ref.thp);
}
else
{
ref.thp -= dmg;
}
}
}
static void summon(std::string creature, int n)
{
std::vector<Animal> field;
int i = 0;
while (i < n)
{
Animal a = Animal(creature);
field.push_back(a);
i++;
}
std::cout << field.size();
gfield = field;
}
};
int main()
{
std::string name;
std::string x;
std::cin >> name;
bool valid = false;
while (!valid)
{
if (stats.contains(name))
{
valid = true;
}
else
{
std::cout << "Invalid name\n";
std::cin >> name;
}
}
std::cin >> x;
int newx;
valid = false;
while (!valid)
{
valid = true;
for (int i = 0; i < x.length(); i++)
{
if (!isdigit(x[i]))
{
valid = false;
}
}
if (valid)
{
newx = stoi(x);
if (newx < 1 || newx > 8)
{
valid = false;
}
}
if (!valid)
{
std::cout << "invalid number\n";
std::cin >> x;
}
}
Animal::summon(name, newx);
}