Merge pull request 'feature/mod-chance-calculation-adjustments' (#7) from feature/mod-chance-calculation-adjustments into master

Reviewed-on: Chomp/BotGenerator#7
This commit is contained in:
Chomp 2021-09-01 17:42:21 +02:00
commit 25e7acacac
9 changed files with 281394 additions and 197 deletions

View File

@ -14,9 +14,9 @@ namespace Common
Console.BackgroundColor = backgroundColour;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(message);
Console.Write(message);
ResetConsoleColours();
Console.WriteLine();
}
private static void ResetConsoleColours()

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace PMCGenerator.Models
namespace Common.Models
{
public class ItemsLibRoot
{
@ -22,6 +22,7 @@ namespace PMCGenerator.Models
public string ShortName { get; set; }
public string Description { get; set; }
public List<Chamber> Chambers { get; set; }
public List<Slot> Slots { get; set; }
public string defAmmo { get; set; }
}
@ -36,6 +37,12 @@ namespace PMCGenerator.Models
public string _proto { get; set; }
}
public class Slot
{
public string _name { get; set; }
public bool _required { get; set; }
}
public class ChamberProps
{
public List<Filter> filters { get; set; }

281263
Generator/Assets/items.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -155,4 +155,10 @@
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Assets\items.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using Generator.Models;
using Generator.Models.Input;
using Generator.Models.Input;
using Generator.Models.Output;
using System.Collections.Generic;
using System.Linq;
@ -10,101 +9,75 @@ namespace Generator.Helpers.Gear
{
public static void CalculateModChances(Bot bot, List<Datum> baseBots)
{
int totalBotsCount = baseBots.Count;
int muzzleCount = 0, barrelCount = 0, handguardCount = 0, stockCount = 0, magazineCount = 0,
mountCount = 0, flashlightCount = 0, tactical001Count = 0, tactical002Count = 0, tactical003Count = 0,
mount000Count = 0, pistolGripCount = 0, tacticalCount = 0, scopeCount = 0, recieverCount = 0,
sightRearCount = 0, chargeCount = 0, mount001Count = 0, equipmentCount = 0, gasBlockCount = 0,
launcherCount = 0, sightFrontCount = 0, stock000Count = 0, foregripCount = 0, tactical000Count = 0,
nvgCount = 0, pistolGripAkmsCount = 0, stockAkmsCount = 0, equipment000Count = 0, equipment001Count = 0,
equipment002Count = 0, bipodCount = 0, mount002Count = 0, mount004Count = 0, triggerCount = 0,
hammerCount = 0, catchCount = 0, stock001Count = 0, muzzle000Count = 0, mount003Count = 0;
// TODO: Further split these counts by equipment slot? (ex. "FirstPrimaryWeapon", "Holster", etc.)
var validSlots = new List<string> { "FirstPrimaryWeapon", "SecondPrimaryWeapon", "Holster", "Headwear" };
var modCounts = new Dictionary<string, int>();
var slotCounts = new Dictionary<string, int>();
foreach (var baseBot in baseBots)
{
muzzleCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_muzzle");
barrelCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_barrel");
handguardCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_handguard");
stockCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_stock");
magazineCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_magazine");
mountCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount");
flashlightCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_flashlight");
tactical001Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_tactical_001");
tactical002Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_tactical_002");
tactical003Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_tactical_003");
mount000Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount_000");
pistolGripCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_pistol_grip");
tacticalCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_tactical");
scopeCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_scope");
recieverCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_reciever");
sightRearCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_sight_rear");
chargeCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_charge");
mount001Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount_001");
equipmentCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_equipment");
gasBlockCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_gas_block");
launcherCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_launcher");
sightFrontCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_sight_front");
stock000Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_stock_000");
foregripCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_foregrip");
tactical000Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_tactical_000");
nvgCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_nvg");
pistolGripAkmsCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_pistol_grip_akms");
stockAkmsCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_stock_akms");
equipment000Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_equipment_000");
equipment001Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_equipment_001");
equipment002Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_equipment_002");
bipodCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_bipod");
mount002Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount_002");
mount004Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount_004");
triggerCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_trigger");
hammerCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_hammer");
catchCount += baseBot.Inventory.items.Count(x => x.slotId == "mod_catch");
stock001Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_stock_001");
muzzle000Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_muzzle_000");
mount003Count += baseBot.Inventory.items.Count(x => x.slotId == "mod_mount_003");
var validParents = new List<string>();
foreach (var inventoryItem in baseBot.Inventory.items)
{
if (validSlots.Contains(inventoryItem.slotId))
{
validParents.Add(inventoryItem._id);
}
else if (validParents.Contains(inventoryItem.parentId))
{
validParents.Add(inventoryItem._id);
}
else
{
continue;
}
var template = ItemTemplateHelper.GetTemplateById(inventoryItem._tpl);
var parentTemplate = ItemTemplateHelper.GetTemplateById(baseBot.Inventory.items.Single(i => i._id == inventoryItem.parentId)._tpl);
if ((inventoryItem.slotId?.StartsWith("mod_") ?? false) && !(parentTemplate?._props?.Slots?.FirstOrDefault(s => s._name == inventoryItem.slotId)?._required ?? false))
{
if (modCounts.ContainsKey(inventoryItem.slotId))
{
modCounts[inventoryItem.slotId]++;
}
else
{
modCounts.Add(inventoryItem.slotId, 1);
}
}
if ((template?._props?.Slots?.Count ?? 0) < 1)
{
// Item has no slots, nothing to count here
continue;
}
foreach (var slot in template._props.Slots.Where(s => s._name.StartsWith("mod_")))
{
if (slot._required)
{
continue;
}
if (slotCounts.ContainsKey(slot._name))
{
slotCounts[slot._name]++;
}
else
{
slotCounts.Add(slot._name, 1);
}
}
}
}
bot.chances.mods = new Mods(
GetPercent(totalBotsCount, muzzleCount),
GetPercent(totalBotsCount, barrelCount),
GetPercent(totalBotsCount, handguardCount),
GetPercent(totalBotsCount, stockCount),
GetPercent(totalBotsCount, magazineCount),
GetPercent(totalBotsCount, mountCount),
GetPercent(totalBotsCount, flashlightCount),
GetPercent(totalBotsCount, tactical001Count),
GetPercent(totalBotsCount, tactical002Count),
GetPercent(totalBotsCount, tactical003Count),
GetPercent(totalBotsCount, mount000Count),
GetPercent(totalBotsCount, pistolGripCount),
GetPercent(totalBotsCount, tacticalCount),
GetPercent(totalBotsCount, scopeCount),
GetPercent(totalBotsCount, recieverCount),
GetPercent(totalBotsCount, sightRearCount),
GetPercent(totalBotsCount, chargeCount),
GetPercent(totalBotsCount, mount001Count),
GetPercent(totalBotsCount, equipmentCount),
GetPercent(totalBotsCount, gasBlockCount),
GetPercent(totalBotsCount, launcherCount),
GetPercent(totalBotsCount, sightFrontCount),
GetPercent(totalBotsCount, stock000Count),
GetPercent(totalBotsCount, foregripCount),
GetPercent(totalBotsCount, tactical000Count),
GetPercent(totalBotsCount, nvgCount),
GetPercent(totalBotsCount, pistolGripAkmsCount),
GetPercent(totalBotsCount, stockAkmsCount),
GetPercent(totalBotsCount, equipment000Count),
GetPercent(totalBotsCount, equipment001Count),
GetPercent(totalBotsCount, equipment002Count),
GetPercent(totalBotsCount, bipodCount),
GetPercent(totalBotsCount, mount002Count),
GetPercent(totalBotsCount, mount004Count),
GetPercent(totalBotsCount, triggerCount),
GetPercent(totalBotsCount, hammerCount),
GetPercent(totalBotsCount, catchCount),
GetPercent(totalBotsCount, stock001Count),
GetPercent(totalBotsCount, muzzle000Count),
GetPercent(totalBotsCount, mount003Count));
bot.chances.mods = slotCounts.ToDictionary(
kvp => kvp.Key,
kvp => GetPercent(kvp.Value, modCounts.GetValueOrDefault(kvp.Key)));
}
public static void AddGenerationChances(Bot bot)
@ -113,6 +86,7 @@ namespace Generator.Helpers.Gear
}
public static void CalculateEquipmentChances(Bot bot, List<Datum> baseBots)
{
// TODO: Convert to dynamic?
var totalBotsCount = baseBots.Count;
int headwearCount = 0, earCount = 0, faceCoverCount = 0, armorVestCount = 0, eyeWearCount = 0, armBandCount = 0,
tacticalVestCount = 0, backpackCount = 0, firstPrimaryCount = 0, secondPrimaryCount = 0, holsterCount = 0,

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Newtonsoft.Json;
using Item = Common.Models.Item;
namespace Generator.Helpers
{
public static class ItemTemplateHelper
{
private static Dictionary<string, Item> _itemCache;
public static Dictionary<string, Item> Items
{
get
{
if (_itemCache == null)
{
var itemsFilePath = $"{Directory.GetCurrentDirectory()}\\Assets\\items.json";
if (!File.Exists(itemsFilePath))
{
throw new Exception($"Missing items.json under assets ({itemsFilePath})");
}
var itemsJson = File.ReadAllText(itemsFilePath);
_itemCache = JsonConvert.DeserializeObject<Dictionary<string, Item>>(itemsJson);
}
return _itemCache;
}
}
public static Item GetTemplateById(string templateId)
{
if (Items.ContainsKey(templateId))
{
return Items[templateId];
}
LoggingHelpers.LogToConsole($"Could not locate item template with id {templateId}", ConsoleColor.Red);
return null;
}
}
}

View File

@ -125,7 +125,7 @@ namespace Generator.Models.Output
}
public EquipmentChances equipment { get; set; }
public Mods mods { get; set; }
public Dictionary<string, int> mods { get; set; }
}
public class EquipmentChances
@ -170,106 +170,7 @@ namespace Generator.Models.Output
public int Pockets { get; set; }
public int SecuredContainer { get; set; }
}
public class Mods
{
public Mods(int muzzle, int barrel, int handguard, int stock,
int magazine, int mount, int flashlight, int tactical_001,
int tactical_002, int tactical_003, int mount_000, int pistol_grip,
int tactical, int scope, int reciever, int sight_rear,
int charge, int mount_001, int equipment, int gas_block,
int launcher, int sight_front, int stock_000, int foregrip,
int tactical_000, int nvg, int pistol_grip_akms, int stock_akms,
int equipment_000, int equipment_001, int equipment_002, int bipod,
int mount_002, int mount_004, int trigger, int hammer, int _catch,
int stock_001, int muzzle_000, int mount_003)
{
mod_muzzle = muzzle;
mod_barrel = barrel;
mod_handguard = handguard;
mod_stock = stock;
mod_magazine = magazine;
mod_mount = mount;
mod_flashlight = flashlight;
mod_tactical_001 = tactical_001;
mod_tactical_002 = tactical_002;
mod_tactical_003 = tactical_003;
mod_mount_000 = mount_000;
mod_pistol_grip = pistol_grip;
mod_tactical = tactical;
mod_scope = scope;
mod_reciever = reciever;
mod_sight_rear = sight_rear;
mod_charge = charge;
mod_mount_001 = mount_001;
mod_equipment = equipment;
mod_gas_block = gas_block;
mod_launcher = launcher;
mod_sight_front = sight_front;
mod_stock_000 = stock_000;
mod_foregrip = foregrip;
mod_tactical_000 = tactical_000;
mod_nvg = nvg;
mod_pistol_grip_akms = pistol_grip_akms;
mod_stock_akms = stock_akms;
mod_equipment_000 = equipment_000;
mod_equipment_001 = equipment_001;
mod_equipment_002 = equipment_002;
mod_bipod = bipod;
mod_mount_002 = mount_002;
mod_mount_004 = mount_004;
mod_trigger = trigger;
mod_hammer = hammer;
mod_catch = _catch;
mod_stock_001 = stock_001;
mod_muzzle_000 = muzzle_000;
mod_mount_003 = mount_003;
}
public int mod_muzzle { get; set; }
public int mod_mount { get; set; }
public int mod_barrel { get; set; }
public int mod_handguard { get; set; }
public int mod_stock { get; set; }
public int mod_flashlight { get; set; }
public int mod_tactical_001 { get; set; }
public int mod_tactical_002 { get; set; }
public int mod_tactical_003 { get; set; }
public int mod_mount_000 { get; set; }
public int mod_magazine { get; set; }
public int mod_pistol_grip { get; set; }
public int mod_gas_block { get; set; }
public int mod_reciever { get; set; }
public int mod_charge { get; set; }
public int mod_sight_rear { get; set; }
public int mod_launcher { get; set; }
public int mod_equipment { get; set; }
public int mod_scope { get; set; }
public int mod_mount_001 { get; set; }
public int mod_mount_002 { get; set; }
public int mod_mount_004 { get; set; }
public int mod_tactical { get; set; }
public int mod_stock_000 { get; set; }
public int mod_sight_front { get; set; }
public int mod_pistol_grip_akms { get; set; }
public int mod_stock_akms { get; set; }
public int mod_foregrip { get; set; }
public int mod_tactical_000 { get; set; }
public int mod_nvg { get; set; }
public int mod_equipment_000 { get; set; }
public int mod_equipment_001 { get; set; }
public int mod_equipment_002 { get; set; }
public int mod_bipod { get; set; }
public int mod_trigger { get; set; }
public int mod_hammer { get; set; }
public int mod_catch { get; set; }
public int mod_stock_001 { get; set; }
public int mod_muzzle_000 { get; set; }
public int mod_mount_003 { get; set; }
}
public class GenerationChances
{
public GenerationChances(int specialMin, int SpecialMax,

View File

@ -51,7 +51,7 @@ namespace Generator
// Generate the base bot class and add basic details (health/body part hp etc)
var baseBotGenerator = new BaseBotGenerator(parsedBots, workingPath, botTypes);
var baseBots = baseBotGenerator.AddBaseDetails();
// Add weapons/armor to bots
var botGearGenerator = new BotGearGenerator(baseBots, parsedBots);
var botsWithGear = botGearGenerator.AddGear();

View File

@ -5,6 +5,7 @@ using PMCGenerator.Models;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Common.Models;
namespace PMCGenerator
{