Skip to content

Commit

Permalink
v0.8.9, once again hopefully fix loot cache getting stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed May 21, 2021
1 parent fe7d2f8 commit 9a9c7d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions LootCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ internal static bool CalculateLoot(NPC npc)

var realRandom = Main.rand;
var fakeRandom = new LootUnifiedRandom();
fakeRandom.realRandom = realRandom;

for (int i = 0; i < MaxNumberLootExperiments; i++)
{
Expand Down
6 changes: 5 additions & 1 deletion LootUnifiedRandom.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Terraria;
using Terraria.Utilities;

namespace RecipeBrowser
Expand All @@ -11,14 +12,17 @@ internal class LootUnifiedRandom : UnifiedRandom
//internal static bool zero;
private int[] returns;

// realRandom avoids deadlock caused by re-rolling prefixes
internal UnifiedRandom realRandom;

public LootUnifiedRandom()
{
returns = new int[5000];
}

public override int Next(int maxValue)
{
if (loop == 0) return 0;
if (loop == 0 && !realRandom.NextBool(100)) return 0;
int index = Math.Abs(maxValue) % 5000;
returns[index]++;
return (maxValue + returns[index]) % maxValue;
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = jopojelly
version = 0.8.8.2
version = 0.8.9
displayName = Recipe Browser
homepage = https://forums.terraria.org/index.php?threads/recipe-browser.62462/
buildIgnore = .vs\*, Properties\*, *.csproj, *.user, *.config, unused\*, .git\*,

0 comments on commit 9a9c7d0

Please sign in to comment.