Refactor to use common.models project

Add project for finding unique bot templates from live data
This commit is contained in:
Chomp 2021-09-18 22:36:59 +01:00
parent 4e399b5518
commit 8237fdbe67
25 changed files with 251 additions and 31 deletions

View File

@ -5,9 +5,13 @@ VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "Generator\Generator.csproj", "{79CD3722-D6A7-4BA1-8CDF-533A77566D93}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PMCGenerator", "PMCGenerator\PMCGenerator.csproj", "{AA738C3F-2BA0-4754-A7A7-82E290BF51CA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PMCGenerator", "PMCGenerator\PMCGenerator.csproj", "{AA738C3F-2BA0-4754-A7A7-82E290BF51CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{DE50047B-01AB-4B99-A270-95C8F6101D0D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{DE50047B-01AB-4B99-A270-95C8F6101D0D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniqueTemplates", "UniqueTemplates\UniqueTemplates.csproj", "{0C7085A3-0692-4F6B-BF88-B228725A105A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Models", "Common.Models\Common.Models.csproj", "{23BCA0BE-C95E-4BFD-A89F-408729E6BDE0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +31,14 @@ Global
{DE50047B-01AB-4B99-A270-95C8F6101D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE50047B-01AB-4B99-A270-95C8F6101D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE50047B-01AB-4B99-A270-95C8F6101D0D}.Release|Any CPU.Build.0 = Release|Any CPU
{0C7085A3-0692-4F6B-BF88-B228725A105A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C7085A3-0692-4F6B-BF88-B228725A105A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C7085A3-0692-4F6B-BF88-B228725A105A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C7085A3-0692-4F6B-BF88-B228725A105A}.Release|Any CPU.Build.0 = Release|Any CPU
{23BCA0BE-C95E-4BFD-A89F-408729E6BDE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23BCA0BE-C95E-4BFD-A89F-408729E6BDE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23BCA0BE-C95E-4BFD-A89F-408729E6BDE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23BCA0BE-C95E-4BFD-A89F-408729E6BDE0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Generator.Models.Input
namespace Common.Models.Input
{
public class Settings
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Generator.Models.Output.Difficulty
namespace Common.Models.Output.Difficulty
{
public class Difficulty
{

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace Generator.Models.Output
namespace Common.Models.Output
{
public class Equipment
{

View File

@ -1,8 +1,7 @@
using Common.Models;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Generator.Models.Output
namespace Common.Models.Output
{
public class Bot
{

View File

@ -1,5 +1,4 @@
using Common;
using Generator.Models.Input;
using Common.Models.Input;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
@ -9,9 +8,9 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Generator
namespace Common.Bots
{
internal class BotParser
public class BotParser
{
private readonly string _dumpPath;

View File

@ -8,6 +8,10 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Models\Common.Models.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Assets\items.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

View File

@ -1,11 +1,11 @@
using Generator.Models.Output;
using Common.Models.Output;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Models.Input;
namespace Generator
namespace Common
{
public class JsonWriter
{
@ -36,5 +36,17 @@ namespace Generator
Console.WriteLine($"file {bot.botType} written to {outputPath}");
}
}
public void WriteJson(List<Datum> bots, string fileName)
{
var outputPath = $"{_workingPath}\\{_outputFolderName}";
DiskHelpers.CreateDirIfDoesntExist(outputPath);
var output = JsonConvert.SerializeObject(bots, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
File.WriteAllText($"{outputPath}\\{fileName.ToLower()}.json", output);
}
}
}

View File

@ -1,9 +1,9 @@
using Common;
using Common.Extensions;
using Common.Models;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers;
using Generator.Models.Input;
using Generator.Models.Output;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,7 +1,7 @@
using Common;
using Generator.Helpers.Gear;
using Generator.Models.Input;
using Generator.Models.Output;
using Common.Models.Input;
using Common.Models.Output;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,7 +1,7 @@
using Common;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers.Gear;
using Generator.Models.Input;
using Generator.Models.Output;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -1,8 +1,8 @@
using Common;
using Common.Extensions;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers.Gear;
using Generator.Models.Input;
using Generator.Models.Output;
using System;
using System.Collections.Generic;
using System.Diagnostics;

View File

@ -152,7 +152,12 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Models\Common.Models.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,5 @@
using Generator.Models.Output;
using Generator.Models.Output.Difficulty;
using Common.Models.Output;
using Common.Models.Output.Difficulty;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;

View File

@ -1,6 +1,6 @@
using System;
using Generator.Models.Input;
using Generator.Models.Output;
using Common.Models.Input;
using Common.Models.Output;
using System.Collections.Generic;
using System.Linq;
using Common.Models;
@ -94,6 +94,9 @@ namespace Generator.Helpers.Gear
botToUpdate.chances.mods["mod_tactical"] = 100; // force ultima thermal camera
botToUpdate.chances.mods["mod_stock"] = 100;
break;
case BotType.pmcBot:
botToUpdate.chances.mods["mod_stock"] = 100;
break;
}
}

View File

@ -1,7 +1,6 @@
using Common.Extensions;
using Generator.Models.Input;
using Generator.Models.Output;
using Newtonsoft.Json;
using Common.Models.Input;
using Common.Models.Output;
using System.Collections.Generic;
using System.Linq;

View File

@ -1,5 +1,4 @@
using Common.Models;
using Generator.Models;
using System.Collections.Generic;
namespace Generator.Helpers.Gear

View File

@ -1,4 +1,6 @@
using Common;
using Common.Bots;
using Common.Models.Output;
using System.IO;
using System.Linq;

View File

@ -10,6 +10,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Models\Common.Models.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

View File

@ -0,0 +1,78 @@
using Common.Models.Input;
using System.Collections.Generic;
using System.Linq;
namespace UniqueTemplates.Extensions
{
public static class BotExtensions
{
public static bool ContainsBot(this List<Datum> list, Datum botToCheck)
{
foreach (var bot in list)
{
var botGear = GetEquippedGear(bot);
if (botGear.CheckMatch(botToCheck.GetEquippedGear()))
{
return true;
}
}
return false;
}
public static EquippedGear GetEquippedGear(this Datum bot)
{
return new EquippedGear
{
ArmorVest = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "ArmorVest"),
Backpack = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "Backpack"),
Eyewear = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "Eyewear"),
FaceCover = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "FaceCover"),
FirstPrimaryWeapon = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "FirstPrimaryWeapon"),
Headwear = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "Headwear"),
Scabbard = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "Scabbard"),
TacticalVest = GeEquipmentItemTemplateIdOrNull(bot.Inventory.items, "TacticalVest"),
};
}
private static string GeEquipmentItemTemplateIdOrNull(List<Item> inventoryItems, string itemTypeWanted)
{
var item = inventoryItems.FirstOrDefault(x => x.slotId == itemTypeWanted);
if (item == null)
{
return null;
}
return item._tpl;
}
public class EquippedGear
{
public string FirstPrimaryWeapon { get; set; }
public string TacticalVest { get; set; }
public string Headwear { get; set; }
public string Scabbard { get; set; }
public string Backpack { get; set; }
public string ArmorVest { get; set; }
public string FaceCover { get; set; }
public string Eyewear { get; set; }
public bool CheckMatch(EquippedGear gearToCheck)
{
if (gearToCheck.FirstPrimaryWeapon == FirstPrimaryWeapon
&& gearToCheck.TacticalVest == TacticalVest
&& gearToCheck.Headwear == Headwear
&& gearToCheck.Scabbard == Scabbard
&& gearToCheck.Backpack == Backpack
&& gearToCheck.ArmorVest == ArmorVest
&& gearToCheck.FaceCover == FaceCover
&& gearToCheck.Eyewear == Eyewear)
{
return true;
}
return false;
}
}
}
}

