BotGenerator/Generator/BotLootGenerator.cs

114 lines
3.8 KiB
C#
Raw Normal View History

2021-08-24 12:08:30 +01:00
using Common;
using Common.Extensions;
using Generator.Helpers;
2021-08-12 16:52:06 +01:00
using Generator.Models.Input;
using Generator.Models.Output;
using System;
2021-08-12 16:52:06 +01:00
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Generator
{
public class BotLootGenerator
{
private readonly List<Bot> _botsWithGear;
private readonly List<Datum> _rawParsedBots;
public BotLootGenerator(List<Bot> botsWithGear, List<Datum> rawParsedBots)
{
_botsWithGear = botsWithGear;
_rawParsedBots = rawParsedBots;
}
internal List<Bot> AddLoot()
{
var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot loot");
// Iterate over assault/raider etc
foreach (var botToUpdate in _botsWithGear)
2021-08-12 16:52:06 +01:00
{
var rawBotsOfSameType = _rawParsedBots
.Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase))
.ToList();
2021-08-17 18:33:55 +01:00
if (rawBotsOfSameType.Count == 0)
{
continue;
2021-08-17 18:33:55 +01:00
}
foreach (var rawParsedBot in rawBotsOfSameType)
2021-08-12 16:52:06 +01:00
{
AddPocketLoot(botToUpdate, rawParsedBot);
2021-08-12 16:52:06 +01:00
}
AddTacticalVestLoot(botToUpdate, rawBotsOfSameType);
AddBackbackLoot(botToUpdate, rawBotsOfSameType);
AddSecureContainerLoot(botToUpdate, rawBotsOfSameType);
2021-08-12 16:52:06 +01:00
}
stopwatch.Stop();
2021-08-12 21:31:15 +01:00
LoggingHelpers.LogToConsole($"Finished processing bot loot. Took: {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
2021-08-12 16:52:06 +01:00
return _botsWithGear;
}
private void AddTacticalVestLoot(Bot finalAssaultBot, List<Datum> bots)
{
var tacVestItems = GetItemsStoredInEquipmentItem(bots, "TacticalVest");
finalAssaultBot.inventory.items.TacticalVest.AddRange(tacVestItems);
}
private void AddBackbackLoot(Bot finalAssaultBot, List<Datum> bots)
{
var backpackItems = GetItemsStoredInEquipmentItem(bots, "Backpack");
finalAssaultBot.inventory.items.Backpack.AddRange(backpackItems);
}
private void AddSecureContainerLoot(Bot finalAssaultBot, List<Datum> 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<string> GetItemsStoredInEquipmentItem(List<Datum> bots, string containerName)
{
var itemsStoredInContainer = new List<string>();
var containers = new List<string>();
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;
}
}
}