Calculate weights for all bot equipment/ammo/appearance

This commit is contained in:
Dev 2023-10-31 19:35:32 +00:00
parent 2df1523ca5
commit 7c2d455b7b
8 changed files with 222 additions and 66 deletions

View File

@ -4,13 +4,14 @@ using System.Collections.Generic;
namespace Common.Extensions;
public static class EnumExtensions
{
private static readonly List<BotType> bossTypes = new List<BotType>(){
private static readonly List<BotType> bossTypes = new(){
BotType.bossbully,
BotType.bossgluhar,
BotType.bosskilla,
BotType.bosskojaniy,
BotType.bosssanitar,
BotType.bosstagilla
BotType.bosstagilla,
BotType.bossboar
};
public static bool IsBoss(this BotType self)

View File

@ -3,6 +3,7 @@ using Common.Models;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers;
using Generator.Helpers.Gear;
using System.Diagnostics;
namespace Generator
@ -53,7 +54,6 @@ namespace Generator
}
}
stopwatch.Stop();
LoggingHelpers.LogToConsole($"Finished processing bot base. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds");
@ -155,10 +155,15 @@ namespace Generator
private static void AddVisualAppearanceItems(Bot botToUpdate, Datum rawBot)
{
GearHelpers.IncrementDictionaryValue(botToUpdate.appearance.feet, rawBot.Customization.Feet);
//botToUpdate.appearance.feet.AddUnique(rawBot.Customization.Feet, 1);
GearHelpers.ReduceWeightValues(botToUpdate.appearance.feet);
GearHelpers.IncrementDictionaryValue(botToUpdate.appearance.body, rawBot.Customization.Body);
GearHelpers.ReduceWeightValues(botToUpdate.appearance.body);
botToUpdate.appearance.head.AddUnique(rawBot.Customization.Head);
botToUpdate.appearance.body.AddUnique(rawBot.Customization.Body, 1);
botToUpdate.appearance.hands.AddUnique(rawBot.Customization.Hands);
botToUpdate.appearance.feet.AddUnique(rawBot.Customization.Feet, 1);
}
private static void AddName(Bot botToUpdate, Datum rawBot)

View File

@ -42,6 +42,9 @@ namespace Generator
GearHelpers.AddEquippedMods(botToUpdate, rawParsedBot);
//GearHelpers.AddCartridges(botToUpdate, rawParsedBot);
}
GearHelpers.ReduceAmmoWeightValues(botToUpdate);
GearHelpers.ReduceEquipmentWeightValues(botToUpdate.inventory.equipment);
}));
}

View File

@ -136,12 +136,6 @@ namespace Generator
if (backpack != null)
{
botToUpdate.inventory.items.Backpack.AddUniqueRange(containerDict[backpack._id]);
// Add generic keys to bosses
if (botToUpdate.botType.IsBoss())
{
botToUpdate.inventory.items.Backpack.AddUniqueRange(SpecialLootHelper.GetGenericBossKeys().ToList());
}
}
if (pocket != null)
@ -161,6 +155,15 @@ namespace Generator
containerDict.Clear();
}
// Add generic keys to bosses
if (botToUpdate.botType.IsBoss())
{
var keys = SpecialLootHelper.GetGenericBossKeys().ToList();
botToUpdate.inventory.items.Backpack.AddUniqueRange(keys);
}
AddSpecialLoot(botToUpdate);
}
private static void AddSpecialLoot(Bot botToUpdate)

View File

