using Generator.Helpers; using Generator.Models.Input; using Generator.Models.Output; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Generator { public class BotLootGenerator { private readonly List _botsWithGear; private readonly List _rawParsedBots; public BotLootGenerator(List botsWithGear, List rawParsedBots) { _botsWithGear = botsWithGear; _rawParsedBots = rawParsedBots; } internal List AddLoot() { var stopwatch = Stopwatch.StartNew(); LoggingHelpers.LogToConsole("Started processing bot loot"); // Iterate over assault/raider etc foreach (var bot in _botsWithGear) { foreach (var rawParsedBot in _rawParsedBots) { AddPocketLoot(bot, rawParsedBot); } AddTacticalVestLoot(bot, _rawParsedBots); AddBackbackLoot(bot, _rawParsedBots); AddSecureContainerLoot(bot, _rawParsedBots); } stopwatch.Stop(); LoggingHelpers.LogToConsole($"Time taken to generate loot: {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); return _botsWithGear; } private void AddTacticalVestLoot(Bot finalAssaultBot, List bots) { var tacVestItems = GetItemsStoredInEquipmentItem(bots, "TacticalVest"); finalAssaultBot.inventory.items.TacticalVest.AddRange(tacVestItems); } private void AddBackbackLoot(Bot finalAssaultBot, List bots) { var backpackItems = GetItemsStoredInEquipmentItem(bots, "Backpack"); finalAssaultBot.inventory.items.Backpack.AddRange(backpackItems); } private void AddSecureContainerLoot(Bot finalAssaultBot, List bots) { var tacVestItems = GetItemsStoredInEquipmentItem(bots, "SecuredContainer"); finalAssaultBot.inventory.items.SecuredContainer.AddRange(tacVestItems); } private void AddPocketLoot(Bot finalBot, Datum bot) { // pocket loot foreach (var lootItem in bot.Inventory.items.Where(x => x?.slotId?.StartsWith("pocket") == true)) { finalBot.inventory.items.Pockets.AddUnique(lootItem._tpl); } } private List GetItemsStoredInEquipmentItem(List bots, string containerName) { var itemsStoredInContainer = new List(); var containers = new List(); foreach (var bot in bots) { // find the container type we want on this bot (backpack etc) // Add to list var botContainers = bot.Inventory.items.Where(x => x.slotId == containerName); foreach (var c in botContainers) { containers.AddUnique(c._id); } foreach (var item in bot.Inventory.items) { if (containers.Contains(item.parentId)) { itemsStoredInContainer.AddUnique(item._tpl); } } } return itemsStoredInContainer; } } }