Code cleanup and attempt at reducing ram usage

Added extra bosses to pmc enemy forcing code
This commit is contained in:
Dev 2023-08-15 12:05:31 +01:00
parent c9c472882e
commit de11386c5a
4 changed files with 40 additions and 48 deletions

View File

@ -1,6 +1,5 @@
using Common.Models.Input;
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@ -12,7 +11,7 @@ namespace Common.Bots;
public static class BotParser
{
static JsonSerializerOptions serialiserOptions = new JsonSerializerOptions { };
static readonly JsonSerializerOptions serialiserOptions = new() { };
public static async Task<List<Datum>> ParseAsync(string dumpPath, string[] botTypes)
{
@ -37,12 +36,6 @@ public static class BotParser
int dupeCount = 0;
var rawInputString = await ReadFileContentsAsync(file);
//var json = rawInputString;
//if (rawInputString.Contains("location\":1,"))
//{
// json = PruneMalformedBsgJson(rawInputString, splitFilePath.Last());
//}
List<Datum> bots = null;
try
{
@ -50,38 +43,50 @@ public static class BotParser
}
catch (Exception ex)
{
Console.WriteLine($"file parse fucked up: {file}");
Console.WriteLine($"File parse fucked up: {file}");
throw;
}
if (bots == null || bots.Count == 0)
{
Console.WriteLine($"skipping file: {splitFilePath.Last()}. no bots found, ");
Console.WriteLine($"Skipping file: {splitFilePath.Last()}. no bots found, ");
return;
}
Console.WriteLine($"parsing: {bots.Count} bots in file {splitFilePath.Last()}");
//Console.WriteLine($"parsing: {bots.Count} bots in file {splitFilePath.Last()}");
foreach (var bot in bots)
{
// I have no idea
if (bot._id == "6483938c53cc9087c70eae86")
{
Console.WriteLine("oh no");
}
// We dont know how to parse this bot type, need to add it to types enum
if (!botTypes.Contains(bot.Info.Settings.Role.ToLower()))
{
continue;
}
// Bot already exists in dictionary, skip
if (parsedBotsDict.ContainsKey(bot._id))
{
//var existingBot = parsedBotsDict[bot._id];
dupeCount++;
continue;
}
if (!parsedBotsDict.ContainsKey(bot._id))
{
// Null out data we don't need for generating bots to save RAM
bot.Stats = null;
bot.Encyclopedia = null;
bot.Hideout = null;
bot.ConditionCounters = null;
bot.Bonuses = null;
bot.BackendCounters = null;
bot.InsuredItems = null;
parsedBotsDict.Add(bot._id, bot);
}
}

View File

@ -1,14 +1,9 @@
using Common;
using Common.Extensions;
using Common.Extensions;
using Common.Models;
using Common.Models.Input;
using Common.Models.Output;
using Generator.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Generator
{
@ -136,18 +131,13 @@ namespace Generator
if (!alreadyExists)
{
var bodyPartHpToAdd = new Common.Models.Output.BodyParts();
bodyPartHpToAdd.Head.min = bot.Health.BodyParts.Head.Health.Current;
bodyPartHpToAdd.Head.max = bot.Health.BodyParts.Head.Health.Maximum;
bodyPartHpToAdd.Chest.min = bot.Health.BodyParts.Chest.Health.Current;
bodyPartHpToAdd.Chest.max = bot.Health.BodyParts.Chest.Health.Maximum;
bodyPartHpToAdd.Stomach.min = bot.Health.BodyParts.Stomach.Health.Current;
bodyPartHpToAdd.Stomach.max = bot.Health.BodyParts.Stomach.Health.Maximum;
bodyPartHpToAdd.LeftArm.min = bot.Health.BodyParts.LeftArm.Health.Current;
bodyPartHpToAdd.LeftArm.max = bot.Health.BodyParts.LeftArm.Health.Maximum;
var bodyPartHpToAdd = new Common.Models.Output.BodyParts()
{
Head = new MinMax(bot.Health.BodyParts.Head.Health.Current, bot.Health.BodyParts.Head.Health.Maximum),
Chest = new MinMax(bot.Health.BodyParts.Chest.Health.Current, bot.Health.BodyParts.Chest.Health.Maximum),
Stomach = new MinMax(bot.Health.BodyParts.Stomach.Health.Current, bot.Health.BodyParts.Stomach.Health.Maximum),
LeftArm = new MinMax(bot.Health.BodyParts.LeftArm.Health.Current, bot.Health.BodyParts.LeftArm.Health.Maximum)
};
bodyPartHpToAdd.RightArm.min = bot.Health.BodyParts.RightArm.Health.Current;
bodyPartHpToAdd.RightArm.max = bot.Health.BodyParts.RightArm.Health.Maximum;

View File

@ -1,8 +1,7 @@
using Common.Models.Output;
using Common.Models;
using Common.Models.Output;
using Common.Models.Output.Difficulty;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
namespace Generator.Helpers
{
@ -15,12 +14,12 @@ namespace Generator.Helpers
// Read bot setting files from assets folder that match this bots type
// Save into dictionary with difficulty as key
var difficultySettingsJsons = new Dictionary<string, DifficultySettings>();
var botType = botToUpdate.botType.ToString();
BotType botType = botToUpdate.botType;
var pathsWithBotType = difficultyFilePaths.Where(x => x.Contains($"_{botType}_", StringComparison.InvariantCultureIgnoreCase));
foreach (var path in pathsWithBotType)
{
var json = File.ReadAllText(path);
var serialisedDifficultySettings = JsonConvert.DeserializeObject<DifficultySettings>(json);
var difficultyJson = File.ReadAllText(path);
var serialisedDifficultySettings = JsonConvert.DeserializeObject<DifficultySettings>(difficultyJson);
serialisedDifficultySettings = ApplyCustomDifficultyValues(botType, serialisedDifficultySettings);
@ -91,16 +90,20 @@ namespace Generator.Helpers
}
private static DifficultySettings ApplyCustomDifficultyValues(string botType, DifficultySettings difficultySettings)
private static DifficultySettings ApplyCustomDifficultyValues(BotType botType, DifficultySettings difficultySettings)
{
switch (botType)
{
// make all bosses fight PMCs
case "bosskilla":
case "bossgluhar":
case "bosstagilla":
case "bossbully":
case "bosskojaniy":
case BotType.bosskilla:
case BotType.bossgluhar:
case BotType.bosstagilla:
case BotType.bossbully:
case BotType.bosskojaniy:
case BotType.bossboar:
case BotType.bossboarsniper:
case BotType.bossknight:
case BotType.bosszryachiy:
AddHostileToPMCSettings(difficultySettings);
break;
default:

View File

@ -1,14 +1,8 @@
using Common.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace Generator.Weighting
{
public class Weightings
{
public Dictionary<string, Dictionary<string, int>> Equipment { get; set; }