@ -180,18 +180,63 @@
</ItemGroup>
<ItemGroup>
<None Update="Assets\easy_assaultGroup_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\generationWeights.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\hard_assaultGroup_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\impossible_assaultGroup_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_arenaFighter_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_assaultGroup_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_bossBoarSniper_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_bossBoar_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_bossKnight_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_bossZryachiy_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_crazyAssaultEvent_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_followerBigPipe_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_followerBirdEye_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_followerBoar_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_followerZryachiy_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_peacefullZryachiyEvent_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_ravangeZryachiyEvent_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\normal_sectactPriestEvent_BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Assets\__BotGlobalSettings.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -12,30 +12,10 @@ namespace Generator.Helpers.Gear
var modItemsInRawBot = new List<Item>();
var itemsWithModsInRawBot = new List<Item>();
//foreach (var inv in rawParsedBot.Inventory.items.Where(x => x.slotId == "mod_magazine"))
//{
//var count = rawParsedBot.Inventory.items.Where(x => x.slotId == "mod_magazine").Count();
// if (inv._tpl == "60dc519adf4c47305f6d410d")
// {
// var y = 1;
// }
//}
modItemsInRawBot = rawParsedBot.Inventory.items
.Where(x => x.slotId != null && (x.slotId.StartsWith("mod_") || x.slotId.StartsWith("patron_in_weapon"))).ToList();
//var x = new List<Item>();
//foreach (var item in rawParsedBot.Inventory.items.Where(x=>x.slotId == "mod_magazine"))
//{
// if (item._tpl == "60dc519adf4c47305f6d410d")
// {
// var wow = 1;
// }
// x.Add(item);
//}
// get items with Mods by iterating over mod items and getting the parent item
// Get items with Mods by iterating over mod items and getting the parent item
itemsWithModsInRawBot.AddRange(modItemsInRawBot
.Select(modItem => rawParsedBot.Inventory.items
.Find(x => x._id == modItem.parentId)));
@ -45,6 +25,16 @@ namespace Generator.Helpers.Gear
{
var modsToAdd = modItemsInRawBot.Where(x => x.parentId == itemToAdd._id).ToList();
// fix pistolgrip that changes slot id name
if (itemToAdd._tpl == "56e0598dd2720bb5668b45a6")
{
var badMod = modsToAdd.FirstOrDefault(x => x.slotId == "mod_pistol_grip" && x._tpl == "56e05a6ed2720bd0748b4567");
if (badMod != null)
{
badMod.slotId = "mod_pistolgrip";
}
}
AddItemToDictionary(itemToAdd, modsToAdd, itemsWithModsDictionary);
// check if these mods have sub-mods and add those
@ -64,14 +54,17 @@ namespace Generator.Helpers.Gear
internal static void AddAmmo(Bot botToUpdate, Datum bot)
{
var weightService = new WeightingService();
foreach (var inventoryItem in bot.Inventory.items.Where(x => x.slotId != null && (x.slotId == "patron_in_weapon" || x.slotId == "cartridges" || x.slotId.StartsWith("camora"))))
//var weightService = new WeightingService();
foreach (var ammo in bot.Inventory.items.Where(
x => x.slotId != null
&& (x.slotId == "patron_in_weapon"
|| (x.slotId == "cartridges" && bot.Inventory.items.FirstOrDefault(parent => parent._id == x.parentId)?.slotId != "main") // Ignore cartridges in ammo boxes for ammo usage calc
|| x.slotId.StartsWith("camora"))))
{
var caliber = ItemTemplateHelper.GetTemplateById(inventoryItem._tpl)._props.ammoCaliber;
var caliber = ItemTemplateHelper.GetTemplateById(ammo._tpl)._props.ammoCaliber;
if (caliber == null)
{
caliber = ItemTemplateHelper.GetTemplateById(inventoryItem._tpl)._props.Caliber;
caliber = ItemTemplateHelper.GetTemplateById(ammo._tpl)._props.Caliber;
}
// Create key if caliber doesnt exist
@ -80,8 +73,34 @@ namespace Generator.Helpers.Gear
botToUpdate.inventory.Ammo[caliber] = new Dictionary<string, int>();
}
botToUpdate.inventory.Ammo[caliber].AddUnique(inventoryItem._tpl, weightService.GetAmmoWeight(inventoryItem._tpl, botToUpdate.botType, caliber));
if (!botToUpdate.inventory.Ammo[caliber].ContainsKey(ammo._tpl))
{
botToUpdate.inventory.Ammo[caliber][ammo._tpl] = 0;
}
botToUpdate.inventory.Ammo[caliber][ammo._tpl] ++;
}
}
public static int CommonDivisor(List<int> numbers)
{
int result = numbers[0];
for (int i = 1; i < numbers.Count; i++)
{
result = GCD(result, numbers[i]);
}
return result;
}
private static int GCD(int a, int b)
{
while (b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
public static void AddEquippedGear(Bot botToUpdate, Datum bot)
@ -93,46 +112,46 @@ namespace Generator.Helpers.Gear
switch (inventoryItem.slotId?.ToLower())
{
case "headwear":
botToUpdate.inventory.equipment.Headwear.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "headwear"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Headwear, inventoryItem._tpl);
break;
case "earpiece":
botToUpdate.inventory.equipment.Earpiece.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "earpiece"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Earpiece, inventoryItem._tpl);
break;
case "facecover":
botToUpdate.inventory.equipment.FaceCover.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "facecover"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.FaceCover, inventoryItem._tpl);
break;
case "armorvest":
botToUpdate.inventory.equipment.ArmorVest.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "armorvest"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.ArmorVest, inventoryItem._tpl);
break;
case "eyewear":
botToUpdate.inventory.equipment.Eyewear.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "eyewear"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Eyewear, inventoryItem._tpl);
break;
case "armband":
botToUpdate.inventory.equipment.ArmBand.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "armband"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.ArmBand, inventoryItem._tpl);
break;
case "tacticalvest":
botToUpdate.inventory.equipment.TacticalVest.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "tacticalvest"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.TacticalVest, inventoryItem._tpl);
break;
case "backpack":
botToUpdate.inventory.equipment.Backpack.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "backpack"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Backpack, inventoryItem._tpl);
break;
case "firstprimaryweapon":
botToUpdate.inventory.equipment.FirstPrimaryWeapon.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "firstprimaryweapon"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.FirstPrimaryWeapon, inventoryItem._tpl);
break;
case "secondprimaryweapon":
botToUpdate.inventory.equipment.SecondPrimaryWeapon.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "secondprimaryweapon"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.SecondPrimaryWeapon, inventoryItem._tpl);
break;
case "holster":
botToUpdate.inventory.equipment.Holster.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "holster"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Holster, inventoryItem._tpl);
break;
case "scabbard":
botToUpdate.inventory.equipment.Scabbard.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "scabbard"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Scabbard, inventoryItem._tpl);
break;
case "pockets":
botToUpdate.inventory.equipment.Pockets.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "pockets"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.Pockets, inventoryItem._tpl);
break;
case "securedcontainer":
botToUpdate.inventory.equipment.SecuredContainer.AddUnique(inventoryItem._tpl, weightService.GetItemWeight(inventoryItem._tpl, botToUpdate.botType, "securedcontainer"));
IncrementDictionaryValue(botToUpdate.inventory.equipment.SecuredContainer, inventoryItem._tpl);
break;
default:
break;
@ -140,6 +159,16 @@ namespace Generator.Helpers.Gear
}
}
public static void IncrementDictionaryValue(Dictionary<string, int> dictToIncrement, string key)
{
if (!dictToIncrement.ContainsKey(key))
{
dictToIncrement[key] = 0;
}
dictToIncrement[key]++;
}
public static void AddCartridges(Bot botToUpdate, Datum rawParsedBot)
{
var cartridgesInRawBot = rawParsedBot.Inventory.items
@ -250,5 +279,72 @@ namespace Generator.Helpers.Gear
return itemsThatTakeCartridgesDict;
}
internal static void ReduceAmmoWeightValues(Bot botToUpdate)
{
foreach (var caliber in botToUpdate.inventory.Ammo)
{
foreach (var cartridge in botToUpdate.inventory.Ammo.Keys)
{
var cartridgeWithWeights = botToUpdate.inventory.Ammo[cartridge];
var weights = cartridgeWithWeights.Values.Select(x => x).ToList();
var commonAmmoDivisor = CommonDivisor(weights);
foreach (var cartridgeWeightKvP in cartridgeWithWeights)
{
botToUpdate.inventory.Ammo[cartridge][cartridgeWeightKvP.Key] /= commonAmmoDivisor;
}
}
}
}
public static void ReduceEquipmentWeightValues(Equipment equipment)
{
ReduceWeightValues(equipment.Headwear);
ReduceWeightValues(equipment.Earpiece);
ReduceWeightValues(equipment.FaceCover);
ReduceWeightValues(equipment.ArmorVest);
ReduceWeightValues(equipment.Eyewear);
ReduceWeightValues(equipment.ArmBand);
ReduceWeightValues(equipment.TacticalVest);
ReduceWeightValues(equipment.Backpack);
ReduceWeightValues(equipment.FirstPrimaryWeapon);
ReduceWeightValues(equipment.SecondPrimaryWeapon);
ReduceWeightValues(equipment.Scabbard);
ReduceWeightValues(equipment.Holster);
ReduceWeightValues(equipment.Pockets);
ReduceWeightValues(equipment.SecuredContainer);
}
public static void ReduceWeightValues(Dictionary<string, int> equipmentDict)
{
// No values, nothing to reduce
if (equipmentDict.Count == 0)
{
return;
}
// Only one value, quickly set to 1 and exit
if (equipmentDict.Count == 1)
{
equipmentDict[equipmentDict.First().Key] = 1;
return;
}
var weights = equipmentDict.Values.Select(x => x).ToList();
var commonAmmoDivisor = CommonDivisor(weights);
// No point in dividing by 1
if (commonAmmoDivisor == 1)
{
return;
}
foreach (var itemTplWithWeight in equipmentDict)
{
equipmentDict[itemTplWithWeight.Key] /= commonAmmoDivisor;
}
}
}
}

