/** * The Forgotten Server - a free and open-source MMORPG server emulator * Copyright (C) 2019 Mark Samman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "otpch.h" #include "outfit.h" #include "pugicast.h" #include "tools.h" bool Outfits::loadFromXml() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file("data/XML/outfits.xml"); if (!result) { printXMLError("Error - Outfits::loadFromXml", "data/XML/outfits.xml", result); return false; } for (auto outfitNode : doc.child("outfits").children()) { pugi::xml_attribute attr; if ((attr = outfitNode.attribute("enabled")) && !attr.as_bool()) { continue; } if (!(attr = outfitNode.attribute("type"))) { std::cout << "[Warning - Outfits::loadFromXml] Missing outfit type." << std::endl; continue; } uint16_t type = pugi::cast(attr.value()); if (type > PLAYERSEX_LAST) { std::cout << "[Warning - Outfits::loadFromXml] Invalid outfit type " << type << "." << std::endl; continue; } pugi::xml_attribute lookTypeAttribute = outfitNode.attribute("looktype"); if (!lookTypeAttribute) { std::cout << "[Warning - Outfits::loadFromXml] Missing looktype on outfit." << std::endl; continue; } uint16_t attackMeleeType = 0; if ((attr = outfitNode.attribute("attackmeleetype"))) { attackMeleeType = pugi::cast(attr.value()); } else if ((attr = outfitNode.attribute("attacktype"))) { attackMeleeType = pugi::cast(attr.value()); } uint16_t attackRangeType = 0; if ((attr = outfitNode.attribute("attackrangetype"))) { attackRangeType = pugi::cast(attr.value()); } else { attackRangeType = attackMeleeType; } uint8_t attackRange = 1; if ((attr = outfitNode.attribute("attackrange"))) { attackRange = std::max( 1, static_cast(pugi::cast(attr.value()))); } Outfit outfit(outfitNode.attribute("name").as_string(), pugi::cast(lookTypeAttribute.value()), attackMeleeType, attackRangeType, attackRange, outfitNode.attribute("premium").as_bool(), outfitNode.attribute("unlocked").as_bool(true)); bool hasOffsets = false; for (auto offsetNode : outfitNode.children("offset")) { int dir = offsetNode.attribute("dir").as_int(-1); if (dir < 0 || dir >= OUTFIT_DIRECTIONS) { std::cout << "[Warning - Outfits::loadFromXml] Invalid offset dir " << dir << " on outfit " << outfit.name << "." << std::endl; continue; } hasOffsets = true; outfit.offsets[dir].lookX = offsetNode.attribute("lookX").as_int(0); outfit.offsets[dir].lookY = offsetNode.attribute("lookY").as_int(0); outfit.offsets[dir].meleeX = offsetNode.attribute("meleeX").as_int(0); outfit.offsets[dir].meleeY = offsetNode.attribute("meleeY").as_int(0); outfit.offsets[dir].rangeX = offsetNode.attribute("rangeX").as_int(0); outfit.offsets[dir].rangeY = offsetNode.attribute("rangeY").as_int(0); } outfits[type].push_back(std::move(outfit)); } return true; } const Outfit *Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const { for (const Outfit &outfit : outfits[sex]) { if (outfit.lookType == lookType) { return &outfit; } } return nullptr; }