Skip to content

Commit

Permalink
Fix & test OpenEnroth#1341
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Oct 15, 2023
1 parent ea1851a commit 7e9ba74
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Engine/Objects/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/Bin/GameTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
14 changes: 14 additions & 0 deletions test/Bin/GameTest/GameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

0 comments on commit 7e9ba74

Please sign in to comment.