Skip to content

Commit

Permalink
Isolate RNG to avoid closed loops in TryRandomUniqueItem()
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills committed May 12, 2024
1 parent 7bb0f48 commit 0b5324b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3326,10 +3326,11 @@ void TryRandomUniqueItem(Item &item, _item_indexes idx, int8_t mLevel, int uper,
Point itemPos = item.position;

// Force generate a non-unique item.
DiabloGenerator itemGenerator(GetLCGEngineState());
do {
item = {}; // Reset item data
item.position = itemPos;
SetupAllItems(*MyPlayer, item, idx, AdvanceRndSeed(), mLevel, uper, onlygood, pregen);
SetupAllItems(*MyPlayer, item, idx, itemGenerator.advanceRndSeed(), mLevel, uper, onlygood, pregen);
} while (item._iMagical == ITEM_QUALITY_UNIQUE);

return;
Expand Down Expand Up @@ -3358,10 +3359,11 @@ void TryRandomUniqueItem(Item &item, _item_indexes idx, int8_t mLevel, int uper,
Point itemPos = item.position;

// Force generate items until we find a uid match.
DiabloGenerator itemGenerator(GetLCGEngineState());
do {
item = {}; // Reset item data
item.position = itemPos;
SetupAllItems(*MyPlayer, item, idx, AdvanceRndSeed(), targetLvl, uper, onlygood, pregen, uidOffset);
SetupAllItems(*MyPlayer, item, idx, itemGenerator.advanceRndSeed(), targetLvl, uper, onlygood, pregen, uidOffset);
} while (item._iUid != uid);

// Set item as obtained to prevent it from being dropped again in SP.
Expand Down

0 comments on commit 0b5324b

Please sign in to comment.