From f8a6a3e57d30f60fcca1c467a2dc1b185e1e4fa4 Mon Sep 17 00:00:00 2001 From: WasabiRaptor Date: Thu, 7 Mar 2024 13:12:11 -0500 Subject: [PATCH] inventory and hotbar size mismatch fixes I realized why that was there checking patch arrays in a more clean manner also support for checking values in other files using a string in the patch arrays Revert "checking patch arrays in a more clean manner" sorry that wasn't supposed to be in this one --- source/game/StarPlayer.cpp | 7 ++++-- source/game/StarPlayerInventory.cpp | 38 ++++++++++++++++++++++------- source/game/StarPlayerInventory.hpp | 4 +++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index adf3334..1ac1234 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -330,6 +330,9 @@ void Player::init(World* world, EntityId entityId, EntityMode mode) { p.second->addCallbacks("celestial", LuaBindings::makeCelestialCallbacks(m_client)); p.second->init(world); } + for (auto& p : m_inventory->clearOverflow()) { + world->addEntity(ItemDrop::createRandomizedDrop(p,m_movementController->position(),true)); + } } m_xAimPositionNetState.setInterpolator(world->geometry().xLerpFunction()); @@ -346,7 +349,7 @@ void Player::uninit() { m_questManager->uninit(); m_companions->uninit(); m_deployment->uninit(); - + for (auto& p : m_genericScriptContexts) { p.second->uninit(); p.second->removeCallbacks("entity"); @@ -2589,7 +2592,7 @@ void Player::setSecretProperty(String const& name, Json const& value) { ds.write(value); auto& data = ds.data(); m_effectsAnimator->setGlobalTag(secretProprefix + name, String(data.ptr(), data.size())); - } + } else m_effectsAnimator->removeGlobalTag(secretProprefix + name); } diff --git a/source/game/StarPlayerInventory.cpp b/source/game/StarPlayerInventory.cpp index b6c4af3..83d2266 100644 --- a/source/game/StarPlayerInventory.cpp +++ b/source/game/StarPlayerInventory.cpp @@ -443,7 +443,7 @@ void PlayerInventory::condenseBagStacks(String const& bagType) {\ auto bag = m_bags[bagType]; bag->condenseStacks(); - + m_customBar.forEach([&](auto const&, CustomBarLink& link) { if (link.first) { if (auto bs = link.first->ptr()) { @@ -756,6 +756,12 @@ Maybe PlayerInventory::secondaryHeldSlot() const { return {}; } +List PlayerInventory::clearOverflow(){ + auto list = m_inventoryLoadOverflow; + m_inventoryLoadOverflow.clear(); + return list; +} + void PlayerInventory::load(Json const& store) { auto itemDatabase = Root::singleton().itemDatabase(); @@ -771,14 +777,21 @@ void PlayerInventory::load(Json const& store) { //reuse ItemBags so the Inventory pane still works after load()'ing into the same PlayerInventory again (from swap) auto itemBags = store.get("itemBags").toObject(); eraseWhere(m_bags, [&](auto const& p) { return !itemBags.contains(p.first); }); + m_inventoryLoadOverflow.clear(); for (auto const& p : itemBags) { auto& bagType = p.first; auto newBag = ItemBag::loadStore(p.second); - auto& bagPtr = m_bags[bagType]; - if (bagPtr) - *bagPtr = std::move(newBag); - else - bagPtr = make_shared(std::move(newBag)); + if (m_bags.keys().contains(bagType)) { + auto& bagPtr = m_bags[bagType]; + auto size = bagPtr.get()->size(); + if (bagPtr) + *bagPtr = std::move(newBag); + else + bagPtr = make_shared(std::move(newBag)); + m_inventoryLoadOverflow.appendAll(bagPtr.get()->resize(size)); + } else { + m_inventoryLoadOverflow.appendAll(ItemBag(newBag).items()); + } } m_swapSlot = itemDatabase->diskLoad(store.get("swapSlot")); @@ -790,10 +803,17 @@ void PlayerInventory::load(Json const& store) { for (size_t i = 0; i < m_customBar.size(0); ++i) { for (size_t j = 0; j < m_customBar.size(1); ++j) { - Json cbl = store.get("customBar").get(i).get(j); + Json cbl = store.get("customBar").get(i,JsonArray()).get(j,JsonArray()); + auto validateLink = [this](Json link) -> Json { + if ((link.isType(Json::Type::Object)) + && (m_bags.keys().contains(link.getString("type"))) + && (m_bags[link.getString("type")].get()->size() > link.getUInt("location"))) + return link; + return Json(); + }; m_customBar.at(i, j) = CustomBarLink{ - jsonToMaybe(cbl.get(0, {}), jsonToInventorySlot), - jsonToMaybe(cbl.get(1, {}), jsonToInventorySlot) + jsonToMaybe(validateLink(cbl.get(0, Json())), jsonToInventorySlot), + jsonToMaybe(validateLink(cbl.get(1, Json())), jsonToInventorySlot) }; } } diff --git a/source/game/StarPlayerInventory.hpp b/source/game/StarPlayerInventory.hpp index 0ec0649..bd5aa9f 100644 --- a/source/game/StarPlayerInventory.hpp +++ b/source/game/StarPlayerInventory.hpp @@ -168,6 +168,8 @@ public: Maybe primaryHeldSlot() const; Maybe secondaryHeldSlot() const; + List clearOverflow(); + void load(Json const& store); Json store() const; @@ -219,6 +221,8 @@ private: NetElementUInt m_customBarGroupNetState; MultiArray, 2> m_customBarNetState; NetElementData m_selectedActionBarNetState; + + List m_inventoryLoadOverflow; }; }