BotGenerator/Generator/BotLootGenerator.cs

116 lines
4.2 KiB
C#
Raw Normal View History

2021-08-24 12:08:30 +01:00
using Common;
using Common.Extensions;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers.Gear;
using System;
2021-08-12 16:52:06 +01:00
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
2021-08-31 18:52:28 +01:00
using System.Threading.Tasks;
2021-08-12 16:52:06 +01:00
namespace Generator
{
2021-09-01 19:19:44 +03:00
public static class BotLootGenerator
2021-08-12 16:52:06 +01:00
{
2021-09-05 12:27:17 +01:00
internal static IEnumerable<Bot> AddLoot(this IEnumerable<Bot> botsWithGear, IEnumerable<Datum> rawBots)
2021-08-12 16:52:06 +01:00
{
var stopwatch = Stopwatch.StartNew();
LoggingHelpers.LogToConsole("Started processing bot loot");
// Iterate over assault/raider etc
2021-09-01 19:19:44 +03:00
Parallel.ForEach(botsWithGear, botToUpdate =>
2021-08-12 16:52:06 +01:00
{
var botType = botToUpdate.botType.ToString();
2021-09-05 12:27:17 +01:00
var rawBotsOfSameType = rawBots
.Where(x => x.Info.Settings.Role.Equals(botType, StringComparison.OrdinalIgnoreCase))
2021-08-31 18:52:28 +01:00
.ToList();
2021-08-17 18:33:55 +01:00
if (rawBotsOfSameType.Count == 0)
{
2021-08-31 18:52:28 +01:00
return;
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);
2021-09-01 15:29:38 +01:00
AddBackpackLoot(botToUpdate, rawBotsOfSameType);
AddSecureContainerLoot(botToUpdate, rawBotsOfSameType);
AddSpecialLoot(botToUpdate);
2021-08-31 18:52:28 +01:00
});
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
2021-09-01 19:19:44 +03:00
return botsWithGear;
2021-08-12 16:52:06 +01:00
}
2021-09-05 12:27:17 +01:00
private static void AddPocketLoot(Bot botToUpdate, Datum rawBot)
{
// pocket loot
2021-09-05 12:27:17 +01:00
foreach (var lootItem in rawBot.Inventory.items.Where(x => x?.slotId?.StartsWith("pocket") == true))
{
2021-09-05 12:20:40 +01:00
botToUpdate.inventory.items.Pockets.AddUnique(lootItem._tpl);
}
}
2021-09-05 12:27:17 +01:00
private static void AddTacticalVestLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
2021-08-12 16:52:06 +01:00
{
2021-09-05 12:27:17 +01:00
var tacVestItems = GetItemsStoredInEquipmentItem(rawBots, "TacticalVest");
2021-09-05 12:20:40 +01:00
botToUpdate.inventory.items.TacticalVest.AddRange(tacVestItems);
2021-08-12 16:52:06 +01:00
}
2021-09-05 12:27:17 +01:00
private static void AddBackpackLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
2021-08-12 16:52:06 +01:00
{
// add generic keys to bosses
2021-09-05 12:20:40 +01:00
if (botToUpdate.botType.IsBoss())
{
2021-09-05 12:20:40 +01:00
botToUpdate.inventory.items.Backpack.AddRange(SpecialLootHelper.GetGenericBossKeys());
}
2021-09-05 12:27:17 +01:00
var backpackItems = GetItemsStoredInEquipmentItem(rawBots, "Backpack");
2021-09-05 12:20:40 +01:00
botToUpdate.inventory.items.Backpack.AddRange(backpackItems);
2021-08-12 16:52:06 +01:00
}
2021-09-05 12:27:17 +01:00
private static void AddSecureContainerLoot(Bot botToUpdate, IEnumerable<Datum> rawBots)
2021-08-12 16:52:06 +01:00
{
2021-09-05 12:27:17 +01:00
var tacVestItems = GetItemsStoredInEquipmentItem(rawBots, "SecuredContainer");
2021-09-05 12:20:40 +01:00
botToUpdate.inventory.items.SecuredContainer.AddRange(tacVestItems);
2021-08-12 16:52:06 +01:00
}
2021-09-01 19:19:44 +03:00
private static void AddSpecialLoot(Bot botToUpdate)
2021-08-12 16:52:06 +01:00
{
botToUpdate.inventory.items.SpecialLoot.AddRange(SpecialLootHelper.GetSpecialLootForBotType(botToUpdate.botType));
2021-08-12 16:52:06 +01:00
}
2021-09-05 12:27:17 +01:00
private static IEnumerable<string> GetItemsStoredInEquipmentItem(IEnumerable<Datum> rawBots, string containerName)
2021-08-12 16:52:06 +01:00
{
var itemsStoredInContainer = new List<string>();
var containers = new List<string>();
2021-09-05 12:27:17 +01:00
foreach (var bot in rawBots)
2021-08-12 16:52:06 +01:00
{
// 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;
}
}
}