-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
501 lines (466 loc) · 20.1 KB
/
Copy pathCharacter.cpp
File metadata and controls
501 lines (466 loc) · 20.1 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
#include "Header.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
//=============================Main functions=============================
void Character::DisplayStats()
{
std::cout << "\n\n" << std::endl;
std::cout <<"============================================="<< std::endl;
std::cout << "Character Stats:" << std::endl;
std::cout << "Name: " << name << std::endl;
std::cout << "Age: " << age << std::endl;
std::cout << "Race: " << race << std::endl;
std::cout << "Profession: " << profession << std::endl;
std::cout << "Level: " << level << std::endl;
std::cout << "Description: " << description << std::endl;
std::cout <<"=================Self Stats=================="<< std::endl;
std::cout << "Health: " << health << std::endl;
std::cout << "Strength: " << strength << std::endl;
std::cout << "Agility: " << agility << std::endl;
std::cout << "Intelligence: " << intelligence << std::endl;
std::cout << "Defense: " << defense << std::endl;
std::cout << "Gold: " << gold << std::endl;
std::cout <<"============================================="<< std::endl;
std::cout << "\n\n" << std::endl;
}
void Character::RandomizeStats()
{
race = (rand() % 5 == 0) ? "Human" : (rand() % 4 == 0) ? "Elf" : (rand() % 3 == 0) ? "Dwarf" : (rand() % 2 == 0) ? "Orc" : "Goblin"; // Random race
//=============================Professions base===============================================
std::string professions_h[] = {"Warrior", "Mage", "Rogue", "Peasant"}; //For_Human
std::string professions_e[] = { "Archer", "Druid", "Ranger"}; //For_Elf
std::string professions_d[] = {"Blacksmith", "Miner", "Berserker"}; //For_Dwarf
std::string professions_o[] = {"Shaman", "Warlord", "Berserker"}; //For_Orc
std::string professions_g[] = {"Thief", "Assassin", "Scavenger"}; //For_Goblin
//=============================Randomize stats based on profession=============================
if(race == "Human") profession = professions_h[rand() % 4];
else if (race == "Elf") profession = professions_e[rand() % 3];
else if (race == "Dwarf") profession = professions_d[rand() % 3];
else if (race == "Orc") profession = professions_o[rand() % 3];
else if (race == "Goblin") profession = professions_g[rand() % 3];
//=============================Stats randomizer================================================
if(profession == "Warrior") {
health = 120;
Shealth = health;
level = 1;
description = "A strong and resilient fighter, skilled in melee combat.";
}
else if (profession == "Mage") {
health = 70;
Shealth = health;
level = 1;
description = "A master of arcane arts, capable of casting powerful spells.";
}
else if (profession == "Rogue") {
health = 80;
Shealth = health;
level = 1;
description = "A stealthy and agile character, excelling in sneaking and critical strikes.";
}
else if (profession == "Peasant") {
health = 70;
Shealth = health;
level = 1;
description = "A simple villager with basic survival skills, but untapped potential.";
}
else if (profession == "Archer") {
health = 100;
Shealth = health;
level = 1;
description = "A skilled marksman, proficient with bows and ranged attacks.";
}
else if (profession == "Druid") {
health = 110;
Shealth = health;
level = 1;
description = "A nature-based spellcaster, able to heal allies and summon creatures.";
}
else if (profession == "Ranger") {
health = 100;
Shealth = health;
level = 1;
description = "A versatile hunter, adept at tracking and surviving in the wilderness.";
}
else if (profession == "Blacksmith") {
health = 120;
Shealth = health;
level = 1;
description = "A master craftsman, able to forge powerful weapons and armor.";
}
else if (profession == "Miner") {
health = 140;
Shealth = health;
level = 1;
description = "A hardy worker, skilled in extracting valuable resources from the earth.";
}
else if (profession == "Berserker") {
health = 130;
Shealth = health;
level = 1;
description = "A fierce warrior who thrives in the heat of battle, gaining strength as they fight.";
}
else if (profession == "Shaman") {
health = 120;
Shealth = health;
level = 1;
description = "A spiritual guide, able to commune with spirits and harness elemental powers.";
}
else if (profession == "Warlord") {
health = 140;
Shealth = health;
level = 1;
description = "A strategic leader, commanding troops and inspiring allies on the battlefield.";
}
else if (profession == "Thief") {
health = 80;
Shealth = health;
level = 1;
description = "A cunning and resourceful character, skilled in stealing and deception.";
}
else if (profession == "Assassin") {
health = 90;
Shealth = health;
level = 1;
description = "A deadly and silent killer, specializing in eliminating targets quickly and efficiently.";
}
else if (profession == "Scavenger") {
health = 100;
Shealth = health;
level = 1;
description = "A resourceful survivor, adept at finding valuable items and making the most of limited resources.";
}
//=============================Name randomizer=================================================
std::string firstNames_h[] = {"Arin", "Bryn", "Cora", "Dain", "Eira", "Finn", "Gwen", "Hale", "Iris", "Jax"};
std::string lastNames_h[] = {"Stormwind", "Shadowbane", "Ironfist", "Silverleaf", "Darkwood", "Brightblade", "Stoneheart", "Moonshadow", "Fireforge", "Duskwhisper"};
std::string firstNames_e[] = {"Elara", "Thalion", "Lirael", "Eldrin", "Sylvara", "Faelar", "Aeris", "Galadriel", "Riven", "Nimriel"};
std::string lastNames_e[] = {"Starweaver", "Moonwhisper", "Sunblade", "Duskbloom", "Silvermoon", "Shadowdancer", "Windrider", "Nightshade", "Frostfall", "Lightbringer"};
std::string firstNames_d[] = {"Thorin", "Balin", "Dwalin", "Gimli", "Oin", "Gloin", "Dori", "Nori", "Ori", "Bifur"};
std::string lastNames_d[] = {"Ironforge", "Stonehelm", "Goldbeard", "Hammerfall", "Deepdelve", "Anvilmar", "Bronzebeard", "Fireforge", "Stormhammer", "Frostbeard"};
std::string firstNames_o[] = {"Grommash", "Garrosh", "Thrall", "Durotan", "Orgrim", "Kargathia", "Zul'jin", "Kilrogg", "Nazgrel", "Mok'Nathal"};
std::string lastNames_o[] = {"Hellscream", "Doomhammer", "Shadowmoon", "Warsong", "Blackrock", "Frostwolf", "Bleeding Hollow", "Shattered Hand", "Burning Blade", "Skullcrusher"};
std::string firstNames_g[] = {"Grimtooth", "Snaggletooth", "Gobblesnort", "Snotgoblin", "Fizzlefink", "Muckwump", "Raggleflap", "Zogmug", "Blightfang", "Wartnose"};
std::string lastNames_g[] = {"Rotfang", "Snotlicker", "Guttergrin", "Pusface", "Filthsnout", "Mucknose", "Raggleflap", "Zogmug", "Blightfang", "Wartnose"};
if (race == "Human") {
name = firstNames_h[rand() % 10] + " " + lastNames_h[rand() % 10];
}
else if (race == "Elf") {
name = firstNames_e[rand() % 10] + " " + lastNames_e[rand() % 10];
}
else if (race == "Dwarf") {
name = firstNames_d[rand() % 10] + " " + lastNames_d[rand() % 10];
}
else if (race == "Orc") {
name = firstNames_o[rand() % 10] + " " + lastNames_o[rand() % 10];
}
else if (race == "Goblin") {
name = firstNames_g[rand() % 10] + " " + lastNames_g[rand() % 10];
}
//=============================Age randomizer=================================================
age = 18 + rand() % 83; // Random age between 18 and 100
//=============================Stats randomizer based on profession=============================
if(profession == "Warrior") {
strength = 25+ rand() % 11; // Random strength between 25 and 35
agility = 15 + rand() % 11; // Random agility between 15 and 25
intelligence = 5 + rand() % 6; // Random intelligence between 5 and 10
defense = 20 + rand() %11; // Random defense between 20 and 28
gold = 40 + rand() % 21; // Random gold between 40 and 60
}
else if (profession == "Mage") {
strength = 15 + rand() % 6; // Random strength between 15 and 20
agility = 10 + rand() % 6; // Random agility between 10 and 15
intelligence =20 + rand() %11; // Random intelligence between 20 and 30
defense = 8 + rand() % 7; // Random defense between 8 and 15
gold = 25 + rand() % 21; // Random gold between 25 and 45
}
else if (profession == "Rogue") {
strength = 10 + rand() % 11; // Random strength between 10 and 15
agility = 15 + rand() % 6; // Random agility between 15 and 20
intelligence = 10 + rand() % 6; // Random intelligence between 10 and 15
defense = 10 + rand() % 6; // Random defense between 10 and 15
gold = 80 + rand() % 21; // Random gold between 80 and 100
}
else if (profession == "Peasant") {
strength = 5 + rand() % 6; // Random strength between 5 and 10
agility = 8 + rand() % 8; // Random agility between 8 and 15
intelligence = 8 + rand() % 8; // Random intelligence between 8 and 15
defense = 5 + rand() % 6; // Random defense between 5 and 10
gold = 20 + rand() % 11; // Random gold between 20 and 30
}
else if (profession == "Archer") {
strength = 15 + rand() % 11; // Random strength between 15 and 25
agility = 20 + rand() % 11; // Random agility between 20 and 30
intelligence = 20 + rand() % 6; // Random intelligence between 20 and 25
defense = 10 + rand() % 6; // Random defense between 10 and 15
gold = 50 + rand() % 21; // Random gold between 50 and 70
}
else if (profession == "Druid") {
strength = 5 + rand() % 6; // Random strength between 5 and 10
agility = 5 + rand() % 5; // Random agility between 5 and 10
intelligence = 30 + rand() %11; // Random intelligence between 30 and 40
defense = 12 + rand() % 4; // Random defense between 12 and 15
gold = 50 + rand() % 21; // Random gold between 50 and 70
}
else if (profession == "Ranger") {
strength = rand() % 15 + 10; // Random strength between 10 and 25
agility = 20 + rand() % 11; // Random agility between 20 and 30
intelligence = 15 + rand() % 11; // Random intelligence between 15 and 25
defense = 15 + rand() % 11; // Random defense between 15 and 25
gold = 50 + rand() % 21; // Random gold between 50 and 70
}
else if (profession == "Blacksmith") {
strength = 15 + rand() % 11; // Random strength between 15 and 25
agility = 8 + rand() % 6; // Random agility between 8 and 14
intelligence = 20 + rand() % 6; // Random intelligence between 20 and 25
defense = 10 + rand() % 11; // Random defense between 10 and 20
gold =50 + rand() % 21; // Random gold between 50 and 70
}
else if (profession == "Miner") {
strength = 20 + rand() % 11; // Random strength between 20 and 30
agility = 5 + rand() % 6; // Random agility between 5 and 10
intelligence = 15 + rand() % 6; // Random intelligence between 10 and 15
defense = 15 + rand() % 11; // Random defense between 15 and 25
gold = 70 + rand() % 21; // Random gold between 70 and 90
}
else if (profession == "Berserker") {
strength = 20 + rand() % 11; // Increased strength for Berserker
agility = 10 + rand() % 6; // Balanced agility
intelligence = 5 + rand() % 11; // Lower intelligence for Berserker
defense = 15 + rand() % 11; // Increased defense for Berserker
gold = 30 + rand() % 21; // Starting gold for Berserker
}
else if (profession == "Shaman") {
strength = 10 + rand() % 6; // Random strength between 10 and 15
agility = 8 + rand() % 7; // Random agility between 8 and 15
intelligence = 25 + rand() % 6; // Random intelligence between 25 and 30
defense = 12 + rand() % 4; // Random defense between 12 and 15
gold = 50 + rand() % 21; // Random gold between 50 and 70
}
else if (profession == "Warlord") {
strength = 20 + rand() % 11; // Random strength between 20 and 30
agility = 15 + rand() % 6; // Random agility between 15 and 20
intelligence = 15 + rand() % 11; // Random intelligence between 15 and 20
defense = 15 + rand() % 11; // Random defense between 15 and 25
gold = 20 + rand() % 21; // Random gold between 20 and 40
}
else if (profession == "Thief") {
strength = 10+ rand() % 6; // Random strength between 10 and 15
agility = 15 + rand() % 11; // Random agility between 15 and 25
intelligence = 10 + rand() % 6; // Random intelligence between 10 and 15
defense = 8 + rand() % 8; // Random defense between 8 and 15
gold = 80 + rand() % 21; // Random gold between 80 and 100
}
else if (profession == "Assassin") {
strength = 15 + rand() % 6; // Random strength between 12 and 20
agility = 18 + rand() % 7; // Random agility between 18 and 24
intelligence = 8 + rand() % 6; // Random intelligence between 8 and 13
defense = 15 + rand() % 6; // Random defense between 10 and 15
gold = 70 + rand() % 21; // Random gold between 70 and 90
age = 18 + rand() % 27; // Random age between 18 and 45 for Assassin
}
else if (profession == "Scavenger") {
strength = 10 + rand() % 6; // Random strength between 10 and 15
agility = 12 + rand() % 6; // Random agility between 12 and 17
intelligence = 8 + rand() % 6; // Random intelligence between 8 and 13
defense = 10 + rand() % 6; // Random defense between 10 and 15
gold = 80 + rand() % 21; // Random gold between 80 and 100
}
//=============================End of randomization=============================
}
std::string GetEffectName(int type) {
switch (type) {
case 0: return "Health";
case 1: return "Defense";
case 2: return "Agility";
case 3: return "Intelligence";
case 4: return "Gold";
case 5: return "Strength";
default: return "Unknown";
}
}
void Character::EquipWeapon(Weapon* w)
{
if (equipped_weapon) {
equipped_weapon->Reset();
}
equipped_weapon = w;
if (equipped_weapon) {
equipped_weapon->Use();
GetTotalAttack();
GetTotalDefense();
}
}
void Character::EquipArmor(Armory* a)
{
if (equipped_armor) {
equipped_armor->Reset();
}
equipped_armor = a;
if (equipped_armor) {
equipped_armor->Use();
GetTotalAttack();
GetTotalDefense();
}
}
void Character::UnequipWeapon()
{
if (equipped_weapon) {
equipped_weapon->Reset();
equipped_weapon = nullptr;
}
}
void Character::UnequipArmor()
{
if (equipped_armor) {
equipped_armor->Reset();
equipped_armor = nullptr;
}
}
void Character::Usage()
{
std::cout << "\n" << this->name << " is using their equipment...\n";
std::cout << "=== Equipped Gear ===\n";
if (equipped_weapon) {
std::cout << "Weapon: " << equipped_weapon->GetName() << std::endl;
equipped_weapon->ShowInfo();
} else {
std::cout << "Weapon: None\n";
}
if (equipped_armor) {
std::cout << "Armor: " << equipped_armor->GetName() << std::endl;
equipped_armor->ShowInfo();
} else {
std::cout << "Armor: None\n";
}
std::cout << "=== Total Stats ===\n";
std::cout << "Total Attack: " << GetTotalAttack() << std::endl;
std::cout << "Total Defense: " << GetTotalDefense() << std::endl;
if (!activeEffects.empty()) {
std::cout << "Active Effects:\n";
for (const auto& eff : activeEffects) {
std::cout << "- " << GetEffectName(eff.type) << (eff.isDebuff ? " (Debuff)" : " (Buff)") << ": " << eff.potency << std::endl;
}
}
std::cout << "=====================\n";
}
void Character::Take() {
if (!currentChest) {
std::cout << "No chest selected!\n";
return;
}
int itemCount = currentChest->GetItemCount();
if (itemCount == 0) {
std::cout << "Chest is empty!\n";
return;
}
std::cout << "\n=== Items in chest ===\n";
for (int i = 0; i < itemCount; ++i) {
std::cout << i + 1 << ". ";
currentChest->GetItem(i)->ShowInfo();
}
std::cout << "0. Cancel\n";
int choice;
std::cout << "Select item to take: ";
std::cin >> choice;
if (choice == 0) return;
if (choice < 1 || choice > itemCount) {
std::cout << "Invalid choice!\n";
return;
}
Item* selectedItem = currentChest->GetItem(choice - 1);
if (inventory) {
inventory->AddItem(selectedItem); // <-- ТУТ inventory->, а не inventory.
currentChest->RemoveItem(choice - 1);
std::cout << "Successfully taken " << selectedItem->GetName() << "!\n";
} else {
std::cout << "Inventory not linked to character!\n";
}
}
void Character::TakeAll() {
if (!currentChest) {
std::cout << "No chest selected!\n";
return;
}
int itemCount = currentChest->GetItemCount();
if (itemCount == 0) {
std::cout << "Chest is already empty!\n";
return;
}
std::cout << "\nTaking all items from chest...\n";
if (!inventory) {
std::cout << "Inventory not linked to character!\n";
return;
}
for (int i = itemCount - 1; i >= 0; --i) {
Item* item = currentChest->GetItem(i);
inventory->AddItem(item); // <-- ТУТ теж inventory->
currentChest->RemoveItem(i);
std::cout << "- Taken " << item->GetName() << std::endl;
}
std::cout << "All items transferred to inventory!\n";
}
void Character::ApplyPotionEffect(int effectType, int potency) {
switch (effectType) {
case 0: // HEALTH
health += potency;
std::cout << name << " restored " << potency << " HP!" << std::endl;
break;
case 1: // DEFENSE
defense += potency;
std::cout << name << " defense increased by " << potency << std::endl;
break;
case 2: // AGILITY
agility += potency;
std::cout << name << " agility increased by " << potency << std::endl;
break;
case 3: // INTELLIGENCE
intelligence += potency;
std::cout << name << " intelligence increased by " << potency << std::endl;
break;
case 4: // GOLD
gold += potency;
std::cout << name << " got " << potency << " gold!" << std::endl;
break;
case 5: // STRENGTH
strength += potency;
std::cout << name << " strength increased by " << potency << std::endl;
break;
default:
std::cout << "Unknown potion effect!" << std::endl;
}
}
Weapon* Character::GetEquippedWeapon() const { return equipped_weapon; }
Armory* Character::GetEquippedArmor() const { return equipped_armor; }
int Character::GetTotalAttack() const { return strength + (equipped_weapon ? equipped_weapon->GetAttack() : 0); }
int Character::GetTotalDefense() const { return defense + (equipped_armor ? equipped_armor->GetDefense() : 0); }
void Character::AddEffect(int type, int potency, bool debuff) {
ActiveEffect eff;
eff.type = type;
eff.potency = potency;
eff.isDebuff = debuff;
activeEffects.push_back(eff);
std::cout << name << " gained effect: " << GetEffectName(type);
}
void Character::ProcessEffects() {
for (auto it = activeEffects.begin(); it != activeEffects.end(); ) {
switch (it->type) {
case 0:
if (it->isDebuff) {
if (health !=Shealth){
health += it->potency;
std::cout << name << " takes " << (-it->potency) << " poison damage! (HP: " << health << ")\n";
}
else std::cout << name << " is at full health.\n";
} else {
// не afford health regen over time from potion (instant only)
}
break;
case 1: defense += it->potency; break;
case 2: agility += it->potency; break;
case 3: intelligence += it->potency; break;
case 4: gold += it->potency; break;
case 5: strength += it->potency; break;;
}
}
}