-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.cpp
More file actions
937 lines (807 loc) · 31.3 KB
/
Inventory.cpp
File metadata and controls
937 lines (807 loc) · 31.3 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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
//Authors Nicolas Post and Ryan Greir
#include <iostream>
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include "Inventory.h"
#include "Cookware.h"
#include "Treasure.h"
#include "Monster.h"
#include "Map.h"
#define BOLDWHITE "\033[1m\033[37m"
#define RESET "\033[0m"
using namespace std;
using namespace std::this_thread;
using namespace std::chrono_literals;
Inventory::Inventory()
{
for(int i = 0; i < 5; i++)
{
weapons_[i] = "";
}
armor_ = 0;
ingredients_ = 0;
}
Inventory::Inventory(string weapons[5], int armor, int ingredients, int gold)
{
for(int i = 0; i < 5; i++)
{
weapons_[i] = weapons[i];
}
armor_ = armor;
ingredients_ = ingredients;
gold_ = gold;
}
string Inventory::getWeapons(int index)
{
return weapons_[index];
}
void Inventory::setWeaponsAt(string weapon, int index)
{
weapons_[index] = weapon;
}
int Inventory::getNumWeapons() {
int num_weapons = 0;
for (int i = 0; i < 5; i++) {
if (weapons_[i].length() > 0)
num_weapons++;
}
return num_weapons;
}
int Inventory::getArmor()
{
return armor_;
}
void Inventory::setArmor(int armor)
{
armor_ = armor;
}
void Inventory::setMemberArmor(int index, bool armor) {
party_[index].setArmor(armor);
}
int Inventory::getIngredients()
{
return ingredients_;
}
void Inventory::setIngredients(int ingredients)
{
ingredients_ = ingredients;
}
int Inventory::getGold()
{
return gold_;
}
void Inventory::setGold(int gold)
{
gold_ = gold;
}
vector<Cookware> Inventory::getCookware() {
return cookwares_;
}
Cookware Inventory::getCookwareAt(int index) {
return cookwares_.at(index);
}
void Inventory::addCookware(Cookware new_ware) {
cookwares_.push_back(new_ware);
}
void Inventory::removeCookware(int index) {
cookwares_.erase(cookwares_.begin() + index);
}
vector<Treasure> Inventory::getTreasures() {
return treasures_;
}
Treasure Inventory::getTreasureAt(int index) {
return treasures_.at(index);
}
void Inventory::addTreasure(Treasure new_treasure) {
treasures_.push_back(new_treasure);
}
void Inventory::setMemberAt(Member m, int index) {
party_[index] = m;
}
//returns member with said name unless it does not exist, else return blank member
Member Inventory::getMemberByName(string name) {
for (int i = 0; i < 5; i++) {
if (party_[i].getName() == name) {
return party_[i];
}
}
return Member();
}
//returns member with said name unless it does not exist, else return blank member
int Inventory::getMemberIndex(string name) {
for (int i = 0; i < 5; i++) {
if (party_[i].getName() == name) {
return i;
}
}
return -1;
}
Member Inventory::getMember(int index) {
return party_[index];
}
//check num players, counts num players other than user
int Inventory::getNumMembers() {
int num_players;
for (int i = 1; i < 4; i++) {
if (party_[i].getName().length() > 0)
num_players++;
}
return num_players;
}
void Inventory::setMemberFullnessAt(int index, int fullness) {
party_[index].setFullness(fullness);
}
void Inventory::setKeys(int keys) {
keys_ = keys;
}
int Inventory::getKeys() {
return keys_;
}
void Inventory::setMonstersKilled(int num_monsters) {
monsters_killed_ = num_monsters;
}
int Inventory::getMonstersKilled() {
return monsters_killed_;
}
void Inventory::addDeadMonster(Monster m) {
dead_monsters_.push_back(m);
}
Monster Inventory::getDeadMonster(string name) {
for (int i = 0; i < dead_monsters_.size(); i++) {
if (dead_monsters_.at(i).getMonsterName() == name) {
return dead_monsters_.at(i);
}
}
return Monster();
}
void Inventory::printInv() {
cout << "________________________________________" << endl;
cout << "INVENTORY:" << endl;
cout << "\tGold: " << gold_ << endl;
cout << "\tIngredients: " << ingredients_ << " kg" << endl;
cout << "\tCookware: ";
for (int i = 0; i < cookwares_.size(); i++)
cout << cookwares_.at(i).getName() << "\t";
cout << endl << endl;
cout << "\tWeapons:" << endl;
for (int i = 0; i < 5; i++)
cout << "\t\t" << party_[i].getName() << ": " << weapons_[i] << endl;
cout << "\tArmor: " << armor_ << endl;
cout << "\tTreasures: ";
for (int i = 0; i < treasures_.size(); i++)
cout << treasures_.at(i).getName() << "\t";
cout << endl << "________________________________________" << endl;
}
//print status each turn
void Inventory::statusUpdate(int rooms_cleared, int keys, int anger) {
sleep_for(.5s);
cout << "________________________________________" << endl;
cout << "STATUS:" << endl;
cout << "\tRooms Cleared: " << rooms_cleared << " | Keys: " << keys << " | Anger Level: " << anger << endl;
// sleep_for(.5s);
printInv();
// sleep_for(.5s);
cout << "PARTY:" << endl;
for (int i = 0; i < 5; i++)
cout << "\t" << party_[i].getName() << "\t| Fullness: " << party_[i].getFullness() << endl;
cout << "________________________________________" << endl;
// sleep_for(.5s);
}
//monster fight
//random num generator in miscFunctions.cpp
bool Inventory::monsterFight(Monster m)
{
int num_weapons = 0;
int add_1 = 0;
int add_2 = 0;
int add_3 = 0;
for (int i = 0; i < 5; i++)
{
if(weapons_[i] != "")
{
if(weapons_[i].substr(0,4) == "(+1)")
{
add_1++;
}
if(weapons_[i].substr(0,4) == "(+2)")
{
add_2++;
}
if(weapons_[i].substr(0,4) == "(+3)")
{
add_3++;
}
num_weapons++;
}
}
int weapon_stats = 0;
weapon_stats = num_weapons + add_1 + add_2 + add_3;
int diff_weapon = 0;
int diff_bonus = 0;
for (int i = 0; i < 5; i++)
{
if (weapons_[i] != weapons_[0] && weapons_[i] != weapons_[1] && weapons_[i] != weapons_[2] && weapons_[i] != weapons_[3] && weapons_[i] != weapons_[4])
{
diff_weapon++;
}
}
if (diff_weapon >= num_weapons && num_weapons != 0)
{
diff_bonus = 4;
}
else
{
diff_bonus = 0;
}
Map random;
//generate random numbers
int r1 = random.randomNum(1, 6);
sleep_for(2.5s);
int r2 = random.randomNum(1, 6);
//actual calculation of the monster fight
int monster_fight = ((r1 * weapon_stats + diff_bonus) - ((r2 * m.getChallengeRating()) / armor_));
if(monster_fight > 0)
{
//add gold and food
gold_ += (10 * m.getChallengeRating());
ingredients_ += (5 * m.getChallengeRating());
cout << endl << "\tYour party has defeated the " << m.getMonsterName() << endl;
cout << endl << "\tYour party found " << 10 * m.getChallengeRating() << " gold and " << 5 * m.getChallengeRating() << " ingredients!" << endl;
if(misfortuneCalc(10) == true)
{
keys_ += 1;
cout << endl << BOLDWHITE << "\tYour party has found a key!" << RESET << endl << endl;
}
dead_monsters_.push_back(m);
return true;
}
else if(monster_fight <= 0)
{
cout << "Your party has failed to defeat the " << m.getMonsterName() << "!" << endl;
gold_ = (int)(gold_ * .75);
if(ingredients_ - 30 < 0)
{
cout << endl << "Your party has lost all its ingredients!" << endl;
ingredients_ = 0;
}
else
{
cout << endl << "Your party has lost 30 ingredients!" << endl;
ingredients_ = ingredients_- 30;
}
//check to see if the party members die
for (int i = 1; i < 4; i++) {
if (party_[i].getArmor()) {
if (misfortuneCalc(5)) {
cout << endl << party_[i].getName() << " has been slain by the " << m.getMonsterName() << "!" << endl;
death(party_[i]);
}
} else {
if (misfortuneCalc(10)) {
cout << endl << party_[i].getName() << " has been slain by the " << m.getMonsterName() << "!" << endl;
death(party_[i]);
}
}
}
dead_monsters_.push_back(m);
return false;
}
return false;
}
Monster Inventory::monsterPick(int rooms_cleared) {
Monster arr[21];
arr[0].readMonster("monsters.txt", arr, 21);
if (rooms_cleared == 0) {
return aliveAtLevel(0, 3, arr);
}
else if (rooms_cleared == 1) {
return aliveAtLevel(4, 7, arr);
}
else if (rooms_cleared == 2) {
return aliveAtLevel(8, 11, arr);
}
else if (rooms_cleared == 3) {
return aliveAtLevel(12, 15, arr);
}
else if (rooms_cleared >= 4) {
return aliveAtLevel(16, 19, arr);
}
return Monster("error", 0);
}
void Inventory::merchantMenu(int rooms_cleared) {
int merchant_menu = 0;
double price_factor;
if (rooms_cleared > 0)
price_factor = 1 + (.25 * rooms_cleared);
else
price_factor = 1;
do {
cout << endl;
cout << "________________________________________" << endl;
cout << "MERCHANT MENU:" << endl;
cout << "________________________________________" << endl;
cout << "Choose one of the following" << endl;
cout << "1. Cookware: You will need something to cook those ingredients." << endl;
cout << "2. Ingredients: To make food, you have to cook raw ingredients. " << endl;
cout << "3. Weapons: It's dangerous to go alone, take this!" << endl;
cout << "4. Armor: If you want to survive monster attacks, you will need some armor." << endl;
cout << "5. Sell treasures: If you find anything shiny, I would be happy to take it off your hands." << endl;
cout << "6. Leave: Make sure you get everything you need, I'm leaving after this sale!" << endl;
cin >> merchant_menu;
if(merchant_menu == 1)
{
//define cookware objs to be added
Cookware ceramic_pot("Ceramic Pot", 2, .25);
Cookware frying_pan("Frying Pan", 10, .1);
Cookware cauldron("Cauldron", 20, .02);
int cookware_choice = 0;
while(cookware_choice != 4) {
cout << endl << endl << "I have a whole assortment of cookware, what kind would you like?" << endl;
cout << "Each type has a different probability of breaking when used, marked with (XX%)." << endl;
cout << "\tChoose one of the following:" << endl;
cout << "\t1. (25%) Ceramic Pot [" << (int)(2*price_factor) << " Gold]" << endl;
cout << "\t2. (10%) Frying Pan [" << (int)(10*price_factor) << " Gold]" << endl;
cout << "\t3. (02%) Cauldron [" << (int)(20*price_factor) << " Gold]" << endl;
cout << "\t4. Exit Menu" << endl;
cin >> cookware_choice;
if(cookware_choice == 1 && getGold() >= (int)(2*price_factor))
{
setGold(getGold() - (int)(2*price_factor));
addCookware(ceramic_pot);
}
else if (cookware_choice == 1)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
if(cookware_choice == 2 && getGold() >= (int)(10*price_factor))
{
setGold( getGold() - (int)(10*price_factor));
addCookware(frying_pan);
}
else if (cookware_choice == 2)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
if(cookware_choice == 3 && getGold() >= (int)(20*price_factor))
{
setGold( getGold() - (int)(20*price_factor));
addCookware(cauldron);
}
else if (cookware_choice == 3)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
if (cookware_choice < 1 || cookware_choice > 4)
cout << "Invalid Input" << endl;
}
}
//ingredients menu
if(merchant_menu == 2){
int num_ingredients = -1;
cout << endl << "I reccomend you purchase at least 10 kg of ingredients per person." << endl << endl;
cout << "How many kg of ingredients do you need [" << (int)(1*price_factor) << " Gold/kg]? (Enter a positive mulitple of 5, or 0 to cancel)" << endl;
cin >> num_ingredients;
while(num_ingredients < 0)
{
cout << "That is an invalid input. Please enter a positive number." << endl;
cin >> num_ingredients;
}
if( getGold() >= num_ingredients * (int)(1*price_factor) && num_ingredients > 0)
{
setIngredients(getIngredients() + num_ingredients);
setGold(getGold() - (num_ingredients * (int)(1*price_factor)));
cout << endl << "Success! Your party now has " << getIngredients() << " kg of ingredients." << endl << endl << endl;
cout << "Thank you for your patronage! What else can I get for you?" << endl;
}
else
cout << "Insufficient funds for " << num_ingredients << " ingredients." << endl;
}
//weapon buying menu
//buy up to 5 weapons, first player gets first weapon, second gets second... so on
if(merchant_menu == 3)
{
int weapon_choice = 0, player_index = 0;
string player_name;
cout << endl << endl << "I have a plentiful collection of weapons to choose from, what would you like?" << endl << "Note that some of them provide you a special bonus in combat, marked by a (+X).";
do {
cout << endl << "\tChoose one of the following: " << endl;
cout << "\t1. Stone Club [" << (int)(2*price_factor) << " Gold]" << endl;
cout << "\t2. Iron Spear [" << (int)(2*price_factor) << " Gold]" << endl;
cout << "\t3. (+1) Mythril Rapier [" << (int)(5*price_factor) << " Gold]" << endl;
cout << "\t4. (+2) Flaming Battle-Axe [" << (int)(15*price_factor) << " Gold]" << endl;
cout << "\t5. (+3) Vorpal Longsword [" << (int)(50*price_factor) << " Gold]" << endl;
cout << "\t6. Cancel" << endl;
cin >> weapon_choice;
if (weapon_choice != 6) {
cout << endl << "\tWhich party member would you like to recieve this weapon? (player name)" << endl;
cin >> player_name;
}
while (getMemberByName(player_name).getName() == "") {
cout << endl << "No player found by the name: " << player_name << endl;
cout << "Please enter the name again" << endl;
cin >> player_name;
}
player_index = getMemberIndex(player_name);
if (weapon_choice == 1 && getGold() >= (int)(2*price_factor)) {
setGold(getGold() - (int)(2*price_factor));
setWeaponsAt("Stone Club", player_index);
cout << endl << "Success! Player: " << getMember(player_index).getName() << " now has a Stone Club!" << endl;
player_index++;
cout << "Thank you for your patronage! You have " << getGold() << " remaining gold. What else can I get for you?" << endl << endl;
} else if (weapon_choice == 1)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
else if (weapon_choice == 2 && getGold() >= (int)(2*price_factor)) {
setGold(getGold() - (int)(2*price_factor));
setWeaponsAt("Iron Spear", player_index);
cout << endl << "Success! Player: " << getMember(player_index).getName() << " now has an Iron Spear!" << endl;
player_index++;
cout << "Thank you for your patronage! You have " << getGold() << " remaining gold. What else can I get for you?" << endl << endl;
} else if (weapon_choice == 2)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
else if (weapon_choice == 3 && getGold() >= (int)(5*price_factor)) {
setGold( getGold() - (int)(5*price_factor));
setWeaponsAt("(+1) Mythril Rapier", player_index);
cout << endl << "Success! Player: " << getMember(player_index).getName() << " now has a (+1) Mythril Rapier!" << endl;
player_index++;
cout << "Thank you for your patronage! You have " << getGold() << " remaining gold. What else can I get for you?" << endl << endl;
} else if (weapon_choice == 3)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
else if (weapon_choice == 4 && getGold() >= (int)(15*price_factor)) {
setGold( getGold() - (int)(15*price_factor));
setWeaponsAt("(+2) Flaming Battle-Axe", player_index);
cout << endl << "Success! Player: " << getMember(player_index).getName() << " now has a (+2) Flaming Battle-Axe!" << endl;
player_index++;
cout << "Thank you for your patronage! You have " << getGold() << " remaining gold. What else can I get for you?" << endl << endl;
} else if (weapon_choice == 4)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
else if (weapon_choice == 5 && getGold() >= (int)(50*price_factor)) {
setGold(getGold() - (int)(50*price_factor));
setWeaponsAt("(+3) Vorpal Longsword", player_index);
cout << endl << "Success! Player: " << getMember(player_index).getName() << " now has a (+3) Vorpal Longsword!" << endl;
player_index++;
cout << "Thank you for your patronage! You have " << getGold() << " remaining gold. What else can I get for you?" << endl << endl;
} else if (weapon_choice == 5)
cout << "Insufficient Funds" << endl << "No items were purchased. Try again." << endl;
else
cout << endl << "Invalid Input. Try again" << endl;
} while (weapon_choice != 6 && player_index < 5);
}
if(merchant_menu == 4)
{
int armor_choice = 0;
cout << "Each suit costs " << (int)(5*price_factor) << " gold. How many suits of armor can I get you? " << endl << "(Enter a positive integer, or 0 to cancel)" << endl;
cin >> armor_choice;
if (getGold() >= (armor_choice * ((int)(5*price_factor))) && armor_ + armor_choice <= 5) {
for (int i = 0; i < armor_choice && armor_ <= 5;) {
if (!(party_[i].getArmor())) {
party_[i].setArmor(true);
setArmor(armor_ + 1);
i++;
}
}
setGold( getGold() - armor_choice * ((int)(5*price_factor)));
cout << endl << "Success! Your party now has " << armor_ << " suits of armor." << endl;
cout << "Thank you for your patronage! What else can I get for you?" << endl;
}
else if (armor_choice > 0 && armor_choice <= 5 && getGold() < (armor_choice * ((int)(5*price_factor))))
cout << "Insufficient funds for " << armor_choice << " suits of armor." << endl;
else if (armor_choice < 0)
cout << "Invalid Input" << endl;
else if (armor_choice + armor_ > getNumMembers()+1)
cout << "You only have " << getNumMembers() + 1 << " players... where are the extra suits going?" << endl << "No suits were purchased. Try again." << endl;
sleep_for(2s);
}
//treasure selling option
if(merchant_menu == 5)
{ char sell_menu;
if(treasures_.size() > 0)
{
cout << endl << "I see you have these item(s), I'd be happy to take them off your hands." << endl << endl;
for (int i = 0; i < treasures_.size(); i++){
if (treasures_.at(i).getName() == "Silver Ring")
cout << "Silver ring - 10 gold pieces each" << endl;
if (treasures_.at(i).getName() == "Ruby Necklace")
cout << "Ruby necklace - 20 gold pieces each" << endl;
if (treasures_.at(i).getName() == "Emerald Bracelet")
cout << "Emerald bracelet - 30 gold pieces each" << endl;
if (treasures_.at(i).getName() == "Diamond Circlet")
cout << "Diamond circlet - 40 gold pieces each" << endl;
if (treasures_.at(i).getName() == "Gem-encrusted Goblet")
cout << "Gem-encrusted goblet - 50 gold pieces each" << endl;
}
cout << endl << "You can sell all your treasures or you can sell none. It's an all in or all out type of deal. " << endl << "Would you like to sell all your treasures? (y/n)" << endl;
cin >> sell_menu;
if (sell_menu == 'y' || sell_menu == 'Y') {
for (int i = 0; i < treasures_.size(); i++){
if (treasures_.at(i).getName() == "Silver Ring") {
gold_ += 10;
}
if (treasures_.at(i).getName() == "Ruby Necklace") {
gold_ += 20;
}
if (treasures_.at(i).getName() == "Emerald Bracelet") {
gold_ += 30;
}
if (treasures_.at(i).getName() == "Diamond Circlet") {
gold_ += 40;
}
if (treasures_.at(i).getName() == "Gem-encrusted Goblet") {
gold_ += 50;
}
}
treasures_.clear();
}
else {
cout << endl << "OK, sorry you can't commit to anything." << endl << "You can keep your treasures and I'll keep my gold." << endl;
}
}
else
cout << "You have no treasures for me to purchase, nice try!" << endl;
}
//leave option
if(merchant_menu == 6)
{
char confirmation = 'x';
do {
//if user says y, set merchant menu to 13, to the terminate do-while loop
cout << "Are you sure you're finished? You won't be able to buy anything else from me! (y/n)" << endl;
cin >> confirmation;
if (confirmation == 'Y' || confirmation == 'y')
merchant_menu = 13;
} while (!(confirmation == 'y' || confirmation == 'Y' || confirmation == 'n' || confirmation == 'N'));
}
printInv();
} while(merchant_menu != 13);
}
bool Inventory::misfortuneCalc(int percent_chance)
{
int reduced_num = percent_chance / 10;
srand(time(NULL));
int rand_num = (rand() % (10 - 1 + 1)) + 1;
if(rand_num > 1 && rand_num <= reduced_num)
{
return true; //there is misfortune
}
else
{
return false; //there is no misfortune
}
}
void Inventory::applyMisfortune(bool in_room) {
Map rand;
int r = rand.randomNum(0,100);
if (r > 0 && r <= 30) {
//robbed
cout << BOLDWHITE << endl << "\tMISFORTUNE" << RESET << endl;
cout << endl << "Oh no! Your party has been robbed." << endl;
r = rand.randomNum(1,3);
//lose 10kg ingredients
if (r == 1) {
cout << endl << "Your party has lost 10kg of ingredients." << endl;
if (ingredients_ >= 10)
ingredients_ -= 10;
else
ingredients_ = 0;
}
//lose cookware item
else if (r == 2) {
cout << endl << "Your party has lost 1 cookware item." << endl;
if (cookwares_.size() > 0){
cookwares_.pop_back();
} else
cout << endl << "Lucky for you all, there are no cookwares to take" << endl;
}
//lose armor
else if (r == 3) {
cout << endl << "Your party has lost 1 piece of armor." << endl;
int r2 = rand.randomNum(0,4);
if (armor_ > 0) {
while(!(party_[r2].getArmor())) {
r2 = rand.randomNum(0,4);
}
cout << endl << party_[r2].getName() << " has lost their armor." << endl;
party_[r2].setArmor(false);
armor_ -= 1;
}
else
cout << endl << "Lucky for you all, there is no armor to take" << endl;
}
}
//weapon or armor breaks
else if (r > 30 && r <= 40) {
r = rand.randomNum(0,10);
int num_weapons;
cout << BOLDWHITE << endl << "\tMISFORTUNE" << RESET << endl;
//count weapons
for (int i = 0; i < 5; i++) {
if (weapons_[i].length() > 0)
num_weapons++;
}
//weapon
if (r >= 0 && r <=5 && num_weapons > 0) {
while (!(weapons_[r].length() > 0)) {
r = rand.randomNum(0,4);
}
cout << endl << party_[r].getName() << "'s weapon has broken." << endl;
weapons_[r] = "";
}
//armor
else if (armor_ > 0){
while(!(party_[r].getArmor())) {
r = rand.randomNum(0,4);
}
cout << endl << party_[r].getName() << "'s armor has broken." << endl;
party_[r].setArmor(false);
armor_ -= 1;
}
//else, no misfortune
}
else if (r > 40 && r <= 70) {
//food poisoning, party member loses 10 pts hunger
r = rand.randomNum(0,4);
cout << BOLDWHITE << endl << "\tMISFORTUNE" << RESET << endl;
if (party_[r].getFullness() > 10) {
cout << endl << party_[r].getName() << " has gotten food poisoning and lost 10 points of fullness!" << endl;
party_[r].setFullness(party_[r].getFullness() - 10);
}
else {
cout << endl << party_[r].getName() << " has gotten food poisoning died of hunger immediately!" << endl;
death(party_[r]);
}
}
else if (r > 70 && in_room)
{
//team member locked in previous room
r = rand.randomNum(1, 4);
cout << BOLDWHITE << endl << "\tMISFORTUNE" << RESET << endl;
while (!(party_[r].getName().length() > 0)) {
r = rand.randomNum(1, 4);
}
cout << endl << party_[r].getName() << " has gotten trapped in the room! Your party must continue on!" << endl;
death(party_[r]);
}
}
Monster Inventory::aliveAtLevel(int bound1, int bound2, Monster arr[21]) {
Map rand;
//traverse dead monster vector
for(int i = 0; i < 21; i++)
{
//picking lvl 1 monster
int random = rand.randomNum(bound1, bound2);
int not_equal = 0;
for (int j = 0; j < dead_monsters_.size(); j++)
{
//check monter pick isnt on dead monsters
if (arr[random].getMonsterName() != dead_monsters_.at(j).getMonsterName())
{
not_equal++;
}
}
if (not_equal >= dead_monsters_.size()) {
return arr[random];
}
}
return Monster();
}
//This function will remove a member of the party
//It will also remove the weapon they were holding
//It will remove one armor from the party if the party has armor
void Inventory::death(Member member)
{
for (int i = 0; i < 5; i++) {
if (party_[i].getName() == member.getName()) {
party_[i] = Member();
party_[i].setFullness(0);
weapons_[i] = "";
if (member.getArmor()) {
cout << "in";
armor_ -= 1;
member.setArmor(false);
}
}
}
}
int Inventory::doorPuzzle(int choice)
{
Map doorgame;
int comp_pick = doorgame.randomNum(1, 3);
int boulder = 1;
int shears = 2;
int parchment = 3;
int num_lose = 0;
cout << "This is the wizards choice " << comp_pick << endl;
if(comp_pick == 1)
{
if(choice == 1)
{
return 0;
}
if(choice == 2)
{
return -1;
}
if(choice == 3)
{
return 1;
}
}
if(comp_pick == 2)
{
if(choice == 2)
{
return 0;
}
if(choice == 3)
{
return -1;
}
if(choice == 1)
{
return 1;
}
}
if(comp_pick == 3)
{
if(choice == 3)
{
return 0;
}
if(choice == 2)
{
return 1;
}
if(choice == 1)
{
return -1;
}
}
return -5;
}
int Inventory::findTreausre(string t_name) {
for (int i = 0; i < treasures_.size(); i++) {
if (treasures_.at(i).getName() == t_name) {
return i;
}
}
return -1;
}
//swap for bubblesort with pass by reference
void swap(vector<int>& vec, int startIndex, int endIndex) {
// vec.sIndex = 5, vec.eIndex = 1
int temp = vec.at(startIndex);
vec.at(startIndex) = vec.at(endIndex);
vec.at(endIndex) = temp;
}
//
void Inventory::bubbleSort(vector<int>& final_score)
{
bool swapped = true;
do
{
swapped = false;
for(int i = 0; i < final_score.size()-1; i++)
{
//if left is bigger than right, swap, do this until there are no more swaps
if (final_score.at(i) > final_score.at(i+1))
{
swap(final_score, final_score.at(i), final_score.at(i+1));
swapped = true;
}
}
} while(swapped);
}
void Inventory::writeGameStats(int rooms_cleared, int anger, int num_spaces, int num_turns)
{
ofstream fout;
fout.open("gameStats.txt");
{
fout << "Name of player: " << party_[0].getName() << endl;
fout << "Rooms Cleared: " << rooms_cleared << endl;
fout << "Gold pieces remaining: " << gold_ << endl;
fout << "Treasure items: ";
for(int i = 0; i < treasures_.size(); i++)
{
treasures_.at(i).getName();
}
fout << endl << "Number of spaces explored: " << num_spaces << endl;
fout << "Number of monsters defeated: " << monsters_killed_ << endl;
fout << "Number of turns taken: " << num_turns << endl;
fout << "Sorcerers anger level: " << anger << endl;
}
}