From 270a643911dcb957c59ea376812f87c381bc735e Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 21 Dec 2024 01:10:09 -0300 Subject: [PATCH 1/2] fix: forge fuse and transfer check queryAdd --- src/creatures/players/player.cpp | 93 +++++++++++++++++++------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 3ef1d64e982..513e9b761b3 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -8858,55 +8858,64 @@ void Player::forgeFuseItems(ForgeAction_t actionType, uint16_t firstItemId, uint history.success = success; history.tierLoss = reduceTierLoss; - const auto &firstForgingItem = getForgeItemFromId(firstItemId, tier); - if (!firstForgingItem) { - g_logger().error("[Log 1] Player with name {} failed to fuse item with id {}", getName(), firstItemId); + const auto &exaltationChest = Item::CreateItem(ITEM_EXALTATION_CHEST, 1); + if (!exaltationChest) { + g_logger().error("Failed to create exaltation chest"); + sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); + return; + } + const auto &exaltationContainer = exaltationChest->getContainer(); + if (!exaltationContainer) { + g_logger().error("Failed to create exaltation container"); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - auto returnValue = g_game().internalRemoveItem(firstForgingItem, 1); + + auto returnValue = queryAdd(CONST_SLOT_BACKPACK, exaltationContainer, 1, 0); if (returnValue != RETURNVALUE_NOERROR) { - g_logger().error("[Log 1] Failed to remove forge item {} from player with name {}", firstItemId, getName()); + g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", firstItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - const auto &secondForgingItem = getForgeItemFromId(secondItemId, tier); - if (!secondForgingItem) { - g_logger().error("[Log 2] Player with name {} failed to fuse item with id {}", getName(), secondItemId); + + const auto &firstForgedItem = Item::CreateItem(firstItemId, 1); + if (!firstForgedItem) { + g_logger().error("[Log 3] Player with name {} failed to fuse item with id {}", getName(), firstItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - if (returnValue = g_game().internalRemoveItem(secondForgingItem, 1); - returnValue != RETURNVALUE_NOERROR) { - g_logger().error("[Log 2] Failed to remove forge item {} from player with name {}", secondItemId, getName()); + + returnValue = g_game().internalAddItem(exaltationContainer, firstForgedItem, INDEX_WHEREEVER); + if (returnValue != RETURNVALUE_NOERROR) { + g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", firstItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - const auto &exaltationChest = Item::CreateItem(ITEM_EXALTATION_CHEST, 1); - if (!exaltationChest) { - g_logger().error("Failed to create exaltation chest"); + const auto &firstForgingItem = getForgeItemFromId(firstItemId, tier); + if (!firstForgingItem) { + g_logger().error("[Log 1] Player with name {} failed to fuse item with id {}", getName(), firstItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - const auto &exaltationContainer = exaltationChest->getContainer(); - if (!exaltationContainer) { - g_logger().error("Failed to create exaltation container"); + returnValue = g_game().internalRemoveItem(firstForgingItem, 1); + if (returnValue != RETURNVALUE_NOERROR) { + g_logger().error("[Log 1] Failed to remove forge item {} from player with name {}", firstItemId, getName()); + sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - - const auto &firstForgedItem = Item::CreateItem(firstItemId, 1); - if (!firstForgedItem) { - g_logger().error("[Log 3] Player with name {} failed to fuse item with id {}", getName(), firstItemId); + const auto &secondForgingItem = getForgeItemFromId(secondItemId, tier); + if (!secondForgingItem) { + g_logger().error("[Log 2] Player with name {} failed to fuse item with id {}", getName(), secondItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - returnValue = g_game().internalAddItem(exaltationContainer, firstForgedItem, INDEX_WHEREEVER); - if (returnValue != RETURNVALUE_NOERROR) { - g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", firstItemId, getName()); + if (returnValue = g_game().internalRemoveItem(secondForgingItem, 1); + returnValue != RETURNVALUE_NOERROR) { + g_logger().error("[Log 2] Failed to remove forge item {} from player with name {}", secondItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; @@ -9100,13 +9109,34 @@ void Player::forgeTransferItemTier(ForgeAction_t actionType, uint16_t donorItemI history.tier = tier; history.success = true; + const auto &exaltationChest = Item::CreateItem(ITEM_EXALTATION_CHEST, 1); + if (!exaltationChest) { + g_logger().error("Exaltation chest is nullptr"); + sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); + return; + } + const auto &exaltationContainer = exaltationChest->getContainer(); + if (!exaltationContainer) { + g_logger().error("Exaltation container is nullptr"); + sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); + return; + } + + auto returnValue = queryAdd(CONST_SLOT_BACKPACK, exaltationContainer, 1, 0); + if (returnValue != RETURNVALUE_NOERROR) { + g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", donorItemId, getName()); + sendCancelMessage(getReturnMessage(returnValue)); + sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); + return; + } + const auto &donorItem = getForgeItemFromId(donorItemId, tier); if (!donorItem) { g_logger().error("[Log 1] Player with name {} failed to transfer item with id {}", getName(), donorItemId); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; } - auto returnValue = g_game().internalRemoveItem(donorItem, 1); + returnValue = g_game().internalRemoveItem(donorItem, 1); if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("[Log 1] Failed to remove transfer item {} from player with name {}", donorItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); @@ -9128,19 +9158,6 @@ void Player::forgeTransferItemTier(ForgeAction_t actionType, uint16_t donorItemI return; } - const auto &exaltationChest = Item::CreateItem(ITEM_EXALTATION_CHEST, 1); - if (!exaltationChest) { - g_logger().error("Exaltation chest is nullptr"); - sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); - return; - } - const auto &exaltationContainer = exaltationChest->getContainer(); - if (!exaltationContainer) { - g_logger().error("Exaltation container is nullptr"); - sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); - return; - } - const auto &newReceiveItem = Item::CreateItem(receiveItemId, 1); if (!newReceiveItem) { g_logger().error("[Log 6] Player with name {} failed to fuse item with id {}", getName(), receiveItemId); From 017611729dff568a9fb7baa17b4a2c9e5d0d7571 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 21 Dec 2024 01:11:52 -0300 Subject: [PATCH 2/2] fix: remove logs --- src/creatures/players/player.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 513e9b761b3..18c344dc3c2 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -8873,7 +8873,6 @@ void Player::forgeFuseItems(ForgeAction_t actionType, uint16_t firstItemId, uint auto returnValue = queryAdd(CONST_SLOT_BACKPACK, exaltationContainer, 1, 0); if (returnValue != RETURNVALUE_NOERROR) { - g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", firstItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; @@ -9124,7 +9123,6 @@ void Player::forgeTransferItemTier(ForgeAction_t actionType, uint16_t donorItemI auto returnValue = queryAdd(CONST_SLOT_BACKPACK, exaltationContainer, 1, 0); if (returnValue != RETURNVALUE_NOERROR) { - g_logger().error("[Log 1] Failed to add forge item {} from player with name {}", donorItemId, getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return;