Skip to content

Commit 56a9b19

Browse files
remyCasesNylux
authored andcommitted
[Major] reference table rework
1 parent 3422ad9 commit 56a9b19

File tree

1 file changed

+59
-29
lines changed

1 file changed

+59
-29
lines changed

ModUtils/LootUtils.cs

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ public RandomItemsTable(int[] listWeight, ItemsTable itemsTable)
4848
}
4949
public class ReferenceTable
5050
{
51-
public int[] Ids { get; }
52-
public string[] Refs { get; }
53-
public ReferenceTable(string[] refs, int[] ids)
51+
public string DefaultTable { get; }
52+
public Dictionary<int, string> Ids { get; }
53+
public Dictionary<int, string> Tiers { get; }
54+
public ReferenceTable(string defaultTable, Dictionary<int, string> ids, Dictionary<int, string> tiers)
5455
{
56+
DefaultTable = defaultTable;
5557
Ids = ids;
56-
Refs = refs;
58+
Tiers = tiers;
5759
}
5860
}
5961
public class LootTable
@@ -158,6 +160,7 @@ public static void InjectLootScripts()
158160
var min_lvl = scr_globaltile_dungeon_get(""mob_lvl_min"");
159161
var max_lvl = scr_globaltile_dungeon_get(""mob_lvl_max"");
160162
var tier = floor(((max_lvl + min_lvl) / 2));
163+
scr_actionsLogUpdate(""current tier: "" + string(tier));
161164
162165
if (!variable_struct_exists(refData, objectName))
163166
{
@@ -168,46 +171,64 @@ public static void InjectLootScripts()
168171
var refStruct = variable_struct_get(refData, objectName);
169172
var referenceLootTableIndex = -1;
170173
174+
if (!variable_struct_exists(refStruct, ""DefaultTable""))
175+
{
176+
scr_actionsLogUpdate(""cant find DefaultTable"");
177+
file_text_close(refFile);
178+
return -4;
179+
}
180+
var defaultTable = variable_struct_get(refStruct, ""DefaultTable"");
181+
171182
if (!variable_struct_exists(refStruct, ""Ids""))
172183
{
173184
scr_actionsLogUpdate(""cant find Ids"");
174185
file_text_close(refFile);
175186
return -4;
176187
}
177-
var idsArray = variable_struct_get(refStruct, ""Ids"");
188+
var idsStruct = variable_struct_get(refStruct, ""Ids"");
178189
179-
for (var i = 0; i < array_length(idsArray); i += 1)
190+
if (variable_struct_exists(idsStruct, argument0.id))
180191
{
181-
if (idsArray[i] == argument0.id)
182-
{
183-
referenceLootTableIndex = i;
184-
break;
185-
}
192+
var referenceLootTable = variable_struct_get(idsStruct, argument0.id);
193+
scr_actionsLogUpdate(""ref: "" + referenceLootTable);
194+
file_text_close(refFile);
195+
return referenceLootTable;
186196
}
187-
scr_actionsLogUpdate(""id ref: "" + string(referenceLootTableIndex));
188197
189-
if (!variable_struct_exists(refStruct, ""Refs""))
198+
if (!variable_struct_exists(refStruct, ""Tiers""))
190199
{
191-
scr_actionsLogUpdate(""cant find Refs"");
200+
scr_actionsLogUpdate(""cant find Tiers"");
192201
file_text_close(refFile);
193202
return -4;
194203
}
195-
var refsTable = variable_struct_get(refStruct, ""Refs"");
196-
var referenceLootTable = refsTable[referenceLootTableIndex + 1];
204+
var tiersStruct = variable_struct_get(refStruct, ""Tiers"");
205+
var tiers = variable_struct_get_names(tiersStruct);
206+
var indexTier = -1;
197207
198-
scr_actionsLogUpdate(""ref: "" + referenceLootTable);
199-
200-
if (!variable_struct_exists(refStruct, ""Refs""))
208+
for (var i = 0; i < array_length(tiers); i++;)
201209
{
202-
scr_actionsLogUpdate(""cant find Refs"");
203-
file_text_close(refFile);
204-
return -4;
210+
if (tier < tiers[i])
211+
{
212+
indexTier = i - 1;
213+
break;
214+
}
215+
else
216+
{
217+
indexTier = i;
218+
}
205219
}
206-
var refsTable = variable_struct_get(refStruct, ""Refs"");
207-
var referenceLootTable = refsTable[referenceLootTableIndex + 1];
208220
221+
if (indexTier == -1)
222+
{
223+
var referenceLootTable = defaultTable;
224+
}
225+
else
226+
{
227+
var referenceLootTable = variable_struct_get(tiersStruct, tiers[indexTier]);
228+
}
229+
230+
scr_actionsLogUpdate(""ref: "" + referenceLootTable);
209231
file_text_close(refFile);
210-
211232
return referenceLootTable;
212233
}";
213234

@@ -416,11 +437,20 @@ public static void AddLootTable(string lootTableID, ItemsTable guaranteedItems,
416437
LootTable lootTable = new(guaranteedItems, randomLootMin, randomLootMax, emptyWeight, randomItemsTable);
417438
LootUtils.LootTables.Add(lootTableID, lootTable);
418439
}
419-
public static void AddReferenceTable(string nameObject, string[] refs, int[]? ids = null)
440+
public static void AddReferenceTable(string nameObject, string table)
441+
{
442+
LootUtils.ReferenceTables.Add(nameObject, new ReferenceTable(table, new Dictionary<int, string>(), new Dictionary<int, string>()));
443+
}
444+
public static void AddReferenceTable(string nameObject, string table, Dictionary<int, string>? ids, Dictionary<int, string>? tiers)
420445
{
421-
ids ??= Array.Empty<int>();
422-
ReferenceTable referenceTable = new(refs, ids);
423-
LootUtils.ReferenceTables.Add(nameObject, referenceTable);
446+
LootUtils.ReferenceTables.Add(nameObject, new ReferenceTable(table, ids ?? new Dictionary<int, string>(), tiers ?? new Dictionary<int, string>()));
447+
}
448+
public static void AddReferenceTableForMultipleObjects(string table, params string[] nameObjects)
449+
{
450+
foreach(string nameObject in nameObjects)
451+
{
452+
LootUtils.ReferenceTables.Add(nameObject, new ReferenceTable(table, new Dictionary<int, string>(), new Dictionary<int, string>()));
453+
}
424454
}
425455
}
426456
}

0 commit comments

Comments
 (0)