From b8c413a10d8a3fd9d39c1d4377f1f70d8136d696 Mon Sep 17 00:00:00 2001
From: Valens <8889280+VforValens@users.noreply.github.com>
Date: Sat, 25 Jan 2025 18:02:34 -0500
Subject: [PATCH] Update LootGenerator.cs
Implement FindAndAddRandomItemToLoot and InitItemLimitCounter
---
Libraries/Core/Generators/LootGenerator.cs | 50 +++++++++++++++++++---
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/Libraries/Core/Generators/LootGenerator.cs b/Libraries/Core/Generators/LootGenerator.cs
index 097f835a..ec2e7bd1 100644
--- a/Libraries/Core/Generators/LootGenerator.cs
+++ b/Libraries/Core/Generators/LootGenerator.cs
@@ -254,9 +254,14 @@ public class LootGenerator(
///
/// limits as defined in config
/// record, key: item tplId, value: current/max item count allowed
- protected Dictionary InitItemLimitCounter(Dictionary limits)
+ private Dictionary InitItemLimitCounter(Dictionary limits)
{
- throw new NotImplementedException();
+ var itemTypeCounts = new Dictionary();
+ foreach (var itemTypeId in limits) {
+ itemTypeCounts[itemTypeId.Key] = new ItemLimit() { Current = 0, Max = limits[itemTypeId.Key] };
+ }
+
+ return itemTypeCounts;
}
///
@@ -267,11 +272,46 @@ public class LootGenerator(
/// item filters
/// array to add found item to
/// true if item was valid and added to pool
- protected bool FindAndAddRandomItemToLoot(object items, object itemTypeCounts,
- LootRequest options, // TODO: items type was [string, ITemplateItem][], itemTypeCounts was Record
+ protected bool FindAndAddRandomItemToLoot(TemplateItem[] items, Dictionary itemTypeCounts,
+ LootRequest options,
List- result)
{
- throw new NotImplementedException();
+ var randomItem = _randomUtil.GetArrayValue(items);
+
+ var itemLimitCount = itemTypeCounts[randomItem.Parent];
+ if (itemLimitCount is not null && itemLimitCount.Current > itemLimitCount.Max) {
+ return false;
+ }
+
+ // Skip armors as they need to come from presets
+ if (_itemHelper.ArmorItemCanHoldMods(randomItem.Id)) {
+ return false;
+ }
+
+ var newLootItem = new Item {
+ Id = _hashUtil.Generate(),
+ Template = randomItem.Id,
+ Upd = {
+ StackObjectsCount = 1,
+ SpawnedInSession = true,
+ },
+ };
+
+ // Special case - handle items that need a stackcount > 1
+ if (randomItem.Properties.StackMaxSize > 1) {
+ newLootItem.Upd.StackObjectsCount = GetRandomisedStackCount(randomItem, options);
+ }
+
+ newLootItem.Template = randomItem.Id;
+ result.Add(newLootItem);
+
+ if (itemLimitCount is not null) {
+ // Increment item count as it's in limit array
+ itemLimitCount.Current++;
+ }
+
+ // Item added okay
+ return true;
}
///