-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChest.cpp
More file actions
207 lines (179 loc) · 5.37 KB
/
Copy pathChest.cpp
File metadata and controls
207 lines (179 loc) · 5.37 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
#include <iostream>
#include "Header.h"
void Chest::ChestCreate(ChestType type) {
this->chestType = type;
this->isOpen = false;
this->capacity =0;
items.clear();
RandomizeChest();
}
void Chest::RandomizeChest()
{
int proc = rand() % 100 + 1;
if(proc <= 52)
{
capacity = rand() % 4 + 1; // Random capacity between 1 and 4
this->chestType = COMMON;
this->isOpen = false;
this->capacity =capacity;
}
else if (proc >52 && proc <=80)
{
this->chestType = RARE;
this->isOpen = false;
this->capacity =capacity;
capacity = rand() % 6 + 1;
}
else if (proc > 80 && proc <= 95)
{
this->chestType = EPIC;
this->isOpen = false;
this->capacity =capacity;
capacity = rand() % 8 + 2;
}
else
{
this->chestType = LEGENDARY;
this->isOpen = false;
this->capacity =capacity;
capacity = rand() % 10 + 3;
}
for (auto item : items) {
delete item;
}
items.clear();
for (int i = 0; i < capacity; ++i) {
int roll = rand() % 100;
Item* newItem = nullptr;
if (chestType == COMMON) {
if (roll < 40) {
Weapon* w = new Weapon();
w->RandomizeWeaponStart("Warrior");
newItem = w;
} else if (roll < 70) {
Armory* a = new Armory();
a->RandomizeArmorStart();
newItem = a;
} else {
Potion* p = new Potion();
p->RandomizePotion();
newItem = p;
}
}
else if (chestType == RARE) {
if (roll < 25) {
Weapon* w = new Weapon();
w->RandomizeWeaponStart("Warrior");
newItem = w;
} else if (roll < 50) {
Armory* a = new Armory();
a->RandomizeArmorStart();
newItem = a;
} else if (roll < 80) {
Weapon* w = new Weapon();
w->RandomizeWeaponSpeacial();
newItem = w;
} else {
Potion* p = new Potion();
p->RandomizePotion();
newItem = p;
}
}
else if (chestType == EPIC) {
if (roll < 40) {
Weapon* w = new Weapon();
w->RandomizeWeaponSpeacial();
newItem = w;
} else if (roll < 70) {
Armory* a = new Armory();
a->RandomizeArmorSpeacial();
newItem = a;
} else {
Potion* p = new Potion();
p->RandomizePotion();
newItem = p;
}
}
else { // LEGENDARY
if (roll < 35) {
Weapon* w = new Weapon();
w->RandomizeWeaponSpeacial();
newItem = w;
} else if (roll < 70) {
Armory* a = new Armory();
a->RandomizeArmorSpeacial();
newItem = a;
} else {
Potion* p = new Potion();
p->RandomizePotion();
newItem = p;
}
}
if (newItem) {
items.push_back(newItem);
}
}
}
void Chest::Open(Character* target) {
int action;
if (!isOpen) {
isOpen = true;
std::cout << "Chest opened!" << std::endl;
ShowItems();
std::cout << "Select actions what to do next : " << std::endl;
std::cout << "1. Take item" << std::endl;
std::cout << "2. Take all" << std::endl;
std::cout << "3. Close chest" << std::endl;
std::cin >> action;
switch(action) {
case 1:
target->SetCurrentChest(this); target->Take(); break;
target->Take();
break;
case 2:
target->SetCurrentChest(this); target->TakeAll(); break;
target->TakeAll();
break;
case 3:
Close();
break;
default:
std::cout << "Bad Choice" << std::endl;
}
} else {
std::cout << "Chest is already open!" << std::endl;
}
}
void Chest::Close() {
if (isOpen) {
isOpen = false;
std::cout << "Chest closed!" << std::endl;
} else {
std::cout << "Chest is already closed!" << std::endl;
}
}
void Chest::ShowInfo(ChestType type) const {
std::cout << "Chest Type: ";
switch (chestType) {
case COMMON: std::cout << "Common"; break;
case RARE: std::cout << "Rare"; break;
case EPIC: std::cout << "Epic"; break;
case LEGENDARY: std::cout << "Legendary"; break;
}
std::cout << "\nCapacity: " << capacity << "\nIs Open: " << (isOpen ? "Yes" : "No") << std::endl;
}
void Chest::ShowItems()
{
for(int i =0; i < items.size(); i++)
{
std::cout << i+1 << ". ";
items[i]->ShowInfo();
}
std::cout << std::endl;
}
void Chest::RemoveItem(int index) {
if (index >= 0 && index < items.size()) {
delete items[index];
items.erase(items.begin() + index);
}
}