-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacteristic.cpp
67 lines (54 loc) · 1.57 KB
/
characteristic.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
#include "characteristic.h"
#ifndef ISHSC
#include "sheet.h"
#endif
Characteristic::Characteristic(const QJsonObject& c)
: _cost(this->cost())
{
if (c.find("base") == c.end()) throw("");
_base = c["base"].toInt(0);
_init = this->init();
_per = this->per();
}
Characteristic& Characteristic::operator=(const Characteristic& c) {
if (this != &c) _base = c._base;
return *this;
}
Characteristic& Characteristic::operator=(Characteristic&& c) {
_base = c._base;
return *this;
}
Points Characteristic::points() {
#ifndef ISHSC
Option& opt = Sheet::ref().option();
#endif
int half = _per / 2;
if (_per % 2 == 0) half--;
#ifndef ISHSC
int max = opt.normalHumanMaxima() ? _maxima : INT_MAX;
#else
int max = INT_MAX;
#endif
int val = _base - _init;
int min = (val + _init > max) ? max - _init : val;
int dbl = val - min;
return Points(((min + dbl) * _cost.points + dbl * _cost.points + half) / _per);
}
QString Characteristic::roll() {
constexpr int baseRoll = 9;
constexpr int step = 5;
constexpr int halfStep = step / 2;
QString r = QString("%1-").arg(baseRoll + (_base + _primary + halfStep) / step);
if (_secondary != 0) r += QString("/%1-").arg(baseRoll + (_base + _primary + _secondary + halfStep) / step);
return r;
}
QJsonObject Characteristic::toJson() {
QJsonObject obj;
obj["base"] = _base;
return obj;
}
QString Characteristic::value() {
QString v = QString("%1").arg(_base + _primary);
if (_secondary != 0) v += QString("/%1").arg(_base + _primary + _secondary);
return v;
}