-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCharacter_Attribute.cpp
More file actions
212 lines (188 loc) · 4.17 KB
/
Character_Attribute.cpp
File metadata and controls
212 lines (188 loc) · 4.17 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
#pragma once
#ifndef WORLDSIM_ATTRIBUTE_CPP
#define WORLDSIM_ATTRIBUTE_CPP
/* WorldSim: Skill.cpp
#include "Skill.cpp"
Manage Character skills
*/
class AttributeManager
{
public:
enum TYPE
{
STRENGTH,
AGILITY,
CHARISMA,
INTELLIGENCE,
PERCEPTION,
ENDURANCE,
COURAGE,
ENUM_COUNT
};
/* Governing attributes 0-10 (Might remove later) */
char strength; // should govern carry capacity
char agility; // governs movement, dodge
char charisma; // governs relationships
char intelligence; // should govern exp gain
char perception; // governs line of sight and traps
char endurance; // should govern energy level and expenditure
char courage; // governs morale, possibly also luck
short int total;
AttributeManager()
{
strength=0;
agility=0;
charisma=0;
intelligence=0;
perception=0;
endurance=0;
courage=0;
}
void roll(bool isMale)
{
strength=flip();
agility=flip();
charisma=flip();
intelligence=flip();
perception=flip();
endurance=flip();
courage=flip();
updateTotal();
}
char flip()
{
return globalRandom.multiFlip(10);
}
void print()
{
std::cout<<"Attributes:\n";
std::cout<<"Strength:\t"<<(int)strength<<"\n";
std::cout<<"Agility:\t"<<(int)agility<<"\n";
std::cout<<"Charisma:\t"<<(int)charisma<<"\n";
std::cout<<"Intelligence:\t"<<(int)intelligence<<"\n";
std::cout<<"Perception:\t"<<(int)perception<<"\n";
std::cout<<"Endurance:\t"<<(int)endurance<<"\n";
std::cout<<"Courage:\t"<<(int)courage<<"\n";
}
std::string toString(bool showStars = true) const
{
std::ostringstream oss;
auto formatSkill = [&oss, showStars](const std::string& skillName, char skillLevel)
{
oss << skillName;
if (showStars)
{
for (int i = 0; i < 10; ++i)
{
oss << (i < skillLevel ? '*' : '_');
}
oss << " (" << static_cast<int>(skillLevel) << ")\n";
}
else
{
oss << std::string(10 - skillName.length(), '_') << static_cast<int>(skillLevel) << "\n";
}
};
formatSkill("Strength: ", strength);
formatSkill("Agility: ", agility);
formatSkill("Charisma: ", charisma);
formatSkill("Intelligence: ", intelligence);
formatSkill("Perception: ", perception);
formatSkill("Endurance: ", endurance);
formatSkill("Courage: ", courage);
return oss.str();
}
void updateTotal()
{
total = (short int)strength+agility+charisma+intelligence+perception+endurance+courage;
}
TYPE getBestSkill()
{
char maxSkillValue = strength;
TYPE bestSkill = STRENGTH;
if (agility > maxSkillValue)
{
maxSkillValue = agility;
bestSkill = AGILITY;
}
if (charisma > maxSkillValue)
{
maxSkillValue = charisma;
bestSkill = CHARISMA;
}
if (intelligence > maxSkillValue)
{
maxSkillValue = intelligence;
bestSkill = INTELLIGENCE;
}
if (perception > maxSkillValue)
{
maxSkillValue = perception;
bestSkill = PERCEPTION;
}
if (endurance > maxSkillValue)
{
maxSkillValue = endurance;
bestSkill = ENDURANCE;
}
if (courage > maxSkillValue)
{
maxSkillValue = courage;
bestSkill = COURAGE;
}
return bestSkill;
}
char getSkillValue(TYPE skillType) const
{
switch (skillType)
{
case STRENGTH:
return strength;
case AGILITY:
return agility;
case CHARISMA:
return charisma;
case INTELLIGENCE:
return intelligence;
case PERCEPTION:
return perception;
case ENDURANCE:
return endurance;
case COURAGE:
return courage;
default:
// Handle invalid skill type if necessary
return 0;
}
}
void setSkillValue(TYPE skillType, char value)
{
switch (skillType)
{
case STRENGTH:
strength = value;
break;
case AGILITY:
agility = value;
break;
case CHARISMA:
charisma = value;
break;
case INTELLIGENCE:
intelligence = value;
break;
case PERCEPTION:
perception = value;
break;
case ENDURANCE:
endurance = value;
break;
case COURAGE:
courage = value;
break;
default:
return;
}
}
};
#endif // WORLDSIM_ATTRIBUTE_CPP