2023-09-18 17:15:30 +01:00
|
|
|
|
using System.Diagnostics;
|
2023-09-18 18:23:07 +01:00
|
|
|
|
using System.Linq;
|
2021-08-24 12:08:30 +01:00
|
|
|
|
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-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
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
internal static IEnumerable<Bot> AddLoot(this IEnumerable<Bot> botsWithGear, Dictionary<string, List<Datum>> rawBots)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
|
|
|
|
var stopwatch = Stopwatch.StartNew();
|
|
|
|
|
LoggingHelpers.LogToConsole("Started processing bot loot");
|
|
|
|
|
|
2023-09-18 17:15:30 +01:00
|
|
|
|
var dictionaryLock = new object();
|
|
|
|
|
|
|
|
|
|
var tasks = new List<Task>(50);
|
|
|
|
|
foreach (var botToUpdate in botsWithGear)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
tasks.Add(Task.Factory.StartNew(() =>
|
2021-08-17 18:33:55 +01:00
|
|
|
|
{
|
2023-09-18 17:15:30 +01:00
|
|
|
|
var botType = botToUpdate.botType.ToString().ToLower();
|
|
|
|
|
List<Datum> rawBotsOfSameType;
|
|
|
|
|
lock (dictionaryLock)
|
|
|
|
|
{
|
|
|
|
|
if (!rawBots.TryGetValue(botType, out rawBotsOfSameType))
|
|
|
|
|
{
|
2023-12-28 09:12:54 +00:00
|
|
|
|
Console.WriteLine($"(loot) Unable to find {botType} on rawBots data");
|
2023-09-18 17:15:30 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-17 18:33:55 +01:00
|
|
|
|
|
2023-09-18 17:15:30 +01:00
|
|
|
|
if (rawBotsOfSameType.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:34:16 +00:00
|
|
|
|
AddLootToContainers(botType, botToUpdate, rawBotsOfSameType);
|
2023-09-18 18:23:07 +01:00
|
|
|
|
|
|
|
|
|
//foreach (var rawParsedBot in rawBotsOfSameType)
|
|
|
|
|
//{
|
|
|
|
|
// AddPocketLoot(botToUpdate, rawParsedBot);
|
|
|
|
|
//}
|
2023-09-18 17:15:30 +01:00
|
|
|
|
|
2023-09-18 18:23:07 +01:00
|
|
|
|
//AddTacticalVestLoot(botToUpdate, rawBotsOfSameType);
|
|
|
|
|
//AddBackpackLoot(botToUpdate, rawBotsOfSameType);
|
|
|
|
|
//AddSecureContainerLoot(botToUpdate, rawBotsOfSameType);
|
|
|
|
|
//AddSpecialLoot(botToUpdate);
|
2023-09-18 17:15:30 +01:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(tasks.ToArray());
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:34:16 +00:00
|
|
|
|
private static void AddLootToContainers(string botType, Bot botToUpdate, List<Datum> rawBotsOfSameType)
|
2023-09-18 18:23:07 +01:00
|
|
|
|
{
|
|
|
|
|
var containerDict = new Dictionary<string, List<string>>();
|
|
|
|
|
foreach (var bot in rawBotsOfSameType)
|
|
|
|
|
{
|
|
|
|
|
var backpack = bot.Inventory.items.FirstOrDefault(x => x.slotId == "Backpack");
|
|
|
|
|
if (backpack != null)
|
|
|
|
|
{
|
|
|
|
|
containerDict.Add(backpack._id, new List<string>());
|
|
|
|
|
}
|
|
|
|
|
var pocket = bot.Inventory.items.FirstOrDefault(x => x.slotId == "Pockets");
|
|
|
|
|
if (pocket != null)
|
|
|
|
|
{
|
|
|
|
|
containerDict.Add(pocket._id, new List<string>());
|
|
|
|
|
}
|
|
|
|
|
var secure = bot.Inventory.items.FirstOrDefault(x => x.slotId == "SecuredContainer");
|
|
|
|
|
if (secure != null)
|
|
|
|
|
{
|
|
|
|
|
containerDict.Add(secure._id, new List<string>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tacVest = bot.Inventory.items.FirstOrDefault(x => x.slotId == "TacticalVest");
|
|
|
|
|
if (tacVest != null)
|
|
|
|
|
{
|
|
|
|
|
containerDict.Add(tacVest._id, new List<string>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var item in bot.Inventory.items)
|
|
|
|
|
{
|
2024-01-01 20:29:58 +00:00
|
|
|
|
// Filter out root items and equipment mod items
|
|
|
|
|
if (item.parentId == null || item.location == null)
|
2023-09-18 18:23:07 +01:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Container (backpack etc) exists in dict
|
|
|
|
|
if (containerDict.ContainsKey(item.parentId))
|
|
|
|
|
{
|
|
|
|
|
containerDict[item.parentId].AddUnique(item._tpl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:34:16 +00:00
|
|
|
|
var forcedLoot = ForcedLootHelper.GetForcedLoot();
|
|
|
|
|
forcedLoot.TryGetValue(botType, out var lootToAdd);
|
|
|
|
|
|
2023-09-18 18:23:07 +01:00
|
|
|
|
if (backpack != null)
|
|
|
|
|
{
|
2024-01-03 22:34:16 +00:00
|
|
|
|
if (lootToAdd?.Backpack != null)
|
|
|
|
|
{
|
|
|
|
|
botToUpdate.inventory.items.Backpack.AddUniqueRange(lootToAdd.Backpack);
|
|
|
|
|
}
|
2023-09-18 18:23:07 +01:00
|
|
|
|
botToUpdate.inventory.items.Backpack.AddUniqueRange(containerDict[backpack._id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pocket != null)
|
|
|
|
|
{
|
2024-01-03 22:34:16 +00:00
|
|
|
|
if (lootToAdd?.Pockets != null)
|
|
|
|
|
{
|
|
|
|
|
botToUpdate.inventory.items.Pockets.AddUniqueRange(lootToAdd.Pockets);
|
|
|
|
|
}
|
2023-09-18 18:23:07 +01:00
|
|
|
|
botToUpdate.inventory.items.Pockets.AddUniqueRange(containerDict[pocket._id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (secure != null)
|
|
|
|
|
{
|
|
|
|
|
botToUpdate.inventory.items.SecuredContainer.AddUniqueRange(containerDict[secure._id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tacVest != null)
|
|
|
|
|
{
|
2024-01-03 22:34:16 +00:00
|
|
|
|
if (lootToAdd?.TacticalVest != null)
|
|
|
|
|
{
|
|
|
|
|
botToUpdate.inventory.items.TacticalVest.AddUniqueRange(lootToAdd.TacticalVest);
|
|
|
|
|
}
|
2023-09-18 18:23:07 +01:00
|
|
|
|
botToUpdate.inventory.items.TacticalVest.AddUniqueRange(containerDict[tacVest._id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
containerDict.Clear();
|
|
|
|
|
}
|
2023-10-31 19:35:32 +00:00
|
|
|
|
|
|
|
|
|
// Add generic keys to bosses
|
|
|
|
|
if (botToUpdate.botType.IsBoss())
|
|
|
|
|
{
|
|
|
|
|
var keys = SpecialLootHelper.GetGenericBossKeys().ToList();
|
|
|
|
|
botToUpdate.inventory.items.Backpack.AddUniqueRange(keys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddSpecialLoot(botToUpdate);
|
2023-09-18 18:23:07 +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);
|
2023-09-18 18:23:07 +01:00
|
|
|
|
foreach (var container in botContainers)
|
2021-08-12 16:52:06 +01:00
|
|
|
|
{
|
2023-09-18 18:23:07 +01:00
|
|
|
|
containers.AddUnique(container._id);
|
2021-08-12 16:52:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var item in bot.Inventory.items)
|
|
|
|
|
{
|
|
|
|
|
if (containers.Contains(item.parentId))
|
|
|
|
|
{
|
|
|
|
|
itemsStoredInContainer.AddUnique(item._tpl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemsStoredInContainer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|