diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 5ba50d7..a04399d 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -223,6 +223,26 @@ static SpawnPoint GetSpawnpoint(const sago::tiled::TileMap& tm) { return ret; } +void ApplyEquippedItems(Player& player) { + player.visible_bottom = ""; + player.visible_top = ""; + for (const std::string& itemName : player.equipped_items) { + auto it = player.item_inventory.find(itemName); + if (it != player.item_inventory.end()) { + // Item is in inventory, apply its effects + if (itemName == "armor_basic_pants") { + player.visible_bottom = "pants_1"; + } + if (itemName == "armor_pirate_shirt_sky" && player.race == "female") { + player.visible_top = "pirate_shirt_sky"; + } + if (itemName == "armor_blouse_black" && player.race == "female") { + player.visible_top = "blouse_black"; + } + } + } +} + void PlayerSave() { std::string playername = Config::getInstance()->getString("player"); nlohmann::json j = globalData.player; @@ -237,6 +257,7 @@ void PlayerLoad() { j = nlohmann::json::parse(sago::GetFileContent(filename.c_str())); globalData.player = j; } + ApplyEquippedItems(globalData.player); } void Game::ResetWorldNoSave(int x, int y, bool forceResetWorld) { diff --git a/src/saland/model/Player.cpp b/src/saland/model/Player.cpp index ab9682e..1a0951d 100644 --- a/src/saland/model/Player.cpp +++ b/src/saland/model/Player.cpp @@ -24,7 +24,7 @@ https://github.com/sago007/saland #include "Player.hpp" void to_json(nlohmann::json& j, const Player& p) { - j = nlohmann::json{ {"race", p.race}, {"hair", p.hair}, {"item_inventory", p.item_inventory} }; + j = nlohmann::json{ {"race", p.race}, {"hair", p.hair}, {"item_inventory", p.item_inventory}, {"equipped_items", p.equipped_items} }; } void from_json(const nlohmann::json& j, Player& p) { @@ -33,4 +33,7 @@ void from_json(const nlohmann::json& j, Player& p) { j.at("hair").get_to(p.hair); } j.at("item_inventory").get_to(p.item_inventory); + if (j.contains("equipped_items")) { + j.at("equipped_items").get_to(p.equipped_items); + } } \ No newline at end of file diff --git a/src/saland/model/Player.hpp b/src/saland/model/Player.hpp index dc282e2..370e3e1 100644 --- a/src/saland/model/Player.hpp +++ b/src/saland/model/Player.hpp @@ -26,6 +26,7 @@ https://github.com/sago007/saland #include #include +#include #include "nlohmann/json.hpp" struct Player { @@ -33,6 +34,8 @@ struct Player { std::string save_name="player1"; std::string race = "female"; std::string hair = "standard_hair"; + std::string visible_bottom; + std::string visible_top; std::string get_visible_race() { return this->race; } @@ -40,21 +43,28 @@ struct Player { return this->hair; } std::string get_visible_bottom() { + if (visible_bottom != "") { + return visible_bottom; + } return "pants_1"; } std::string get_visible_top() { + if (visible_top != "") { + return visible_top; + } if (race == "male") { return ""; } return "pirate_shirt_sky"; } - std::string get_visibla_hat() { + std::string get_visible_hat() { return ""; } std::string get_visible_shoes() { return ""; } std::map item_inventory; + std::vector equipped_items = {"armor_basic_pants"}; }; void to_json(nlohmann::json& j, const Player& p);