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; } ///