BotGenerator/Generator/BotLootGenerator.cs

106 lines
4.2 KiB
C#
Raw Normal View History

2023-09-18 17:15:30 +01:00
using System.Diagnostics;
using System.Linq;
2021-08-24 12:08:30 +01:00
using Common.Extensions;
using Common.Models;
using Common.Models.Input;
using Common.Models.Output;
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
{
internal static void AddLoot(Bot botToUpdate, Datum rawBotData)
2021-08-12 16:52:06 +01:00
{
AddLootToContainers(botToUpdate, rawBotData);
2021-08-12 16:52:06 +01:00
}
private static void AddLootToContainers(Bot botToUpdate, Datum rawBot)
{
// Filter out base inventory items and equipment mod items
var rawBotItems = rawBot.Inventory.items.Where(item => item.location != null);
var botBackpack = rawBot.Inventory.items.FirstOrDefault(item => item.slotId == "Backpack");
if (botBackpack != null)
{
AddLootItemsToContainerDictionary(rawBotItems, botBackpack._id, botToUpdate.inventory.items.Backpack, "backpack", botToUpdate.botType);
}
var botPockets = rawBot.Inventory.items.FirstOrDefault(item => item.slotId == "Pockets");
if (botPockets != null)
{
AddLootItemsToContainerDictionary(rawBotItems, botPockets._id, botToUpdate.inventory.items.Pockets);
}
var botVest = rawBot.Inventory.items.FirstOrDefault(item => item.slotId == "TacticalVest");
if (botVest != null)
{
AddLootItemsToContainerDictionary(rawBotItems, botVest._id, botToUpdate.inventory.items.TacticalVest);
}
var botSecure = rawBot.Inventory.items.FirstOrDefault(item => item.slotId == "SecuredContainer");
if (botSecure != null)
{
AddLootItemsToContainerDictionary(rawBotItems, botSecure._id, botToUpdate.inventory.items.SecuredContainer);
}
// Add generic keys to bosses
if (botToUpdate.botType.IsBoss())
{
var keys = SpecialLootHelper.GetGenericBossKeysDictionary();
foreach (var bosskey in keys)
{
if (!botToUpdate.inventory.items.Backpack.ContainsKey(bosskey.Key))
{
botToUpdate.inventory.items.Backpack.Add(bosskey.Key, bosskey.Value);
}
}
}
AddSpecialLoot(botToUpdate);
2024-12-13 13:18:06 +00:00
// Cleanup of weights
GearHelpers.ReduceWeightValues(botToUpdate.inventory.items.Backpack);
GearHelpers.ReduceWeightValues(botToUpdate.inventory.items.Pockets);
GearHelpers.ReduceWeightValues(botToUpdate.inventory.items.TacticalVest);
GearHelpers.ReduceWeightValues(botToUpdate.inventory.items.SecuredContainer);
}
/// <summary>
/// Look for items inside itemsToFilter that have the parentid of `containerId` and add them to dictToAddTo
/// Keep track of how many items are added in the dictToAddTo value
/// </summary>
/// <param name="itemsToFilter">Bots inventory items</param>
/// <param name="containerId"></param>
/// <param name="dictToAddTo"></param>
private static void AddLootItemsToContainerDictionary(IEnumerable<Common.Models.Input.Item> itemsToFilter, string containerId, Dictionary<string, int> dictToAddTo, string container = "", BotType type = BotType.arenafighterevent)
{
foreach (var itemToAdd in itemsToFilter)
{
if (itemToAdd.parentId != containerId) continue;
2024-02-22 00:39:47 +00:00
if (!dictToAddTo.ContainsKey(itemToAdd._tpl))
{
2024-02-22 00:39:47 +00:00
dictToAddTo[itemToAdd._tpl] = 1;
continue;
}
2024-02-22 00:39:47 +00:00
dictToAddTo[itemToAdd._tpl]++;
}
}
2021-09-01 19:19:44 +03:00
private static void AddSpecialLoot(Bot botToUpdate)
2021-08-12 16:52:06 +01:00
{
var itemsToAdd = SpecialLootHelper.GetSpecialLootForBotType(botToUpdate.botType);
foreach (var item in itemsToAdd)
2021-08-12 16:52:06 +01:00
{
if (!botToUpdate.inventory.items.SpecialLoot.ContainsKey(item.Key))
2021-08-12 16:52:06 +01:00
{
botToUpdate.inventory.items.SpecialLoot.Add(item.Key, item.Value);
2021-08-12 16:52:06 +01:00
}
}
}
}
}