| @@ -0,0 +1,68 @@ | |||
| 1 | + | #ifndef FS_CONSOLE_UI_H | |
| 2 | + | #define FS_CONSOLE_UI_H | |
| 3 | + | ||
| 4 | + | #include <iostream> | |
| 5 | + | #include <string> | |
| 6 | + | ||
| 7 | + | #ifdef _WIN32 | |
| 8 | + | #include <windows.h> | |
| 9 | + | #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING | |
| 10 | + | #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 | |
| 11 | + | #endif | |
| 12 | + | #endif | |
| 13 | + | ||
| 14 | + | namespace ConsoleUI { | |
| 15 | + | // ANSI Color Codes | |
| 16 | + | const std::string RESET = "\033[0m"; | |
| 17 | + | const std::string BOLD = "\033[1m"; | |
| 18 | + | const std::string RED = "\033[31m"; | |
| 19 | + | const std::string GREEN = "\033[32m"; | |
| 20 | + | const std::string YELLOW = "\033[33m"; | |
| 21 | + | const std::string BLUE = "\033[34m"; | |
| 22 | + | const std::string MAGENTA = "\033[35m"; | |
| 23 | + | const std::string CYAN = "\033[36m"; | |
| 24 | + | const std::string WHITE = "\033[37m"; | |
| 25 | + | const std::string DARK_GRAY = "\033[90m"; | |
| 26 | + | ||
| 27 | + | inline void init() { | |
| 28 | + | #ifdef _WIN32 | |
| 29 | + | HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
| 30 | + | if (hOut == INVALID_HANDLE_VALUE) return; | |
| 31 | + | DWORD dwMode = 0; | |
| 32 | + | if (!GetConsoleMode(hOut, &dwMode)) return; | |
| 33 | + | dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | |
| 34 | + | SetConsoleMode(hOut, dwMode); | |
| 35 | + | #endif | |
| 36 | + | } | |
| 37 | + | ||
| 38 | + | inline void printBanner() { | |
| 39 | + | std::cout << CYAN << BOLD << " [ RD Core Server ] " << RESET << std::endl; | |
| 40 | + | std::cout << DARK_GRAY << " -------------------------------------------------------------------" << RESET << std::endl; | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | inline void printStep(const std::string& step, bool success = true) { | |
| 44 | + | if (success) { | |
| 45 | + | std::cout << GREEN << " [ DONE ] " << RESET << WHITE << step << std::endl; | |
| 46 | + | } else { | |
| 47 | + | std::cout << RED << " [ FAIL ] " << RESET << WHITE << step << std::endl; | |
| 48 | + | } | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | inline void printStatus(const std::string& label, const std::string& value, const std::string& color = WHITE) { | |
| 52 | + | std::cout << CYAN << " >> " << label << ": " << color << value << RESET << std::endl; | |
| 53 | + | } | |
| 54 | + | ||
| 55 | + | inline void printSeparator() { | |
| 56 | + | std::cout << DARK_GRAY << " -------------------------------------------------------------------" << RESET << std::endl; | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | inline void printWarning(const std::string& msg) { | |
| 60 | + | std::cout << YELLOW << " [ WARN ] " << RESET << WHITE << msg << std::endl; | |
| 61 | + | } | |
| 62 | + | ||
| 63 | + | inline void printError(const std::string& msg) { | |
| 64 | + | std::cout << RED << " [ ERR ] " << RESET << BOLD << msg << std::endl; | |
| 65 | + | } | |
| 66 | + | } | |
| 67 | + | ||
| 68 | + | #endif |
| @@ -0,0 +1,724 @@ | |||
| 1 | + | /** | |
| 2 | + | * The Forgotten Server - a free and open-source MMORPG server emulator | |
| 3 | + | * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com> | |
| 4 | + | * | |
| 5 | + | * This program is free software; you can redistribute it and/or modify | |
| 6 | + | * it under the terms of the GNU General Public License as published by | |
| 7 | + | * the Free Software Foundation; either version 2 of the License, or | |
| 8 | + | * (at your option) any later version. | |
| 9 | + | * | |
| 10 | + | * This program is distributed in the hope that it will be useful, | |
| 11 | + | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | + | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | + | * GNU General Public License for more details. | |
| 14 | + | * | |
| 15 | + | * You should have received a copy of the GNU General Public License along | |
| 16 | + | * with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 | + | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 | + | */ | |
| 19 | + | ||
| 20 | + | #ifndef FS_CONST_H_0A49B5996F074465BF44B90F4F780E8B | |
| 21 | + | #define FS_CONST_H_0A49B5996F074465BF44B90F4F780E8B | |
| 22 | + | ||
| 23 | + | static constexpr int32_t NETWORKMESSAGE_MAXSIZE = 65500; | |
| 24 | + | ||
| 25 | + | enum MagicEffectClasses : uint16_t { | |
| 26 | + | CONST_ME_NONE, | |
| 27 | + | ||
| 28 | + | CONST_ME_DRAWBLOOD = 1, | |
| 29 | + | CONST_ME_LOSEENERGY = 2, | |
| 30 | + | CONST_ME_POFF = 3, | |
| 31 | + | CONST_ME_BLOCKHIT = 4, | |
| 32 | + | CONST_ME_EXPLOSIONAREA = 5, | |
| 33 | + | CONST_ME_EXPLOSIONHIT = 6, | |
| 34 | + | CONST_ME_FIREAREA = 7, | |
| 35 | + | CONST_ME_YELLOW_RINGS = 8, | |
| 36 | + | CONST_ME_GREEN_RINGS = 9, | |
| 37 | + | CONST_ME_HITAREA = 10, | |
| 38 | + | CONST_ME_TELEPORT = 11, | |
| 39 | + | CONST_ME_ENERGYHIT = 12, | |
| 40 | + | CONST_ME_MAGIC_BLUE = 13, | |
| 41 | + | CONST_ME_MAGIC_RED = 14, | |
| 42 | + | CONST_ME_MAGIC_GREEN = 15, | |
| 43 | + | CONST_ME_HITBYFIRE = 16, | |
| 44 | + | CONST_ME_HITBYPOISON = 17, | |
| 45 | + | CONST_ME_MORTAREA = 18, | |
| 46 | + | CONST_ME_SOUND_GREEN = 19, | |
| 47 | + | CONST_ME_SOUND_RED = 20, | |
| 48 | + | CONST_ME_POISONAREA = 21, | |
| 49 | + | CONST_ME_SOUND_YELLOW = 22, | |
| 50 | + | CONST_ME_SOUND_PURPLE = 23, | |
| 51 | + | CONST_ME_SOUND_BLUE = 24, | |
| 52 | + | CONST_ME_SOUND_WHITE = 25, | |
| 53 | + | CONST_ME_BUBBLES = 26, | |
| 54 | + | CONST_ME_CRAPS = 27, | |
| 55 | + | CONST_ME_GIFT_WRAPS = 28, | |
| 56 | + | CONST_ME_FIREWORK_YELLOW = 29, | |
| 57 | + | CONST_ME_FIREWORK_RED = 30, | |
| 58 | + | CONST_ME_FIREWORK_BLUE = 31, | |
| 59 | + | CONST_ME_STUN = 32, | |
| 60 | + | CONST_ME_SLEEP = 33, | |
| 61 | + | CONST_ME_WATERCREATURE = 34, | |
| 62 | + | CONST_ME_GROUNDSHAKER = 35, | |
| 63 | + | CONST_ME_HEARTS = 36, | |
| 64 | + | CONST_ME_FIREATTACK = 37, | |
| 65 | + | CONST_ME_ENERGYAREA = 38, | |
| 66 | + | CONST_ME_SMALLCLOUDS = 39, | |
| 67 | + | CONST_ME_HOLYDAMAGE = 40, | |
| 68 | + | CONST_ME_BIGCLOUDS = 41, | |
| 69 | + | CONST_ME_ICEAREA = 42, | |
| 70 | + | CONST_ME_ICETORNADO = 43, | |
| 71 | + | CONST_ME_ICEATTACK = 44, | |
| 72 | + | CONST_ME_STONES = 45, | |
| 73 | + | CONST_ME_SMALLPLANTS = 46, | |
| 74 | + | CONST_ME_CARNIPHILA = 47, | |
| 75 | + | CONST_ME_PURPLEENERGY = 48, | |
| 76 | + | CONST_ME_YELLOWENERGY = 49, | |
| 77 | + | CONST_ME_HOLYAREA = 50, | |
| 78 | + | CONST_ME_BIGPLANTS = 51, | |
| 79 | + | CONST_ME_CAKE = 52, | |
| 80 | + | CONST_ME_GIANTICE = 53, | |
| 81 | + | CONST_ME_WATERSPLASH = 54, | |
| 82 | + | CONST_ME_PLANTATTACK = 55, | |
| 83 | + | CONST_ME_TUTORIALARROW = 56, | |
| 84 | + | CONST_ME_TUTORIALSQUARE = 57, | |
| 85 | + | CONST_ME_MIRRORHORIZONTAL = 58, | |
| 86 | + | CONST_ME_MIRRORVERTICAL = 59, | |
| 87 | + | CONST_ME_SKULLHORIZONTAL = 60, | |
| 88 | + | CONST_ME_SKULLVERTICAL = 61, | |
| 89 | + | CONST_ME_ASSASSIN = 62, | |
| 90 | + | CONST_ME_STEPSHORIZONTAL = 63, | |
| 91 | + | CONST_ME_BLOODYSTEPS = 64, | |
| 92 | + | CONST_ME_STEPSVERTICAL = 65, | |
| 93 | + | CONST_ME_YALAHARIGHOST = 66, | |
| 94 | + | CONST_ME_BATS = 67, | |
| 95 | + | CONST_ME_SMOKE = 68, | |
| 96 | + | CONST_ME_INSECTS = 69, | |
| 97 | + | CONST_ME_DRAGONHEAD = 70, | |
| 98 | + | CONST_ME_ORCSHAMAN = 71, | |
| 99 | + | CONST_ME_ORCSHAMAN_FIRE = 72, | |
| 100 | + | CONST_ME_THUNDER = 73, | |
| 101 | + | CONST_ME_FERUMBRAS = 74, | |
| 102 | + | CONST_ME_CONFETTI_HORIZONTAL = 75, | |
| 103 | + | CONST_ME_CONFETTI_VERTICAL = 76, | |
| 104 | + | // 77-157 are empty | |
| 105 | + | CONST_ME_BLACKSMOKE = 158, | |
| 106 | + | // 159-166 are empty | |
| 107 | + | CONST_ME_REDSMOKE = 167, | |
| 108 | + | CONST_ME_YELLOWSMOKE = 168, | |
| 109 | + | CONST_ME_GREENSMOKE = 169, | |
| 110 | + | CONST_ME_PURPLESMOKE = 170, | |
| 111 | + | CONST_ME_EARLY_THUNDER = 171, | |
| 112 | + | CONST_ME_RAGIAZ_BONECAPSULE = 172, | |
| 113 | + | CONST_ME_CRITICAL_DAMAGE = 173, | |
| 114 | + | // 174 is empty | |
| 115 | + | CONST_ME_PLUNGING_FISH = 175, | |
| 116 | + | }; | |
| 117 | + | ||
| 118 | + | enum ShootType_t : uint8_t { | |
| 119 | + | CONST_ANI_NONE, | |
| 120 | + | ||
| 121 | + | CONST_ANI_SPEAR = 1, | |
| 122 | + | CONST_ANI_BOLT = 2, | |
| 123 | + | CONST_ANI_ARROW = 3, | |
| 124 | + | CONST_ANI_FIRE = 4, | |
| 125 | + | CONST_ANI_ENERGY = 5, | |
| 126 | + | CONST_ANI_POISONARROW = 6, | |
| 127 | + | CONST_ANI_BURSTARROW = 7, | |
| 128 | + | CONST_ANI_THROWINGSTAR = 8, | |
| 129 | + | CONST_ANI_THROWINGKNIFE = 9, | |
| 130 | + | CONST_ANI_SMALLSTONE = 10, | |
| 131 | + | CONST_ANI_DEATH = 11, | |
| 132 | + | CONST_ANI_LARGEROCK = 12, | |
| 133 | + | CONST_ANI_SNOWBALL = 13, | |
| 134 | + | CONST_ANI_POWERBOLT = 14, | |
| 135 | + | CONST_ANI_POISON = 15, | |
| 136 | + | CONST_ANI_INFERNALBOLT = 16, | |
| 137 | + | CONST_ANI_HUNTINGSPEAR = 17, | |
| 138 | + | CONST_ANI_ENCHANTEDSPEAR = 18, | |
| 139 | + | CONST_ANI_REDSTAR = 19, | |
| 140 | + | CONST_ANI_GREENSTAR = 20, | |
| 141 | + | CONST_ANI_ROYALSPEAR = 21, | |
| 142 | + | CONST_ANI_SNIPERARROW = 22, | |
| 143 | + | CONST_ANI_ONYXARROW = 23, | |
| 144 | + | CONST_ANI_PIERCINGBOLT = 24, | |
| 145 | + | CONST_ANI_WHIRLWINDSWORD = 25, | |
| 146 | + | CONST_ANI_WHIRLWINDAXE = 26, | |
| 147 | + | CONST_ANI_WHIRLWINDCLUB = 27, | |
| 148 | + | CONST_ANI_ETHEREALSPEAR = 28, | |
| 149 | + | CONST_ANI_ICE = 29, | |
| 150 | + | CONST_ANI_EARTH = 30, | |
| 151 | + | CONST_ANI_HOLY = 31, | |
| 152 | + | CONST_ANI_SUDDENDEATH = 32, | |
| 153 | + | CONST_ANI_FLASHARROW = 33, | |
| 154 | + | CONST_ANI_FLAMMINGARROW = 34, | |
| 155 | + | CONST_ANI_SHIVERARROW = 35, | |
| 156 | + | CONST_ANI_ENERGYBALL = 36, | |
| 157 | + | CONST_ANI_SMALLICE = 37, | |
| 158 | + | CONST_ANI_SMALLHOLY = 38, | |
| 159 | + | CONST_ANI_SMALLEARTH = 39, | |
| 160 | + | CONST_ANI_EARTHARROW = 40, | |
| 161 | + | CONST_ANI_EXPLOSION = 41, | |
| 162 | + | CONST_ANI_CAKE = 42, | |
| 163 | + | ||
| 164 | + | CONST_ANI_TARSALARROW = 44, | |
| 165 | + | CONST_ANI_VORTEXBOLT = 45, | |
| 166 | + | ||
| 167 | + | CONST_ANI_PRISMATICBOLT = 48, | |
| 168 | + | CONST_ANI_CRYSTALLINEARROW = 49, | |
| 169 | + | CONST_ANI_DRILLBOLT = 50, | |
| 170 | + | CONST_ANI_ENVENOMEDARROW = 51, | |
| 171 | + | ||
| 172 | + | CONST_ANI_GLOOTHSPEAR = 53, | |
| 173 | + | CONST_ANI_SIMPLEARROW = 54, | |
| 174 | + | ||
| 175 | + | // for internal use, don't send to client | |
| 176 | + | CONST_ANI_WEAPONTYPE = 0xFE, // 254 | |
| 177 | + | }; | |
| 178 | + | ||
| 179 | + | enum SpeakClasses : uint8_t { | |
| 180 | + | TALKTYPE_SAY = 1, | |
| 181 | + | TALKTYPE_WHISPER = 2, | |
| 182 | + | TALKTYPE_YELL = 3, | |
| 183 | + | TALKTYPE_PRIVATE_FROM = 4, | |
| 184 | + | TALKTYPE_PRIVATE_TO = 5, | |
| 185 | + | TALKTYPE_CHANNEL_Y = 7, | |
| 186 | + | TALKTYPE_CHANNEL_O = 8, | |
| 187 | + | TALKTYPE_PRIVATE_NP = 10, | |
| 188 | + | TALKTYPE_PRIVATE_PN = 12, | |
| 189 | + | TALKTYPE_BROADCAST = 13, | |
| 190 | + | TALKTYPE_CHANNEL_R1 = 14, // red - #c text | |
| 191 | + | TALKTYPE_PRIVATE_RED_FROM = 15, //@name@text | |
| 192 | + | TALKTYPE_PRIVATE_RED_TO = 16, //@name@text | |
| 193 | + | TALKTYPE_MONSTER_SAY = 36, | |
| 194 | + | TALKTYPE_MONSTER_YELL = 37, | |
| 195 | + | ||
| 196 | + | TALKTYPE_CHANNEL_R2 = 0xFF, // #d | |
| 197 | + | }; | |
| 198 | + | ||
| 199 | + | enum MessageClasses : uint8_t { | |
| 200 | + | MESSAGE_STATUS_CONSOLE_BLUE = 4, /*FIXME Blue message in the console*/ | |
| 201 | + | ||
| 202 | + | MESSAGE_STATUS_CONSOLE_RED = 13, /*Red message in the console*/ | |
| 203 | + | ||
| 204 | + | MESSAGE_STATUS_DEFAULT = | |
| 205 | + | 17, /*White message at the bottom of the game window and in the console*/ | |
| 206 | + | MESSAGE_STATUS_WARNING = 18, /*Red message in game window and in the console*/ | |
| 207 | + | MESSAGE_EVENT_ADVANCE = | |
| 208 | + | 19, /*White message in game window and in the console*/ | |
| 209 | + | ||
| 210 | + | MESSAGE_STATUS_SMALL = 21, /*White message at the bottom of the game window"*/ | |
| 211 | + | MESSAGE_INFO_DESCR = 22, /*Green message in game window and in the console*/ | |
| 212 | + | MESSAGE_DAMAGE_DEALT = 23, | |
| 213 | + | MESSAGE_DAMAGE_RECEIVED = 24, | |
| 214 | + | MESSAGE_HEALED = 25, | |
| 215 | + | MESSAGE_EXPERIENCE = 26, | |
| 216 | + | MESSAGE_DAMAGE_OTHERS = 27, | |
| 217 | + | MESSAGE_HEALED_OTHERS = 28, | |
| 218 | + | MESSAGE_EXPERIENCE_OTHERS = 29, | |
| 219 | + | MESSAGE_EVENT_DEFAULT = | |
| 220 | + | 30, /*White message at the bottom of the game window and in the console*/ | |
| 221 | + | MESSAGE_LOOT = 31, | |
| 222 | + | ||
| 223 | + | MESSAGE_GUILD = 33, /*White message in channel (+ channelId)*/ | |
| 224 | + | MESSAGE_PARTY_MANAGEMENT = 34, /*White message in channel (+ channelId)*/ | |
| 225 | + | MESSAGE_PARTY = 35, /*White message in channel (+ channelId)*/ | |
| 226 | + | MESSAGE_EVENT_ORANGE = 36, /*Orange message in the console*/ | |
| 227 | + | MESSAGE_STATUS_CONSOLE_ORANGE = 37, /*Orange message in the console*/ | |
| 228 | + | }; | |
| 229 | + | ||
| 230 | + | enum FluidColors_t : uint8_t { | |
| 231 | + | FLUID_EMPTY, | |
| 232 | + | FLUID_BLUE, | |
| 233 | + | FLUID_RED, | |
| 234 | + | FLUID_BROWN, | |
| 235 | + | FLUID_GREEN, | |
| 236 | + | FLUID_YELLOW, | |
| 237 | + | FLUID_WHITE, | |
| 238 | + | FLUID_PURPLE, | |
| 239 | + | }; | |
| 240 | + | ||
| 241 | + | enum FluidTypes_t : uint8_t { | |
| 242 | + | FLUID_NONE = FLUID_EMPTY, | |
| 243 | + | FLUID_WATER = FLUID_BLUE, | |
| 244 | + | FLUID_BLOOD = FLUID_RED, | |
| 245 | + | FLUID_BEER = FLUID_BROWN, | |
| 246 | + | FLUID_SLIME = FLUID_GREEN, | |
| 247 | + | FLUID_LEMONADE = FLUID_YELLOW, | |
| 248 | + | FLUID_MILK = FLUID_WHITE, | |
| 249 | + | FLUID_MANA = FLUID_PURPLE, | |
| 250 | + | ||
| 251 | + | FLUID_LIFE = FLUID_RED + 8, | |
| 252 | + | FLUID_OIL = FLUID_BROWN + 8, | |
| 253 | + | FLUID_URINE = FLUID_YELLOW + 8, | |
| 254 | + | FLUID_COCONUTMILK = FLUID_WHITE + 8, | |
| 255 | + | FLUID_WINE = FLUID_PURPLE + 8, | |
| 256 | + | ||
| 257 | + | FLUID_MUD = FLUID_BROWN + 16, | |
| 258 | + | FLUID_FRUITJUICE = FLUID_YELLOW + 16, | |
| 259 | + | ||
| 260 | + | FLUID_LAVA = FLUID_RED + 24, | |
| 261 | + | FLUID_RUM = FLUID_BROWN + 24, | |
| 262 | + | FLUID_SWAMP = FLUID_GREEN + 24, | |
| 263 | + | ||
| 264 | + | FLUID_TEA = FLUID_BROWN + 32, | |
| 265 | + | ||
| 266 | + | FLUID_MEAD = FLUID_BROWN + 40, | |
| 267 | + | }; | |
| 268 | + | ||
| 269 | + | const uint8_t reverseFluidMap[] = { | |
| 270 | + | FLUID_EMPTY, FLUID_WATER, FLUID_MANA, FLUID_BEER, FLUID_EMPTY, | |
| 271 | + | FLUID_BLOOD, FLUID_SLIME, FLUID_EMPTY, FLUID_LEMONADE, FLUID_MILK, | |
| 272 | + | }; | |
| 273 | + | ||
| 274 | + | const uint8_t clientToServerFluidMap[] = { | |
| 275 | + | FLUID_EMPTY, FLUID_WATER, FLUID_MANA, FLUID_BEER, | |
| 276 | + | FLUID_MUD, FLUID_BLOOD, FLUID_SLIME, FLUID_RUM, | |
| 277 | + | FLUID_LEMONADE, FLUID_MILK, FLUID_WINE, FLUID_LIFE, | |
| 278 | + | FLUID_URINE, FLUID_OIL, FLUID_FRUITJUICE, FLUID_COCONUTMILK, | |
| 279 | + | FLUID_TEA, FLUID_MEAD, | |
| 280 | + | }; | |
| 281 | + | ||
| 282 | + | enum ClientFluidTypes_t : uint8_t { | |
| 283 | + | CLIENTFLUID_EMPTY = 0, | |
| 284 | + | CLIENTFLUID_BLUE = 1, | |
| 285 | + | CLIENTFLUID_PURPLE = 2, | |
| 286 | + | CLIENTFLUID_BROWN_1 = 3, | |
| 287 | + | CLIENTFLUID_BROWN_2 = 4, | |
| 288 | + | CLIENTFLUID_RED = 5, | |
| 289 | + | CLIENTFLUID_GREEN = 6, | |
| 290 | + | CLIENTFLUID_BROWN = 7, | |
| 291 | + | CLIENTFLUID_YELLOW = 8, | |
| 292 | + | CLIENTFLUID_WHITE = 9, | |
| 293 | + | }; | |
| 294 | + | ||
| 295 | + | const uint8_t fluidMap[] = { | |
| 296 | + | CLIENTFLUID_EMPTY, CLIENTFLUID_BLUE, CLIENTFLUID_RED, | |
| 297 | + | CLIENTFLUID_BROWN_1, CLIENTFLUID_GREEN, CLIENTFLUID_YELLOW, | |
| 298 | + | CLIENTFLUID_WHITE, CLIENTFLUID_PURPLE, | |
| 299 | + | }; | |
| 300 | + | ||
| 301 | + | enum SquareColor_t : uint8_t { | |
| 302 | + | SQ_COLOR_BLACK = 0, | |
| 303 | + | }; | |
| 304 | + | ||
| 305 | + | enum TextColor_t : uint8_t { | |
| 306 | + | TEXTCOLOR_BLUE = 5, | |
| 307 | + | TEXTCOLOR_LIGHTGREEN = 30, | |
| 308 | + | TEXTCOLOR_LIGHTBLUE = 35, | |
| 309 | + | TEXTCOLOR_MAYABLUE = 95, | |
| 310 | + | TEXTCOLOR_DARKRED = 108, | |
| 311 | + | TEXTCOLOR_LIGHTGREY = 129, | |
| 312 | + | TEXTCOLOR_SKYBLUE = 143, | |
| 313 | + | TEXTCOLOR_PURPLE = 154, | |
| 314 | + | TEXTCOLOR_ELECTRICPURPLE = 155, | |
| 315 | + | TEXTCOLOR_RED = 180, | |
| 316 | + | TEXTCOLOR_PASTELRED = 194, | |
| 317 | + | TEXTCOLOR_ORANGE = 198, | |
| 318 | + | TEXTCOLOR_YELLOW = 210, | |
| 319 | + | TEXTCOLOR_WHITE_EXP = 215, | |
| 320 | + | TEXTCOLOR_NONE = 255, | |
| 321 | + | }; | |
| 322 | + | ||
| 323 | + | enum Icons_t { | |
| 324 | + | ICON_POISON = 1 << 0, | |
| 325 | + | ICON_BURN = 1 << 1, | |
| 326 | + | ICON_ENERGY = 1 << 2, | |
| 327 | + | ICON_DRUNK = 1 << 3, | |
| 328 | + | ICON_MANASHIELD = 1 << 4, | |
| 329 | + | ICON_PARALYZE = 1 << 5, | |
| 330 | + | ICON_HASTE = 1 << 6, | |
| 331 | + | ICON_SWORDS = 1 << 7, | |
| 332 | + | ICON_DROWNING = 1 << 8, | |
| 333 | + | ICON_FREEZING = 1 << 9, | |
| 334 | + | ICON_DAZZLED = 1 << 10, | |
| 335 | + | ICON_CURSED = 1 << 11, | |
| 336 | + | ICON_PARTY_BUFF = 1 << 12, | |
| 337 | + | ICON_REDSWORDS = 1 << 13, | |
| 338 | + | ICON_PIGEON = 1 << 14, | |
| 339 | + | ICON_BLEEDING = 1 << 15, | |
| 340 | + | }; | |
| 341 | + | ||
| 342 | + | enum WeaponType_t : uint8_t { | |
| 343 | + | WEAPON_NONE, | |
| 344 | + | WEAPON_SWORD, | |
| 345 | + | WEAPON_CLUB, | |
| 346 | + | WEAPON_AXE, | |
| 347 | + | WEAPON_SHIELD, | |
| 348 | + | WEAPON_DISTANCE, | |
| 349 | + | WEAPON_WAND, | |
| 350 | + | WEAPON_AMMO, | |
| 351 | + | }; | |
| 352 | + | ||
| 353 | + | enum Ammo_t : uint8_t { | |
| 354 | + | AMMO_NONE, | |
| 355 | + | AMMO_BOLT, | |
| 356 | + | AMMO_ARROW, | |
| 357 | + | AMMO_SPEAR, | |
| 358 | + | AMMO_THROWINGSTAR, | |
| 359 | + | AMMO_THROWINGKNIFE, | |
| 360 | + | AMMO_STONE, | |
| 361 | + | AMMO_SNOWBALL, | |
| 362 | + | }; | |
| 363 | + | ||
| 364 | + | enum WeaponAction_t : uint8_t { | |
| 365 | + | WEAPONACTION_NONE, | |
| 366 | + | WEAPONACTION_REMOVECOUNT, | |
| 367 | + | WEAPONACTION_REMOVECHARGE, | |
| 368 | + | WEAPONACTION_MOVE, | |
| 369 | + | }; | |
| 370 | + | ||
| 371 | + | enum WieldInfo_t { | |
| 372 | + | WIELDINFO_NONE = 0 << 0, | |
| 373 | + | WIELDINFO_LEVEL = 1 << 0, | |
| 374 | + | WIELDINFO_MAGLV = 1 << 1, | |
| 375 | + | WIELDINFO_VOCREQ = 1 << 2, | |
| 376 | + | WIELDINFO_PREMIUM = 1 << 3, | |
| 377 | + | }; | |
| 378 | + | ||
| 379 | + | enum Skulls_t : uint8_t { | |
| 380 | + | SKULL_NONE = 0, | |
| 381 | + | SKULL_YELLOW = 1, | |
| 382 | + | SKULL_GREEN = 2, | |
| 383 | + | SKULL_WHITE = 3, | |
| 384 | + | SKULL_RED = 4, | |
| 385 | + | SKULL_BLACK = 5, | |
| 386 | + | SKULL_ORANGE = 6, | |
| 387 | + | }; | |
| 388 | + | ||
| 389 | + | enum PartyShields_t : uint8_t { | |
| 390 | + | SHIELD_NONE = 0, | |
| 391 | + | SHIELD_WHITEYELLOW = 1, | |
| 392 | + | SHIELD_WHITEBLUE = 2, | |
| 393 | + | SHIELD_BLUE = 3, | |
| 394 | + | SHIELD_YELLOW = 4, | |
| 395 | + | SHIELD_BLUE_SHAREDEXP = 5, | |
| 396 | + | SHIELD_YELLOW_SHAREDEXP = 6, | |
| 397 | + | SHIELD_BLUE_NOSHAREDEXP_BLINK = 7, | |
| 398 | + | SHIELD_YELLOW_NOSHAREDEXP_BLINK = 8, | |
| 399 | + | SHIELD_BLUE_NOSHAREDEXP = 9, | |
| 400 | + | SHIELD_YELLOW_NOSHAREDEXP = 10, | |
| 401 | + | SHIELD_GRAY = 11, | |
| 402 | + | }; | |
| 403 | + | ||
| 404 | + | enum GuildEmblems_t : uint8_t { | |
| 405 | + | GUILDEMBLEM_NONE = 0, | |
| 406 | + | GUILDEMBLEM_ALLY = 1, | |
| 407 | + | GUILDEMBLEM_ENEMY = 2, | |
| 408 | + | GUILDEMBLEM_NEUTRAL = 3, | |
| 409 | + | GUILDEMBLEM_MEMBER = 4, | |
| 410 | + | GUILDEMBLEM_OTHER = 5, | |
| 411 | + | }; | |
| 412 | + | ||
| 413 | + | enum item_t : uint16_t { | |
| 414 | + | ITEM_BROWSEFIELD = 460, // for internal use | |
| 415 | + | ||
| 416 | + | ITEM_FIREFIELD_PVP_FULL = 1487, | |
| 417 | + | ITEM_FIREFIELD_PVP_MEDIUM = 1488, | |
| 418 | + | ITEM_FIREFIELD_PVP_SMALL = 1489, | |
| 419 | + | ITEM_FIREFIELD_PERSISTENT_FULL = 1492, | |
| 420 | + | ITEM_FIREFIELD_PERSISTENT_MEDIUM = 1493, | |
| 421 | + | ITEM_FIREFIELD_PERSISTENT_SMALL = 1494, | |
| 422 | + | ITEM_FIREFIELD_NOPVP = 1500, | |
| 423 | + | ||
| 424 | + | ITEM_POISONFIELD_PVP = 1490, | |
| 425 | + | ITEM_POISONFIELD_PERSISTENT = 1496, | |
| 426 | + | ITEM_POISONFIELD_NOPVP = 1503, | |
| 427 | + | ||
| 428 | + | ITEM_ENERGYFIELD_PVP = 1491, | |
| 429 | + | ITEM_ENERGYFIELD_PERSISTENT = 1495, | |
| 430 | + | ITEM_ENERGYFIELD_NOPVP = 1504, | |
| 431 | + | ||
| 432 | + | ITEM_MAGICWALL = 1497, | |
| 433 | + | ITEM_MAGICWALL_PERSISTENT = 1498, | |
| 434 | + | ITEM_MAGICWALL_SAFE = 11098, | |
| 435 | + | ITEM_MAGICWALL_NOPVP = 20669, | |
| 436 | + | ||
| 437 | + | ITEM_WILDGROWTH = 1499, | |
| 438 | + | ITEM_WILDGROWTH_PERSISTENT = 2721, | |
| 439 | + | ITEM_WILDGROWTH_SAFE = 11099, | |
| 440 | + | ITEM_WILDGROWTH_NOPVP = 20670, | |
| 441 | + | ||
| 442 | + | ITEM_BAG = 1987, | |
| 443 | + | ITEM_SHOPPING_BAG = 23782, | |
| 444 | + | ||
| 445 | + | ITEM_GOLD_COIN = 2148, | |
| 446 | + | ITEM_PLATINUM_COIN = 2152, | |
| 447 | + | ITEM_CRYSTAL_COIN = 2160, | |
| 448 | + | ITEM_STORE_COIN = 24774, // in-game store currency | |
| 449 | + | ||
| 450 | + | ITEM_DEPOT = 2594, | |
| 451 | + | ITEM_LOCKER1 = 2589, | |
| 452 | + | ITEM_INBOX = 14404, | |
| 453 | + | ITEM_MARKET = 14405, | |
| 454 | + | ITEM_STORE_INBOX = 26052, | |
| 455 | + | ITEM_DEPOT_BOX_I = 25453, | |
| 456 | + | ITEM_DEPOT_BOX_II = 25454, | |
| 457 | + | ITEM_DEPOT_BOX_III = 25455, | |
| 458 | + | ITEM_DEPOT_BOX_IV = 25456, | |
| 459 | + | ITEM_DEPOT_BOX_V = 25457, | |
| 460 | + | ITEM_DEPOT_BOX_VI = 25458, | |
| 461 | + | ITEM_DEPOT_BOX_VII = 25459, | |
| 462 | + | ITEM_DEPOT_BOX_VIII = 25460, | |
| 463 | + | ITEM_DEPOT_BOX_IX = 25461, | |
| 464 | + | ITEM_DEPOT_BOX_X = 25462, | |
| 465 | + | ITEM_DEPOT_BOX_XI = 25463, | |
| 466 | + | ITEM_DEPOT_BOX_XII = 25464, | |
| 467 | + | ITEM_DEPOT_BOX_XIII = 25465, | |
| 468 | + | ITEM_DEPOT_BOX_XIV = 25466, | |
| 469 | + | ITEM_DEPOT_BOX_XV = 25467, | |
| 470 | + | ITEM_DEPOT_BOX_XVI = 25468, | |
| 471 | + | ITEM_DEPOT_BOX_XVII = 25469, | |
| 472 | + | ||
| 473 | + | ITEM_MALE_CORPSE = 3058, | |
| 474 | + | ITEM_FEMALE_CORPSE = 3065, | |
| 475 | + | ||
| 476 | + | ITEM_FULLSPLASH = 2016, | |
| 477 | + | ITEM_SMALLSPLASH = 2019, | |
| 478 | + | ||
| 479 | + | ITEM_PARCEL = 2595, | |
| 480 | + | ITEM_LETTER = 2597, | |
| 481 | + | ITEM_LETTER_STAMPED = 2598, | |
| 482 | + | ITEM_LABEL = 2599, | |
| 483 | + | ||
| 484 | + | ITEM_AMULETOFLOSS = 2173, | |
| 485 | + | ||
| 486 | + | ITEM_DOCUMENT_RO = 1968, // read-only | |
| 487 | + | }; | |
| 488 | + | ||
| 489 | + | enum PlayerFlags : uint64_t { | |
| 490 | + | PlayerFlag_CannotUseCombat = 1 << 0, | |
| 491 | + | PlayerFlag_CannotAttackPlayer = 1 << 1, | |
| 492 | + | PlayerFlag_CannotAttackMonster = 1 << 2, | |
| 493 | + | PlayerFlag_CannotBeAttacked = 1 << 3, | |
| 494 | + | PlayerFlag_CanConvinceAll = 1 << 4, | |
| 495 | + | PlayerFlag_CanSummonAll = 1 << 5, | |
| 496 | + | PlayerFlag_CanIllusionAll = 1 << 6, | |
| 497 | + | PlayerFlag_CanSenseInvisibility = 1 << 7, | |
| 498 | + | PlayerFlag_IgnoredByMonsters = 1 << 8, | |
| 499 | + | PlayerFlag_NotGainInFight = 1 << 9, | |
| 500 | + | PlayerFlag_HasInfiniteMana = 1 << 10, | |
| 501 | + | PlayerFlag_HasInfiniteSoul = 1 << 11, | |
| 502 | + | PlayerFlag_HasNoExhaustion = 1 << 12, | |
| 503 | + | PlayerFlag_CannotUseSpells = 1 << 13, | |
| 504 | + | PlayerFlag_CannotPickupItem = 1 << 14, | |
| 505 | + | PlayerFlag_CanAlwaysLogin = 1 << 15, | |
| 506 | + | PlayerFlag_CanBroadcast = 1 << 16, | |
| 507 | + | PlayerFlag_CanEditHouses = 1 << 17, | |
| 508 | + | PlayerFlag_CannotBeBanned = 1 << 18, | |
| 509 | + | PlayerFlag_CannotBePushed = 1 << 19, | |
| 510 | + | PlayerFlag_HasInfiniteCapacity = 1 << 20, | |
| 511 | + | PlayerFlag_CanPushAllCreatures = 1 << 21, | |
| 512 | + | PlayerFlag_CanTalkRedPrivate = 1 << 22, | |
| 513 | + | PlayerFlag_CanTalkRedChannel = 1 << 23, | |
| 514 | + | PlayerFlag_TalkOrangeHelpChannel = 1 << 24, | |
| 515 | + | PlayerFlag_NotGainExperience = 1 << 25, | |
| 516 | + | PlayerFlag_NotGainMana = 1 << 26, | |
| 517 | + | PlayerFlag_NotGainHealth = 1 << 27, | |
| 518 | + | PlayerFlag_NotGainSkill = 1 << 28, | |
| 519 | + | PlayerFlag_SetMaxSpeed = 1 << 29, | |
| 520 | + | PlayerFlag_SpecialVIP = 1 << 30, | |
| 521 | + | PlayerFlag_NotGenerateLoot = static_cast<uint64_t>(1) << 31, | |
| 522 | + | PlayerFlag_CanTalkRedChannelAnonymous = static_cast<uint64_t>(1) << 32, | |
| 523 | + | PlayerFlag_IgnoreProtectionZone = static_cast<uint64_t>(1) << 33, | |
| 524 | + | PlayerFlag_IgnoreSpellCheck = static_cast<uint64_t>(1) << 34, | |
| 525 | + | PlayerFlag_IgnoreWeaponCheck = static_cast<uint64_t>(1) << 35, | |
| 526 | + | PlayerFlag_CannotBeMuted = static_cast<uint64_t>(1) << 36, | |
| 527 | + | PlayerFlag_IsAlwaysPremium = static_cast<uint64_t>(1) << 37, | |
| 528 | + | }; | |
| 529 | + | ||
| 530 | + | enum ReloadTypes_t : uint8_t { | |
| 531 | + | RELOAD_TYPE_ALL, | |
| 532 | + | RELOAD_TYPE_ACTIONS, | |
| 533 | + | RELOAD_TYPE_AURAS, | |
| 534 | + | RELOAD_TYPE_EFFECTS, | |
| 535 | + | RELOAD_TYPE_CHAT, | |
| 536 | + | RELOAD_TYPE_CONFIG, | |
| 537 | + | RELOAD_TYPE_CREATURESCRIPTS, | |
| 538 | + | RELOAD_TYPE_EVENTS, | |
| 539 | + | RELOAD_TYPE_GLOBAL, | |
| 540 | + | RELOAD_TYPE_GLOBALEVENTS, | |
| 541 | + | RELOAD_TYPE_ITEMS, | |
| 542 | + | RELOAD_TYPE_MONSTERS, | |
| 543 | + | RELOAD_TYPE_MOUNTS, | |
| 544 | + | RELOAD_TYPE_MOVEMENTS, | |
| 545 | + | RELOAD_TYPE_NPCS, | |
| 546 | + | RELOAD_TYPE_QUESTS, | |
| 547 | + | RELOAD_TYPE_RAIDS, | |
| 548 | + | RELOAD_TYPE_SCRIPTS, | |
| 549 | + | RELOAD_TYPE_SHADERS, | |
| 550 | + | RELOAD_TYPE_SPELLS, | |
| 551 | + | RELOAD_TYPE_TALKACTIONS, | |
| 552 | + | RELOAD_TYPE_RUNEEFFECTS, | |
| 553 | + | RELOAD_TYPE_OUTFITS, | |
| 554 | + | RELOAD_TYPE_WEAPONS, | |
| 555 | + | RELOAD_TYPE_WINGS, | |
| 556 | + | }; | |
| 557 | + | ||
| 558 | + | // OTCv8 features (from src/client/const.h) | |
| 559 | + | enum GameFeature : uint8_t { | |
| 560 | + | GameProtocolChecksum = 1, | |
| 561 | + | GameAccountNames = 2, | |
| 562 | + | GameChallengeOnLogin = 3, | |
| 563 | + | GamePenalityOnDeath = 4, | |
| 564 | + | GameNameOnNpcTrade = 5, | |
| 565 | + | GameDoubleFreeCapacity = 6, | |
| 566 | + | GameDoubleExperience = 7, | |
| 567 | + | GameTotalCapacity = 8, | |
| 568 | + | GameSkillsBase = 9, | |
| 569 | + | GamePlayerRegenerationTime = 10, | |
| 570 | + | GameChannelPlayerList = 11, | |
| 571 | + | GamePlayerMounts = 12, | |
| 572 | + | GameEnvironmentEffect = 13, | |
| 573 | + | GameCreatureEmblems = 14, | |
| 574 | + | GameItemAnimationPhase = 15, | |
| 575 | + | GameMagicEffectU16 = 16, | |
| 576 | + | GamePlayerMarket = 17, | |
| 577 | + | GameSpritesU32 = 18, | |
| 578 | + | GameTileAddThingWithStackpos = 19, | |
| 579 | + | GameOfflineTrainingTime = 20, | |
| 580 | + | GamePurseSlot = 21, | |
| 581 | + | GameFormatCreatureName = 22, | |
| 582 | + | GameSpellList = 23, | |
| 583 | + | GameClientPing = 24, | |
| 584 | + | GameExtendedClientPing = 25, | |
| 585 | + | GameDoubleHealth = 28, | |
| 586 | + | GameDoubleSkills = 29, | |
| 587 | + | GameChangeMapAwareRange = 30, | |
| 588 | + | GameMapMovePosition = 31, | |
| 589 | + | GameAttackSeq = 32, | |
| 590 | + | GameBlueNpcNameColor = 33, | |
| 591 | + | GameDiagonalAnimatedText = 34, | |
| 592 | + | GameLoginPending = 35, | |
| 593 | + | GameNewSpeedLaw = 36, | |
| 594 | + | GameForceFirstAutoWalkStep = 37, | |
| 595 | + | GameMinimapRemove = 38, | |
| 596 | + | GameDoubleShopSellAmount = 39, | |
| 597 | + | GameContainerPagination = 40, | |
| 598 | + | GameThingMarks = 41, | |
| 599 | + | GameLooktypeU16 = 42, | |
| 600 | + | GamePlayerStamina = 43, | |
| 601 | + | GamePlayerAddons = 44, | |
| 602 | + | GameMessageStatements = 45, | |
| 603 | + | GameMessageLevel = 46, | |
| 604 | + | GameNewFluids = 47, | |
| 605 | + | GamePlayerStateU16 = 48, | |
| 606 | + | GameNewOutfitProtocol = 49, | |
| 607 | + | GamePVPMode = 50, | |
| 608 | + | GameWritableDate = 51, | |
| 609 | + | GameAdditionalVipInfo = 52, | |
| 610 | + | GameBaseSkillU16 = 53, | |
| 611 | + | GameCreatureIcons = 54, | |
| 612 | + | GameHideNpcNames = 55, | |
| 613 | + | GameSpritesAlphaChannel = 56, | |
| 614 | + | GamePremiumExpiration = 57, | |
| 615 | + | GameBrowseField = 58, | |
| 616 | + | GameEnhancedAnimations = 59, | |
| 617 | + | GameOGLInformation = 60, | |
| 618 | + | GameMessageSizeCheck = 61, | |
| 619 | + | GamePreviewState = 62, | |
| 620 | + | GameLoginPacketEncryption = 63, | |
| 621 | + | GameClientVersion = 64, | |
| 622 | + | GameContentRevision = 65, | |
| 623 | + | GameExperienceBonus = 66, | |
| 624 | + | GameAuthenticator = 67, | |
| 625 | + | GameUnjustifiedPoints = 68, | |
| 626 | + | GameSessionKey = 69, | |
| 627 | + | GameDeathType = 70, | |
| 628 | + | GameIdleAnimations = 71, | |
| 629 | + | GameKeepUnawareTiles = 72, | |
| 630 | + | GameIngameStore = 73, | |
| 631 | + | GameIngameStoreHighlights = 74, | |
| 632 | + | GameIngameStoreServiceType = 75, | |
| 633 | + | GameAdditionalSkills = 76, | |
| 634 | + | GameDistanceEffectU16 = 77, | |
| 635 | + | GamePrey = 78, | |
| 636 | + | GameDoubleMagicLevel = 79, | |
| 637 | + | ||
| 638 | + | GameExtendedOpcode = 80, | |
| 639 | + | GameMinimapLimitedToSingleFloor = 81, | |
| 640 | + | GameSendWorldName = 82, | |
| 641 | + | ||
| 642 | + | GameDoubleLevel = 83, | |
| 643 | + | GameDoubleSoul = 84, | |
| 644 | + | GameDoublePlayerGoodsMoney = 85, | |
| 645 | + | GameCreatureWalkthrough = 86, | |
| 646 | + | GameDoubleTradeMoney = 87, | |
| 647 | + | GameSequencedPackets = 88, | |
| 648 | + | GameTibia12Protocol = 89, | |
| 649 | + | ||
| 650 | + | // 90-99 otclientv8 features | |
| 651 | + | GameNewWalking = 90, | |
| 652 | + | GameSlowerManualWalking = 91, | |
| 653 | + | ||
| 654 | + | GameItemTooltip = 93, | |
| 655 | + | ||
| 656 | + | GameBot = 95, | |
| 657 | + | GameBiggerMapCache = 96, | |
| 658 | + | GameForceLight = 97, | |
| 659 | + | GameNoDebug = 98, | |
| 660 | + | GameBotProtection = 99, | |
| 661 | + | ||
| 662 | + | // Custom features for customer | |
| 663 | + | GameFasterAnimations = 101, | |
| 664 | + | GameCenteredOutfits = 102, | |
| 665 | + | GameSendIdentifiers = 103, | |
| 666 | + | GameWingsAndAura = 104, | |
| 667 | + | GamePlayerStateU32 = 105, | |
| 668 | + | GameOutfitShaders = 106, | |
| 669 | + | ||
| 670 | + | // advanced features | |
| 671 | + | GamePacketSizeU32 = 110, | |
| 672 | + | GamePacketCompression = 111, | |
| 673 | + | ||
| 674 | + | LastGameFeature = 120 | |
| 675 | + | }; | |
| 676 | + | ||
| 677 | + | static constexpr int32_t CHANNEL_GUILD = 0x00; | |
| 678 | + | static constexpr int32_t CHANNEL_PARTY = 0x01; | |
| 679 | + | static constexpr int32_t CHANNEL_PRIVATE = 0xFFFF; | |
| 680 | + | ||
| 681 | + | // Reserved player storage key ranges; | |
| 682 | + | //[10000000 - 20000000]; | |
| 683 | + | static constexpr int32_t PSTRG_RESERVED_RANGE_START = 10000000; | |
| 684 | + | static constexpr int32_t PSTRG_RESERVED_RANGE_SIZE = 10000000; | |
| 685 | + | //[1000 - 1500]; | |
| 686 | + | static constexpr int32_t PSTRG_OUTFITS_RANGE_START = | |
| 687 | + | (PSTRG_RESERVED_RANGE_START + 1000); | |
| 688 | + | static constexpr int32_t PSTRG_OUTFITS_RANGE_SIZE = 500; | |
| 689 | + | //[2001 - 2011]; | |
| 690 | + | static constexpr int32_t PSTRG_MOUNTS_RANGE_START = | |
| 691 | + | (PSTRG_RESERVED_RANGE_START + 2001); | |
| 692 | + | static constexpr int32_t PSTRG_MOUNTS_RANGE_SIZE = 10; | |
| 693 | + | static constexpr int32_t PSTRG_MOUNTS_CURRENTMOUNT = | |
| 694 | + | (PSTRG_MOUNTS_RANGE_START + 10); | |
| 695 | + | //[2012 - 2022]; | |
| 696 | + | static constexpr int32_t PSTRG_WINGS_RANGE_START = | |
| 697 | + | (PSTRG_RESERVED_RANGE_START + 2012); | |
| 698 | + | static constexpr int32_t PSTRG_WINGS_RANGE_SIZE = 10; | |
| 699 | + | static constexpr int32_t PSTRG_WINGS_CURRENTWINGS = | |
| 700 | + | (PSTRG_WINGS_RANGE_START + 10); | |
| 701 | + | //[2023 - 2033]; | |
| 702 | + | static constexpr int32_t PSTRG_AURAS_RANGE_START = | |
| 703 | + | (PSTRG_RESERVED_RANGE_START + 2023); | |
| 704 | + | static constexpr int32_t PSTRG_AURAS_RANGE_SIZE = 10; | |
| 705 | + | static constexpr int32_t PSTRG_AURAS_CURRENTAURA = | |
| 706 | + | (PSTRG_AURAS_RANGE_START + 10); | |
| 707 | + | //[2034 - 2044]; | |
| 708 | + | static constexpr int32_t PSTRG_SHADERS_RANGE_START = | |
| 709 | + | (PSTRG_RESERVED_RANGE_START + 2034); | |
| 710 | + | static constexpr int32_t PSTRG_SHADERS_RANGE_SIZE = 10; | |
| 711 | + | static constexpr int32_t PSTRG_SHADERS_CURRENTSHADER = | |
| 712 | + | (PSTRG_SHADERS_RANGE_START + 10); | |
| 713 | + | //[2045 - 2055]; | |
| 714 | + | static constexpr int32_t PSTRG_EFFECTS_RANGE_START = | |
| 715 | + | (PSTRG_RESERVED_RANGE_START + 2045); | |
| 716 | + | static constexpr int32_t PSTRG_EFFECTS_RANGE_SIZE = 10; | |
| 717 | + | static constexpr int32_t PSTRG_EFFECTS_CURRENTEFFECT = | |
| 718 | + | (PSTRG_EFFECTS_RANGE_START + 10); | |
| 719 | + | ||
| 720 | + | #define IS_IN_KEYRANGE(key, range) \ | |
| 721 | + | (key >= PSTRG_##range##_START && \ | |
| 722 | + | ((key - PSTRG_##range##_START) <= PSTRG_##range##_SIZE)) | |
| 723 | + | ||
| 724 | + | #endif |
| @@ -0,0 +1,729 @@ | |||
| 1 | + | /** | |
| 2 | + | * The Forgotten Server - a free and open-source MMORPG server emulator | |
| 3 | + | * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com> | |
| 4 | + | * | |
| 5 | + | * This program is free software; you can redistribute it and/or modify | |
| 6 | + | * it under the terms of the GNU General Public License as published by | |
| 7 | + | * the Free Software Foundation; either version 2 of the License, or | |
| 8 | + | * (at your option) any later version. | |
| 9 | + | * | |
| 10 | + | * This program is distributed in the hope that it will be useful, | |
| 11 | + | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | + | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | + | * GNU General Public License for more details. | |
| 14 | + | * | |
| 15 | + | * You should have received a copy of the GNU General Public License along | |
| 16 | + | * with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 | + | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 | + | */ | |
| 19 | + | ||
| 20 | + | #include "otpch.h" | |
| 21 | + | ||
| 22 | + | #include "container.h" | |
| 23 | + | #include "iomap.h" | |
| 24 | + | #include "game.h" | |
| 25 | + | ||
| 26 | + | extern Game g_game; | |
| 27 | + | ||
| 28 | + | Container::Container(uint16_t type) : | |
| 29 | + | Container(type, items[type].maxItems) {} | |
| 30 | + | ||
| 31 | + | Container::Container(uint16_t type, uint16_t size, bool unlocked /*= true*/, bool pagination /*= false*/) : | |
| 32 | + | Item(type), | |
| 33 | + | maxSize(size), | |
| 34 | + | unlocked(unlocked), | |
| 35 | + | pagination(pagination) | |
| 36 | + | {} | |
| 37 | + | ||
| 38 | + | Container::Container(Tile* tile) : Container(ITEM_BROWSEFIELD, 30, false, true) | |
| 39 | + | { | |
| 40 | + | TileItemVector* itemVector = tile->getItemList(); | |
| 41 | + | if (itemVector) { | |
| 42 | + | for (Item* item : *itemVector) { | |
| 43 | + | if ((item->getContainer() || item->hasProperty(CONST_PROP_MOVEABLE)) && !item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID)) { | |
| 44 | + | itemlist.push_front(item); | |
| 45 | + | item->setParent(this); | |
| 46 | + | } | |
| 47 | + | } | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | setParent(tile); | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | Container::~Container() | |
| 54 | + | { | |
| 55 | + | if (getID() == ITEM_BROWSEFIELD) { | |
| 56 | + | g_game.browseFields.erase(getTile()); | |
| 57 | + | ||
| 58 | + | for (Item* item : itemlist) { | |
| 59 | + | item->setParent(parent); | |
| 60 | + | } | |
| 61 | + | } else { | |
| 62 | + | for (Item* item : itemlist) { | |
| 63 | + | item->setParent(nullptr); | |
| 64 | + | item->decrementReferenceCounter(); | |
| 65 | + | } | |
| 66 | + | } | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | Item* Container::clone() const | |
| 70 | + | { | |
| 71 | + | Container* clone = static_cast<Container*>(Item::clone()); | |
| 72 | + | for (Item* item : itemlist) { | |
| 73 | + | clone->addItem(item->clone()); | |
| 74 | + | } | |
| 75 | + | clone->totalWeight = totalWeight; | |
| 76 | + | return clone; | |
| 77 | + | } | |
| 78 | + | ||
| 79 | + | Container* Container::getParentContainer() | |
| 80 | + | { | |
| 81 | + | Thing* thing = getParent(); | |
| 82 | + | if (!thing) { | |
| 83 | + | return nullptr; | |
| 84 | + | } | |
| 85 | + | return thing->getContainer(); | |
| 86 | + | } | |
| 87 | + | ||
| 88 | + | std::string Container::getName(bool addArticle /* = false*/) const { | |
| 89 | + | const ItemType& it = items[id]; | |
| 90 | + | return getNameDescription(it, this, -1, addArticle); | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | bool Container::hasParent() const | |
| 94 | + | { | |
| 95 | + | return getID() != ITEM_BROWSEFIELD && dynamic_cast<const Player*>(getParent()) == nullptr; | |
| 96 | + | } | |
| 97 | + | ||
| 98 | + | void Container::addItem(Item* item) | |
| 99 | + | { | |
| 100 | + | itemlist.push_back(item); | |
| 101 | + | item->setParent(this); | |
| 102 | + | } | |
| 103 | + | ||
| 104 | + | Attr_ReadValue Container::readAttr(AttrTypes_t attr, PropStream& propStream) | |
| 105 | + | { | |
| 106 | + | if (attr == ATTR_CONTAINER_ITEMS) { | |
| 107 | + | if (!propStream.read<uint32_t>(serializationCount)) { | |
| 108 | + | return ATTR_READ_ERROR; | |
| 109 | + | } | |
| 110 | + | return ATTR_READ_END; | |
| 111 | + | } | |
| 112 | + | return Item::readAttr(attr, propStream); | |
| 113 | + | } | |
| 114 | + | ||
| 115 | + | bool Container::unserializeItemNode(OTB::Loader& loader, const OTB::Node& node, PropStream& propStream) | |
| 116 | + | { | |
| 117 | + | bool ret = Item::unserializeItemNode(loader, node, propStream); | |
| 118 | + | if (!ret) { | |
| 119 | + | return false; | |
| 120 | + | } | |
| 121 | + | ||
| 122 | + | for (auto& itemNode : node.children) { | |
| 123 | + | //load container items | |
| 124 | + | if (itemNode.type != OTBM_ITEM) { | |
| 125 | + | // unknown type | |
| 126 | + | return false; | |
| 127 | + | } | |
| 128 | + | ||
| 129 | + | PropStream itemPropStream; | |
| 130 | + | if (!loader.getProps(itemNode, itemPropStream)) { | |
| 131 | + | return false; | |
| 132 | + | } | |
| 133 | + | ||
| 134 | + | Item* item = Item::CreateItem(itemPropStream); | |
| 135 | + | if (!item) { | |
| 136 | + | return false; | |
| 137 | + | } | |
| 138 | + | ||
| 139 | + | if (!item->unserializeItemNode(loader, itemNode, itemPropStream)) { | |
| 140 | + | return false; | |
| 141 | + | } | |
| 142 | + | ||
| 143 | + | addItem(item); | |
| 144 | + | updateItemWeight(item->getWeight()); | |
| 145 | + | } | |
| 146 | + | return true; | |
| 147 | + | } | |
| 148 | + | ||
| 149 | + | void Container::updateItemWeight(int32_t diff) | |
| 150 | + | { | |
| 151 | + | totalWeight += diff; | |
| 152 | + | if (Container* parentContainer = getParentContainer()) { | |
| 153 | + | parentContainer->updateItemWeight(diff); | |
| 154 | + | } | |
| 155 | + | } | |
| 156 | + | ||
| 157 | + | uint32_t Container::getWeight() const | |
| 158 | + | { | |
| 159 | + | return Item::getWeight() + totalWeight; | |
| 160 | + | } | |
| 161 | + | ||
| 162 | + | std::string Container::getContentDescription() const | |
| 163 | + | { | |
| 164 | + | std::ostringstream os; | |
| 165 | + | return getContentDescription(os).str(); | |
| 166 | + | } | |
| 167 | + | ||
| 168 | + | std::ostringstream& Container::getContentDescription(std::ostringstream& os) const | |
| 169 | + | { | |
| 170 | + | bool firstitem = true; | |
| 171 | + | for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { | |
| 172 | + | Item* item = *it; | |
| 173 | + | ||
| 174 | + | Container* container = item->getContainer(); | |
| 175 | + | if (container && !container->empty()) { | |
| 176 | + | continue; | |
| 177 | + | } | |
| 178 | + | ||
| 179 | + | if (firstitem) { | |
| 180 | + | firstitem = false; | |
| 181 | + | } else { | |
| 182 | + | os << ", "; | |
| 183 | + | } | |
| 184 | + | ||
| 185 | + | os << item->getNameDescription(); | |
| 186 | + | } | |
| 187 | + | ||
| 188 | + | if (firstitem) { | |
| 189 | + | os << "nothing"; | |
| 190 | + | } | |
| 191 | + | return os; | |
| 192 | + | } | |
| 193 | + | ||
| 194 | + | Item* Container::getItemByIndex(size_t index) const | |
| 195 | + | { | |
| 196 | + | if (index >= size()) { | |
| 197 | + | return nullptr; | |
| 198 | + | } | |
| 199 | + | return itemlist[index]; | |
| 200 | + | } | |
| 201 | + | ||
| 202 | + | uint32_t Container::getItemHoldingCount() const | |
| 203 | + | { | |
| 204 | + | uint32_t counter = 0; | |
| 205 | + | for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { | |
| 206 | + | ++counter; | |
| 207 | + | } | |
| 208 | + | return counter; | |
| 209 | + | } | |
| 210 | + | ||
| 211 | + | bool Container::isHoldingItem(const Item* item) const | |
| 212 | + | { | |
| 213 | + | for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { | |
| 214 | + | if (*it == item) { | |
| 215 | + | return true; | |
| 216 | + | } | |
| 217 | + | } | |
| 218 | + | return false; | |
| 219 | + | } | |
| 220 | + | ||
| 221 | + | void Container::onAddContainerItem(Item* item) | |
| 222 | + | { | |
| 223 | + | SpectatorVec spectators; | |
| 224 | + | g_game.map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); | |
| 225 | + | ||
| 226 | + | //send to client | |
| 227 | + | for (Creature* spectator : spectators) { | |
| 228 | + | spectator->getPlayer()->sendAddContainerItem(this, item); | |
| 229 | + | } | |
| 230 | + | ||
| 231 | + | //event methods | |
| 232 | + | for (Creature* spectator : spectators) { | |
| 233 | + | spectator->getPlayer()->onAddContainerItem(item); | |
| 234 | + | } | |
| 235 | + | } | |
| 236 | + | ||
| 237 | + | void Container::onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem) | |
| 238 | + | { | |
| 239 | + | SpectatorVec spectators; | |
| 240 | + | g_game.map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); | |
| 241 | + | ||
| 242 | + | //send to client | |
| 243 | + | for (Creature* spectator : spectators) { | |
| 244 | + | spectator->getPlayer()->sendUpdateContainerItem(this, index, newItem); | |
| 245 | + | } | |
| 246 | + | ||
| 247 | + | //event methods | |
| 248 | + | for (Creature* spectator : spectators) { | |
| 249 | + | spectator->getPlayer()->onUpdateContainerItem(this, oldItem, newItem); | |
| 250 | + | } | |
| 251 | + | } | |
| 252 | + | ||
| 253 | + | void Container::onRemoveContainerItem(uint32_t index, Item* item) | |
| 254 | + | { | |
| 255 | + | SpectatorVec spectators; | |
| 256 | + | g_game.map.getSpectators(spectators, getPosition(), false, true, 2, 2, 2, 2); | |
| 257 | + | ||
| 258 | + | //send change to client | |
| 259 | + | for (Creature* spectator : spectators) { | |
| 260 | + | spectator->getPlayer()->sendRemoveContainerItem(this, index); | |
| 261 | + | } | |
| 262 | + | ||
| 263 | + | //event methods | |
| 264 | + | for (Creature* spectator : spectators) { | |
| 265 | + | spectator->getPlayer()->onRemoveContainerItem(this, item); | |
| 266 | + | } | |
| 267 | + | } | |
| 268 | + | ||
| 269 | + | ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t count, | |
| 270 | + | uint32_t flags, Creature* actor/* = nullptr*/) const | |
| 271 | + | { | |
| 272 | + | bool childIsOwner = hasBitSet(FLAG_CHILDISOWNER, flags); | |
| 273 | + | if (childIsOwner) { | |
| 274 | + | //a child container is querying, since we are the top container (not carried by a player) | |
| 275 | + | //just return with no error. | |
| 276 | + | return RETURNVALUE_NOERROR; | |
| 277 | + | } | |
| 278 | + | ||
| 279 | + | if (!unlocked) { | |
| 280 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 281 | + | } | |
| 282 | + | ||
| 283 | + | const Item* item = thing.getItem(); | |
| 284 | + | if (item == nullptr) { | |
| 285 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 286 | + | } | |
| 287 | + | ||
| 288 | + | if (!item->isPickupable()) { | |
| 289 | + | return RETURNVALUE_CANNOTPICKUP; | |
| 290 | + | } | |
| 291 | + | ||
| 292 | + | if (item == this) { | |
| 293 | + | return RETURNVALUE_THISISIMPOSSIBLE; | |
| 294 | + | } | |
| 295 | + | ||
| 296 | + | const Cylinder* cylinder = getParent(); | |
| 297 | + | if (!hasBitSet(FLAG_NOLIMIT, flags)) { | |
| 298 | + | while (cylinder) { | |
| 299 | + | if (cylinder == &thing) { | |
| 300 | + | return RETURNVALUE_THISISIMPOSSIBLE; | |
| 301 | + | } | |
| 302 | + | ||
| 303 | + | if (dynamic_cast<const Inbox*>(cylinder)) { | |
| 304 | + | return RETURNVALUE_CONTAINERNOTENOUGHROOM; | |
| 305 | + | } | |
| 306 | + | ||
| 307 | + | cylinder = cylinder->getParent(); | |
| 308 | + | } | |
| 309 | + | ||
| 310 | + | if (index == INDEX_WHEREEVER && size() >= capacity()) { | |
| 311 | + | return RETURNVALUE_CONTAINERNOTENOUGHROOM; | |
| 312 | + | } | |
| 313 | + | } else { | |
| 314 | + | while (cylinder) { | |
| 315 | + | if (cylinder == &thing) { | |
| 316 | + | return RETURNVALUE_THISISIMPOSSIBLE; | |
| 317 | + | } | |
| 318 | + | ||
| 319 | + | cylinder = cylinder->getParent(); | |
| 320 | + | } | |
| 321 | + | } | |
| 322 | + | ||
| 323 | + | const Cylinder* topParent = getTopParent(); | |
| 324 | + | if (topParent != this) { | |
| 325 | + | return topParent->queryAdd(INDEX_WHEREEVER, *item, count, flags | FLAG_CHILDISOWNER, actor); | |
| 326 | + | } else { | |
| 327 | + | return RETURNVALUE_NOERROR; | |
| 328 | + | } | |
| 329 | + | } | |
| 330 | + | ||
| 331 | + | ReturnValue Container::queryMaxCount(int32_t index, const Thing& thing, uint32_t count, | |
| 332 | + | uint32_t& maxQueryCount, uint32_t flags) const | |
| 333 | + | { | |
| 334 | + | const Item* item = thing.getItem(); | |
| 335 | + | if (item == nullptr) { | |
| 336 | + | maxQueryCount = 0; | |
| 337 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 338 | + | } | |
| 339 | + | ||
| 340 | + | if (hasBitSet(FLAG_NOLIMIT, flags)) { | |
| 341 | + | maxQueryCount = std::max<uint32_t>(1, count); | |
| 342 | + | return RETURNVALUE_NOERROR; | |
| 343 | + | } | |
| 344 | + | ||
| 345 | + | int32_t freeSlots = std::max<int32_t>(capacity() - size(), 0); | |
| 346 | + | ||
| 347 | + | if (item->isStackable()) { | |
| 348 | + | uint32_t n = 0; | |
| 349 | + | ||
| 350 | + | if (index == INDEX_WHEREEVER) { | |
| 351 | + | //Iterate through every item and check how much free stackable slots there is. | |
| 352 | + | uint32_t slotIndex = 0; | |
| 353 | + | for (Item* containerItem : itemlist) { | |
| 354 | + | if (containerItem != item && containerItem->equals(item) && containerItem->getItemCount() < 100) { | |
| 355 | + | if (queryAdd(slotIndex++, *item, count, flags) == RETURNVALUE_NOERROR) { | |
| 356 | + | n += 100 - containerItem->getItemCount(); | |
| 357 | + | } | |
| 358 | + | } | |
| 359 | + | } | |
| 360 | + | } else { | |
| 361 | + | const Item* destItem = getItemByIndex(index); | |
| 362 | + | if (item->equals(destItem) && destItem->getItemCount() < 100) { | |
| 363 | + | if (queryAdd(index, *item, count, flags) == RETURNVALUE_NOERROR) { | |
| 364 | + | n = 100 - destItem->getItemCount(); | |
| 365 | + | } | |
| 366 | + | } | |
| 367 | + | } | |
| 368 | + | ||
| 369 | + | maxQueryCount = freeSlots * 100 + n; | |
| 370 | + | if (maxQueryCount < count) { | |
| 371 | + | return RETURNVALUE_CONTAINERNOTENOUGHROOM; | |
| 372 | + | } | |
| 373 | + | } else { | |
| 374 | + | maxQueryCount = freeSlots; | |
| 375 | + | if (maxQueryCount == 0) { | |
| 376 | + | return RETURNVALUE_CONTAINERNOTENOUGHROOM; | |
| 377 | + | } | |
| 378 | + | } | |
| 379 | + | return RETURNVALUE_NOERROR; | |
| 380 | + | } | |
| 381 | + | ||
| 382 | + | ReturnValue Container::queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const | |
| 383 | + | { | |
| 384 | + | int32_t index = getThingIndex(&thing); | |
| 385 | + | if (index == -1) { | |
| 386 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 387 | + | } | |
| 388 | + | ||
| 389 | + | const Item* item = thing.getItem(); | |
| 390 | + | if (item == nullptr) { | |
| 391 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 392 | + | } | |
| 393 | + | ||
| 394 | + | if (count == 0 || (item->isStackable() && count > item->getItemCount())) { | |
| 395 | + | return RETURNVALUE_NOTPOSSIBLE; | |
| 396 | + | } | |
| 397 | + | ||
| 398 | + | if (!item->isMoveable() && !hasBitSet(FLAG_IGNORENOTMOVEABLE, flags)) { | |
| 399 | + | return RETURNVALUE_NOTMOVEABLE; | |
| 400 | + | } | |
| 401 | + | return RETURNVALUE_NOERROR; | |
| 402 | + | } | |
| 403 | + | ||
| 404 | + | Cylinder* Container::queryDestination(int32_t& index, const Thing& thing, Item** destItem, | |
| 405 | + | uint32_t& flags) | |
| 406 | + | { | |
| 407 | + | if (!unlocked) { | |
| 408 | + | *destItem = nullptr; | |
| 409 | + | return this; | |
| 410 | + | } | |
| 411 | + | ||
| 412 | + | if (index == 254 /*move up*/) { | |
| 413 | + | index = INDEX_WHEREEVER; | |
| 414 | + | *destItem = nullptr; | |
| 415 | + | ||
| 416 | + | Container* parentContainer = dynamic_cast<Container*>(getParent()); | |
| 417 | + | if (parentContainer) { | |
| 418 | + | return parentContainer; | |
| 419 | + | } | |
| 420 | + | return this; | |
| 421 | + | } | |
| 422 | + | ||
| 423 | + | if (index == 255 /*add wherever*/) { | |
| 424 | + | index = INDEX_WHEREEVER; | |
| 425 | + | *destItem = nullptr; | |
| 426 | + | } else if (index >= static_cast<int32_t>(capacity())) { | |
| 427 | + | /* | |
| 428 | + | if you have a container, maximize it to show all 20 slots | |
| 429 | + | then you open a bag that is inside the container you will have a bag with 8 slots | |
| 430 | + | and a "grey" area where the other 12 slots where from the container | |
| 431 | + | if you drop the item on that grey area | |
| 432 | + | the client calculates the slot position as if the bag has 20 slots | |
| 433 | + | */ | |
| 434 | + | index = INDEX_WHEREEVER; | |
| 435 | + | *destItem = nullptr; | |
| 436 | + | } | |
| 437 | + | ||
| 438 | + | const Item* item = thing.getItem(); | |
| 439 | + | if (!item) { | |
| 440 | + | return this; | |
| 441 | + | } | |
| 442 | + | ||
| 443 | + | if (index != INDEX_WHEREEVER) { | |
| 444 | + | Item* itemFromIndex = getItemByIndex(index); | |
| 445 | + | if (itemFromIndex) { | |
| 446 | + | *destItem = itemFromIndex; | |
| 447 | + | } | |
| 448 | + | ||
| 449 | + | Cylinder* subCylinder = dynamic_cast<Cylinder*>(*destItem); | |
| 450 | + | if (subCylinder) { | |
| 451 | + | index = INDEX_WHEREEVER; | |
| 452 | + | *destItem = nullptr; | |
| 453 | + | return subCylinder; | |
| 454 | + | } | |
| 455 | + | } | |
| 456 | + | ||
| 457 | + | bool autoStack = !hasBitSet(FLAG_IGNOREAUTOSTACK, flags); | |
| 458 | + | if (autoStack && item->isStackable() && item->getParent() != this) { | |
| 459 | + | if (*destItem && (*destItem)->equals(item) && (*destItem)->getItemCount() < 100) { | |
| 460 | + | return this; | |
| 461 | + | } | |
| 462 | + | ||
| 463 | + | //try find a suitable item to stack with | |
| 464 | + | uint32_t n = 0; | |
| 465 | + | for (Item* listItem : itemlist) { | |
| 466 | + | if (listItem != item && listItem->equals(item) && listItem->getItemCount() < 100) { | |
| 467 | + | *destItem = listItem; | |
| 468 | + | index = n; | |
| 469 | + | return this; | |
| 470 | + | } | |
| 471 | + | ++n; | |
| 472 | + | } | |
| 473 | + | } | |
| 474 | + | return this; | |
| 475 | + | } | |
| 476 | + | ||
| 477 | + | void Container::addThing(Thing* thing) | |
| 478 | + | { | |
| 479 | + | return addThing(0, thing); | |
| 480 | + | } | |
| 481 | + | ||
| 482 | + | void Container::addThing(int32_t index, Thing* thing) | |
| 483 | + | { | |
| 484 | + | if (index >= static_cast<int32_t>(capacity())) { | |
| 485 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 486 | + | } | |
| 487 | + | ||
| 488 | + | Item* item = thing->getItem(); | |
| 489 | + | if (item == nullptr) { | |
| 490 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 491 | + | } | |
| 492 | + | ||
| 493 | + | item->setParent(this); | |
| 494 | + | itemlist.push_front(item); | |
| 495 | + | updateItemWeight(item->getWeight()); | |
| 496 | + | ||
| 497 | + | //send change to client | |
| 498 | + | if (getParent() && (getParent() != VirtualCylinder::virtualCylinder)) { | |
| 499 | + | onAddContainerItem(item); | |
| 500 | + | } | |
| 501 | + | } | |
| 502 | + | ||
| 503 | + | void Container::addItemBack(Item* item) | |
| 504 | + | { | |
| 505 | + | addItem(item); | |
| 506 | + | updateItemWeight(item->getWeight()); | |
| 507 | + | ||
| 508 | + | //send change to client | |
| 509 | + | if (getParent() && (getParent() != VirtualCylinder::virtualCylinder)) { | |
| 510 | + | onAddContainerItem(item); | |
| 511 | + | } | |
| 512 | + | } | |
| 513 | + | ||
| 514 | + | void Container::updateThing(Thing* thing, uint16_t itemId, uint32_t count) | |
| 515 | + | { | |
| 516 | + | int32_t index = getThingIndex(thing); | |
| 517 | + | if (index == -1) { | |
| 518 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 519 | + | } | |
| 520 | + | ||
| 521 | + | Item* item = thing->getItem(); | |
| 522 | + | if (item == nullptr) { | |
| 523 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 524 | + | } | |
| 525 | + | ||
| 526 | + | const int32_t oldWeight = item->getWeight(); | |
| 527 | + | item->setID(itemId); | |
| 528 | + | item->setSubType(count); | |
| 529 | + | updateItemWeight(-oldWeight + item->getWeight()); | |
| 530 | + | ||
| 531 | + | //send change to client | |
| 532 | + | if (getParent()) { | |
| 533 | + | onUpdateContainerItem(index, item, item); | |
| 534 | + | } | |
| 535 | + | } | |
| 536 | + | ||
| 537 | + | void Container::replaceThing(uint32_t index, Thing* thing) | |
| 538 | + | { | |
| 539 | + | Item* item = thing->getItem(); | |
| 540 | + | if (!item) { | |
| 541 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 542 | + | } | |
| 543 | + | ||
| 544 | + | Item* replacedItem = getItemByIndex(index); | |
| 545 | + | if (!replacedItem) { | |
| 546 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 547 | + | } | |
| 548 | + | ||
| 549 | + | itemlist[index] = item; | |
| 550 | + | item->setParent(this); | |
| 551 | + | updateItemWeight(-static_cast<int32_t>(replacedItem->getWeight()) + item->getWeight()); | |
| 552 | + | ||
| 553 | + | //send change to client | |
| 554 | + | if (getParent()) { | |
| 555 | + | onUpdateContainerItem(index, replacedItem, item); | |
| 556 | + | } | |
| 557 | + | ||
| 558 | + | replacedItem->setParent(nullptr); | |
| 559 | + | } | |
| 560 | + | ||
| 561 | + | void Container::removeThing(Thing* thing, uint32_t count) | |
| 562 | + | { | |
| 563 | + | Item* item = thing->getItem(); | |
| 564 | + | if (item == nullptr) { | |
| 565 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 566 | + | } | |
| 567 | + | ||
| 568 | + | int32_t index = getThingIndex(thing); | |
| 569 | + | if (index == -1) { | |
| 570 | + | return /*RETURNVALUE_NOTPOSSIBLE*/; | |
| 571 | + | } | |
| 572 | + | ||
| 573 | + | if (item->isStackable() && count != item->getItemCount()) { | |
| 574 | + | uint8_t newCount = static_cast<uint8_t>(std::max<int32_t>(0, item->getItemCount() - count)); | |
| 575 | + | const int32_t oldWeight = item->getWeight(); | |
| 576 | + | item->setItemCount(newCount); | |
| 577 | + | updateItemWeight(-oldWeight + item->getWeight()); | |
| 578 | + | ||
| 579 | + | //send change to client | |
| 580 | + | if (getParent()) { | |
| 581 | + | onUpdateContainerItem(index, item, item); | |
| 582 | + | } | |
| 583 | + | } else { | |
| 584 | + | updateItemWeight(-static_cast<int32_t>(item->getWeight())); | |
| 585 | + | ||
| 586 | + | //send change to client | |
| 587 | + | if (getParent()) { | |
| 588 | + | onRemoveContainerItem(index, item); | |
| 589 | + | } | |
| 590 | + | ||
| 591 | + | item->setParent(nullptr); | |
| 592 | + | itemlist.erase(itemlist.begin() + index); | |
| 593 | + | } | |
| 594 | + | } | |
| 595 | + | ||
| 596 | + | int32_t Container::getThingIndex(const Thing* thing) const | |
| 597 | + | { | |
| 598 | + | int32_t index = 0; | |
| 599 | + | for (Item* item : itemlist) { | |
| 600 | + | if (item == thing) { | |
| 601 | + | return index; | |
| 602 | + | } | |
| 603 | + | ++index; | |
| 604 | + | } | |
| 605 | + | return -1; | |
| 606 | + | } | |
| 607 | + | ||
| 608 | + | size_t Container::getFirstIndex() const | |
| 609 | + | { | |
| 610 | + | return 0; | |
| 611 | + | } | |
| 612 | + | ||
| 613 | + | size_t Container::getLastIndex() const | |
| 614 | + | { | |
| 615 | + | return size(); | |
| 616 | + | } | |
| 617 | + | ||
| 618 | + | uint32_t Container::getItemTypeCount(uint16_t itemId, int32_t subType/* = -1*/) const | |
| 619 | + | { | |
| 620 | + | uint32_t count = 0; | |
| 621 | + | for (Item* item : itemlist) { | |
| 622 | + | if (item->getID() == itemId) { | |
| 623 | + | count += countByType(item, subType); | |
| 624 | + | } | |
| 625 | + | } | |
| 626 | + | return count; | |
| 627 | + | } | |
| 628 | + | ||
| 629 | + | std::map<uint32_t, uint32_t>& Container::getAllItemTypeCount(std::map<uint32_t, uint32_t>& countMap) const | |
| 630 | + | { | |
| 631 | + | for (Item* item : itemlist) { | |
| 632 | + | countMap[item->getID()] += item->getItemCount(); | |
| 633 | + | } | |
| 634 | + | return countMap; | |
| 635 | + | } | |
| 636 | + | ||
| 637 | + | Thing* Container::getThing(size_t index) const | |
| 638 | + | { | |
| 639 | + | return getItemByIndex(index); | |
| 640 | + | } | |
| 641 | + | ||
| 642 | + | void Container::postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t) | |
| 643 | + | { | |
| 644 | + | Cylinder* topParent = getTopParent(); | |
| 645 | + | if (topParent->getCreature()) { | |
| 646 | + | topParent->postAddNotification(thing, oldParent, index, LINK_TOPPARENT); | |
| 647 | + | } else if (topParent == this) { | |
| 648 | + | //let the tile class notify surrounding players | |
| 649 | + | if (topParent->getParent()) { | |
| 650 | + | topParent->getParent()->postAddNotification(thing, oldParent, index, LINK_NEAR); | |
| 651 | + | } | |
| 652 | + | } else { | |
| 653 | + | topParent->postAddNotification(thing, oldParent, index, LINK_PARENT); | |
| 654 | + | } | |
| 655 | + | } | |
| 656 | + | ||
| 657 | + | void Container::postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t) | |
| 658 | + | { | |
| 659 | + | Cylinder* topParent = getTopParent(); | |
| 660 | + | if (topParent->getCreature()) { | |
| 661 | + | topParent->postRemoveNotification(thing, newParent, index, LINK_TOPPARENT); | |
| 662 | + | } else if (topParent == this) { | |
| 663 | + | //let the tile class notify surrounding players | |
| 664 | + | if (topParent->getParent()) { | |
| 665 | + | topParent->getParent()->postRemoveNotification(thing, newParent, index, LINK_NEAR); | |
| 666 | + | } | |
| 667 | + | } else { | |
| 668 | + | topParent->postRemoveNotification(thing, newParent, index, LINK_PARENT); | |
| 669 | + | } | |
| 670 | + | } | |
| 671 | + | ||
| 672 | + | void Container::internalAddThing(Thing* thing) | |
| 673 | + | { | |
| 674 | + | internalAddThing(0, thing); | |
| 675 | + | } | |
| 676 | + | ||
| 677 | + | void Container::internalAddThing(uint32_t, Thing* thing) | |
| 678 | + | { | |
| 679 | + | Item* item = thing->getItem(); | |
| 680 | + | if (item == nullptr) { | |
| 681 | + | return; | |
| 682 | + | } | |
| 683 | + | ||
| 684 | + | item->setParent(this); | |
| 685 | + | itemlist.push_front(item); | |
| 686 | + | updateItemWeight(item->getWeight()); | |
| 687 | + | } | |
| 688 | + | ||
| 689 | + | void Container::startDecaying() | |
| 690 | + | { | |
| 691 | + | for (Item* item : itemlist) { | |
| 692 | + | item->startDecaying(); | |
| 693 | + | } | |
| 694 | + | } | |
| 695 | + | ||
| 696 | + | ContainerIterator Container::iterator() const | |
| 697 | + | { | |
| 698 | + | ContainerIterator cit; | |
| 699 | + | if (!itemlist.empty()) { | |
| 700 | + | cit.over.push_back(this); | |
| 701 | + | cit.cur = itemlist.begin(); | |
| 702 | + | } | |
| 703 | + | return cit; | |
| 704 | + | } | |
| 705 | + | ||
| 706 | + | Item* ContainerIterator::operator*() | |
| 707 | + | { | |
| 708 | + | return *cur; | |
| 709 | + | } | |
| 710 | + | ||
| 711 | + | void ContainerIterator::advance() | |
| 712 | + | { | |
| 713 | + | if (Item* i = *cur) { | |
| 714 | + | if (Container* c = i->getContainer()) { | |
| 715 | + | if (!c->empty()) { | |
| 716 | + | over.push_back(c); | |
| 717 | + | } | |
| 718 | + | } | |
| 719 | + | } | |
| 720 | + | ||
| 721 | + | ++cur; | |
| 722 | + | ||
| 723 | + | if (cur == over.front()->itemlist.end()) { | |
| 724 | + | over.pop_front(); | |
| 725 | + | if (!over.empty()) { | |
| 726 | + | cur = over.front()->itemlist.begin(); | |
| 727 | + | } | |
| 728 | + | } | |
| 729 | + | } |
| @@ -0,0 +1,177 @@ | |||
| 1 | + | /** | |
| 2 | + | * The Forgotten Server - a free and open-source MMORPG server emulator | |
| 3 | + | * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com> | |
| 4 | + | * | |
| 5 | + | * This program is free software; you can redistribute it and/or modify | |
| 6 | + | * it under the terms of the GNU General Public License as published by | |
| 7 | + | * the Free Software Foundation; either version 2 of the License, or | |
| 8 | + | * (at your option) any later version. | |
| 9 | + | * | |
| 10 | + | * This program is distributed in the hope that it will be useful, | |
| 11 | + | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | + | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | + | * GNU General Public License for more details. | |
| 14 | + | * | |
| 15 | + | * You should have received a copy of the GNU General Public License along | |
| 16 | + | * with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 | + | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 | + | */ | |
| 19 | + | ||
| 20 | + | #ifndef FS_CONTAINER_H_5590165FD8A2451B98D71F13CD3ED8DC | |
| 21 | + | #define FS_CONTAINER_H_5590165FD8A2451B98D71F13CD3ED8DC | |
| 22 | + | ||
| 23 | + | #include <queue> | |
| 24 | + | ||
| 25 | + | #include "cylinder.h" | |
| 26 | + | #include "item.h" | |
| 27 | + | ||
| 28 | + | class Container; | |
| 29 | + | class DepotChest; | |
| 30 | + | class DepotLocker; | |
| 31 | + | ||
| 32 | + | class ContainerIterator | |
| 33 | + | { | |
| 34 | + | public: | |
| 35 | + | bool hasNext() const { | |
| 36 | + | return !over.empty(); | |
| 37 | + | } | |
| 38 | + | ||
| 39 | + | void advance(); | |
| 40 | + | Item* operator*(); | |
| 41 | + | ||
| 42 | + | private: | |
| 43 | + | std::list<const Container*> over; | |
| 44 | + | ItemDeque::const_iterator cur; | |
| 45 | + | ||
| 46 | + | friend class Container; | |
| 47 | + | }; | |
| 48 | + | ||
| 49 | + | class Container : public Item, public Cylinder | |
| 50 | + | { | |
| 51 | + | public: | |
| 52 | + | explicit Container(uint16_t type); | |
| 53 | + | Container(uint16_t type, uint16_t size, bool unlocked = true, bool pagination = false); | |
| 54 | + | explicit Container(Tile* tile); | |
| 55 | + | ~Container(); | |
| 56 | + | ||
| 57 | + | // non-copyable | |
| 58 | + | Container(const Container&) = delete; | |
| 59 | + | Container& operator=(const Container&) = delete; | |
| 60 | + | ||
| 61 | + | Item* clone() const override final; | |
| 62 | + | ||
| 63 | + | Container* getContainer() override final { | |
| 64 | + | return this; | |
| 65 | + | } | |
| 66 | + | const Container* getContainer() const override final { | |
| 67 | + | return this; | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | virtual DepotLocker* getDepotLocker() { | |
| 71 | + | return nullptr; | |
| 72 | + | } | |
| 73 | + | virtual const DepotLocker* getDepotLocker() const { | |
| 74 | + | return nullptr; | |
| 75 | + | } | |
| 76 | + | ||
| 77 | + | Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream) override; | |
| 78 | + | bool unserializeItemNode(OTB::Loader& loader, const OTB::Node& node, PropStream& propStream) override; | |
| 79 | + | std::string getContentDescription() const; | |
| 80 | + | ||
| 81 | + | size_t size() const { | |
| 82 | + | return itemlist.size(); | |
| 83 | + | } | |
| 84 | + | bool empty() const { | |
| 85 | + | return itemlist.empty(); | |
| 86 | + | } | |
| 87 | + | uint32_t capacity() const { | |
| 88 | + | return maxSize; | |
| 89 | + | } | |
| 90 | + | ||
| 91 | + | ContainerIterator iterator() const; | |
| 92 | + | ||
| 93 | + | const ItemDeque& getItemList() const { | |
| 94 | + | return itemlist; | |
| 95 | + | } | |
| 96 | + | ||
| 97 | + | ItemDeque::const_reverse_iterator getReversedItems() const { | |
| 98 | + | return itemlist.rbegin(); | |
| 99 | + | } | |
| 100 | + | ItemDeque::const_reverse_iterator getReversedEnd() const { | |
| 101 | + | return itemlist.rend(); | |
| 102 | + | } | |
| 103 | + | ||
| 104 | + | std::string getName(bool addArticle = false) const; | |
| 105 | + | ||
| 106 | + | bool hasParent() const; | |
| 107 | + | void addItem(Item* item); | |
| 108 | + | Item* getItemByIndex(size_t index) const; | |
| 109 | + | bool isHoldingItem(const Item* item) const; | |
| 110 | + | ||
| 111 | + | uint32_t getItemHoldingCount() const; | |
| 112 | + | uint32_t getWeight() const override final; | |
| 113 | + | ||
| 114 | + | bool isUnlocked() const { | |
| 115 | + | return unlocked; | |
| 116 | + | } | |
| 117 | + | bool hasPagination() const { | |
| 118 | + | return pagination; | |
| 119 | + | } | |
| 120 | + | ||
| 121 | + | //cylinder implementations | |
| 122 | + | virtual ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count, | |
| 123 | + | uint32_t flags, Creature* actor = nullptr) const override; | |
| 124 | + | ReturnValue queryMaxCount(int32_t index, const Thing& thing, uint32_t count, uint32_t& maxQueryCount, | |
| 125 | + | uint32_t flags) const override final; | |
| 126 | + | ReturnValue queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const override final; | |
| 127 | + | Cylinder* queryDestination(int32_t& index, const Thing& thing, Item** destItem, | |
| 128 | + | uint32_t& flags) override final; | |
| 129 | + | ||
| 130 | + | void addThing(Thing* thing) override final; | |
| 131 | + | void addThing(int32_t index, Thing* thing) override final; | |
| 132 | + | void addItemBack(Item* item); | |
| 133 | + | ||
| 134 | + | void updateThing(Thing* thing, uint16_t itemId, uint32_t count) override final; | |
| 135 | + | void replaceThing(uint32_t index, Thing* thing) override final; | |
| 136 | + | ||
| 137 | + | void removeThing(Thing* thing, uint32_t count) override final; | |
| 138 | + | ||
| 139 | + | int32_t getThingIndex(const Thing* thing) const override final; | |
| 140 | + | size_t getFirstIndex() const override final; | |
| 141 | + | size_t getLastIndex() const override final; | |
| 142 | + | uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const override final; | |
| 143 | + | std::map<uint32_t, uint32_t>& getAllItemTypeCount(std::map<uint32_t, uint32_t>& countMap) const override final; | |
| 144 | + | Thing* getThing(size_t index) const override final; | |
| 145 | + | ||
| 146 | + | void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; | |
| 147 | + | void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, cylinderlink_t link = LINK_OWNER) override; | |
| 148 | + | ||
| 149 | + | void internalAddThing(Thing* thing) override final; | |
| 150 | + | void internalAddThing(uint32_t index, Thing* thing) override final; | |
| 151 | + | void startDecaying() override final; | |
| 152 | + | ||
| 153 | + | protected: | |
| 154 | + | ItemDeque itemlist; | |
| 155 | + | ||
| 156 | + | private: | |
| 157 | + | std::ostringstream& getContentDescription(std::ostringstream& os) const; | |
| 158 | + | ||
| 159 | + | uint32_t maxSize; | |
| 160 | + | uint32_t totalWeight = 0; | |
| 161 | + | uint32_t serializationCount = 0; | |
| 162 | + | ||
| 163 | + | bool unlocked; | |
| 164 | + | bool pagination; | |
| 165 | + | ||
| 166 | + | void onAddContainerItem(Item* item); | |
| 167 | + | void onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem); | |
| 168 | + | void onRemoveContainerItem(uint32_t index, Item* item); | |
| 169 | + | ||
| 170 | + | Container* getParentContainer(); | |
| 171 | + | void updateItemWeight(int32_t diff); | |
| 172 | + | ||
| 173 | + | friend class ContainerIterator; | |
| 174 | + | friend class IOMapSerialize; | |
| 175 | + | }; | |
| 176 | + | ||
| 177 | + | #endif |