Skip to content

Commit

Permalink
improvement of 'getOutfitByLookType' function, and recovered function…
Browse files Browse the repository at this point in the history
… 'getOpositeSexOutfitByLookType'.
  • Loading branch information
elsongabriel committed May 15, 2024
1 parent 63c43f5 commit 61110bc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool Outfits::loadFromXml() {
return true;
}

std::shared_ptr<Outfit> Outfits::getOutfitByLookType(uint16_t lookType, const std::shared_ptr<const Player> &player) const {
std::shared_ptr<Outfit> Outfits::getOutfitByLookType(const std::shared_ptr<const Player> &player, uint16_t lookType, bool isOppositeOutfit) const {
if (!player) {
g_logger().error("[{}] - Player not found", __FUNCTION__);
return nullptr;
Expand All @@ -90,6 +90,10 @@ std::shared_ptr<Outfit> Outfits::getOutfitByLookType(uint16_t lookType, const st
return nullptr;
}

if (isOppositeOutfit) {
sex = (sex == PLAYERSEX_MALE) ? PLAYERSEX_FEMALE : PLAYERSEX_MALE;
}

auto it = std::ranges::find_if(outfits[sex], [&lookType](const auto &outfit) {
return outfit->lookType == lookType;
});
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/appearance/outfit/outfit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Outfits {
bool reload();
bool loadFromXml();

[[nodiscard]] std::shared_ptr<Outfit> getOutfitByLookType(uint16_t lookType, const std::shared_ptr<const Player> &player) const;
[[nodiscard]] std::shared_ptr<Outfit> getOutfitByLookType(const std::shared_ptr<const Player> &player, uint16_t lookType, bool isOppositeOutfit = false) const;
[[nodiscard]] const std::vector<std::shared_ptr<Outfit>> &getOutfits(PlayerSex_t sex) const {
return outfits[sex];
}
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4982,7 +4982,7 @@ bool Player::canWear(uint16_t lookType, uint8_t addons) const {
return true;
}

const auto &outfit = Outfits::getInstance().getOutfitByLookType(lookType, getPlayer());
const auto &outfit = Outfits::getInstance().getOutfitByLookType(getPlayer(), lookType);
if (!outfit) {
return false;
}
Expand Down Expand Up @@ -5894,7 +5894,7 @@ bool Player::toggleMount(bool mount) {
return false;
}

const auto &playerOutfit = Outfits::getInstance().getOutfitByLookType(defaultOutfit.lookType, getPlayer());
const auto &playerOutfit = Outfits::getInstance().getOutfitByLookType(getPlayer(), defaultOutfit.lookType);
if (!playerOutfit) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/functions/game_reload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,5 @@ bool GameReload::reloadFamiliars() {
bool GameReload::reloadVocations() {
const bool result = g_vocations().reload();
logReloadStatus("Vocations", result);
return result;
return result && reloadScripts();
}
4 changes: 2 additions & 2 deletions src/game/functions/game_reload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Game;
enum class Reload_t : uint8_t {
RELOAD_TYPE_NONE,
RELOAD_TYPE_ALL,
RELOAD_TYPE_VOCATIONS,
RELOAD_TYPE_SCRIPTS,
RELOAD_TYPE_CHAT,
RELOAD_TYPE_CONFIG,
RELOAD_TYPE_EVENTS,
Expand All @@ -28,10 +30,8 @@ enum class Reload_t : uint8_t {
RELOAD_TYPE_OUTFITS,
RELOAD_TYPE_NPCS,
RELOAD_TYPE_RAIDS,
RELOAD_TYPE_SCRIPTS,
RELOAD_TYPE_GROUPS,
RELOAD_TYPE_FAMILIARS,
RELOAD_TYPE_VOCATIONS,

// Every is last
RELOAD_TYPE_LAST
Expand Down
4 changes: 2 additions & 2 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4257,7 +4257,7 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos
name << item->getName() << " displaying the ";
bool outfited = false;
if (outfit.lookType != 0) {
const auto &outfitInfo = Outfits::getInstance().getOutfitByLookType(outfit.lookType, player);
const auto &outfitInfo = Outfits::getInstance().getOutfitByLookType(player, outfit.lookType);
if (!outfitInfo) {
return;
}
Expand Down Expand Up @@ -5906,7 +5906,7 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun
outfit.lookMount = randomMount->clientId;
}

const auto playerOutfit = Outfits::getInstance().getOutfitByLookType(outfit.lookType, player);
const auto playerOutfit = Outfits::getInstance().getOutfitByLookType(player, outfit.lookType);
if (!playerOutfit) {
outfit.lookMount = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,7 @@ void ProtocolGame::sendCyclopediaCharacterInspection() {
// Outfit description
playerDescriptionSize++;
msg.addString("Outfit", "ProtocolGame::sendCyclopediaCharacterInspection - Outfit");
if (const auto outfit = Outfits::getInstance().getOutfitByLookType(player->getDefaultOutfit().lookType, player)) {
if (const auto outfit = Outfits::getInstance().getOutfitByLookType(player, player->getDefaultOutfit().lookType)) {
msg.addString(outfit->name, "ProtocolGame::sendCyclopediaCharacterInspection - outfit->name");
} else {
msg.addString("unknown", "ProtocolGame::sendCyclopediaCharacterInspection - unknown");
Expand Down

0 comments on commit 61110bc

Please sign in to comment.