| @@ -0,0 +1,975 @@ | |||
| 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 "combat.h" | |
| 23 | + | #include "configmanager.h" | |
| 24 | + | #include "game.h" | |
| 25 | + | #include "pugicast.h" | |
| 26 | + | #include "weapons.h" | |
| 27 | + | ||
| 28 | + | extern Game g_game; | |
| 29 | + | extern Vocations g_vocations; | |
| 30 | + | extern ConfigManager g_config; | |
| 31 | + | extern Weapons *g_weapons; | |
| 32 | + | ||
| 33 | + | Weapons::Weapons() { scriptInterface.initState(); } | |
| 34 | + | ||
| 35 | + | Weapons::~Weapons() { clear(false); } | |
| 36 | + | ||
| 37 | + | const Weapon *Weapons::getWeapon(const Item *item) const { | |
| 38 | + | if (!item) { | |
| 39 | + | return nullptr; | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | auto it = weapons.find(item->getID()); | |
| 43 | + | if (it == weapons.end()) { | |
| 44 | + | return nullptr; | |
| 45 | + | } | |
| 46 | + | return it->second; | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | void Weapons::clear(bool fromLua) { | |
| 50 | + | for (auto it = weapons.begin(); it != weapons.end();) { | |
| 51 | + | if (fromLua == it->second->fromLua) { | |
| 52 | + | it = weapons.erase(it); | |
| 53 | + | } else { | |
| 54 | + | ++it; | |
| 55 | + | } | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | reInitState(fromLua); | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | LuaScriptInterface &Weapons::getScriptInterface() { return scriptInterface; } | |
| 62 | + | ||
| 63 | + | std::string Weapons::getScriptBaseName() const { return "weapons"; } | |
| 64 | + | ||
| 65 | + | void Weapons::loadDefaults() { | |
| 66 | + | for (size_t i = 100, size = Item::items.size(); i < size; ++i) { | |
| 67 | + | const ItemType &it = Item::items.getItemType(i); | |
| 68 | + | if (it.id == 0 || weapons.find(i) != weapons.end()) { | |
| 69 | + | continue; | |
| 70 | + | } | |
| 71 | + | ||
| 72 | + | switch (it.weaponType) { | |
| 73 | + | case WEAPON_AXE: | |
| 74 | + | case WEAPON_SWORD: | |
| 75 | + | case WEAPON_CLUB: { | |
| 76 | + | WeaponMelee *weapon = new WeaponMelee(&scriptInterface); | |
| 77 | + | weapon->configureWeapon(it); | |
| 78 | + | weapons[i] = weapon; | |
| 79 | + | break; | |
| 80 | + | } | |
| 81 | + | ||
| 82 | + | case WEAPON_AMMO: | |
| 83 | + | case WEAPON_DISTANCE: { | |
| 84 | + | if (it.weaponType == WEAPON_DISTANCE && it.ammoType != AMMO_NONE) { | |
| 85 | + | continue; | |
| 86 | + | } | |
| 87 | + | ||
| 88 | + | WeaponDistance *weapon = new WeaponDistance(&scriptInterface); | |
| 89 | + | weapon->configureWeapon(it); | |
| 90 | + | weapons[i] = weapon; | |
| 91 | + | break; | |
| 92 | + | } | |
| 93 | + | ||
| 94 | + | default: | |
| 95 | + | break; | |
| 96 | + | } | |
| 97 | + | } | |
| 98 | + | } | |
| 99 | + | ||
| 100 | + | Event_ptr Weapons::getEvent(const std::string &nodeName) { | |
| 101 | + | if (strcasecmp(nodeName.c_str(), "melee") == 0) { | |
| 102 | + | return Event_ptr(new WeaponMelee(&scriptInterface)); | |
| 103 | + | } else if (strcasecmp(nodeName.c_str(), "distance") == 0) { | |
| 104 | + | return Event_ptr(new WeaponDistance(&scriptInterface)); | |
| 105 | + | } else if (strcasecmp(nodeName.c_str(), "wand") == 0) { | |
| 106 | + | return Event_ptr(new WeaponWand(&scriptInterface)); | |
| 107 | + | } | |
| 108 | + | return nullptr; | |
| 109 | + | } | |
| 110 | + | ||
| 111 | + | bool Weapons::registerEvent(Event_ptr event, const pugi::xml_node &) { | |
| 112 | + | Weapon *weapon = static_cast<Weapon *>( | |
| 113 | + | event.release()); // event is guaranteed to be a Weapon | |
| 114 | + | ||
| 115 | + | auto result = weapons.emplace(weapon->getID(), weapon); | |
| 116 | + | if (!result.second) { | |
| 117 | + | std::cout << "[Warning - Weapons::registerEvent] Duplicate registered item " | |
| 118 | + | "with id: " | |
| 119 | + | << weapon->getID() << std::endl; | |
| 120 | + | } | |
| 121 | + | return result.second; | |
| 122 | + | } | |
| 123 | + | ||
| 124 | + | bool Weapons::registerLuaEvent(Weapon *event) { | |
| 125 | + | Weapon_ptr weapon{event}; | |
| 126 | + | weapons[weapon->getID()] = weapon.release(); | |
| 127 | + | ||
| 128 | + | return true; | |
| 129 | + | } | |
| 130 | + | ||
| 131 | + | // monsters | |
| 132 | + | int32_t Weapons::getMaxMeleeDamage(int32_t attackSkill, int32_t attackValue) { | |
| 133 | + | return static_cast<int32_t>( | |
| 134 | + | std::ceil((attackSkill * (attackValue * 0.05)) + (attackValue * 0.5))); | |
| 135 | + | } | |
| 136 | + | ||
| 137 | + | // players | |
| 138 | + | int32_t Weapons::getMaxWeaponDamage(uint32_t level, int32_t attackSkill, | |
| 139 | + | int32_t attackValue, float attackFactor) { | |
| 140 | + | return static_cast<int32_t>(std::round( | |
| 141 | + | (level / 5) + (((((attackSkill / 4.) + 1) * (attackValue / 3.)) * 1.03) / | |
| 142 | + | attackFactor))); | |
| 143 | + | } | |
| 144 | + | ||
| 145 | + | bool Weapon::configureEvent(const pugi::xml_node &node) { | |
| 146 | + | pugi::xml_attribute attr; | |
| 147 | + | if (!(attr = node.attribute("id"))) { | |
| 148 | + | std::cout << "[Error - Weapon::configureEvent] Weapon without id." | |
| 149 | + | << std::endl; | |
| 150 | + | return false; | |
| 151 | + | } | |
| 152 | + | id = pugi::cast<uint16_t>(attr.value()); | |
| 153 | + | ||
| 154 | + | if ((attr = node.attribute("level"))) { | |
| 155 | + | level = pugi::cast<uint32_t>(attr.value()); | |
| 156 | + | } | |
| 157 | + | ||
| 158 | + | if ((attr = node.attribute("maglv")) || (attr = node.attribute("maglevel"))) { | |
| 159 | + | magLevel = pugi::cast<uint32_t>(attr.value()); | |
| 160 | + | } | |
| 161 | + | ||
| 162 | + | if ((attr = node.attribute("mana"))) { | |
| 163 | + | mana = pugi::cast<uint32_t>(attr.value()); | |
| 164 | + | } | |
| 165 | + | ||
| 166 | + | if ((attr = node.attribute("manapercent"))) { | |
| 167 | + | manaPercent = pugi::cast<uint32_t>(attr.value()); | |
| 168 | + | } | |
| 169 | + | ||
| 170 | + | if ((attr = node.attribute("soul"))) { | |
| 171 | + | soul = pugi::cast<uint32_t>(attr.value()); | |
| 172 | + | } | |
| 173 | + | ||
| 174 | + | if ((attr = node.attribute("prem"))) { | |
| 175 | + | premium = attr.as_bool(); | |
| 176 | + | } | |
| 177 | + | ||
| 178 | + | if ((attr = node.attribute("breakchance"))) { | |
| 179 | + | breakChance = std::min<uint8_t>(100, pugi::cast<uint16_t>(attr.value())); | |
| 180 | + | } | |
| 181 | + | ||
| 182 | + | if ((attr = node.attribute("action"))) { | |
| 183 | + | action = getWeaponAction(asLowerCaseString(attr.as_string())); | |
| 184 | + | if (action == WEAPONACTION_NONE) { | |
| 185 | + | std::cout << "[Warning - Weapon::configureEvent] Unknown action " | |
| 186 | + | << attr.as_string() << std::endl; | |
| 187 | + | } | |
| 188 | + | } | |
| 189 | + | ||
| 190 | + | if ((attr = node.attribute("enabled"))) { | |
| 191 | + | enabled = attr.as_bool(); | |
| 192 | + | } | |
| 193 | + | ||
| 194 | + | if ((attr = node.attribute("unproperly"))) { | |
| 195 | + | wieldUnproperly = attr.as_bool(); | |
| 196 | + | } | |
| 197 | + | ||
| 198 | + | std::list<std::string> vocStringList; | |
| 199 | + | for (auto vocationNode : node.children()) { | |
| 200 | + | if (!(attr = vocationNode.attribute("name"))) { | |
| 201 | + | continue; | |
| 202 | + | } | |
| 203 | + | ||
| 204 | + | int32_t vocationId = g_vocations.getVocationId(attr.as_string()); | |
| 205 | + | if (vocationId != -1) { | |
| 206 | + | vocWeaponMap[vocationId] = true; | |
| 207 | + | int32_t promotedVocation = g_vocations.getPromotedVocation(vocationId); | |
| 208 | + | if (promotedVocation != VOCATION_NONE) { | |
| 209 | + | vocWeaponMap[promotedVocation] = true; | |
| 210 | + | } | |
| 211 | + | ||
| 212 | + | if (vocationNode.attribute("showInDescription").as_bool(true)) { | |
| 213 | + | vocStringList.push_back(asLowerCaseString(attr.as_string())); | |
| 214 | + | } | |
| 215 | + | } | |
| 216 | + | } | |
| 217 | + | ||
| 218 | + | std::string vocationString; | |
| 219 | + | for (const std::string &str : vocStringList) { | |
| 220 | + | if (!vocationString.empty()) { | |
| 221 | + | if (str != vocStringList.back()) { | |
| 222 | + | vocationString.push_back(','); | |
| 223 | + | vocationString.push_back(' '); | |
| 224 | + | } else { | |
| 225 | + | vocationString += " and "; | |
| 226 | + | } | |
| 227 | + | } | |
| 228 | + | ||
| 229 | + | vocationString += str; | |
| 230 | + | vocationString.push_back('s'); | |
| 231 | + | } | |
| 232 | + | ||
| 233 | + | uint32_t wieldInfo = 0; | |
| 234 | + | if (getReqLevel() > 0) { | |
| 235 | + | wieldInfo |= WIELDINFO_LEVEL; | |
| 236 | + | } | |
| 237 | + | ||
| 238 | + | if (getReqMagLv() > 0) { | |
| 239 | + | wieldInfo |= WIELDINFO_MAGLV; | |
| 240 | + | } | |
| 241 | + | ||
| 242 | + | if (!vocationString.empty()) { | |
| 243 | + | wieldInfo |= WIELDINFO_VOCREQ; | |
| 244 | + | } | |
| 245 | + | ||
| 246 | + | if (isPremium()) { | |
| 247 | + | wieldInfo |= WIELDINFO_PREMIUM; | |
| 248 | + | } | |
| 249 | + | ||
| 250 | + | if (wieldInfo != 0) { | |
| 251 | + | ItemType &it = Item::items.getItemType(id); | |
| 252 | + | it.wieldInfo = wieldInfo; | |
| 253 | + | it.vocationString = vocationString; | |
| 254 | + | it.minReqLevel = getReqLevel(); | |
| 255 | + | it.minReqMagicLevel = getReqMagLv(); | |
| 256 | + | } | |
| 257 | + | ||
| 258 | + | configureWeapon(Item::items[id]); | |
| 259 | + | return true; | |
| 260 | + | } | |
| 261 | + | ||
| 262 | + | void Weapon::configureWeapon(const ItemType &it) { id = it.id; } | |
| 263 | + | ||
| 264 | + | std::string Weapon::getScriptEventName() const { return "onUseWeapon"; } | |
| 265 | + | ||
| 266 | + | int32_t Weapon::playerWeaponCheck(Player *player, Creature *target, | |
| 267 | + | uint8_t shootRange) const { | |
| 268 | + | const Position &playerPos = player->getPosition(); | |
| 269 | + | const Position &targetPos = target->getPosition(); | |
| 270 | + | if (playerPos.z != targetPos.z) { | |
| 271 | + | return 0; | |
| 272 | + | } | |
| 273 | + | ||
| 274 | + | uint8_t effectiveRange = shootRange; | |
| 275 | + | const Outfit *outfit = Outfits::getInstance().getOutfitByLookType( | |
| 276 | + | player->getSex(), player->getCurrentOutfit().lookType); | |
| 277 | + | if (outfit && outfit->attackRange > effectiveRange) { | |
| 278 | + | effectiveRange = outfit->attackRange; | |
| 279 | + | } | |
| 280 | + | ||
| 281 | + | if (std::max<uint32_t>(Position::getDistanceX(playerPos, targetPos), | |
| 282 | + | Position::getDistanceY(playerPos, targetPos)) > | |
| 283 | + | effectiveRange) { | |
| 284 | + | return 0; | |
| 285 | + | } | |
| 286 | + | ||
| 287 | + | if (!player->hasFlag(PlayerFlag_IgnoreWeaponCheck)) { | |
| 288 | + | if (!enabled) { | |
| 289 | + | return 0; | |
| 290 | + | } | |
| 291 | + | ||
| 292 | + | if (player->getMana() < getManaCost(player)) { | |
| 293 | + | return 0; | |
| 294 | + | } | |
| 295 | + | ||
| 296 | + | if (player->getHealth() < getHealthCost(player)) { | |
| 297 | + | return 0; | |
| 298 | + | } | |
| 299 | + | ||
| 300 | + | if (player->getSoul() < soul) { | |
| 301 | + | return 0; | |
| 302 | + | } | |
| 303 | + | ||
| 304 | + | if (isPremium() && !player->isPremium()) { | |
| 305 | + | return 0; | |
| 306 | + | } | |
| 307 | + | ||
| 308 | + | if (!vocWeaponMap.empty()) { | |
| 309 | + | if (vocWeaponMap.find(player->getVocationId()) == vocWeaponMap.end()) { | |
| 310 | + | return 0; | |
| 311 | + | } | |
| 312 | + | } | |
| 313 | + | ||
| 314 | + | int32_t damageModifier = 100; | |
| 315 | + | if (player->getLevel() < getReqLevel()) { | |
| 316 | + | damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); | |
| 317 | + | } | |
| 318 | + | ||
| 319 | + | if (player->getMagicLevel() < getReqMagLv()) { | |
| 320 | + | damageModifier = (isWieldedUnproperly() ? damageModifier / 2 : 0); | |
| 321 | + | } | |
| 322 | + | return damageModifier; | |
| 323 | + | } | |
| 324 | + | ||
| 325 | + | return 100; | |
| 326 | + | } | |
| 327 | + | ||
| 328 | + | bool Weapon::useWeapon(Player *player, Item *item, Creature *target) const { | |
| 329 | + | int32_t damageModifier = | |
| 330 | + | playerWeaponCheck(player, target, item->getShootRange()); | |
| 331 | + | if (damageModifier == 0) { | |
| 332 | + | return false; | |
| 333 | + | } | |
| 334 | + | ||
| 335 | + | internalUseWeapon(player, item, target, damageModifier); | |
| 336 | + | return true; | |
| 337 | + | } | |
| 338 | + | ||
| 339 | + | bool Weapon::useFist(Player *player, Creature *target) { | |
| 340 | + | uint8_t range = 1; | |
| 341 | + | const Outfit *outfit = Outfits::getInstance().getOutfitByLookType( | |
| 342 | + | player->getSex(), player->getCurrentOutfit().lookType); | |
| 343 | + | if (outfit) { | |
| 344 | + | range = outfit->attackRange; | |
| 345 | + | } | |
| 346 | + | ||
| 347 | + | if (std::max<uint32_t>( | |
| 348 | + | Position::getDistanceX(player->getPosition(), target->getPosition()), | |
| 349 | + | Position::getDistanceY(player->getPosition(), | |
| 350 | + | target->getPosition())) > range) { | |
| 351 | + | return false; | |
| 352 | + | } | |
| 353 | + | ||
| 354 | + | float attackFactor = player->getAttackFactor(); | |
| 355 | + | int32_t attackSkill = player->getSkillLevel(SKILL_FIST); | |
| 356 | + | int32_t attackValue = 7; | |
| 357 | + | ||
| 358 | + | int32_t maxDamage = Weapons::getMaxWeaponDamage( | |
| 359 | + | player->getLevel(), attackSkill, attackValue, attackFactor); | |
| 360 | + | ||
| 361 | + | CombatParams params; | |
| 362 | + | params.combatType = COMBAT_PHYSICALDAMAGE; | |
| 363 | + | params.blockedByArmor = true; | |
| 364 | + | params.blockedByShield = true; | |
| 365 | + | ||
| 366 | + | CombatDamage damage; | |
| 367 | + | damage.origin = ORIGIN_MELEE; | |
| 368 | + | damage.primary.type = params.combatType; | |
| 369 | + | damage.primary.value = -normal_random(0, maxDamage); | |
| 370 | + | ||
| 371 | + | Combat::doTargetCombat(player, target, damage, params); | |
| 372 | + | if (!player->hasFlag(PlayerFlag_NotGainSkill) && | |
| 373 | + | player->getAddAttackSkill()) { | |
| 374 | + | player->addSkillAdvance(SKILL_FIST, 1); | |
| 375 | + | } | |
| 376 | + | ||
| 377 | + | return true; | |
| 378 | + | } | |
| 379 | + | ||
| 380 | + | void Weapon::internalUseWeapon(Player *player, Item *item, Creature *target, | |
| 381 | + | int32_t damageModifier) const { | |
| 382 | + | if (scripted) { | |
| 383 | + | LuaVariant var; | |
| 384 | + | var.type = VARIANT_NUMBER; | |
| 385 | + | var.number = target->getID(); | |
| 386 | + | executeUseWeapon(player, var); | |
| 387 | + | } else { | |
| 388 | + | CombatDamage damage; | |
| 389 | + | WeaponType_t weaponType = item->getWeaponType(); | |
| 390 | + | if (weaponType == WEAPON_AMMO || weaponType == WEAPON_DISTANCE) { | |
| 391 | + | damage.origin = ORIGIN_RANGED; | |
| 392 | + | } else { | |
| 393 | + | damage.origin = ORIGIN_MELEE; | |
| 394 | + | } | |
| 395 | + | damage.primary.type = params.combatType; | |
| 396 | + | damage.primary.value = | |
| 397 | + | (getWeaponDamage(player, target, item) * damageModifier) / 100; | |
| 398 | + | damage.secondary.type = getElementType(); | |
| 399 | + | damage.secondary.value = getElementDamage(player, target, item); | |
| 400 | + | Combat::doTargetCombat(player, target, damage, params); | |
| 401 | + | } | |
| 402 | + | ||
| 403 | + | onUsedWeapon(player, item, target->getTile()); | |
| 404 | + | } | |
| 405 | + | ||
| 406 | + | void Weapon::internalUseWeapon(Player *player, Item *item, Tile *tile) const { | |
| 407 | + | if (scripted) { | |
| 408 | + | LuaVariant var; | |
| 409 | + | var.type = VARIANT_TARGETPOSITION; | |
| 410 | + | var.pos = tile->getPosition(); | |
| 411 | + | executeUseWeapon(player, var); | |
| 412 | + | } else { | |
| 413 | + | Combat::postCombatEffects(player, tile->getPosition(), params); | |
| 414 | + | g_game.addMagicEffect(tile->getPosition(), CONST_ME_POFF); | |
| 415 | + | } | |
| 416 | + | ||
| 417 | + | onUsedWeapon(player, item, tile); | |
| 418 | + | } | |
| 419 | + | ||
| 420 | + | void Weapon::onUsedWeapon(Player *player, Item *item, Tile *destTile) const { | |
| 421 | + | if (!player->hasFlag(PlayerFlag_NotGainSkill)) { | |
| 422 | + | skills_t skillType; | |
| 423 | + | uint32_t skillPoint; | |
| 424 | + | if (getSkillType(player, item, skillType, skillPoint)) { | |
| 425 | + | player->addSkillAdvance(skillType, skillPoint); | |
| 426 | + | } | |
| 427 | + | } | |
| 428 | + | ||
| 429 | + | uint32_t manaCost = getManaCost(player); | |
| 430 | + | if (manaCost != 0) { | |
| 431 | + | player->addManaSpent(manaCost); | |
| 432 | + | player->changeMana(-static_cast<int32_t>(manaCost)); | |
| 433 | + | } | |
| 434 | + | ||
| 435 | + | uint32_t healthCost = getHealthCost(player); | |
| 436 | + | if (healthCost != 0) { | |
| 437 | + | player->changeHealth(-static_cast<int32_t>(healthCost)); | |
| 438 | + | } | |
| 439 | + | ||
| 440 | + | if (!player->hasFlag(PlayerFlag_HasInfiniteSoul) && soul > 0) { | |
| 441 | + | player->changeSoul(-static_cast<int32_t>(soul)); | |
| 442 | + | } | |
| 443 | + | ||
| 444 | + | if (breakChance != 0 && uniform_random(1, 100) <= breakChance) { | |
| 445 | + | Weapon::decrementItemCount(item); | |
| 446 | + | return; | |
| 447 | + | } | |
| 448 | + | ||
| 449 | + | switch (action) { | |
| 450 | + | case WEAPONACTION_REMOVECOUNT: | |
| 451 | + | if (g_config.getBoolean(ConfigManager::REMOVE_WEAPON_AMMO)) { | |
| 452 | + | Weapon::decrementItemCount(item); | |
| 453 | + | } | |
| 454 | + | break; | |
| 455 | + | ||
| 456 | + | case WEAPONACTION_REMOVECHARGE: { | |
| 457 | + | uint16_t charges = item->getCharges(); | |
| 458 | + | if (charges != 0 && | |
| 459 | + | g_config.getBoolean(ConfigManager::REMOVE_WEAPON_CHARGES)) { | |
| 460 | + | g_game.transformItem(item, item->getID(), charges - 1); | |
| 461 | + | } | |
| 462 | + | break; | |
| 463 | + | } | |
| 464 | + | ||
| 465 | + | case WEAPONACTION_MOVE: | |
| 466 | + | g_game.internalMoveItem(item->getParent(), destTile, INDEX_WHEREEVER, item, | |
| 467 | + | 1, nullptr, FLAG_NOLIMIT); | |
| 468 | + | break; | |
| 469 | + | ||
| 470 | + | default: | |
| 471 | + | break; | |
| 472 | + | } | |
| 473 | + | } | |
| 474 | + | ||
| 475 | + | uint32_t Weapon::getManaCost(const Player *player) const { | |
| 476 | + | if (mana != 0) { | |
| 477 | + | return mana; | |
| 478 | + | } | |
| 479 | + | ||
| 480 | + | if (manaPercent == 0) { | |
| 481 | + | return 0; | |
| 482 | + | } | |
| 483 | + | ||
| 484 | + | return (player->getMaxMana() * manaPercent) / 100; | |
| 485 | + | } | |
| 486 | + | ||
| 487 | + | int32_t Weapon::getHealthCost(const Player *player) const { | |
| 488 | + | if (health != 0) { | |
| 489 | + | return health; | |
| 490 | + | } | |
| 491 | + | ||
| 492 | + | if (healthPercent == 0) { | |
| 493 | + | return 0; | |
| 494 | + | } | |
| 495 | + | ||
| 496 | + | return (player->getMaxHealth() * healthPercent) / 100; | |
| 497 | + | } | |
| 498 | + | ||
| 499 | + | bool Weapon::executeUseWeapon(Player *player, const LuaVariant &var) const { | |
| 500 | + | // onUseWeapon(player, var) | |
| 501 | + | if (!scriptInterface->reserveScriptEnv()) { | |
| 502 | + | std::cout << "[Error - Weapon::executeUseWeapon] Call stack overflow" | |
| 503 | + | << std::endl; | |
| 504 | + | return false; | |
| 505 | + | } | |
| 506 | + | ||
| 507 | + | ScriptEnvironment *env = scriptInterface->getScriptEnv(); | |
| 508 | + | env->setScriptId(scriptId, scriptInterface); | |
| 509 | + | ||
| 510 | + | lua_State *L = scriptInterface->getLuaState(); | |
| 511 | + | ||
| 512 | + | scriptInterface->pushFunction(scriptId); | |
| 513 | + | LuaScriptInterface::pushUserdata<Player>(L, player); | |
| 514 | + | LuaScriptInterface::setMetatable(L, -1, "Player"); | |
| 515 | + | scriptInterface->pushVariant(L, var); | |
| 516 | + | ||
| 517 | + | return scriptInterface->callFunction(2); | |
| 518 | + | } | |
| 519 | + | ||
| 520 | + | void Weapon::decrementItemCount(Item *item) { | |
| 521 | + | uint16_t count = item->getItemCount(); | |
| 522 | + | if (count > 1) { | |
| 523 | + | g_game.transformItem(item, item->getID(), count - 1); | |
| 524 | + | } else { | |
| 525 | + | g_game.internalRemoveItem(item); | |
| 526 | + | } | |
| 527 | + | } | |
| 528 | + | ||
| 529 | + | WeaponMelee::WeaponMelee(LuaScriptInterface *interface) : Weapon(interface) { | |
| 530 | + | params.blockedByArmor = true; | |
| 531 | + | params.blockedByShield = true; | |
| 532 | + | params.combatType = COMBAT_PHYSICALDAMAGE; | |
| 533 | + | } | |
| 534 | + | ||
| 535 | + | void WeaponMelee::configureWeapon(const ItemType &it) { | |
| 536 | + | if (it.abilities) { | |
| 537 | + | elementType = it.abilities->elementType; | |
| 538 | + | elementDamage = it.abilities->elementDamage; | |
| 539 | + | params.aggressive = true; | |
| 540 | + | params.useCharges = true; | |
| 541 | + | } else { | |
| 542 | + | elementType = COMBAT_NONE; | |
| 543 | + | elementDamage = 0; | |
| 544 | + | } | |
| 545 | + | Weapon::configureWeapon(it); | |
| 546 | + | } | |
| 547 | + | ||
| 548 | + | bool WeaponMelee::useWeapon(Player *player, Item *item, | |
| 549 | + | Creature *target) const { | |
| 550 | + | int32_t damageModifier = | |
| 551 | + | playerWeaponCheck(player, target, item->getShootRange()); | |
| 552 | + | if (damageModifier == 0) { | |
| 553 | + | return false; | |
| 554 | + | } | |
| 555 | + | ||
| 556 | + | internalUseWeapon(player, item, target, damageModifier); | |
| 557 | + | return true; | |
| 558 | + | } | |
| 559 | + | ||
| 560 | + | bool WeaponMelee::getSkillType(const Player *player, const Item *item, | |
| 561 | + | skills_t &skill, uint32_t &skillpoint) const { | |
| 562 | + | if (player->getAddAttackSkill() && | |
| 563 | + | player->getLastAttackBlockType() != BLOCK_IMMUNITY) { | |
| 564 | + | skillpoint = 1; | |
| 565 | + | } else { | |
| 566 | + | skillpoint = 0; | |
| 567 | + | } | |
| 568 | + | ||
| 569 | + | WeaponType_t weaponType = item->getWeaponType(); | |
| 570 | + | switch (weaponType) { | |
| 571 | + | case WEAPON_SWORD: { | |
| 572 | + | skill = SKILL_SWORD; | |
| 573 | + | return true; | |
| 574 | + | } | |
| 575 | + | ||
| 576 | + | case WEAPON_CLUB: { | |
| 577 | + | skill = SKILL_CLUB; | |
| 578 | + | return true; | |
| 579 | + | } | |
| 580 | + | ||
| 581 | + | case WEAPON_AXE: { | |
| 582 | + | skill = SKILL_AXE; | |
| 583 | + | return true; | |
| 584 | + | } | |
| 585 | + | ||
| 586 | + | default: | |
| 587 | + | break; | |
| 588 | + | } | |
| 589 | + | return false; | |
| 590 | + | } | |
| 591 | + | ||
| 592 | + | int32_t WeaponMelee::getElementDamage(const Player *player, const Creature *, | |
| 593 | + | const Item *item) const { | |
| 594 | + | if (elementType == COMBAT_NONE) { | |
| 595 | + | return 0; | |
| 596 | + | } | |
| 597 | + | ||
| 598 | + | int32_t attackSkill = player->getWeaponSkill(item); | |
| 599 | + | int32_t attackValue = elementDamage; | |
| 600 | + | float attackFactor = player->getAttackFactor(); | |
| 601 | + | ||
| 602 | + | int32_t maxValue = Weapons::getMaxWeaponDamage( | |
| 603 | + | player->getLevel(), attackSkill, attackValue, attackFactor); | |
| 604 | + | return -normal_random( | |
| 605 | + | 0, static_cast<int32_t>(maxValue * | |
| 606 | + | player->getVocation()->meleeDamageMultiplier)); | |
| 607 | + | } | |
| 608 | + | ||
| 609 | + | int32_t WeaponMelee::getWeaponDamage(const Player *player, const Creature *, | |
| 610 | + | const Item *item, | |
| 611 | + | bool maxDamage /*= false*/) const { | |
| 612 | + | int32_t attackSkill = player->getWeaponSkill(item); | |
| 613 | + | int32_t attackValue = std::max<int32_t>(0, item->getAttack()); | |
| 614 | + | float attackFactor = player->getAttackFactor(); | |
| 615 | + | ||
| 616 | + | int32_t maxValue = static_cast<int32_t>( | |
| 617 | + | Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, | |
| 618 | + | attackFactor) * | |
| 619 | + | player->getVocation()->meleeDamageMultiplier); | |
| 620 | + | if (maxDamage) { | |
| 621 | + | return -maxValue; | |
| 622 | + | } | |
| 623 | + | ||
| 624 | + | return -normal_random(0, maxValue); | |
| 625 | + | } | |
| 626 | + | ||
| 627 | + | WeaponDistance::WeaponDistance(LuaScriptInterface *interface) | |
| 628 | + | : Weapon(interface) { | |
| 629 | + | params.blockedByArmor = true; | |
| 630 | + | params.combatType = COMBAT_PHYSICALDAMAGE; | |
| 631 | + | } | |
| 632 | + | ||
| 633 | + | void WeaponDistance::configureWeapon(const ItemType &it) { | |
| 634 | + | params.distanceEffect = it.shootType; | |
| 635 | + | ||
| 636 | + | if (it.abilities) { | |
| 637 | + | elementType = it.abilities->elementType; | |
| 638 | + | elementDamage = it.abilities->elementDamage; | |
| 639 | + | params.aggressive = true; | |
| 640 | + | params.useCharges = true; | |
| 641 | + | } else { | |
| 642 | + | elementType = COMBAT_NONE; | |
| 643 | + | elementDamage = 0; | |
| 644 | + | } | |
| 645 | + | ||
| 646 | + | Weapon::configureWeapon(it); | |
| 647 | + | } | |
| 648 | + | ||
| 649 | + | bool WeaponDistance::useWeapon(Player *player, Item *item, | |
| 650 | + | Creature *target) const { | |
| 651 | + | int32_t damageModifier = 0; | |
| 652 | + | const ItemType &it = Item::items[id]; | |
| 653 | + | if (it.weaponType == WEAPON_AMMO) { | |
| 654 | + | Item *mainWeaponItem = player->getWeapon(true); | |
| 655 | + | const Weapon *mainWeapon = g_weapons->getWeapon(mainWeaponItem); | |
| 656 | + | if (mainWeapon) { | |
| 657 | + | damageModifier = mainWeapon->playerWeaponCheck( | |
| 658 | + | player, target, mainWeaponItem->getShootRange()); | |
| 659 | + | } else if (mainWeaponItem) { | |
| 660 | + | damageModifier = | |
| 661 | + | playerWeaponCheck(player, target, mainWeaponItem->getShootRange()); | |
| 662 | + | } | |
| 663 | + | } else { | |
| 664 | + | damageModifier = playerWeaponCheck(player, target, item->getShootRange()); | |
| 665 | + | } | |
| 666 | + | ||
| 667 | + | if (damageModifier == 0) { | |
| 668 | + | return false; | |
| 669 | + | } | |
| 670 | + | ||
| 671 | + | int32_t chance; | |
| 672 | + | if (it.hitChance == 0) { | |
| 673 | + | // hit chance is based on distance to target and distance skill | |
| 674 | + | uint32_t skill = player->getSkillLevel(SKILL_DISTANCE); | |
| 675 | + | const Position &playerPos = player->getPosition(); | |
| 676 | + | const Position &targetPos = target->getPosition(); | |
| 677 | + | uint32_t distance = | |
| 678 | + | std::max<uint32_t>(Position::getDistanceX(playerPos, targetPos), | |
| 679 | + | Position::getDistanceY(playerPos, targetPos)); | |
| 680 | + | ||
| 681 | + | uint32_t maxHitChance; | |
| 682 | + | if (it.maxHitChance != -1) { | |
| 683 | + | maxHitChance = it.maxHitChance; | |
| 684 | + | } else if (it.ammoType != AMMO_NONE) { | |
| 685 | + | // hit chance on two-handed weapons is limited to 90% | |
| 686 | + | maxHitChance = 90; | |
| 687 | + | } else { | |
| 688 | + | // one-handed is set to 75% | |
| 689 | + | maxHitChance = 75; | |
| 690 | + | } | |
| 691 | + | ||
| 692 | + | if (maxHitChance == 75) { | |
| 693 | + | // chance for one-handed weapons | |
| 694 | + | switch (distance) { | |
| 695 | + | case 1: | |
| 696 | + | case 5: | |
| 697 | + | chance = std::min<uint32_t>(skill, 74) + 1; | |
| 698 | + | break; | |
| 699 | + | case 2: | |
| 700 | + | chance = | |
| 701 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 28) * 2.40f) + 8; | |
| 702 | + | break; | |
| 703 | + | case 3: | |
| 704 | + | chance = | |
| 705 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 45) * 1.55f) + 6; | |
| 706 | + | break; | |
| 707 | + | case 4: | |
| 708 | + | chance = | |
| 709 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 58) * 1.25f) + 3; | |
| 710 | + | break; | |
| 711 | + | case 6: | |
| 712 | + | chance = | |
| 713 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 90) * 0.80f) + 3; | |
| 714 | + | break; | |
| 715 | + | case 7: | |
| 716 | + | chance = | |
| 717 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 104) * 0.70f) + 2; | |
| 718 | + | break; | |
| 719 | + | default: | |
| 720 | + | chance = it.hitChance; | |
| 721 | + | break; | |
| 722 | + | } | |
| 723 | + | } else if (maxHitChance == 90) { | |
| 724 | + | // formula for two-handed weapons | |
| 725 | + | switch (distance) { | |
| 726 | + | case 1: | |
| 727 | + | case 5: | |
| 728 | + | chance = | |
| 729 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 74) * 1.20f) + 1; | |
| 730 | + | break; | |
| 731 | + | case 2: | |
| 732 | + | chance = static_cast<uint32_t>(std::min<uint32_t>(skill, 28) * 3.20f); | |
| 733 | + | break; | |
| 734 | + | case 3: | |
| 735 | + | chance = std::min<uint32_t>(skill, 45) * 2; | |
| 736 | + | break; | |
| 737 | + | case 4: | |
| 738 | + | chance = static_cast<uint32_t>(std::min<uint32_t>(skill, 58) * 1.55f); | |
| 739 | + | break; | |
| 740 | + | case 6: | |
| 741 | + | case 7: | |
| 742 | + | chance = std::min<uint32_t>(skill, 90); | |
| 743 | + | break; | |
| 744 | + | default: | |
| 745 | + | chance = it.hitChance; | |
| 746 | + | break; | |
| 747 | + | } | |
| 748 | + | } else if (maxHitChance == 100) { | |
| 749 | + | switch (distance) { | |
| 750 | + | case 1: | |
| 751 | + | case 5: | |
| 752 | + | chance = | |
| 753 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 73) * 1.35f) + 1; | |
| 754 | + | break; | |
| 755 | + | case 2: | |
| 756 | + | chance = | |
| 757 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 30) * 3.20f) + 4; | |
| 758 | + | break; | |
| 759 | + | case 3: | |
| 760 | + | chance = | |
| 761 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 48) * 2.05f) + 2; | |
| 762 | + | break; | |
| 763 | + | case 4: | |
| 764 | + | chance = | |
| 765 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 65) * 1.50f) + 2; | |
| 766 | + | break; | |
| 767 | + | case 6: | |
| 768 | + | chance = | |
| 769 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 87) * 1.20f) - 4; | |
| 770 | + | break; | |
| 771 | + | case 7: | |
| 772 | + | chance = | |
| 773 | + | static_cast<uint32_t>(std::min<uint32_t>(skill, 90) * 1.10f) + 1; | |
| 774 | + | break; | |
| 775 | + | default: | |
| 776 | + | chance = it.hitChance; | |
| 777 | + | break; | |
| 778 | + | } | |
| 779 | + | } else { | |
| 780 | + | chance = maxHitChance; | |
| 781 | + | } | |
| 782 | + | } else { | |
| 783 | + | chance = it.hitChance; | |
| 784 | + | } | |
| 785 | + | ||
| 786 | + | if (item->getWeaponType() == WEAPON_AMMO) { | |
| 787 | + | Item *bow = player->getWeapon(true); | |
| 788 | + | if (bow && bow->getHitChance() != 0) { | |
| 789 | + | chance += bow->getHitChance(); | |
| 790 | + | } | |
| 791 | + | } | |
| 792 | + | ||
| 793 | + | if (chance >= uniform_random(1, 100)) { | |
| 794 | + | Weapon::internalUseWeapon(player, item, target, damageModifier); | |
| 795 | + | } else { | |
| 796 | + | // miss target | |
| 797 | + | Tile *destTile = target->getTile(); | |
| 798 | + | ||
| 799 | + | if (!Position::areInRange<1, 1, 0>(player->getPosition(), | |
| 800 | + | target->getPosition())) { | |
| 801 | + | static std::vector<std::pair<int32_t, int32_t>> destList{ | |
| 802 | + | {-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {0, 0}, | |
| 803 | + | {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; | |
| 804 | + | std::shuffle(destList.begin(), destList.end(), getRandomGenerator()); | |
| 805 | + | ||
| 806 | + | Position destPos = target->getPosition(); | |
| 807 | + | ||
| 808 | + | for (const auto &dir : destList) { | |
| 809 | + | // Blocking tiles or tiles without ground ain't valid targets for spears | |
| 810 | + | Tile *tmpTile = g_game.map.getTile(destPos.x + dir.first, | |
| 811 | + | destPos.y + dir.second, destPos.z); | |
| 812 | + | if (tmpTile && !tmpTile->hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) && | |
| 813 | + | tmpTile->getGround() != nullptr) { | |
| 814 | + | destTile = tmpTile; | |
| 815 | + | break; | |
| 816 | + | } | |
| 817 | + | } | |
| 818 | + | } | |
| 819 | + | ||
| 820 | + | Weapon::internalUseWeapon(player, item, destTile); | |
| 821 | + | } | |
| 822 | + | return true; | |
| 823 | + | } | |
| 824 | + | ||
| 825 | + | int32_t WeaponDistance::getElementDamage(const Player *player, | |
| 826 | + | const Creature *target, | |
| 827 | + | const Item *item) const { | |
| 828 | + | if (elementType == COMBAT_NONE) { | |
| 829 | + | return 0; | |
| 830 | + | } | |
| 831 | + | ||
| 832 | + | int32_t attackValue = elementDamage; | |
| 833 | + | if (item->getWeaponType() == WEAPON_AMMO) { | |
| 834 | + | Item *weapon = player->getWeapon(true); | |
| 835 | + | if (weapon) { | |
| 836 | + | attackValue += weapon->getAttack(); | |
| 837 | + | } | |
| 838 | + | } | |
| 839 | + | ||
| 840 | + | int32_t attackSkill = player->getSkillLevel(SKILL_DISTANCE); | |
| 841 | + | float attackFactor = player->getAttackFactor(); | |
| 842 | + | ||
| 843 | + | int32_t minValue = 0; | |
| 844 | + | int32_t maxValue = Weapons::getMaxWeaponDamage( | |
| 845 | + | player->getLevel(), attackSkill, attackValue, attackFactor); | |
| 846 | + | if (target) { | |
| 847 | + | if (target->getPlayer()) { | |
| 848 | + | minValue = static_cast<int32_t>(std::ceil(player->getLevel() * 0.1)); | |
| 849 | + | } else { | |
| 850 | + | minValue = static_cast<int32_t>(std::ceil(player->getLevel() * 0.2)); | |
| 851 | + | } | |
| 852 | + | } | |
| 853 | + | ||
| 854 | + | return -normal_random( | |
| 855 | + | minValue, static_cast<int32_t>( | |
| 856 | + | maxValue * player->getVocation()->distDamageMultiplier)); | |
| 857 | + | } | |
| 858 | + | ||
| 859 | + | int32_t WeaponDistance::getWeaponDamage(const Player *player, | |
| 860 | + | const Creature *target, | |
| 861 | + | const Item *item, | |
| 862 | + | bool maxDamage /*= false*/) const { | |
| 863 | + | int32_t attackValue = item->getAttack(); | |
| 864 | + | ||
| 865 | + | if (item->getWeaponType() == WEAPON_AMMO) { | |
| 866 | + | Item *weapon = player->getWeapon(true); | |
| 867 | + | if (weapon) { | |
| 868 | + | attackValue += weapon->getAttack(); | |
| 869 | + | } | |
| 870 | + | } | |
| 871 | + | ||
| 872 | + | int32_t attackSkill = player->getSkillLevel(SKILL_DISTANCE); | |
| 873 | + | float attackFactor = player->getAttackFactor(); | |
| 874 | + | ||
| 875 | + | int32_t maxValue = static_cast<int32_t>( | |
| 876 | + | Weapons::getMaxWeaponDamage(player->getLevel(), attackSkill, attackValue, | |
| 877 | + | attackFactor) * | |
| 878 | + | player->getVocation()->distDamageMultiplier); | |
| 879 | + | if (maxDamage) { | |
| 880 | + | return -maxValue; | |
| 881 | + | } | |
| 882 | + | ||
| 883 | + | int32_t minValue; | |
| 884 | + | if (target) { | |
| 885 | + | if (target->getPlayer()) { | |
| 886 | + | minValue = static_cast<int32_t>(std::ceil(player->getLevel() * 0.1)); | |
| 887 | + | } else { | |
| 888 | + | minValue = static_cast<int32_t>(std::ceil(player->getLevel() * 0.2)); | |
| 889 | + | } | |
| 890 | + | } else { | |
| 891 | + | minValue = 0; | |
| 892 | + | } | |
| 893 | + | return -normal_random(minValue, maxValue); | |
| 894 | + | } | |
| 895 | + | ||
| 896 | + | bool WeaponDistance::getSkillType(const Player *player, const Item *, | |
| 897 | + | skills_t &skill, uint32_t &skillpoint) const { | |
| 898 | + | skill = SKILL_DISTANCE; | |
| 899 | + | ||
| 900 | + | if (player->getAddAttackSkill()) { | |
| 901 | + | switch (player->getLastAttackBlockType()) { | |
| 902 | + | case BLOCK_NONE: { | |
| 903 | + | skillpoint = 2; | |
| 904 | + | break; | |
| 905 | + | } | |
| 906 | + | ||
| 907 | + | case BLOCK_DEFENSE: | |
| 908 | + | case BLOCK_ARMOR: { | |
| 909 | + | skillpoint = 1; | |
| 910 | + | break; | |
| 911 | + | } | |
| 912 | + | ||
| 913 | + | default: | |
| 914 | + | skillpoint = 0; | |
| 915 | + | break; | |
| 916 | + | } | |
| 917 | + | } else { | |
| 918 | + | skillpoint = 0; | |
| 919 | + | } | |
| 920 | + | return true; | |
| 921 | + | } | |
| 922 | + | ||
| 923 | + | bool WeaponWand::configureEvent(const pugi::xml_node &node) { | |
| 924 | + | if (!Weapon::configureEvent(node)) { | |
| 925 | + | return false; | |
| 926 | + | } | |
| 927 | + | ||
| 928 | + | pugi::xml_attribute attr; | |
| 929 | + | if ((attr = node.attribute("min"))) { | |
| 930 | + | minChange = pugi::cast<int32_t>(attr.value()); | |
| 931 | + | } | |
| 932 | + | ||
| 933 | + | if ((attr = node.attribute("max"))) { | |
| 934 | + | maxChange = pugi::cast<int32_t>(attr.value()); | |
| 935 | + | } | |
| 936 | + | ||
| 937 | + | attr = node.attribute("type"); | |
| 938 | + | if (!attr) { | |
| 939 | + | return true; | |
| 940 | + | } | |
| 941 | + | ||
| 942 | + | std::string tmpStrValue = asLowerCaseString(attr.as_string()); | |
| 943 | + | if (tmpStrValue == "earth") { | |
| 944 | + | params.combatType = COMBAT_EARTHDAMAGE; | |
| 945 | + | } else if (tmpStrValue == "ice") { | |
| 946 | + | params.combatType = COMBAT_ICEDAMAGE; | |
| 947 | + | } else if (tmpStrValue == "energy") { | |
| 948 | + | params.combatType = COMBAT_ENERGYDAMAGE; | |
| 949 | + | } else if (tmpStrValue == "fire") { | |
| 950 | + | params.combatType = COMBAT_FIREDAMAGE; | |
| 951 | + | } else if (tmpStrValue == "death") { | |
| 952 | + | params.combatType = COMBAT_DEATHDAMAGE; | |
| 953 | + | } else if (tmpStrValue == "holy") { | |
| 954 | + | params.combatType = COMBAT_HOLYDAMAGE; | |
| 955 | + | } else { | |
| 956 | + | std::cout << "[Warning - WeaponWand::configureEvent] Type \"" | |
| 957 | + | << attr.as_string() << "\" does not exist." << std::endl; | |
| 958 | + | } | |
| 959 | + | return true; | |
| 960 | + | } | |
| 961 | + | ||
| 962 | + | void WeaponWand::configureWeapon(const ItemType &it) { | |
| 963 | + | params.distanceEffect = it.shootType; | |
| 964 | + | ||
| 965 | + | Weapon::configureWeapon(it); | |
| 966 | + | } | |
| 967 | + | ||
| 968 | + | int32_t WeaponWand::getWeaponDamage(const Player *, const Creature *, | |
| 969 | + | const Item *, | |
| 970 | + | bool maxDamage /*= false*/) const { | |
| 971 | + | if (maxDamage) { | |
| 972 | + | return -maxChange; | |
| 973 | + | } | |
| 974 | + | return -normal_random(minChange, maxChange); | |
| 975 | + | } |
| @@ -0,0 +1,311 @@ | |||
| 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_WEAPONS_H_69D1993478AA42948E24C0B90B8F5BF5 | |
| 21 | + | #define FS_WEAPONS_H_69D1993478AA42948E24C0B90B8F5BF5 | |
| 22 | + | ||
| 23 | + | #include "luascript.h" | |
| 24 | + | #include "player.h" | |
| 25 | + | #include "baseevents.h" | |
| 26 | + | #include "combat.h" | |
| 27 | + | #include "const.h" | |
| 28 | + | #include "vocation.h" | |
| 29 | + | ||
| 30 | + | extern Vocations g_vocations; | |
| 31 | + | ||
| 32 | + | class Weapon; | |
| 33 | + | class WeaponMelee; | |
| 34 | + | class WeaponDistance; | |
| 35 | + | class WeaponWand; | |
| 36 | + | ||
| 37 | + | using Weapon_ptr = std::unique_ptr<Weapon>; | |
| 38 | + | ||
| 39 | + | class Weapons final : public BaseEvents | |
| 40 | + | { | |
| 41 | + | public: | |
| 42 | + | Weapons(); | |
| 43 | + | ~Weapons(); | |
| 44 | + | ||
| 45 | + | // non-copyable | |
| 46 | + | Weapons(const Weapons&) = delete; | |
| 47 | + | Weapons& operator=(const Weapons&) = delete; | |
| 48 | + | ||
| 49 | + | void loadDefaults(); | |
| 50 | + | const Weapon* getWeapon(const Item* item) const; | |
| 51 | + | ||
| 52 | + | static int32_t getMaxMeleeDamage(int32_t attackSkill, int32_t attackValue); | |
| 53 | + | static int32_t getMaxWeaponDamage(uint32_t level, int32_t attackSkill, int32_t attackValue, float attackFactor); | |
| 54 | + | ||
| 55 | + | bool registerLuaEvent(Weapon* event); | |
| 56 | + | void clear(bool fromLua) override final; | |
| 57 | + | ||
| 58 | + | private: | |
| 59 | + | LuaScriptInterface& getScriptInterface() override; | |
| 60 | + | std::string getScriptBaseName() const override; | |
| 61 | + | Event_ptr getEvent(const std::string& nodeName) override; | |
| 62 | + | bool registerEvent(Event_ptr event, const pugi::xml_node& node) override; | |
| 63 | + | ||
| 64 | + | std::map<uint32_t, Weapon*> weapons; | |
| 65 | + | ||
| 66 | + | LuaScriptInterface scriptInterface { "Weapon Interface" }; | |
| 67 | + | }; | |
| 68 | + | ||
| 69 | + | class Weapon : public Event | |
| 70 | + | { | |
| 71 | + | public: | |
| 72 | + | explicit Weapon(LuaScriptInterface* interface) : Event(interface) {} | |
| 73 | + | ||
| 74 | + | bool configureEvent(const pugi::xml_node& node) override; | |
| 75 | + | bool loadFunction(const pugi::xml_attribute&, bool) final { | |
| 76 | + | return true; | |
| 77 | + | } | |
| 78 | + | virtual void configureWeapon(const ItemType& it); | |
| 79 | + | virtual bool interruptSwing() const { | |
| 80 | + | return false; | |
| 81 | + | } | |
| 82 | + | ||
| 83 | + | int32_t playerWeaponCheck(Player* player, Creature* target, uint8_t shootRange) const; | |
| 84 | + | static bool useFist(Player* player, Creature* target); | |
| 85 | + | virtual bool useWeapon(Player* player, Item* item, Creature* target) const; | |
| 86 | + | ||
| 87 | + | virtual int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const = 0; | |
| 88 | + | virtual int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const = 0; | |
| 89 | + | virtual CombatType_t getElementType() const = 0; | |
| 90 | + | ||
| 91 | + | uint16_t getID() const { | |
| 92 | + | return id; | |
| 93 | + | } | |
| 94 | + | void setID(uint16_t newId) { | |
| 95 | + | id = newId; | |
| 96 | + | } | |
| 97 | + | ||
| 98 | + | uint32_t getReqLevel() const { | |
| 99 | + | return level; | |
| 100 | + | } | |
| 101 | + | void setRequiredLevel(uint32_t reqlvl) { | |
| 102 | + | level = reqlvl; | |
| 103 | + | } | |
| 104 | + | ||
| 105 | + | uint32_t getReqMagLv() const { | |
| 106 | + | return magLevel; | |
| 107 | + | } | |
| 108 | + | void setRequiredMagLevel(uint32_t reqlvl) { | |
| 109 | + | magLevel = reqlvl; | |
| 110 | + | } | |
| 111 | + | ||
| 112 | + | bool isPremium() const { | |
| 113 | + | return premium; | |
| 114 | + | } | |
| 115 | + | void setNeedPremium(bool prem) { | |
| 116 | + | premium = prem; | |
| 117 | + | } | |
| 118 | + | ||
| 119 | + | bool isWieldedUnproperly() const { | |
| 120 | + | return wieldUnproperly; | |
| 121 | + | } | |
| 122 | + | void setWieldUnproperly(bool unproperly) { | |
| 123 | + | wieldUnproperly = unproperly; | |
| 124 | + | } | |
| 125 | + | ||
| 126 | + | uint32_t getMana() const { | |
| 127 | + | return mana; | |
| 128 | + | } | |
| 129 | + | void setMana(uint32_t m) { | |
| 130 | + | mana = m; | |
| 131 | + | } | |
| 132 | + | ||
| 133 | + | uint32_t getManaPercent() const { | |
| 134 | + | return manaPercent; | |
| 135 | + | } | |
| 136 | + | void setManaPercent(uint32_t m) { | |
| 137 | + | manaPercent = m; | |
| 138 | + | } | |
| 139 | + | ||
| 140 | + | int32_t getHealth() const { | |
| 141 | + | return health; | |
| 142 | + | } | |
| 143 | + | void setHealth(int32_t h) { | |
| 144 | + | health = h; | |
| 145 | + | } | |
| 146 | + | ||
| 147 | + | uint32_t getHealthPercent() const { | |
| 148 | + | return healthPercent; | |
| 149 | + | } | |
| 150 | + | void setHealthPercent(uint32_t m) { | |
| 151 | + | healthPercent = m; | |
| 152 | + | } | |
| 153 | + | ||
| 154 | + | uint32_t getSoul() const { | |
| 155 | + | return soul; | |
| 156 | + | } | |
| 157 | + | void setSoul(uint32_t s) { | |
| 158 | + | soul = s; | |
| 159 | + | } | |
| 160 | + | ||
| 161 | + | uint8_t getBreakChance() const { | |
| 162 | + | return breakChance; | |
| 163 | + | } | |
| 164 | + | void setBreakChance(uint8_t b) { | |
| 165 | + | breakChance = b; | |
| 166 | + | } | |
| 167 | + | ||
| 168 | + | bool isEnabled() const { | |
| 169 | + | return enabled; | |
| 170 | + | } | |
| 171 | + | void setIsEnabled(bool e) { | |
| 172 | + | enabled = e; | |
| 173 | + | } | |
| 174 | + | ||
| 175 | + | uint32_t getWieldInfo() const { | |
| 176 | + | return wieldInfo; | |
| 177 | + | } | |
| 178 | + | void setWieldInfo(uint32_t info) { | |
| 179 | + | wieldInfo |= info; | |
| 180 | + | } | |
| 181 | + | ||
| 182 | + | void addVocWeaponMap(std::string vocName) { | |
| 183 | + | int32_t vocationId = g_vocations.getVocationId(vocName); | |
| 184 | + | if (vocationId != -1) { | |
| 185 | + | vocWeaponMap[vocationId] = true; | |
| 186 | + | } | |
| 187 | + | } | |
| 188 | + | ||
| 189 | + | const std::string& getVocationString() const { | |
| 190 | + | return vocationString; | |
| 191 | + | } | |
| 192 | + | void setVocationString(const std::string& str) { | |
| 193 | + | vocationString = str; | |
| 194 | + | } | |
| 195 | + | ||
| 196 | + | WeaponAction_t action = WEAPONACTION_NONE; | |
| 197 | + | CombatParams params; | |
| 198 | + | WeaponType_t weaponType; | |
| 199 | + | std::map<uint16_t, bool> vocWeaponMap; | |
| 200 | + | ||
| 201 | + | protected: | |
| 202 | + | void internalUseWeapon(Player* player, Item* item, Creature* target, int32_t damageModifier) const; | |
| 203 | + | void internalUseWeapon(Player* player, Item* item, Tile* tile) const; | |
| 204 | + | ||
| 205 | + | uint16_t id = 0; | |
| 206 | + | ||
| 207 | + | private: | |
| 208 | + | virtual bool getSkillType(const Player*, const Item*, skills_t&, uint32_t&) const { | |
| 209 | + | return false; | |
| 210 | + | } | |
| 211 | + | ||
| 212 | + | uint32_t getManaCost(const Player* player) const; | |
| 213 | + | int32_t getHealthCost(const Player* player) const; | |
| 214 | + | ||
| 215 | + | uint32_t level = 0; | |
| 216 | + | uint32_t magLevel = 0; | |
| 217 | + | uint32_t mana = 0; | |
| 218 | + | uint32_t manaPercent = 0; | |
| 219 | + | uint32_t health = 0; | |
| 220 | + | uint32_t healthPercent = 0; | |
| 221 | + | uint32_t soul = 0; | |
| 222 | + | uint32_t wieldInfo = WIELDINFO_NONE; | |
| 223 | + | uint8_t breakChance = 0; | |
| 224 | + | bool enabled = true; | |
| 225 | + | bool premium = false; | |
| 226 | + | bool wieldUnproperly = false; | |
| 227 | + | std::string vocationString = ""; | |
| 228 | + | ||
| 229 | + | std::string getScriptEventName() const override final; | |
| 230 | + | ||
| 231 | + | bool executeUseWeapon(Player* player, const LuaVariant& var) const; | |
| 232 | + | void onUsedWeapon(Player* player, Item* item, Tile* destTile) const; | |
| 233 | + | ||
| 234 | + | static void decrementItemCount(Item* item); | |
| 235 | + | ||
| 236 | + | friend class Combat; | |
| 237 | + | }; | |
| 238 | + | ||
| 239 | + | class WeaponMelee final : public Weapon | |
| 240 | + | { | |
| 241 | + | public: | |
| 242 | + | explicit WeaponMelee(LuaScriptInterface* interface); | |
| 243 | + | ||
| 244 | + | void configureWeapon(const ItemType& it) override; | |
| 245 | + | ||
| 246 | + | bool useWeapon(Player* player, Item* item, Creature* target) const override; | |
| 247 | + | ||
| 248 | + | int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; | |
| 249 | + | int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const override; | |
| 250 | + | CombatType_t getElementType() const override { return elementType; } | |
| 251 | + | ||
| 252 | + | private: | |
| 253 | + | bool getSkillType(const Player* player, const Item* item, skills_t& skill, uint32_t& skillpoint) const override; | |
| 254 | + | ||
| 255 | + | CombatType_t elementType = COMBAT_NONE; | |
| 256 | + | uint16_t elementDamage = 0; | |
| 257 | + | }; | |
| 258 | + | ||
| 259 | + | class WeaponDistance final : public Weapon | |
| 260 | + | { | |
| 261 | + | public: | |
| 262 | + | explicit WeaponDistance(LuaScriptInterface* interface); | |
| 263 | + | ||
| 264 | + | void configureWeapon(const ItemType& it) override; | |
| 265 | + | bool interruptSwing() const override { | |
| 266 | + | return true; | |
| 267 | + | } | |
| 268 | + | ||
| 269 | + | bool useWeapon(Player* player, Item* item, Creature* target) const override; | |
| 270 | + | ||
| 271 | + | int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; | |
| 272 | + | int32_t getElementDamage(const Player* player, const Creature* target, const Item* item) const override; | |
| 273 | + | CombatType_t getElementType() const override { return elementType; } | |
| 274 | + | ||
| 275 | + | private: | |
| 276 | + | bool getSkillType(const Player* player, const Item* item, skills_t& skill, uint32_t& skillpoint) const override; | |
| 277 | + | ||
| 278 | + | CombatType_t elementType = COMBAT_NONE; | |
| 279 | + | uint16_t elementDamage = 0; | |
| 280 | + | }; | |
| 281 | + | ||
| 282 | + | class WeaponWand final : public Weapon | |
| 283 | + | { | |
| 284 | + | public: | |
| 285 | + | explicit WeaponWand(LuaScriptInterface* interface) : Weapon(interface) {} | |
| 286 | + | ||
| 287 | + | bool configureEvent(const pugi::xml_node& node) override; | |
| 288 | + | void configureWeapon(const ItemType& it) override; | |
| 289 | + | ||
| 290 | + | int32_t getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage = false) const override; | |
| 291 | + | int32_t getElementDamage(const Player*, const Creature*, const Item*) const override { return 0; } | |
| 292 | + | CombatType_t getElementType() const override { return COMBAT_NONE; } | |
| 293 | + | ||
| 294 | + | void setMinChange(int32_t change) { | |
| 295 | + | minChange = change; | |
| 296 | + | } | |
| 297 | + | ||
| 298 | + | void setMaxChange(int32_t change) { | |
| 299 | + | maxChange = change; | |
| 300 | + | } | |
| 301 | + | ||
| 302 | + | private: | |
| 303 | + | bool getSkillType(const Player*, const Item*, skills_t&, uint32_t&) const override { | |
| 304 | + | return false; | |
| 305 | + | } | |
| 306 | + | ||
| 307 | + | int32_t minChange = 0; | |
| 308 | + | int32_t maxChange = 0; | |
| 309 | + | }; | |
| 310 | + | ||
| 311 | + | #endif |
| @@ -0,0 +1,129 @@ | |||
| 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 <stack> | |
| 23 | + | ||
| 24 | + | #include "wildcardtree.h" | |
| 25 | + | ||
| 26 | + | WildcardTreeNode* WildcardTreeNode::getChild(char ch) | |
| 27 | + | { | |
| 28 | + | auto it = children.find(ch); | |
| 29 | + | if (it == children.end()) { | |
| 30 | + | return nullptr; | |
| 31 | + | } | |
| 32 | + | return &it->second; | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | const WildcardTreeNode* WildcardTreeNode::getChild(char ch) const | |
| 36 | + | { | |
| 37 | + | auto it = children.find(ch); | |
| 38 | + | if (it == children.end()) { | |
| 39 | + | return nullptr; | |
| 40 | + | } | |
| 41 | + | return &it->second; | |
| 42 | + | } | |
| 43 | + | ||
| 44 | + | WildcardTreeNode* WildcardTreeNode::addChild(char ch, bool breakpoint) | |
| 45 | + | { | |
| 46 | + | WildcardTreeNode* child = getChild(ch); | |
| 47 | + | if (child) { | |
| 48 | + | if (breakpoint && !child->breakpoint) { | |
| 49 | + | child->breakpoint = true; | |
| 50 | + | } | |
| 51 | + | } else { | |
| 52 | + | auto pair = children.emplace(std::piecewise_construct, | |
| 53 | + | std::forward_as_tuple(ch), std::forward_as_tuple(breakpoint)); | |
| 54 | + | child = &pair.first->second; | |
| 55 | + | } | |
| 56 | + | return child; | |
| 57 | + | } | |
| 58 | + | ||
| 59 | + | void WildcardTreeNode::insert(const std::string& str) | |
| 60 | + | { | |
| 61 | + | WildcardTreeNode* cur = this; | |
| 62 | + | ||
| 63 | + | size_t length = str.length() - 1; | |
| 64 | + | for (size_t pos = 0; pos < length; ++pos) { | |
| 65 | + | cur = cur->addChild(str[pos], false); | |
| 66 | + | } | |
| 67 | + | ||
| 68 | + | cur->addChild(str[length], true); | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | void WildcardTreeNode::remove(const std::string& str) | |
| 72 | + | { | |
| 73 | + | WildcardTreeNode* cur = this; | |
| 74 | + | ||
| 75 | + | std::stack<WildcardTreeNode*> path; | |
| 76 | + | path.push(cur); | |
| 77 | + | size_t len = str.length(); | |
| 78 | + | for (size_t pos = 0; pos < len; ++pos) { | |
| 79 | + | cur = cur->getChild(str[pos]); | |
| 80 | + | if (!cur) { | |
| 81 | + | return; | |
| 82 | + | } | |
| 83 | + | path.push(cur); | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | cur->breakpoint = false; | |
| 87 | + | ||
| 88 | + | do { | |
| 89 | + | cur = path.top(); | |
| 90 | + | path.pop(); | |
| 91 | + | ||
| 92 | + | if (!cur->children.empty() || cur->breakpoint || path.empty()) { | |
| 93 | + | break; | |
| 94 | + | } | |
| 95 | + | ||
| 96 | + | cur = path.top(); | |
| 97 | + | ||
| 98 | + | auto it = cur->children.find(str[--len]); | |
| 99 | + | if (it != cur->children.end()) { | |
| 100 | + | cur->children.erase(it); | |
| 101 | + | } | |
| 102 | + | } while (true); | |
| 103 | + | } | |
| 104 | + | ||
| 105 | + | ReturnValue WildcardTreeNode::findOne(const std::string& query, std::string& result) const | |
| 106 | + | { | |
| 107 | + | const WildcardTreeNode* cur = this; | |
| 108 | + | for (char pos : query) { | |
| 109 | + | cur = cur->getChild(pos); | |
| 110 | + | if (!cur) { | |
| 111 | + | return RETURNVALUE_PLAYERWITHTHISNAMEISNOTONLINE; | |
| 112 | + | } | |
| 113 | + | } | |
| 114 | + | ||
| 115 | + | result = query; | |
| 116 | + | ||
| 117 | + | do { | |
| 118 | + | size_t size = cur->children.size(); | |
| 119 | + | if (size == 0) { | |
| 120 | + | return RETURNVALUE_NOERROR; | |
| 121 | + | } else if (size > 1 || cur->breakpoint) { | |
| 122 | + | return RETURNVALUE_NAMEISTOOAMBIGUOUS; | |
| 123 | + | } | |
| 124 | + | ||
| 125 | + | auto it = cur->children.begin(); | |
| 126 | + | result += it->first; | |
| 127 | + | cur = &it->second; | |
| 128 | + | } while (true); | |
| 129 | + | } |
| @@ -0,0 +1,49 @@ | |||
| 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_WILDCARDTREE_H_054C9BA46A1D4EA4B7C77ECE60ED4DEB | |
| 21 | + | #define FS_WILDCARDTREE_H_054C9BA46A1D4EA4B7C77ECE60ED4DEB | |
| 22 | + | ||
| 23 | + | #include "enums.h" | |
| 24 | + | ||
| 25 | + | class WildcardTreeNode | |
| 26 | + | { | |
| 27 | + | public: | |
| 28 | + | explicit WildcardTreeNode(bool breakpoint) : breakpoint(breakpoint) {} | |
| 29 | + | WildcardTreeNode(WildcardTreeNode&& other) = default; | |
| 30 | + | ||
| 31 | + | // non-copyable | |
| 32 | + | WildcardTreeNode(const WildcardTreeNode&) = delete; | |
| 33 | + | WildcardTreeNode& operator=(const WildcardTreeNode&) = delete; | |
| 34 | + | ||
| 35 | + | WildcardTreeNode* getChild(char ch); | |
| 36 | + | const WildcardTreeNode* getChild(char ch) const; | |
| 37 | + | WildcardTreeNode* addChild(char ch, bool breakpoint); | |
| 38 | + | ||
| 39 | + | void insert(const std::string& str); | |
| 40 | + | void remove(const std::string& str); | |
| 41 | + | ||
| 42 | + | ReturnValue findOne(const std::string& query, std::string& result) const; | |
| 43 | + | ||
| 44 | + | private: | |
| 45 | + | std::map<char, WildcardTreeNode> children; | |
| 46 | + | bool breakpoint; | |
| 47 | + | }; | |
| 48 | + | ||
| 49 | + | #endif |
| @@ -0,0 +1,63 @@ | |||
| 1 | + | #include "otpch.h" | |
| 2 | + | ||
| 3 | + | #include "wings.h" | |
| 4 | + | ||
| 5 | + | #include "pugicast.h" | |
| 6 | + | #include "tools.h" | |
| 7 | + | ||
| 8 | + | bool Wings::reload() | |
| 9 | + | { | |
| 10 | + | wings.clear(); | |
| 11 | + | return loadFromXml(); | |
| 12 | + | } | |
| 13 | + | ||
| 14 | + | bool Wings::loadFromXml() | |
| 15 | + | { | |
| 16 | + | pugi::xml_document doc; | |
| 17 | + | pugi::xml_parse_result result = doc.load_file("data/XML/wings.xml"); | |
| 18 | + | if (!result) { | |
| 19 | + | printXMLError("Error - Wings::loadFromXml", "data/XML/wings.xml", result); | |
| 20 | + | return false; | |
| 21 | + | } | |
| 22 | + | ||
| 23 | + | for (auto wingNode : doc.child("wings").children()) { | |
| 24 | + | wings.emplace_back( | |
| 25 | + | static_cast<uint8_t>(pugi::cast<uint16_t>(wingNode.attribute("id").value())), | |
| 26 | + | pugi::cast<uint16_t>(wingNode.attribute("clientid").value()), | |
| 27 | + | wingNode.attribute("name").as_string(), | |
| 28 | + | pugi::cast<int32_t>(wingNode.attribute("speed").value()), | |
| 29 | + | wingNode.attribute("premium").as_bool() | |
| 30 | + | ); | |
| 31 | + | } | |
| 32 | + | wings.shrink_to_fit(); | |
| 33 | + | return true; | |
| 34 | + | } | |
| 35 | + | ||
| 36 | + | Wing* Wings::getWingByID(uint8_t id) | |
| 37 | + | { | |
| 38 | + | auto it = std::find_if(wings.begin(), wings.end(), [id](const Wing& wing) { | |
| 39 | + | return wing.id == id; | |
| 40 | + | }); | |
| 41 | + | ||
| 42 | + | return it != wings.end() ? &*it : nullptr; | |
| 43 | + | } | |
| 44 | + | ||
| 45 | + | Wing* Wings::getWingByName(const std::string& name) { | |
| 46 | + | auto wingName = name.c_str(); | |
| 47 | + | for (auto& it : wings) { | |
| 48 | + | if (strcasecmp(wingName, it.name.c_str()) == 0) { | |
| 49 | + | return ⁢ | |
| 50 | + | } | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | return nullptr; | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | Wing* Wings::getWingByClientID(uint16_t clientId) | |
| 57 | + | { | |
| 58 | + | auto it = std::find_if(wings.begin(), wings.end(), [clientId](const Wing& wing) { | |
| 59 | + | return wing.clientId == clientId; | |
| 60 | + | }); | |
| 61 | + | ||
| 62 | + | return it != wings.end() ? &*it : nullptr; | |
| 63 | + | } |
| @@ -0,0 +1,34 @@ | |||
| 1 | + | #ifndef FS_WINGS_H | |
| 2 | + | #define FS_WINGS_H | |
| 3 | + | ||
| 4 | + | struct Wing | |
| 5 | + | { | |
| 6 | + | Wing(uint8_t id, uint16_t clientId, std::string name, int32_t speed, bool premium) : | |
| 7 | + | name(std::move(name)), speed(speed), clientId(clientId), id(id), premium(premium) {} | |
| 8 | + | ||
| 9 | + | std::string name; | |
| 10 | + | int32_t speed; | |
| 11 | + | uint16_t clientId; | |
| 12 | + | uint8_t id; | |
| 13 | + | bool premium; | |
| 14 | + | }; | |
| 15 | + | ||
| 16 | + | class Wings | |
| 17 | + | { | |
| 18 | + | public: | |
| 19 | + | bool reload(); | |
| 20 | + | bool loadFromXml(); | |
| 21 | + | Wing* getWingByID(uint8_t id); | |
| 22 | + | Wing* getWingByName(const std::string& name); | |
| 23 | + | Wing* getWingByClientID(uint16_t clientId); | |
| 24 | + | std::string getWingNameByID(uint8_t id); | |
| 25 | + | ||
| 26 | + | const std::vector<Wing>& getWings() const { | |
| 27 | + | return wings; | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | private: | |
| 31 | + | std::vector<Wing> wings; | |
| 32 | + | }; | |
| 33 | + | ||
| 34 | + | #endif |
| @@ -0,0 +1,75 @@ | |||
| 1 | + | /** | |
| 2 | + | * The Forgotten Server - a free and open-source MMORPG server emulator | |
| 3 | + | * Copyright (C) 2020 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 "xtea.h" | |
| 23 | + | ||
| 24 | + | #include <array> | |
| 25 | + | #include <assert.h> | |
| 26 | + | ||
| 27 | + | namespace xtea { | |
| 28 | + | ||
| 29 | + | namespace { | |
| 30 | + | ||
| 31 | + | constexpr uint32_t delta = 0x9E3779B9; | |
| 32 | + | ||
| 33 | + | template<typename Round> | |
| 34 | + | void apply_rounds(uint8_t* data, size_t length, Round round) | |
| 35 | + | { | |
| 36 | + | for (auto j = 0u; j < length; j += 8) { | |
| 37 | + | uint32_t left = data[j+0] | data[j+1] << 8u | data[j+2] << 16u | data[j+3] << 24u, | |
| 38 | + | right = data[j+4] | data[j+5] << 8u | data[j+6] << 16u | data[j+7] << 24u; | |
| 39 | + | ||
| 40 | + | round(left, right); | |
| 41 | + | ||
| 42 | + | data[j] = static_cast<uint8_t>(left); | |
| 43 | + | data[j+1] = static_cast<uint8_t>(left >> 8u); | |
| 44 | + | data[j+2] = static_cast<uint8_t>(left >> 16u); | |
| 45 | + | data[j+3] = static_cast<uint8_t>(left >> 24u); | |
| 46 | + | data[j+4] = static_cast<uint8_t>(right); | |
| 47 | + | data[j+5] = static_cast<uint8_t>(right >> 8u); | |
| 48 | + | data[j+6] = static_cast<uint8_t>(right >> 16u); | |
| 49 | + | data[j+7] = static_cast<uint8_t>(right >> 24u); | |
| 50 | + | } | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | } | |
| 54 | + | ||
| 55 | + | void encrypt(uint8_t* data, size_t length, const key& k) | |
| 56 | + | { | |
| 57 | + | for (uint32_t i = 0, sum = 0, next_sum = sum + delta; i < 32; ++i, sum = next_sum, next_sum += delta) { | |
| 58 | + | apply_rounds(data, length, [&](uint32_t& left, uint32_t& right) { | |
| 59 | + | left += ((right << 4 ^ right >> 5) + right) ^ (sum + k[sum & 3]); | |
| 60 | + | right += ((left << 4 ^ left >> 5) + left) ^ (next_sum + k[(next_sum >> 11) & 3]); | |
| 61 | + | }); | |
| 62 | + | }; | |
| 63 | + | } | |
| 64 | + | ||
| 65 | + | void decrypt(uint8_t* data, size_t length, const key& k) | |
| 66 | + | { | |
| 67 | + | for (uint32_t i = 0, sum = delta << 5, next_sum = sum - delta; i < 32; ++i, sum = next_sum, next_sum -= delta) { | |
| 68 | + | apply_rounds(data, length, [&](uint32_t& left, uint32_t& right) { | |
| 69 | + | right -= ((left << 4 ^ left >> 5) + left) ^ (sum + k[(sum >> 11) & 3]); | |
| 70 | + | left -= ((right << 4 ^ right >> 5) + right) ^ (next_sum + k[next_sum & 3]); | |
| 71 | + | }); | |
| 72 | + | }; | |
| 73 | + | } | |
| 74 | + | ||
| 75 | + | } // namespace xtea |
| @@ -0,0 +1,32 @@ | |||
| 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 TFS_XTEA_H | |
| 21 | + | #define TFS_XTEA_H | |
| 22 | + | ||
| 23 | + | namespace xtea { | |
| 24 | + | ||
| 25 | + | using key = std::array<uint32_t, 4>; | |
| 26 | + | ||
| 27 | + | void encrypt(uint8_t* data, size_t length, const key& k); | |
| 28 | + | void decrypt(uint8_t* data, size_t length, const key& k); | |
| 29 | + | ||
| 30 | + | } // namespace xtea | |
| 31 | + | ||
| 32 | + | #endif // TFS_XTEA_H |
| @@ -0,0 +1,12 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ImportGroup Label="PropertySheets" /> | |
| 4 | + | <PropertyGroup Label="UserMacros" /> | |
| 5 | + | <PropertyGroup /> | |
| 6 | + | <ItemDefinitionGroup> | |
| 7 | + | <Link> | |
| 8 | + | <LargeAddressAware>true</LargeAddressAware> | |
| 9 | + | </Link> | |
| 10 | + | </ItemDefinitionGroup> | |
| 11 | + | <ItemGroup /> | |
| 12 | + | </Project> |
| @@ -0,0 +1,11 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ImportGroup Label="PropertySheets" /> | |
| 4 | + | <PropertyGroup Label="UserMacros" /> | |
| 5 | + | <PropertyGroup /> | |
| 6 | + | <ItemDefinitionGroup> | |
| 7 | + | <Link> | |
| 8 | + | </Link> | |
| 9 | + | </ItemDefinitionGroup> | |
| 10 | + | <ItemGroup /> | |
| 11 | + | </Project> |
| @@ -0,0 +1,19 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ImportGroup Label="PropertySheets" /> | |
| 4 | + | <PropertyGroup Label="UserMacros" /> | |
| 5 | + | <PropertyGroup> | |
| 6 | + | <LinkIncremental>true</LinkIncremental> | |
| 7 | + | </PropertyGroup> | |
| 8 | + | <ItemDefinitionGroup> | |
| 9 | + | <ClCompile> | |
| 10 | + | <WholeProgramOptimization>false</WholeProgramOptimization> | |
| 11 | + | <MinimalRebuild>false</MinimalRebuild> | |
| 12 | + | <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> | |
| 13 | + | <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> | |
| 14 | + | <ObjectFileName>$(IntDir)\obj_d\</ObjectFileName> | |
| 15 | + | </ClCompile> | |
| 16 | + | </ItemDefinitionGroup> | |
| 17 | + | <ItemGroup /> | |
| 18 | + | </Project> | |
| 19 | + |
| @@ -0,0 +1,4 @@ | |||
| 1 | + | #include <winres.h> | |
| 2 | + | ||
| 3 | + | // Main executable icon. | |
| 4 | + | 1 ICON "RD_Core_Icon.ico" |
| @@ -0,0 +1,31 @@ | |||
| 1 | + | ||
| 2 | + | Microsoft Visual Studio Solution File, Format Version 12.00 | |
| 3 | + | # Visual Studio Version 16 | |
| 4 | + | VisualStudioVersion = 16.0.30611.23 | |
| 5 | + | MinimumVisualStudioVersion = 10.0.40219.1 | |
| 6 | + | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RD_Core", "RD_Core.vcxproj", "{A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}" | |
| 7 | + | EndProject | |
| 8 | + | Global | |
| 9 | + | GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
| 10 | + | Debug|Win32 = Debug|Win32 | |
| 11 | + | Debug|x64 = Debug|x64 | |
| 12 | + | Release|Win32 = Release|Win32 | |
| 13 | + | Release|x64 = Release|x64 | |
| 14 | + | EndGlobalSection | |
| 15 | + | GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
| 16 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Debug|Win32.ActiveCfg = Debug|Win32 | |
| 17 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Debug|Win32.Build.0 = Debug|Win32 | |
| 18 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Debug|x64.ActiveCfg = Debug|x64 | |
| 19 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Debug|x64.Build.0 = Debug|x64 | |
| 20 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Release|Win32.ActiveCfg = Release|x64 | |
| 21 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Release|Win32.Build.0 = Release|x64 | |
| 22 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Release|x64.ActiveCfg = Release|x64 | |
| 23 | + | {A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}.Release|x64.Build.0 = Release|x64 | |
| 24 | + | EndGlobalSection | |
| 25 | + | GlobalSection(SolutionProperties) = preSolution | |
| 26 | + | HideSolutionNode = FALSE | |
| 27 | + | EndGlobalSection | |
| 28 | + | GlobalSection(ExtensibilityGlobals) = postSolution | |
| 29 | + | SolutionGuid = {81EB239E-6AEB-4015-9915-256C2C90D3FD} | |
| 30 | + | EndGlobalSection | |
| 31 | + | EndGlobal |
| @@ -0,0 +1,353 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ItemGroup Label="ProjectConfigurations"> | |
| 4 | + | <ProjectConfiguration Include="Debug|Win32"> | |
| 5 | + | <Configuration>Debug</Configuration> | |
| 6 | + | <Platform>Win32</Platform> | |
| 7 | + | </ProjectConfiguration> | |
| 8 | + | <ProjectConfiguration Include="Debug|x64"> | |
| 9 | + | <Configuration>Debug</Configuration> | |
| 10 | + | <Platform>x64</Platform> | |
| 11 | + | </ProjectConfiguration> | |
| 12 | + | <ProjectConfiguration Include="Release|Win32"> | |
| 13 | + | <Configuration>Release</Configuration> | |
| 14 | + | <Platform>Win32</Platform> | |
| 15 | + | </ProjectConfiguration> | |
| 16 | + | <ProjectConfiguration Include="Release|x64"> | |
| 17 | + | <Configuration>Release</Configuration> | |
| 18 | + | <Platform>x64</Platform> | |
| 19 | + | </ProjectConfiguration> | |
| 20 | + | </ItemGroup> | |
| 21 | + | <PropertyGroup Label="Globals"> | |
| 22 | + | <Keyword>Win32Proj</Keyword> | |
| 23 | + | <ProjectGuid>{A10F9657-129F-0FEF-14CB-CEE0B0E5AA3E}</ProjectGuid> | |
| 24 | + | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |
| 25 | + | </PropertyGroup> | |
| 26 | + | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |
| 27 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |
| 28 | + | <ConfigurationType>Application</ConfigurationType> | |
| 29 | + | <UseDebugLibraries>true</UseDebugLibraries> | |
| 30 | + | <PlatformToolset>v143</PlatformToolset> | |
| 31 | + | </PropertyGroup> | |
| 32 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |
| 33 | + | <ConfigurationType>Application</ConfigurationType> | |
| 34 | + | <UseDebugLibraries>true</UseDebugLibraries> | |
| 35 | + | <PlatformToolset>v143</PlatformToolset> | |
| 36 | + | </PropertyGroup> | |
| 37 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |
| 38 | + | <ConfigurationType>Application</ConfigurationType> | |
| 39 | + | <UseDebugLibraries>false</UseDebugLibraries> | |
| 40 | + | <PlatformToolset>v143</PlatformToolset> | |
| 41 | + | </PropertyGroup> | |
| 42 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |
| 43 | + | <ConfigurationType>Application</ConfigurationType> | |
| 44 | + | <UseDebugLibraries>false</UseDebugLibraries> | |
| 45 | + | <PlatformToolset>v143</PlatformToolset> | |
| 46 | + | </PropertyGroup> | |
| 47 | + | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |
| 48 | + | <ImportGroup Label="ExtensionSettings"> | |
| 49 | + | </ImportGroup> | |
| 50 | + | <Import Project="settings.props" /> | |
| 51 | + | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
| 52 | + | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
| 53 | + | <Import Project="arch32.props" /> | |
| 54 | + | <Import Project="debug.props" /> | |
| 55 | + | </ImportGroup> | |
| 56 | + | <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> | |
| 57 | + | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
| 58 | + | <Import Project="arch64.props" /> | |
| 59 | + | <Import Project="debug.props" /> | |
| 60 | + | </ImportGroup> | |
| 61 | + | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
| 62 | + | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
| 63 | + | <Import Project="arch32.props" /> | |
| 64 | + | <Import Project="release.props" /> | |
| 65 | + | </ImportGroup> | |
| 66 | + | <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> | |
| 67 | + | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
| 68 | + | <Import Project="arch64.props" /> | |
| 69 | + | <Import Project="release.props" /> | |
| 70 | + | </ImportGroup> | |
| 71 | + | <PropertyGroup Label="UserMacros" /> | |
| 72 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
| 73 | + | <TargetName>$(ProjectName)-$(Platform)</TargetName> | |
| 74 | + | <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath> | |
| 75 | + | </PropertyGroup> | |
| 76 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |
| 77 | + | <TargetName>$(ProjectName)-$(Platform)</TargetName> | |
| 78 | + | <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath> | |
| 79 | + | </PropertyGroup> | |
| 80 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
| 81 | + | <TargetName>$(ProjectName)-$(Platform)</TargetName> | |
| 82 | + | <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath> | |
| 83 | + | </PropertyGroup> | |
| 84 | + | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |
| 85 | + | <TargetName>$(ProjectName)-$(Platform)</TargetName> | |
| 86 | + | <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath> | |
| 87 | + | </PropertyGroup> | |
| 88 | + | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
| 89 | + | <ClCompile> | |
| 90 | + | <PreprocessorDefinitions>_CONSOLE;$(PREPROCESSOR_DEFS);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 91 | + | <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | |
| 92 | + | <Optimization>Disabled</Optimization> | |
| 93 | + | <EnableParallelCodeGeneration>true</EnableParallelCodeGeneration> | |
| 94 | + | <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> | |
| 95 | + | <AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 96 | + | </ClCompile> | |
| 97 | + | <Link> | |
| 98 | + | <TargetMachine>MachineX86</TargetMachine> | |
| 99 | + | <GenerateDebugInformation>true</GenerateDebugInformation> | |
| 100 | + | <SubSystem>Console</SubSystem> | |
| 101 | + | <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | |
| 102 | + | </Link> | |
| 103 | + | </ItemDefinitionGroup> | |
| 104 | + | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |
| 105 | + | <ClCompile> | |
| 106 | + | <PreprocessorDefinitions>_CONSOLE;$(PREPROCESSOR_DEFS);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 107 | + | <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | |
| 108 | + | <EnableParallelCodeGeneration>true</EnableParallelCodeGeneration> | |
| 109 | + | <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> | |
| 110 | + | <AdditionalIncludeDirectories>$(VcpkgRoot)\include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 111 | + | <LanguageStandard>stdcpp14</LanguageStandard> | |
| 112 | + | </ClCompile> | |
| 113 | + | <Link> | |
| 114 | + | <GenerateDebugInformation>true</GenerateDebugInformation> | |
| 115 | + | <SubSystem>Console</SubSystem> | |
| 116 | + | <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | |
| 117 | + | </Link> | |
| 118 | + | </ItemDefinitionGroup> | |
| 119 | + | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
| 120 | + | <ClCompile> | |
| 121 | + | <PreprocessorDefinitions>NDEBUG;_CONSOLE;$(PREPROCESSOR_DEFS);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 122 | + | <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> | |
| 123 | + | <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | |
| 124 | + | <Optimization>MaxSpeed</Optimization> | |
| 125 | + | <IntrinsicFunctions>true</IntrinsicFunctions> | |
| 126 | + | <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> | |
| 127 | + | <EnableParallelCodeGeneration>true</EnableParallelCodeGeneration> | |
| 128 | + | <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet> | |
| 129 | + | <AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 130 | + | </ClCompile> | |
| 131 | + | <Link> | |
| 132 | + | <TargetMachine>MachineX86</TargetMachine> | |
| 133 | + | <GenerateDebugInformation>true</GenerateDebugInformation> | |
| 134 | + | <SubSystem>Console</SubSystem> | |
| 135 | + | <EnableCOMDATFolding>true</EnableCOMDATFolding> | |
| 136 | + | <OptimizeReferences>true</OptimizeReferences> | |
| 137 | + | <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | |
| 138 | + | </Link> | |
| 139 | + | </ItemDefinitionGroup> | |
| 140 | + | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |
| 141 | + | <ClCompile> | |
| 142 | + | <PreprocessorDefinitions>NDEBUG;_CONSOLE;$(PREPROCESSOR_DEFS);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |
| 143 | + | <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> | |
| 144 | + | <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> | |
| 145 | + | <WarningLevel>Level4</WarningLevel> | |
| 146 | + | <Optimization>MaxSpeed</Optimization> | |
| 147 | + | <IntrinsicFunctions>true</IntrinsicFunctions> | |
| 148 | + | <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> | |
| 149 | + | <EnableParallelCodeGeneration>false</EnableParallelCodeGeneration> | |
| 150 | + | <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> | |
| 151 | + | <AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |
| 152 | + | <LanguageStandard>stdcpp14</LanguageStandard> | |
| 153 | + | </ClCompile> | |
| 154 | + | <Link> | |
| 155 | + | <GenerateDebugInformation>true</GenerateDebugInformation> | |
| 156 | + | <SubSystem>Console</SubSystem> | |
| 157 | + | <EnableCOMDATFolding>true</EnableCOMDATFolding> | |
| 158 | + | <OptimizeReferences>true</OptimizeReferences> | |
| 159 | + | <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;mswsock.lib;bcrypt.lib;boost_filesystem-vc140-mt.lib;boost_iostreams-vc140-mt.lib;cryptopp-static.lib;fmt.lib;libmariadb.lib;lua51.lib;pugixml.lib;zlib.lib</AdditionalDependencies> | |
| 160 | + | </Link> | |
| 161 | + | </ItemDefinitionGroup> | |
| 162 | + | <ItemGroup> | |
| 163 | + | <ClCompile Include="..\src\actions.cpp" /> | |
| 164 | + | <ClCompile Include="..\src\auras.cpp" /> | |
| 165 | + | <ClCompile Include="..\src\ban.cpp" /> | |
| 166 | + | <ClCompile Include="..\src\baseevents.cpp" /> | |
| 167 | + | <ClCompile Include="..\src\bed.cpp" /> | |
| 168 | + | <ClCompile Include="..\src\chat.cpp" /> | |
| 169 | + | <ClCompile Include="..\src\combat.cpp" /> | |
| 170 | + | <ClCompile Include="..\src\condition.cpp" /> | |
| 171 | + | <ClCompile Include="..\src\configmanager.cpp" /> | |
| 172 | + | <ClCompile Include="..\src\connection.cpp" /> | |
| 173 | + | <ClCompile Include="..\src\container.cpp" /> | |
| 174 | + | <ClCompile Include="..\src\creature.cpp" /> | |
| 175 | + | <ClCompile Include="..\src\creatureevent.cpp" /> | |
| 176 | + | <ClCompile Include="..\src\cylinder.cpp" /> | |
| 177 | + | <ClCompile Include="..\src\database.cpp" /> | |
| 178 | + | <ClCompile Include="..\src\databasemanager.cpp" /> | |
| 179 | + | <ClCompile Include="..\src\databasetasks.cpp" /> | |
| 180 | + | <ClCompile Include="..\src\depotchest.cpp" /> | |
| 181 | + | <ClCompile Include="..\src\depotlocker.cpp" /> | |
| 182 | + | <ClCompile Include="..\src\effects.cpp" /> | |
| 183 | + | <ClCompile Include="..\src\events.cpp" /> | |
| 184 | + | <ClCompile Include="..\src\fileloader.cpp" /> | |
| 185 | + | <ClCompile Include="..\src\game.cpp" /> | |
| 186 | + | <ClCompile Include="..\src\globalevent.cpp" /> | |
| 187 | + | <ClCompile Include="..\src\groups.cpp" /> | |
| 188 | + | <ClCompile Include="..\src\guild.cpp" /> | |
| 189 | + | <ClCompile Include="..\src\house.cpp" /> | |
| 190 | + | <ClCompile Include="..\src\housetile.cpp" /> | |
| 191 | + | <ClCompile Include="..\src\inbox.cpp" /> | |
| 192 | + | <ClCompile Include="..\src\ioguild.cpp" /> | |
| 193 | + | <ClCompile Include="..\src\iologindata.cpp" /> | |
| 194 | + | <ClCompile Include="..\src\iomap.cpp" /> | |
| 195 | + | <ClCompile Include="..\src\iomapserialize.cpp" /> | |
| 196 | + | <ClCompile Include="..\src\iomarket.cpp" /> | |
| 197 | + | <ClCompile Include="..\src\item.cpp" /> | |
| 198 | + | <ClCompile Include="..\src\items.cpp" /> | |
| 199 | + | <ClCompile Include="..\src\luascript.cpp" /> | |
| 200 | + | <ClCompile Include="..\src\mailbox.cpp" /> | |
| 201 | + | <ClCompile Include="..\src\map.cpp" /> | |
| 202 | + | <ClCompile Include="..\src\monster.cpp" /> | |
| 203 | + | <ClCompile Include="..\src\monsters.cpp" /> | |
| 204 | + | <ClCompile Include="..\src\mounts.cpp" /> | |
| 205 | + | <ClCompile Include="..\src\movement.cpp" /> | |
| 206 | + | <ClCompile Include="..\src\networkmessage.cpp" /> | |
| 207 | + | <ClCompile Include="..\src\npc.cpp" /> | |
| 208 | + | <ClCompile Include="..\src\otpch.cpp"> | |
| 209 | + | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | |
| 210 | + | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | |
| 211 | + | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | |
| 212 | + | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | |
| 213 | + | <PrecompiledHeaderFile>otpch.h</PrecompiledHeaderFile> | |
| 214 | + | </ClCompile> | |
| 215 | + | <ClCompile Include="..\src\otserv.cpp" /> | |
| 216 | + | <ClCompile Include="..\src\outfit.cpp" /> | |
| 217 | + | <ClCompile Include="..\src\outputmessage.cpp" /> | |
| 218 | + | <ClCompile Include="..\src\party.cpp" /> | |
| 219 | + | <ClCompile Include="..\src\player.cpp" /> | |
| 220 | + | <ClCompile Include="..\src\position.cpp" /> | |
| 221 | + | <ClCompile Include="..\src\protocol.cpp" /> | |
| 222 | + | <ClCompile Include="..\src\protocolgame.cpp" /> | |
| 223 | + | <ClCompile Include="..\src\protocollogin.cpp" /> | |
| 224 | + | <ClCompile Include="..\src\protocolold.cpp" /> | |
| 225 | + | <ClCompile Include="..\src\quests.cpp" /> | |
| 226 | + | <ClCompile Include="..\src\raids.cpp" /> | |
| 227 | + | <ClCompile Include="..\src\rsa.cpp" /> | |
| 228 | + | <ClCompile Include="..\src\runeeffects.cpp" /> | |
| 229 | + | <ClCompile Include="..\src\scheduler.cpp" /> | |
| 230 | + | <ClCompile Include="..\src\script.cpp" /> | |
| 231 | + | <ClCompile Include="..\src\scriptmanager.cpp" /> | |
| 232 | + | <ClCompile Include="..\src\server.cpp" /> | |
| 233 | + | <ClCompile Include="..\src\shaders.cpp" /> | |
| 234 | + | <ClCompile Include="..\src\signals.cpp" /> | |
| 235 | + | <ClCompile Include="..\src\spawn.cpp" /> | |
| 236 | + | <ClCompile Include="..\src\spells.cpp" /> | |
| 237 | + | <ClCompile Include="..\src\protocolstatus.cpp" /> | |
| 238 | + | <ClCompile Include="..\src\talkaction.cpp" /> | |
| 239 | + | <ClCompile Include="..\src\tasks.cpp" /> | |
| 240 | + | <ClCompile Include="..\src\teleport.cpp" /> | |
| 241 | + | <ClCompile Include="..\src\thing.cpp" /> | |
| 242 | + | <ClCompile Include="..\src\tile.cpp" /> | |
| 243 | + | <ClCompile Include="..\src\tools.cpp" /> | |
| 244 | + | <ClCompile Include="..\src\trashholder.cpp" /> | |
| 245 | + | <ClCompile Include="..\src\vocation.cpp" /> | |
| 246 | + | <ClCompile Include="..\src\waitlist.cpp" /> | |
| 247 | + | <ClCompile Include="..\src\weapons.cpp" /> | |
| 248 | + | <ClCompile Include="..\src\wildcardtree.cpp" /> | |
| 249 | + | <ClCompile Include="..\src\wings.cpp" /> | |
| 250 | + | <ClCompile Include="..\src\xtea.cpp" /> | |
| 251 | + | </ItemGroup> | |
| 252 | + | <ItemGroup> | |
| 253 | + | <ClInclude Include="..\src\account.h" /> | |
| 254 | + | <ClInclude Include="..\src\actions.h" /> | |
| 255 | + | <ClInclude Include="..\src\auras.h" /> | |
| 256 | + | <ClInclude Include="..\src\ban.h" /> | |
| 257 | + | <ClInclude Include="..\src\baseevents.h" /> | |
| 258 | + | <ClInclude Include="..\src\bed.h" /> | |
| 259 | + | <ClInclude Include="..\src\chat.h" /> | |
| 260 | + | <ClInclude Include="..\src\combat.h" /> | |
| 261 | + | <ClInclude Include="..\src\condition.h" /> | |
| 262 | + | <ClInclude Include="..\src\configmanager.h" /> | |
| 263 | + | <ClInclude Include="..\src\connection.h" /> | |
| 264 | + | <ClInclude Include="..\src\console_ui.h" /> | |
| 265 | + | <ClInclude Include="..\src\const.h" /> | |
| 266 | + | <ClInclude Include="..\src\container.h" /> | |
| 267 | + | <ClInclude Include="..\src\creature.h" /> | |
| 268 | + | <ClInclude Include="..\src\creatureevent.h" /> | |
| 269 | + | <ClInclude Include="..\src\cylinder.h" /> | |
| 270 | + | <ClInclude Include="..\src\database.h" /> | |
| 271 | + | <ClInclude Include="..\src\databasemanager.h" /> | |
| 272 | + | <ClInclude Include="..\src\databasetasks.h" /> | |
| 273 | + | <ClInclude Include="..\src\definitions.h" /> | |
| 274 | + | <ClInclude Include="..\src\depotchest.h" /> | |
| 275 | + | <ClInclude Include="..\src\depotlocker.h" /> | |
| 276 | + | <ClInclude Include="..\src\effects.h" /> | |
| 277 | + | <ClInclude Include="..\src\enums.h" /> | |
| 278 | + | <ClInclude Include="..\src\events.h" /> | |
| 279 | + | <ClInclude Include="..\src\fileloader.h" /> | |
| 280 | + | <ClInclude Include="..\src\game.h" /> | |
| 281 | + | <ClInclude Include="..\src\globalevent.h" /> | |
| 282 | + | <ClInclude Include="..\src\groups.h" /> | |
| 283 | + | <ClInclude Include="..\src\guild.h" /> | |
| 284 | + | <ClInclude Include="..\src\house.h" /> | |
| 285 | + | <ClInclude Include="..\src\housetile.h" /> | |
| 286 | + | <ClInclude Include="..\src\inbox.h" /> | |
| 287 | + | <ClInclude Include="..\src\ioguild.h" /> | |
| 288 | + | <ClInclude Include="..\src\iologindata.h" /> | |
| 289 | + | <ClInclude Include="..\src\iomap.h" /> | |
| 290 | + | <ClInclude Include="..\src\iomapserialize.h" /> | |
| 291 | + | <ClInclude Include="..\src\iomarket.h" /> | |
| 292 | + | <ClInclude Include="..\src\item.h" /> | |
| 293 | + | <ClInclude Include="..\src\itemloader.h" /> | |
| 294 | + | <ClInclude Include="..\src\items.h" /> | |
| 295 | + | <ClInclude Include="..\src\lockfree.h" /> | |
| 296 | + | <ClInclude Include="..\src\luascript.h" /> | |
| 297 | + | <ClInclude Include="..\src\mailbox.h" /> | |
| 298 | + | <ClInclude Include="..\src\map.h" /> | |
| 299 | + | <ClInclude Include="..\src\monster.h" /> | |
| 300 | + | <ClInclude Include="..\src\monsters.h" /> | |
| 301 | + | <ClInclude Include="..\src\mounts.h" /> | |
| 302 | + | <ClInclude Include="..\src\movement.h" /> | |
| 303 | + | <ClInclude Include="..\src\networkmessage.h" /> | |
| 304 | + | <ClInclude Include="..\src\npc.h" /> | |
| 305 | + | <ClInclude Include="..\src\otpch.h" /> | |
| 306 | + | <ClInclude Include="..\src\outfit.h" /> | |
| 307 | + | <ClInclude Include="..\src\outputmessage.h" /> | |
| 308 | + | <ClInclude Include="..\src\party.h" /> | |
| 309 | + | <ClInclude Include="..\src\player.h" /> | |
| 310 | + | <ClInclude Include="..\src\position.h" /> | |
| 311 | + | <ClInclude Include="..\src\protocol.h" /> | |
| 312 | + | <ClInclude Include="..\src\protocolgame.h" /> | |
| 313 | + | <ClInclude Include="..\src\protocollogin.h" /> | |
| 314 | + | <ClInclude Include="..\src\protocolold.h" /> | |
| 315 | + | <ClInclude Include="..\src\pugicast.h" /> | |
| 316 | + | <ClInclude Include="..\src\quests.h" /> | |
| 317 | + | <ClInclude Include="..\src\raids.h" /> | |
| 318 | + | <ClInclude Include="..\src\rsa.h" /> | |
| 319 | + | <ClInclude Include="..\src\scheduler.h" /> | |
| 320 | + | <ClInclude Include="..\src\script.h" /> | |
| 321 | + | <ClInclude Include="..\src\scriptmanager.h" /> | |
| 322 | + | <ClInclude Include="..\src\server.h" /> | |
| 323 | + | <ClInclude Include="..\src\shaders.h" /> | |
| 324 | + | <ClInclude Include="..\src\signals.h" /> | |
| 325 | + | <ClInclude Include="..\src\spawn.h" /> | |
| 326 | + | <ClInclude Include="..\src\spectators.h" /> | |
| 327 | + | <ClInclude Include="..\src\spells.h" /> | |
| 328 | + | <ClInclude Include="..\src\protocolstatus.h" /> | |
| 329 | + | <ClInclude Include="..\src\talkaction.h" /> | |
| 330 | + | <ClInclude Include="..\src\tasks.h" /> | |
| 331 | + | <ClInclude Include="..\src\teleport.h" /> | |
| 332 | + | <ClInclude Include="..\src\thing.h" /> | |
| 333 | + | <ClInclude Include="..\src\thread_holder_base.h" /> | |
| 334 | + | <ClInclude Include="..\src\tile.h" /> | |
| 335 | + | <ClInclude Include="..\src\tools.h" /> | |
| 336 | + | <ClInclude Include="..\src\town.h" /> | |
| 337 | + | <ClInclude Include="..\src\trashholder.h" /> | |
| 338 | + | <ClInclude Include="..\src\vocation.h" /> | |
| 339 | + | <ClInclude Include="..\src\waitlist.h" /> | |
| 340 | + | <ClInclude Include="..\src\walkmatrix.h" /> | |
| 341 | + | <ClInclude Include="..\src\weapons.h" /> | |
| 342 | + | <ClInclude Include="..\src\wildcardtree.h" /> | |
| 343 | + | <ClInclude Include="..\src\wings.h" /> | |
| 344 | + | <ClInclude Include="..\src\xtea.h" /> | |
| 345 | + | </ItemGroup> | |
| 346 | + | <ItemGroup> | |
| 347 | + | <ResourceCompile Include="RD_Core.rc" /> | |
| 348 | + | <Image Include="RD_Core_Icon.ico" /> | |
| 349 | + | </ItemGroup> | |
| 350 | + | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |
| 351 | + | <ImportGroup Label="ExtensionTargets"> | |
| 352 | + | </ImportGroup> | |
| 353 | + | </Project> |
| @@ -0,0 +1,19 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ImportGroup Label="PropertySheets" /> | |
| 4 | + | <PropertyGroup Label="UserMacros" /> | |
| 5 | + | <PropertyGroup> | |
| 6 | + | <LinkIncremental>false</LinkIncremental> | |
| 7 | + | </PropertyGroup> | |
| 8 | + | <ItemDefinitionGroup> | |
| 9 | + | <ClCompile> | |
| 10 | + | <Optimization>Full</Optimization> | |
| 11 | + | <ObjectFileName>$(IntDir)\obj_r\</ObjectFileName> | |
| 12 | + | </ClCompile> | |
| 13 | + | <Link> | |
| 14 | + | <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> | |
| 15 | + | </Link> | |
| 16 | + | </ItemDefinitionGroup> | |
| 17 | + | <ItemGroup /> | |
| 18 | + | </Project> | |
| 19 | + |
| @@ -0,0 +1,32 @@ | |||
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| 3 | + | <ImportGroup Label="PropertySheets" /> | |
| 4 | + | <PropertyGroup Label="UserMacros"> | |
| 5 | + | <PREPROCESSOR_DEFS>_CRT_SECURE_NO_WARNINGS;</PREPROCESSOR_DEFS> | |
| 6 | + | </PropertyGroup> | |
| 7 | + | <PropertyGroup> | |
| 8 | + | <LinkIncremental>false</LinkIncremental> | |
| 9 | + | </PropertyGroup> | |
| 10 | + | <ItemDefinitionGroup> | |
| 11 | + | <ClCompile> | |
| 12 | + | <WarningLevel>Level3</WarningLevel> | |
| 13 | + | <MultiProcessorCompilation>true</MultiProcessorCompilation> | |
| 14 | + | <WholeProgramOptimization>true</WholeProgramOptimization> | |
| 15 | + | <PrecompiledHeader>Use</PrecompiledHeader> | |
| 16 | + | <PrecompiledHeaderFile>otpch.h</PrecompiledHeaderFile> | |
| 17 | + | <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> | |
| 18 | + | </ClCompile> | |
| 19 | + | <Link> | |
| 20 | + | <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration> | |
| 21 | + | </Link> | |
| 22 | + | <ResourceCompile> | |
| 23 | + | <PreprocessorDefinitions>$(PREPROCESSOR_DEFS)</PreprocessorDefinitions> | |
| 24 | + | </ResourceCompile> | |
| 25 | + | </ItemDefinitionGroup> | |
| 26 | + | <ItemGroup> | |
| 27 | + | <BuildMacro Include="PREPROCESSOR_DEFS"> | |
| 28 | + | <Value>$(PREPROCESSOR_DEFS)</Value> | |
| 29 | + | <EnvironmentVariable>true</EnvironmentVariable> | |
| 30 | + | </BuildMacro> | |
| 31 | + | </ItemGroup> | |
| 32 | + | </Project> |