Skip to content

Commit 97b3c07

Browse files
committed
Optimize loot function
1 parent e436bd5 commit 97b3c07

4 files changed

Lines changed: 33 additions & 32 deletions

File tree

Patches/LootItems.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,16 @@ static bool FillLootDropListPatch(ArrayList _arrayList, int _playerCount, FTK_en
9090
Debug.Log("##### init");
9191
FTK_itembase item2_stats = FTK_itemsDB.GetDB()?.GetEntry(item2);
9292

93-
while (
94-
entry == null ||
95-
entry.m_MaxLevel > ((int)GameFlow.Instance.AveragePlayerLevel) ||
96-
entry._goldValue > 20 * Math.Max((int)GameFlow.Instance.AveragePlayerLevel, 1) || // 90, 40, 20 -> bug fix + max level-> 20
97-
FOUND_ITEMS.Contains(item_id)
98-
)
99-
{
100-
item_id = (FTK_itembase.ID)values.GetValue(rand.Next(values.Length));
101-
entry = FTK_itemsDB.GetDB()?.GetEntry(item_id);
102-
}
103-
FOUND_ITEMS.Add(item_id);
104-
105-
Debug.Log("##### random done");
106-
Debug.Log("valid item id:: " + item2.ToString());
10793
if (
10894
item2_stats == null ||
109-
//entry.m_MinLevel <= ((int)GameFlow.Instance.AveragePlayerLevel) || // game might become too easy and not fun on the long run
110-
11195
item2_stats.m_ItemRarity == FTK_itemRarityLevel.ID.quest ||
11296
item2_stats.m_ItemRarity == FTK_itemRarityLevel.ID.lore ||
11397
item2_stats.m_ItemRarity == FTK_itemRarityLevel.ID.artifact)
11498
{
115-
Debug.Log("##### item normal mod");
99+
Debug.Log("##### item normal mod"); // If you see this in console, it means the item did not get replaced
116100
_arrayList.Add(item2.ToString());
101+
102+
FOUND_ITEMS.Add(item2); // ensure we can not find unmodded items
117103
}
118104
else
119105
{
@@ -134,8 +120,12 @@ static bool FillLootDropListPatch(ArrayList _arrayList, int _playerCount, FTK_en
134120

135121
// FTK_itembase.ID.reapersplume still goes through
136122
!entry.m_Dropable ||
137-
entry.m_FilterDebug
123+
entry.m_FilterDebug ||
138124
// now it seems to be properly fixed
125+
126+
entry.m_MaxLevel > Math.Max((int)GameFlow.Instance.AveragePlayerLevel, 1) ||
127+
entry._goldValue > 20 * Math.Max((int)GameFlow.Instance.AveragePlayerLevel, 1) ||
128+
FOUND_ITEMS.Contains(item_id) // The same drop should not happen twice
139129
)
140130
{
141131
item_id = (FTK_itembase.ID)values.GetValue(rand.Next(values.Length));
@@ -146,10 +136,13 @@ static bool FillLootDropListPatch(ArrayList _arrayList, int _playerCount, FTK_en
146136

147137

148138
if (entry._goldValue > 1)
139+
{
140+
FOUND_ITEMS.Add(item_id);
149141
break;
142+
}
150143
}
151144
Debug.Log("##### item super mod");
152-
Debug.Log("new item id: " + item_id.ToString());
145+
Debug.Log("new item id: " + item_id.ToString()); // item got replaced
153146
_arrayList.Add(item_id.ToString());
154147
}
155148

Patches/RandomizeAllItemStats.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static bool Prefix(FTK_weaponStats2DB __instance, ref FTK_weaponStats2 __result,
4747
// Weighted random selection
4848
// but for now I'm going to use a simple random
4949

50+
// Randomze the rolls too lol
5051
if(__result.m_IsWeapon)
5152
__result._slots = rand.Next(1, 5);
5253

Patches/RandomizeDItemEffects.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,14 @@ namespace FTKRandomizer.Patches
1212
class RandomizeDItemEffects
1313
{
1414

15-
// TODO: ensure mobs do not get randomized too? perhaps it's a feature
16-
// TODO: prevent bad skills from being selected (debug, wip, remove immunities from mobs, kraken attack, ecc..) ..how?
17-
// ^-- we swap a skill with another of the same
18-
// ProficiencyBase.Category
19-
// The idea is that it should naturally eliminate the ones that don't make sense
20-
//
21-
// Or we swap it with same weapon skills (if bow, then I can use any skill dedicated to bows)
22-
2315
// WeaponID:ProficiencyID
2416
public static Dictionary<FTK_proficiencyTable.ID, FTK_proficiencyTable.ID> ProfDB = new Dictionary<FTK_proficiencyTable.ID, FTK_proficiencyTable.ID>();
2517
public static List<FTK_proficiencyTable.ID> UsedProf = new List<FTK_proficiencyTable.ID>();
2618

2719

2820
static bool Prefix(Weapon __instance, ref List<FTK_proficiencyTable.ID> __result)
2921
{
22+
// Default behavior when gamelogic does not exist
3023
List<FTK_proficiencyTable.ID> list = new List<FTK_proficiencyTable.ID>();
3124
if (GameLogic.Instance == null)
3225
{
@@ -41,11 +34,11 @@ static bool Prefix(Weapon __instance, ref List<FTK_proficiencyTable.ID> __result
4134
return false;
4235
}
4336

37+
// Some mobs will have randomized skills too, you may even get a bat that protects itself, good luck!
38+
4439
int MapSeed = GameLogic.Instance.m_MapGenRandomSeed;
4540
int SEED = MapSeed;
4641

47-
48-
4942
if (__instance.m_ProficiencyEffects != null)
5043
{
5144
foreach (ProficiencyID key in __instance.m_ProficiencyEffects.Keys)
@@ -57,9 +50,23 @@ static bool Prefix(Weapon __instance, ref List<FTK_proficiencyTable.ID> __result
5750
SEED += (int)__instance.m_WeaponType;
5851
SEED += (int)__instance.m_WeaponSubType;
5952
SEED += (int)__instance.m_WeaponMaterial;
53+
54+
55+
/*
56+
Since I haven't found a way to get the specific item id of the weapon,
57+
58+
I'm storing the original proficiency id and its replacement into a dictionary
59+
60+
I need to keep things as simple as possible, because of sync
61+
62+
Eg. this one can not be used:
63+
SEED += ProfDB.Count;
64+
65+
even a simple delay caused by lag, will make things out of sync ! Meaning players may see different proficiencies (weapon skills)
66+
Which is fun, but when you want to share your weapon with a friend, if not in sync, they will see other stats, rendering the trade (potentially) useless
67+
*/
6068

6169

62-
//SEED += ProfDB.Count;
6370
System.Random rand = new System.Random(SEED);
6471

6572

@@ -80,7 +87,7 @@ static bool Prefix(Weapon __instance, ref List<FTK_proficiencyTable.ID> __result
8087
var uno = FTK_proficiencyTableDB.Get(assign);
8188

8289

83-
// Assuming FTK_proficiencyTable has a default constructor
90+
// Assuming FTK_proficiencyTable has a default constructor (spoiler, it does)
8491
var instance = new FTK_proficiencyTable();
8592
var method = instance.GetType().GetMethod("GetCategoryDescription", BindingFlags.NonPublic | BindingFlags.Instance);
8693
string result = (string)method.Invoke(instance, null);

Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void Awake()
3636
harmony.PatchAll(typeof(RandomizeDShopItems));
3737
harmony.PatchAll(typeof(RandomizeDInitialStats));
3838
harmony.PatchAll(typeof(RandomizeAllItemStats));
39-
harmony.PatchAll(typeof(TownEE));
39+
//harmony.PatchAll(typeof(TownEE));
4040

4141
harmony.PatchAll(typeof(LootItems));
4242
harmony.PatchAll(typeof(RandomizeDItemEffects));

0 commit comments

Comments
 (0)