-
-
Notifications
You must be signed in to change notification settings - Fork 675
/
Copy pathtools.hpp
224 lines (176 loc) · 7.92 KB
/
tools.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
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 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.com/
*/
#pragma once
#include "utils/utils_definitions.hpp"
#include "declarations.hpp"
#include "enums/item_attribute.hpp"
#include "game/movement/position.hpp"
#include "enums/object_category.hpp"
namespace pugi {
class xml_parse_result;
}
#ifndef USE_PRECOMPILED_HEADERS
#include <random>
#endif
void printXMLError(const std::string &where, const std::string &fileName, const pugi::xml_parse_result &result);
std::string transformToSHA1(const std::string &input);
uint16_t getStashSize(StashItemList itemList);
std::string generateToken(const std::string &secret, uint32_t ticks);
void replaceString(std::string &str, const std::string &sought, const std::string &replacement);
void trim_right(std::string &source, char t);
void trim_left(std::string &source, char t);
std::string keepFirstWordOnly(std::string &str);
void toLowerCaseString(std::string &source);
std::string asLowerCaseString(std::string source);
std::string asUpperCaseString(std::string source);
std::string toCamelCase(const std::string &str);
std::string toPascalCase(const std::string &str);
std::string toSnakeCase(const std::string &str);
std::string toKebabCase(const std::string &str);
std::string toStartCaseWithSpace(const std::string &str);
using StringVector = std::vector<std::string>;
using IntegerVector = std::vector<int32_t>;
StringVector explodeString(const std::string &inString, const std::string &separator, int32_t limit = -1);
IntegerVector vectorAtoi(const StringVector &stringVector);
constexpr bool hasBitSet(uint32_t flag, uint32_t flags) {
return (flags & flag) != 0;
}
std::mt19937 &getRandomGenerator();
int32_t uniform_random(int32_t minNumber, int32_t maxNumber);
int32_t normal_random(int32_t minNumber, int32_t maxNumber);
bool boolean_random(double probability = 0.5);
BedItemPart_t getBedPart(const std::string_view string);
Direction getDirection(const std::string &string);
Position getNextPosition(Direction direction, Position pos);
/**
* @param exactDiagonalOnly - defines if diagonals are calculated only for dy = dx (true) or any dx != 0 and dy != 0 (false).
*/
Direction getDirectionTo(const Position &from, const Position &to, bool exactDiagonalOnly = true);
std::string getFirstLine(const std::string &str);
std::string formatDate(time_t time);
std::string formatDateShort(time_t time);
std::string formatTime(time_t time);
/**
* @brief Format the enum name by replacing underscores with spaces and converting to lowercase.
* @param name The enum name to format.
* @return A string with the formatted enum name.
*/
std::string formatEnumName(std::string_view name);
std::time_t getTimeNow();
int64_t getTimeMsNow();
int64_t getTimeUsNow();
std::string convertIPToString(uint32_t ip);
void trimString(std::string &str);
MagicEffectClasses getMagicEffect(const std::string &strValue);
ShootType_t getShootType(const std::string &strValue);
Ammo_t getAmmoType(const std::string &strValue);
WeaponAction_t getWeaponAction(const std::string &strValue);
Skulls_t getSkullType(const std::string &strValue);
ImbuementTypes_t getImbuementType(const std::string &strValue);
/**
* @Deprecated
* It will be dropped with monsters. Use RespawnPeriod_t instead.
*/
SpawnType_t getSpawnType(const std::string &strValue);
std::string getSkillName(uint8_t skillid);
uint32_t adlerChecksum(const uint8_t* data, size_t len);
std::string ucfirst(std::string str);
std::string ucwords(std::string str);
bool booleanString(const std::string &str);
std::string getWeaponName(WeaponType_t weaponType);
WeaponType_t getWeaponType(const std::string &name);
MoveEvent_t getMoveEventType(const std::string &name);
std::string getCombatName(CombatType_t combatType);
CombatType_t getCombatTypeByName(const std::string &combatname);
/**
* @brief Convert the CombatType_t enumeration to its corresponding index.
* @param combatType The CombatType_t enumeration to convert.
* @return The corresponding index of the CombatType_t enumeration.
* If the CombatType_t is out of range, this function will log an error and return an empty size_t.
*/
size_t combatTypeToIndex(CombatType_t combatType);
/**
* @brief Convert the CombatType_t enumeration to its corresponding string representation.
* @param combatType The CombatType_t enumeration to convert.
* @return The corresponding string representation of the CombatType_t enumeration.
* If the CombatType_t is out of range, this function will log an error and return an empty string.
*/
std::string combatTypeToName(CombatType_t combatType);
CombatType_t indexToCombatType(size_t v);
ItemAttribute_t stringToItemAttribute(const std::string &str);
const char* getReturnMessage(ReturnValue value);
void sleep_for(uint64_t ms);
void capitalizeWords(std::string &source);
void capitalizeWordsIgnoringString(std::string &source, const std::string stringToIgnore);
void consoleHandlerExit();
NameEval_t validateName(const std::string &name);
bool isCaskItem(uint16_t itemId);
std::string getObjectCategoryName(ObjectCategory_t category);
bool isValidObjectCategory(ObjectCategory_t category);
int64_t OTSYS_TIME(bool useTime = false);
void UPDATE_OTSYS_TIME();
SpellGroup_t stringToSpellGroup(const std::string &value);
uint8_t forgeBonus(int32_t number);
std::string formatPrice(std::string price, bool space /* = false*/);
std::vector<std::string> split(const std::string &str, char delimiter = ',');
std::string getFormattedTimeRemaining(uint32_t time);
unsigned int getNumberOfCores();
static inline Cipbia_Elementals_t getCipbiaElement(CombatType_t combatType) {
switch (combatType) {
case COMBAT_PHYSICALDAMAGE:
return CIPBIA_ELEMENTAL_PHYSICAL;
case COMBAT_ENERGYDAMAGE:
return CIPBIA_ELEMENTAL_ENERGY;
case COMBAT_EARTHDAMAGE:
return CIPBIA_ELEMENTAL_EARTH;
case COMBAT_FIREDAMAGE:
return CIPBIA_ELEMENTAL_FIRE;
case COMBAT_LIFEDRAIN:
return CIPBIA_ELEMENTAL_LIFEDRAIN;
case COMBAT_HEALING:
return CIPBIA_ELEMENTAL_HEALING;
case COMBAT_DROWNDAMAGE:
return CIPBIA_ELEMENTAL_DROWN;
case COMBAT_ICEDAMAGE:
return CIPBIA_ELEMENTAL_ICE;
case COMBAT_HOLYDAMAGE:
return CIPBIA_ELEMENTAL_HOLY;
case COMBAT_DEATHDAMAGE:
return CIPBIA_ELEMENTAL_DEATH;
case COMBAT_MANADRAIN:
return CIPBIA_ELEMENTAL_MANADRAIN;
case COMBAT_AGONYDAMAGE:
return CIPBIA_ELEMENTAL_AGONY;
case COMBAT_NEUTRALDAMAGE:
return CIPBIA_ELEMENTAL_AGONY;
default:
return CIPBIA_ELEMENTAL_UNDEFINED;
}
}
std::string formatNumber(uint64_t number);
std::string getPlayerSubjectPronoun(PlayerPronoun_t pronoun, PlayerSex_t sex, const std::string &name);
std::string getPlayerObjectPronoun(PlayerPronoun_t pronoun, PlayerSex_t sex, const std::string &name);
std::string getPlayerPossessivePronoun(PlayerPronoun_t pronoun, PlayerSex_t sex, const std::string &name);
std::string getPlayerReflexivePronoun(PlayerPronoun_t pronoun, PlayerSex_t sex, const std::string &name);
std::string getVerbForPronoun(PlayerPronoun_t pronoun, bool pastTense = false);
std::string formatWithArticle(const std::string &value, bool withSpace = true);
std::string toKey(const std::string &str);
static inline double quadraticPoly(double a, double b, double c, double x) {
return a * x * x + b * x + c;
}
uint8_t convertWheelGemAffinityToDomain(uint8_t affinity);
template <typename EnumType, typename UnderlyingType = std::underlying_type_t<EnumType>>
UnderlyingType enumToValue(EnumType value) {
return static_cast<UnderlyingType>(value);
}
template <typename EnumType, typename UnderlyingType = std::underlying_type_t<EnumType>>
EnumType enumFromValue(UnderlyingType value) {
return static_cast<EnumType>(value);
}
bool caseInsensitiveCompare(std::string_view str1, std::string_view str2, size_t length = std::string_view::npos);