From 7e9ba74b6d53be119d8a8d2bfb10a7b77ebd8f00 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Sun, 15 Oct 2023 08:42:21 +0100 Subject: [PATCH] Fix & test #1341 --- src/Engine/Objects/Character.cpp | 12 ++++++------ test/Bin/GameTest/CMakeLists.txt | 2 +- test/Bin/GameTest/GameTests.cpp | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Engine/Objects/Character.cpp b/src/Engine/Objects/Character.cpp index 3e334b390500..e4b61bb7491b 100644 --- a/src/Engine/Objects/Character.cpp +++ b/src/Engine/Objects/Character.cpp @@ -1537,16 +1537,16 @@ StealResult Character::StealFromActor(unsigned int uActorID, int _steal_perm, in return STEAL_NOTHING; } - unsigned int enchBonusSum = grng->randomDice(stealingSkill.level(), StealingEnchantmentBonusForSkill[stealingSkill.mastery()]); + int enchBonusSum = grng->randomDice(stealingSkill.level(), StealingEnchantmentBonusForSkill[stealingSkill.mastery()]); - int *enchTypePtr = (int*)&actroPtr->items[3].special_enchantment; // actor has this amount of gold + int *goldPtr = &actroPtr->items[3].goldAmount; // actor has this amount of gold - if ((int)enchBonusSum >= *enchTypePtr) { // steal all the gold - enchBonusSum = *enchTypePtr; + if (enchBonusSum >= *goldPtr) { // steal all the gold + enchBonusSum = *goldPtr; actroPtr->items[3].uItemID = ITEM_NULL; - *enchTypePtr = 0; + *goldPtr = 0; } else { - *enchTypePtr -= enchBonusSum; // steal some of the gold + *goldPtr -= enchBonusSum; // steal some of the gold } if (enchBonusSum) { diff --git a/test/Bin/GameTest/CMakeLists.txt b/test/Bin/GameTest/CMakeLists.txt index 04be3775b68d..87c02e2287b5 100644 --- a/test/Bin/GameTest/CMakeLists.txt +++ b/test/Bin/GameTest/CMakeLists.txt @@ -19,7 +19,7 @@ if(OE_BUILD_TESTS) ExternalProject_Add(OpenEnroth_TestData PREFIX ${CMAKE_CURRENT_BINARY_DIR}/test_data_tmp GIT_REPOSITORY https://github.com/OpenEnroth/OpenEnroth_TestData.git - GIT_TAG b11f684625eb68dde884b53525212073ae96d2dd + GIT_TAG a880c8bc91c4bfb16398c4064529cb4857a74dc6 SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_data CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/test/Bin/GameTest/GameTests.cpp b/test/Bin/GameTest/GameTests.cpp index e9f86b392661..b752f8c7aa35 100644 --- a/test/Bin/GameTest/GameTests.cpp +++ b/test/Bin/GameTest/GameTests.cpp @@ -1734,3 +1734,17 @@ GAME_TEST(Issues, Issue1340) { for (int gold : goldTape.adjacentDeltas()) EXPECT_TRUE(statusTape.contains(fmt::format("You found {} gold!", gold))); } + +GAME_TEST(Issues, Issue1341) { + // Can't steal gold from peasants. + auto goldTape = tapes.gold(); + auto peasantGoldTape = tapes.custom([] { return pActors[6].items[3].goldAmount; }); + auto statusTape = tapes.statusBar(); + auto deadTape = actorTapes.countByState(AIState::Dead); + test.playTraceFromTestData("issue_1341.mm7", "issue_1341.json"); + EXPECT_GT(goldTape.delta(), 0); // We did steal some gold. + EXPECT_EQ(peasantGoldTape.max(), goldTape.delta()); // And we did steal it from this peasant. + EXPECT_TRUE(statusTape.contains("Roderick failed to steal anything!")); // We have tried many times. + EXPECT_TRUE(statusTape.contains(fmt::format("Roderick stole {} gold!", peasantGoldTape.max()))); // And succeeded. + EXPECT_EQ(deadTape, tape(0)); // No one died in the process. +}