forked from opentibiabr/canary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_store.hpp
344 lines (299 loc) · 8.67 KB
/
io_store.hpp
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
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2022 OpenTibiaBR <opentibiabr@outlook.com>
* Repository: https://github.com/opentibiabr/canary
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors
* Website: https://docs.opentibiabr.org/
*/
#ifndef SRC_IO_IO_STORE_HPP_
#define SRC_IO_IO_STORE_HPP_
#include "utils/pugicast.h"
#include <map>
#include <string>
#include <vector>
// XML
enum class OfferTypes_t : uint8_t {
NONE = 0,
ITEM = 1,
STACKABLE = 2,
CHARGES = 3,
OUTFIT = 4,
MOUNT = 5,
NAMECHANGE = 6,
SEXCHANGE = 7,
HOUSE = 8,
EXPBOOST = 9,
PREYSLOT = 10,
PREYBONUS = 11,
TEMPLE = 12,
BLESSINGS = 13,
ALLBLESSINGS = 14,
PREMIUM = 15,
POUCH = 16,
INSTANT_REWARD_ACCESS = 17,
CHARM_EXPANSION = 18,
HUNTINGSLOT = 19,
HIRELING = 20,
HIRELING_NAMECHANGE = 21,
HIRELING_SEXCHANGE = 22,
HIRELING_SKILL = 23,
HIRELING_OUTFIT = 24
};
enum class States_t : uint8_t {
NONE = 0,
NEW = 1,
SALE = 2,
TIMED = 3
};
// Internal
enum class ConverType_t : uint8_t {
NONE = 0,
MOUNT = 1,
OUTFIT = 2,
ITEM = 3,
HIRELING = 4
};
enum class SubActions_t : uint8_t {
PREY_THIRDSLOT_REAL = 0,
PREY_WILDCARD = 1,
INSTANT_REWARD = 2,
BLESSING_TWIST = 3,
BLESSING_SOLITUDE = 4,
BLESSING_PHOENIX = 5,
BLESSING_SUNS = 6,
BLESSING_SPIRITUAL = 7,
BLESSING_EMBRACE = 8,
BLESSING_HEART = 9,
BLESSING_BLOOD = 10,
BLESSING_ALL_PVE = 11,
BLESSING_ALL_PVP = 12,
CHARM_EXPANSION = 13,
TASKHUNTING_THIRDSLOT = 14,
PREY_THIRDSLOT_REDIRECT = 15
};
enum class HistoryTypes_t : uint8_t {
NONE = 0,
GIFT = 1,
REFUND = 2
};
enum class StoreErrors_t : uint8_t {
PURCHASE = 0,
NETWORK = 1,
HISTORY = 2,
TRANSFER = 3,
INFORMATION = 4
};
// Others
enum class ActionType_t : uint8_t {
OPEN_HOME = 0,
OPEN_PREMIUM_BOOST = 1,
OPEN_CATEGORY = 2,
OPEN_USEFUL_THINGS = 3,
OPEN_OFFER = 4,
};
enum class CoinType_t : uint8_t {
COIN = 0,
TRANSFERABLE = 1,
};
// Structs
struct OutfitIds {
uint16_t maleId;
uint16_t femaleId;
};
struct BannerInfo {
std::string bannerName;
uint32_t offerId;
};
class Category;
class Offer;
class IOStore {
public:
IOStore(const IOStore&) = delete;
void operator=(const IOStore&) = delete;
static IOStore& getInstance() {
static IOStore instance;
return instance;
}
bool loadFromXml();
const std::map<std::string, OfferTypes_t> stringToOfferTypeMap = {
{ "none", OfferTypes_t::NONE },
{ "item", OfferTypes_t::ITEM },
{ "stackable", OfferTypes_t::STACKABLE },
{ "charges", OfferTypes_t::CHARGES },
{ "outfit", OfferTypes_t::OUTFIT },
{ "mount", OfferTypes_t::MOUNT },
{ "nameChange", OfferTypes_t::NAMECHANGE },
{ "sexChange", OfferTypes_t::SEXCHANGE },
{ "house", OfferTypes_t::HOUSE },
{ "expBoost", OfferTypes_t::EXPBOOST },
{ "preySlot", OfferTypes_t::PREYSLOT },
{ "preyBonus", OfferTypes_t::PREYBONUS },
{ "temple", OfferTypes_t::TEMPLE },
{ "blessings", OfferTypes_t::BLESSINGS },
{ "allblessings", OfferTypes_t::ALLBLESSINGS },
{ "premium", OfferTypes_t::PREMIUM },
{ "pouch", OfferTypes_t::POUCH },
{ "instantReward", OfferTypes_t::INSTANT_REWARD_ACCESS },
{ "charmExpansion", OfferTypes_t::CHARM_EXPANSION },
{ "huntingSlot", OfferTypes_t::HUNTINGSLOT },
{ "hireling", OfferTypes_t::HIRELING },
{ "hirelingNameChange", OfferTypes_t::HIRELING_NAMECHANGE },
{ "hirelingSexChange", OfferTypes_t::HIRELING_SEXCHANGE },
{ "hirelingSkill", OfferTypes_t::HIRELING_SKILL },
{ "hirelingOutfit", OfferTypes_t::HIRELING_OUTFIT }
};
const std::map<OfferTypes_t, uint16_t> offersDisableIndex = {
{ OfferTypes_t::OUTFIT, 0 },
{ OfferTypes_t::MOUNT, 1 },
{ OfferTypes_t::EXPBOOST, 2 },
{ OfferTypes_t::PREYSLOT, 3 },
{ OfferTypes_t::HUNTINGSLOT, 3 },
{ OfferTypes_t::PREYBONUS, 4 },
{ OfferTypes_t::BLESSINGS, 5 },
{ OfferTypes_t::ALLBLESSINGS, 6 },
{ OfferTypes_t::POUCH, 7 },
{ OfferTypes_t::INSTANT_REWARD_ACCESS, 8 },
{ OfferTypes_t::CHARM_EXPANSION, 9 }
};
const std::map<std::string, States_t> stringToOfferStateMap = {
{ "none", States_t::NONE }, { "new", States_t::NEW }, { "sale", States_t::SALE }, { "timed", States_t::TIMED }
};
std::vector<Category> getCategoryVector() const;
const Category* getCategoryByName(std::string categoryName) const;
const Category* getSubCategoryByName(std::string subCategoryName) const;
const Offer* getOfferById(uint32_t offerId) const;
std::vector<BannerInfo> getBannersVector() const;
std::vector<uint32_t> getHomeOffersVector() const;
uint32_t getBannerDelay() const;
void setBannerDelay(uint8_t delay);
const Category* findCategory(std::string categoryName);
const std::vector<std::string> getOffersDisableReasonVector();
std::vector<Offer> getOffersContainingSubstring(const std::string &searchString);
private:
IOStore() = default;
~IOStore() = default;
// Home
std::vector<BannerInfo> banners;
uint8_t bannerDelay = 5;
std::vector<uint32_t> homeOffers;
std::vector<Category> categoryVector;
std::vector<Category> subCategoryVector;
std::map<uint32_t, Offer> offersMap;
bool loadOfferFromXml(Category* category, pugi::xml_node offer);
bool loadStoreHome(pugi::xml_node homeNode);
void addCategory(Category newCategory);
void addOffer(uint32_t offerId, Offer offer);
std::vector<std::string> offersDisableReason = {
"You already own this outfit.",
"You already own this mount.",
"You can't buy XP Boost for today.",
"You already have 3 slots released.",
"You already have maximum of prey wildcards.",
"You reached the maximum amount for this blessing.",
"You reached the maximum amount for some blessing.",
"You already have a pouch.",
"You already have maximum of reward tokens.",
"You already have charm expansion."
};
};
class Category { // We're gonna use the same class for Category and Subcategory
public:
Category(std::string name, std::string icon, bool rookgaard, States_t state = States_t::NONE) :
categoryName(name), categoryIcon(icon), canRookgaardAcess(rookgaard), categoryState(state) { }
std::string getCategoryName() const {
return categoryName;
}
std::string getCategoryIcon() const {
return categoryIcon;
}
States_t getCategoryState() const {
return categoryState;
}
bool getRookgaardAcess() const {
return canRookgaardAcess;
}
bool isSpecialCategory() const {
return specialCategory;
}
const Category* getFirstSubCategory() const;
std::vector<Category> getSubCategoriesVector() const;
std::vector<Offer> getOffersVector() const;
private:
friend class IOStore;
std::string categoryName;
std::string categoryIcon;
bool canRookgaardAcess;
States_t categoryState = States_t::NONE;
bool specialCategory = false;
// Used when Category class is a Category
std::vector<Category> subCategories;
// Used when Category class is a Subcategory or a "Special Category"
std::vector<Offer> offers;
void addSubCategory(Category newSubCategory);
void addOffer(Offer newOffer);
void setSpecialCategory(bool state) {
specialCategory = state;
}
};
class Offer {
public:
Offer(std::string parentName, std::string name, std::string icon, uint32_t id, uint32_t price, OfferTypes_t type, States_t state, uint16_t count, uint16_t duration, CoinType_t coin, std::string description, OutfitIds outfitIds) :
parentName(parentName), offerName(name), offerIcon(icon), offerId(id), offerPrice(price), offerType(type), offerState(state), offerCount(count), validUntil(duration), coinType(coin), offerDescription(description), outfitId(outfitIds) { }
std::string getOfferName() const {
return offerName;
}
std::string getOfferIcon() const {
return offerIcon;
}
uint32_t getOfferId() const {
return offerId;
}
uint32_t getOfferPrice() const {
return offerPrice;
}
OfferTypes_t getOfferType() const {
return offerType;
}
States_t getOfferState() const {
return offerState;
}
uint16_t getOfferCount() const {
return offerCount;
}
uint16_t getValidUntil() const {
return validUntil;
}
CoinType_t getCoinType() const {
return coinType;
}
std::string getOfferDescription() const {
return offerDescription;
}
OutfitIds getOutfitIds() const {
return outfitId;
}
std::string getParentName() const {
return parentName;
}
ConverType_t getConverType() const;
bool getUseConfigure() const;
private:
// Mandatory
std::string offerName;
uint32_t offerId; // Any identifier (itemId, mountId, ...)
uint32_t offerPrice;
OfferTypes_t offerType = OfferTypes_t::NONE;
// Optional
std::string offerIcon;
States_t offerState = States_t::NONE;
uint16_t offerCount = 0; // Or charges
uint16_t validUntil;
CoinType_t coinType = CoinType_t::COIN;
std::string offerDescription;
OutfitIds outfitId;
// Internal
std::string parentName;
};
constexpr auto g_ioStore = &IOStore::getInstance;
#endif // SRC_IO_IO_STORE_HPP_