-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVulnerability.h
80 lines (73 loc) · 2.7 KB
/
Vulnerability.h
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
#ifndef VULNERABILITY_H
#define VULNERABILITY_H
#include "complication.h"
#include "fraction.h"
class Vulnerability: public Complication
{
public:
Vulnerability(): Complication() { }
Vulnerability(const Vulnerability& ac)
: Complication()
, v(ac.v) { }
Vulnerability(Vulnerability&& ac)
: Complication()
, v(ac.v) { }
Vulnerability(const QJsonObject& json)
: Complication()
, v { json["attack"].toInt(0), json["where"].toInt(0), json["what"].toString("") } { }
Vulnerability& operator=(const Vulnerability& ac) {
if (this != &ac) v = ac.v;
return *this;
}
Vulnerability& operator=(Vulnerability&& ac) {
v = ac.v;
return *this;
}
QString description() override {
static QList<QString> attk { "Uncommon", "Common", "Very Common" };
static QStringList where { Fraction(1, 1, 2).toString() + "xBODY", Fraction(1, 1, 2).toString() + "xSTUN",
Fraction(1, 1, 2).toString() + "xEffect", "2xBODY", "2xSTUN", "2xEffect" };
if (v._attack < 0 || v._where < 0 || v._what.isEmpty()) return "<incomplete>";
return QString("Vulnerability: %1 (%2, %3)").arg(v._what, attk[v._attack], where[v._where]);
}
void form(QWidget* parent, QVBoxLayout* layout) override {
what = createLineEdit(parent, layout, "What are you vulnerable to?");
attack = createComboBox(parent, layout, "How common is the attack", { "Uncommmon", "Common", "Very Common" });
where = createComboBox(parent, layout, "Effect?", { Fraction(1, 2).toString() + "xBODY", Fraction(1, 2).toString() + "xSTUN",
Fraction(1, 2).toString() + "xEffect", "2xBODY", "2xSTUN", "2xEffect" });
}
Points points(bool noStore = false) override {
if (!noStore) store();
return (v._where > 2 ? 2_cp : 1_cp) * (v._attack + 1) * 5_cp;
}
void restore() override {
vars s = v;
what->setText(s._what);
where->setCurrentIndex(s._where);
attack->setCurrentIndex(s._attack);
v = s;
}
void store() override {
v._what = what->text();
v._where = where->currentIndex();
v._attack = attack->currentIndex();
}
QJsonObject toJson() override {
QJsonObject obj;
obj["name"] = "Vulnerability";
obj["attack"] = v._attack;
obj["where"] = v._where;
obj["what"] = v._what;
return obj;
}
private:
struct vars {
int _attack = -1;
int _where = -1;
QString _what = "";
} v;
QComboBox* attack;
QComboBox* where;
QLineEdit* what;
};
#endif // VULNERABILITY_H