-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruleeffect.h
116 lines (113 loc) · 4.31 KB
/
ruleeffect.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
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
#ifndef RULEEFFECT_H
#define RULEEFFECT_H
#include "json_macros.h"
#include "game.h"
class RuleEffect {
public:
QString ApplyTo;
QList<Gender> Genders;
QList<StatChange> StatChanges;
QList<BodySizeChange> BodySizeChanges;
RuleEffect(QJsonObject *d = NULL) : ApplyTo("")
{
if (d) init(d);
}
void init(QJsonObject *d)
{
for (QJsonObject::iterator it = d->begin(); it != d->end(); ++it) {
__IF_VAR_FROM_JSON_AS(it, ApplyTo, toString)
else __IF_LIST_FROM_JSON_ENUM(it, Genders, Gender)
else __IF_OBJLIST_FROM_JSON(it, StatChanges, StatChange)
else __IF_OBJLIST_FROM_JSON(it, BodySizeChanges, BodySizeChange)
}
}
bool ShouldSerializeGenders()
{
return Genders.count() > 0;
}
bool ShouldSerializeStatChanges()
{
return StatChanges.count() != 0;
}
bool ShouldSerializeBodySizeChanges()
{
return BodySizeChanges.count() != 0;
}
void ExecuteRuleForGroup()
{
/*if (ApplyTo.contains("Student")) {
for (QHash<QString, Person>::iterator it = Game.OwnStudents.Values->begin();
it != Game.OwnStudents.Values->end(); ++it)
if (!it->IsRogue)
ExecuteRuleForPerson(*it);
}
if (ApplyTo.contains("Detention") && !ApplyTo.contains("Student")) {
for (QHash<QString, Person>::iterator it = Game.OwnStudents.Values->begin();
it != Game.OwnStudents.Values->end(); ++it)
if (it->HasDetention)
ExecuteRuleForPerson(*it);
}
if (ApplyTo.contains("Parent")) {
for (QHash<QString, Person>::iterator it = Game.DictOfPersonNames.Values->begin();
it != Game.DictOfPersonNames.Values->end(); ++it)
if (it->IsParent)
ExecuteRuleForPerson(*it);
}
if (ApplyTo.contains("Staff")) {
if (ApplyTo.contains("Parent")) {
for (QMap<Person>::iterator it = Game.HiredStaff.Values->begin();
it != Game.HiredStaff.Values->end(); ++it)
if (!it->IsParent)
ExecuteRuleForPerson(*it);
} else {
for (IEnumerator<Person>::iterator it = Game.HiredStaff.Values->begin();
it != Game.HiredStaff.Values->end(); ++it)
ExecuteRuleForPerson(*it);
}
}
if (ApplyTo.contains("Teacher") && !ApplyTo.contains("Staff")) {
if (ApplyTo.contains("Parent")) {
for (IEnumerator<Person>::iterator it = Game.HiredTeacher.Values->begin();
it != Game.HiredTeacher.Values->end(); ++it)
if (!it->IsParent)
ExecuteRuleForPerson(*it);
} else {
for (IEnumerator<Person>::iterator it = Game.HiredTeacher.Values->begin();
it != Game.HiredTeacher.Values->end(); ++it)
ExecuteRuleForPerson(*it);
}
}
if (ApplyTo.contains("Principal"))
ExecuteRuleForPerson(Game.HeadTeacher);*/
}
void ExecuteRuleForPerson(Person Per)
{
if (Genders.contains(Per.gender))
AdjustPerson(&Per);
}
void AdjustPerson(Person *Per)
{
if (Per != NULL){
for (QList<StatChange>::iterator it = StatChanges.begin();
it != StatChanges.end(); ++it)
it->AdjustStat(Per);
/* for (QList<BodySizeChange>::iterator it = BodySizeChanges.begin();
it != BodySizeChanges.end(); ++it)
Per->ApplyBodySizeChange(*it);*/
}
}
/*RuleEffect(RuleEffect& rhs)
{
rhs.ApplyTo = ApplyTo;
rhs.Genders = Genders;
rhs.StatChanges = StatChanges;
rhs.BodySizeChanges = BodySizeChanges;
}*/
RuleEffect& operator=(const RuleEffect& rhs) {
ApplyTo = rhs.ApplyTo;
Genders = rhs.Genders;
StatChanges = rhs.StatChanges;
BodySizeChanges = rhs.BodySizeChanges;
};
};
#endif // RULEEFFECT_H