View File

@ -25,7 +25,6 @@ internal static class Program
"bossboar",
"bossboarsniper",
"followerbully",
"followergluharassault",
"followergluharscout",
@ -38,9 +37,8 @@ internal static class Program
"followerbigpipe",
"followerzryachiy",
"followerboar",
// //
"cursedassault",
// //
"sectantpriest",
"sectantwarrior",
"gifter",
@ -53,19 +51,24 @@ internal static class Program
var dumpPath = $"{workingPath}//dumps";
var parsedBots = BotParser.ParseAsync(dumpPath, botTypes.ToHashSet());
// put in dictionary for better use later on
// Put in dictionary for better use later on
var rawBotsCache = new Dictionary<string, List<Datum>>(40);
foreach (var rawBot in parsedBots)
{
if (rawBotsCache.TryGetValue(rawBot.Info.Settings.Role.ToLower(), out var botList))
{
botList.Add(rawBot);
else
continue;
}
// Doesnt exist, add key and bot
rawBotsCache.Add(rawBot.Info.Settings.Role.ToLower(), new List<Datum> { rawBot });
}
if (parsedBots.Count == 0)
{
LoggingHelpers.LogToConsole("no bots found, unable to continue");
LoggingHelpers.LogToConsole("No bots found, unable to continue");
LoggingHelpers.LogToConsole("Check your dumps are in 'Generator\\bin\\Debug\\net6.0\\dumps' and start with 'resp.' NOT 'req.'");
return;
}

View File

@ -15,8 +15,8 @@ namespace Generator.Weighting
public class WeightingService
{
private readonly Dictionary<BotType, Weightings> _weights;
private readonly Dictionary<string, Dictionary<string, GenerationWeightData>> _generationWeights;
public WeightingService()
{
var assetsPath = $"{Directory.GetCurrentDirectory()}\\Assets";