2021-08-24 12:08:30 +01:00
|
|
|
|
using Common;
|
|
|
|
|
using Common.Extensions;
|
2021-09-18 22:36:59 +01:00
|
|
|
|
using Common.Models.Input;
|
|
|
|
|
using Common.Models.Output;
|
2021-08-27 21:01:59 +01:00
|
|
|
|
using Generator.Helpers.Gear;
|
2021-08-13 16:24:45 +01:00
|
|
|
|
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
|
|
|
|
{
|
2022-06-30 11:20:34 +01:00
|
|
|
|
var botType = botToUpdate.botType.ToString();
|
2021-09-05 12:27:17 +01:00
|
|
|
|
var rawBotsOfSameType = rawBots
|
2022-06-30 11:20:34 +01:00
|
|
|
|
.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
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 16:24:45 +01:00
|
|
|
|
foreach (var rawParsedBot in rawBotsOfSameType)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
2021-08-13 16:24:45 +01:00
|
|
|
|
AddPocketLoot(botToUpdate, rawParsedBot);
|
2021-08-12 16:52:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 16:24:45 +01:00
|
|
|
|
AddTacticalVestLoot(botToUpdate, rawBotsOfSameType);
|
2021-09-01 15:29:38 +01:00
|
|
|
|
AddBackpackLoot(botToUpdate, rawBotsOfSameType);
|
2021-08-13 16:24:45 +01:00
|
|
|
|
AddSecureContainerLoot(botToUpdate, rawBotsOfSameType);
|
2021-08-27 21:01:59 +01:00
|
|
|
|
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)
|
2021-08-27 21:01:59 +01:00
|
|
|
|
{
|
|
|
|
|
// 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-08-27 21:01:59 +01:00
|
|
|
|
{
|
2021-09-05 12:20:40 +01:00
|
|
|
|
botToUpdate.inventory.items.Pockets.AddUnique(lootItem._tpl);
|
2021-08-27 21:01:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-08-31 18:39:30 +01:00
|
|
|
|
// add generic keys to bosses
|
2021-09-05 12:20:40 +01:00
|
|
|
|
if (botToUpdate.botType.IsBoss())
|
2021-08-31 18:39:30 +01:00
|
|
|
|
{
|
2021-09-05 12:20:40 +01:00
|
|
|
|
botToUpdate.inventory.items.Backpack.AddRange(SpecialLootHelper.GetGenericBossKeys());
|
2021-08-31 18:39:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-08-30 22:32:54 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|