diff --git a/source/frontend/StarInventory.cpp b/source/frontend/StarInventory.cpp index 650d2e3..71d2081 100644 --- a/source/frontend/StarInventory.cpp +++ b/source/frontend/StarInventory.cpp @@ -110,7 +110,7 @@ InventoryPane::InventoryPane(MainInterface* parent, PlayerPtr player, ContainerI auto actionData = sourceItem->instanceValue("interactData", Json()); if (actionData.isType(Json::Type::Object)) actionData = actionData.set("openWithInventory", false); - InteractAction action(actionType, m_player->entityId(), actionData); + InteractAction action(actionType, NullEntityId, actionData); m_player->interact(action); } } diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index 4098705..4303a28 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -199,10 +199,7 @@ bool MainInterface::escapeDialogOpen() const { void MainInterface::openCraftingWindow(Json const& config, EntityId sourceEntityId) { if (m_craftingWindow && m_paneManager.isDisplayed(m_craftingWindow)) { m_paneManager.dismissPane(m_craftingWindow); - bool fromPlayer = false; - if (auto player = m_client->mainPlayer()) - fromPlayer = player->inWorld() && player->entityId() == sourceEntityId; - if (m_craftingWindow->sourceEntityId() == sourceEntityId) { + if (sourceEntityId != NullEntityId && m_craftingWindow->sourceEntityId() == sourceEntityId) { m_craftingWindow.reset(); return; } @@ -218,10 +215,7 @@ void MainInterface::openCraftingWindow(Json const& config, EntityId sourceEntity void MainInterface::openMerchantWindow(Json const& config, EntityId sourceEntityId) { if (m_merchantWindow && m_paneManager.isDisplayed(m_merchantWindow)) { m_paneManager.dismissPane(m_merchantWindow); - bool fromPlayer = false; - if (auto player = m_client->mainPlayer()) - fromPlayer = player->inWorld() && player->entityId() == sourceEntityId; - if (!fromPlayer && m_merchantWindow->sourceEntityId() == sourceEntityId) { + if (sourceEntityId != NullEntityId && m_merchantWindow->sourceEntityId() == sourceEntityId) { m_merchantWindow.reset(); return; } @@ -426,19 +420,19 @@ void MainInterface::handleInteractAction(InteractAction interactAction) { } else if (interactAction.type == InteractActionType::SitDown) { m_client->mainPlayer()->lounge(interactAction.entityId, interactAction.data.toUInt()); } else if (interactAction.type == InteractActionType::OpenCraftingInterface) { - if (!world->entity(interactAction.entityId)) + if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) return; openCraftingWindow(interactAction.data, interactAction.entityId); } else if (interactAction.type == InteractActionType::OpenSongbookInterface) { m_paneManager.displayRegisteredPane(MainInterfacePanes::Songbook); } else if (interactAction.type == InteractActionType::OpenNpcCraftingInterface) { - if (!world->entity(interactAction.entityId)) + if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) return; - + // wait, this is literally the exact same as OpenCraftingInterface. what the fuck? lol openCraftingWindow(interactAction.data, interactAction.entityId); } else if (interactAction.type == InteractActionType::OpenMerchantInterface) { - if (!world->entity(interactAction.entityId)) + if (interactAction.entityId != NullEntityId && !world->entity(interactAction.entityId)) return; openMerchantWindow(interactAction.data, interactAction.entityId); diff --git a/source/frontend/StarMerchantInterface.cpp b/source/frontend/StarMerchantInterface.cpp index ec17391..51bccb6 100644 --- a/source/frontend/StarMerchantInterface.cpp +++ b/source/frontend/StarMerchantInterface.cpp @@ -118,7 +118,8 @@ void MerchantPane::dismissed() { for (auto unsold : m_itemBag->takeAll()) m_player->giveItem(unsold); - m_worldClient->sendEntityMessage(m_sourceEntityId, "onMerchantClosed"); + if (m_sourceEntityId != NullEntityId) + m_worldClient->sendEntityMessage(m_sourceEntityId, "onMerchantClosed"); } PanePtr MerchantPane::createTooltip(Vec2I const& screenPosition) { @@ -141,7 +142,7 @@ PanePtr MerchantPane::createTooltip(Vec2I const& screenPosition) { void MerchantPane::update(float dt) { Pane::update(dt); - if (!m_worldClient->playerCanReachEntity(m_sourceEntityId)) + if (m_sourceEntityId != NullEntityId && !m_worldClient->playerCanReachEntity(m_sourceEntityId)) dismiss(); if (m_refreshTimer.wrapTick()) { @@ -315,7 +316,8 @@ void MerchantPane::buy() { auto reportItem = m_selectedItem->clone(); reportItem->setCount(reportItem->count() * m_buyCount, true); auto buySummary = JsonObject{{"item", reportItem->descriptor().toJson()}, {"total", m_buyTotal}}; - m_worldClient->sendEntityMessage(m_sourceEntityId, "onBuy", {buySummary}); + if (m_sourceEntityId != NullEntityId) + m_worldClient->sendEntityMessage(m_sourceEntityId, "onBuy", {buySummary}); auto& guiContext = GuiContext::singleton(); guiContext.playAudio(Root::singleton().assets()->json("/merchant.config:buySound").toString());