View File

@ -0,0 +1,83 @@
using Common;
using Common.Bots;
using Common.Models.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UniqueTemplates.Extensions;
namespace UniqueTemplates
{
public class Program
{
static void Main(string[] args)
{
// Get the unique bot types that bsg generate from live dumps
// Read raw bot dumps and turn into c# objects
var workingPath = Directory.GetCurrentDirectory();
var dumpPath = $"{workingPath}//dumps";
var botParser = new BotParser(dumpPath);
var parsedBots = botParser.Parse();
if (parsedBots.Count == 0)
{
LoggingHelpers.LogToConsole("no bots found, unable to continue");
LoggingHelpers.LogToConsole("Check your dumps are in 'Generator\\bin\\Debug\\netcoreapp3.1\\dumps' and start with 'resp.' NOT 'req.'");
return;
}
//var dupeCount = 0;
//var botTemplates = new List<Datum>();
//foreach (var bot in parsedBots)
//{
// if (botTemplates.ContainsBot(bot))
// {
// dupeCount++;
// continue;
// }
// botTemplates.Add(bot);
//}
var dictDupeCount = 0;
var uniqueBotTemplates = new Dictionary<string, Datum>();
foreach (var bot in parsedBots)
{
if (uniqueBotTemplates.ContainsKey(bot._id))
{
dictDupeCount++;
continue;
}
uniqueBotTemplates.Add(bot._id, bot);
}
//LoggingHelpers.LogToConsole($"LIST templates found: {botTemplates.Count}, {dupeCount} bots rejected as duplicate");
LoggingHelpers.LogToConsole($"DICTIONARY templates found: {uniqueBotTemplates.Count}, {dictDupeCount} bots rejected as duplicate");
var groupedBots = uniqueBotTemplates.GroupBy(x => x.Value.Info.Settings.Role).ToList();
foreach (var group in groupedBots)
{
var botList = new List<Datum>();
foreach (var bot in group)
{
botList.Add(bot.Value);
}
LoggingHelpers.LogToConsole($"{botList.Count} unique {group.Key} bots found");
var jsonWriter = new JsonWriter(workingPath, "output");
jsonWriter.WriteJson(botList, group.Key);
}
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Models\Common.Models.csproj" />
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project>