Added id generation for BaseClasses, updated references

This commit is contained in:
Chomp
2025-07-27 17:40:27 +01:00
parent 85b47f494e
commit 623fce1484
8 changed files with 249 additions and 104 deletions
@@ -16,7 +16,7 @@ public class UbglExternalMagGen(BotWeaponGeneratorHelper botWeaponGeneratorHelpe
public bool CanHandleInventoryMagGen(InventoryMagGen inventoryMagGen)
{
return inventoryMagGen.GetWeaponTemplate().Parent == BaseClasses.UBGL;
return inventoryMagGen.GetWeaponTemplate().Parent == BaseClasses.LAUNCHER;
}
public void Process(InventoryMagGen inventoryMagGen)
@@ -174,7 +174,7 @@ public class BotGeneratorHelper(
hasProperties = true;
}
if (itemTemplate?.Parent == BaseClasses.NIGHTVISION)
if (itemTemplate?.Parent == BaseClasses.NIGHT_VISION)
{
// Get chance from botconfig for bot type
var nvgActiveChance =
@@ -46,7 +46,7 @@ public class BotWeaponGeneratorHelper(
? 1 // Rotating grenade launcher
: magTemplate.Properties.Slots.Count(); // Shotguns/revolvers. We count the number of camoras as the _max_count of the magazine is 0
}
else if (parentItem.Id == BaseClasses.UBGL)
else if (parentItem.Id == BaseClasses.LAUNCHER)
{
// Underbarrel launchers can only have 1 chambered grenade
chamberBulletCount = 1;
@@ -257,7 +257,7 @@ public class ItemHelper(
itemProperties.Light = new UpdLight { IsActive = false, SelectedMode = 0 };
}
if (itemTemplate.Parent == BaseClasses.NIGHTVISION)
if (itemTemplate.Parent == BaseClasses.NIGHT_VISION)
{
itemProperties.Togglable = new UpdTogglable { On = false };
}
@@ -1514,7 +1514,7 @@ public class ItemHelper(
double minSizeMultiplier = 0.25
)
{
var isUBGL = IsOfBaseclass(magTemplate.Id, BaseClasses.UBGL);
var isUBGL = IsOfBaseclass(magTemplate.Id, BaseClasses.LAUNCHER);
if (isUBGL)
// UBGL don't have mags
{
@@ -1,117 +1,125 @@
using SPTarkov.Server.Core.Models.Common;
namespace SPTarkov.Server.Core.Models.Enums;
// This is an auto generated file, do not modify. Re-generate by running MongoIdTplGenerator.exe
public static class BaseClasses
{
public static readonly MongoId WEAPON = new MongoId("5422acb9af1c889c16000029");
public static readonly MongoId UBGL = new MongoId("55818b014bdc2ddc698b456b");
public static readonly MongoId AMMO = new MongoId("5485a8684bdc2da71d8b4567");
public static readonly MongoId AMMO_BOX = new MongoId("543be5cb4bdc2deb348b4568");
public static readonly MongoId ARM_BAND = new MongoId("5b3f15d486f77432d0509248");
public static readonly MongoId ARMOR = new MongoId("5448e54d4bdc2dcc718b4568");
public static readonly MongoId ARMOR_PLATE = new MongoId("644120aa86ffbe10ee032b6f");
public static readonly MongoId ARMORED_EQUIPMENT = new MongoId("57bef4c42459772e8d35a53b");
public static readonly MongoId REPAIR_KITS = new MongoId("616eb7aea207f41933308f46");
public static readonly MongoId HEADWEAR = new MongoId("5a341c4086f77401f2541505");
public static readonly MongoId FACECOVER = new MongoId("5a341c4686f77469e155819e");
public static readonly MongoId VEST = new MongoId("5448e5284bdc2dcb718b4567");
public static readonly MongoId ASSAULT_CARBINE = new MongoId("5447b5fc4bdc2d87278b4567");
public static readonly MongoId ASSAULT_RIFLE = new MongoId("5447b5f14bdc2d61278b4567");
public static readonly MongoId ASSAULT_SCOPE = new MongoId("55818add4bdc2d5b648b456f");
public static readonly MongoId AUXILIARY_MOD = new MongoId("5a74651486f7744e73386dd1");
public static readonly MongoId BACKPACK = new MongoId("5448e53e4bdc2d60728b4567");
public static readonly MongoId COMPOUND = new MongoId("566162e44bdc2d3f298b4573");
public static readonly MongoId VISORS = new MongoId("5448e5724bdc2ddf718b4568");
public static readonly MongoId FOOD = new MongoId("5448e8d04bdc2ddf718b4569");
public static readonly MongoId GAS_BLOCK = new MongoId("56ea9461d2720b67698b456f");
public static readonly MongoId RAIL_COVER = new MongoId("55818b1d4bdc2d5b648b4572");
public static readonly MongoId DRINK = new MongoId("5448e8d64bdc2dce718b4568");
public static readonly MongoId BARREL = new MongoId("555ef6e44bdc2de9068b457e");
public static readonly MongoId BARTER_ITEM = new MongoId("5448eb774bdc2d0a728b4567");
public static readonly MongoId INFO = new MongoId("5448ecbe4bdc2d60728b4568");
public static readonly MongoId MEDKIT = new MongoId("5448f39d4bdc2d0a728b4568");
public static readonly MongoId BATTERY = new MongoId("57864ee62459775490116fc1");
public static readonly MongoId BIPOD = new MongoId("55818afb4bdc2dde698b456d");
public static readonly MongoId BUILDING_MATERIAL = new MongoId("57864ada245977548638de91");
public static readonly MongoId BUILT_IN_INSERTS = new MongoId("65649eb40bf0ed77b8044453");
public static readonly MongoId CHARGE = new MongoId("55818a6f4bdc2db9688b456b");
public static readonly MongoId COLLIMATOR = new MongoId("55818ad54bdc2ddc698b4569");
public static readonly MongoId COMPACT_COLLIMATOR = new MongoId("55818acf4bdc2dde698b456b");
public static readonly MongoId COMPASS = new MongoId("5f4fbaaca5573a5ac31db429");
public static readonly MongoId COMPENSATOR = new MongoId("550aa4af4bdc2dd4348b456e");
public static readonly MongoId COMPOUND_ITEM = new MongoId("566162e44bdc2d3f298b4573");
public static readonly MongoId CULTIST_AMULET = new MongoId("64b69b0c8f3be32ed22682f8");
public static readonly MongoId CYLINDER_MAGAZINE = new MongoId("610720f290b75a49ff2e5e25");
public static readonly MongoId DRINK = new MongoId("5448e8d64bdc2dce718b4568");
public static readonly MongoId DRUGS = new MongoId("5448f3a14bdc2d27728b4569");
public static readonly MongoId STIMULATOR = new MongoId("5448f3a64bdc2d60728b456a");
public static readonly MongoId MEDICAL = new MongoId("5448f3ac4bdc2dce718b4569");
public static readonly MongoId MEDICAL_SUPPLIES = new MongoId("57864c8c245977548867e7f1");
public static readonly MongoId MOD = new MongoId("5448fe124bdc2da5018b4567");
public static readonly MongoId FUNCTIONAL_MOD = new MongoId("550aa4154bdc2dd8348b456b");
public static readonly MongoId FUEL = new MongoId("5d650c3e815116009f6201d2");
public static readonly MongoId GEAR_MOD = new MongoId("55802f3e4bdc2de7118b4584");
public static readonly MongoId STOCK = new MongoId("55818a594bdc2db9688b456a");
public static readonly MongoId ELECTRONICS = new MongoId("57864a66245977548f04a81f");
public static readonly MongoId EQUIPMENT = new MongoId("543be5f84bdc2dd4348b456a");
public static readonly MongoId FACE_COVER = new MongoId("5a341c4686f77469e155819e");
public static readonly MongoId FLASH_HIDER = new MongoId("550aa4bf4bdc2dd6348b456b");
public static readonly MongoId FLASHLIGHT = new MongoId("55818b084bdc2d5b648b4571");
public static readonly MongoId FLYER = new MongoId("6759673c76e93d8eb20b2080");
public static readonly MongoId FOOD = new MongoId("5448e8d04bdc2ddf718b4569");
public static readonly MongoId FOOD_DRINK = new MongoId("543be6674bdc2df1348b4569");
public static readonly MongoId FOREGRIP = new MongoId("55818af64bdc2d5b648b4570");
public static readonly MongoId MASTER_MOD = new MongoId("55802f4a4bdc2ddb688b4569");
public static readonly MongoId MOUNT = new MongoId("55818b224bdc2dde698b456f");
public static readonly MongoId MUZZLE = new MongoId("5448fe394bdc2d0d028b456c");
public static readonly MongoId SIGHTS = new MongoId("5448fe7a4bdc2d6f028b456b");
public static readonly MongoId MEDS = new MongoId("543be5664bdc2dd4348b4569");
public static readonly MongoId MAP = new MongoId("567849dd4bdc2d150f8b456e");
public static readonly MongoId MONEY = new MongoId("543be5dd4bdc2deb348b4569");
public static readonly MongoId NIGHTVISION = new MongoId("5a2c3a9486f774688b05e574");
public static readonly MongoId THERMAL_VISION = new MongoId("5d21f59b6dbe99052b54ef83");
public static readonly MongoId FUEL = new MongoId("5d650c3e815116009f6201d2");
public static readonly MongoId FUNCTIONAL_MOD = new MongoId("550aa4154bdc2dd8348b456b");
public static readonly MongoId GASBLOCK = new MongoId("56ea9461d2720b67698b456f");
public static readonly MongoId GEAR_MOD = new MongoId("55802f3e4bdc2de7118b4584");
public static readonly MongoId GRENADE_LAUNCHER = new MongoId("5447bedf4bdc2d87278b4568");
public static readonly MongoId HANDGUARD = new MongoId("55818a104bdc2db9688b4569");
public static readonly MongoId HEADPHONES = new MongoId("5645bcb74bdc2ded0b8b4578");
public static readonly MongoId HEADWEAR = new MongoId("5a341c4086f77401f2541505");
public static readonly MongoId HIDEOUT_AREA_CONTAINER = new MongoId("63da6da4784a55176c018dba");
public static readonly MongoId HOUSEHOLD_GOODS = new MongoId("57864c322459775490116fbf");
public static readonly MongoId INFO = new MongoId("5448ecbe4bdc2d60728b4568");
public static readonly MongoId INVENTORY = new MongoId("55d720f24bdc2d88028b456d");
public static readonly MongoId IRON_SIGHT = new MongoId("55818ac54bdc2d5b648b456e");
public static readonly MongoId ITEM = new MongoId("54009119af1c881c07000029");
public static readonly MongoId JEWELRY = new MongoId("57864a3d24597754843f8721");
public static readonly MongoId KEY = new MongoId("543be5e94bdc2df1348b4568");
public static readonly MongoId KEY_MECHANICAL = new MongoId("5c99f98d86f7745c314214b3");
public static readonly MongoId KEYCARD = new MongoId("5c164d2286f774194c5e69fa");
public static readonly MongoId EQUIPMENT = new MongoId("543be5f84bdc2dd4348b456a");
public static readonly MongoId THROW_WEAPON = new MongoId("543be6564bdc2df4348b4568");
public static readonly MongoId FOOD_DRINK = new MongoId("543be6674bdc2df1348b4569");
public static readonly MongoId PISTOL = new MongoId("5447b5cf4bdc2d65278b4567");
public static readonly MongoId REVOLVER = new MongoId("617f1ef5e8b54b0998387733");
public static readonly MongoId SMG = new MongoId("5447b5e04bdc2d62278b4567");
public static readonly MongoId ASSAULT_RIFLE = new MongoId("5447b5f14bdc2d61278b4567");
public static readonly MongoId ASSAULT_CARBINE = new MongoId("5447b5fc4bdc2d87278b4567");
public static readonly MongoId SHOTGUN = new MongoId("5447b6094bdc2dc3278b4567");
public static readonly MongoId MARKSMAN_RIFLE = new MongoId("5447b6194bdc2d67278b4567");
public static readonly MongoId SNIPER_RIFLE = new MongoId("5447b6254bdc2dc3278b4568");
public static readonly MongoId MACHINE_GUN = new MongoId("5447bed64bdc2d97278b4568");
public static readonly MongoId GRENADE_LAUNCHER = new MongoId("5447bedf4bdc2d87278b4568");
public static readonly MongoId SPECIAL_WEAPON = new MongoId("5447bee84bdc2dc3278b4569");
public static readonly MongoId SPEC_ITEM = new MongoId("5447e0e74bdc2d3c308b4567");
public static readonly MongoId SPRING_DRIVEN_CYLINDER = new MongoId("627a137bf21bc425b06ab944");
public static readonly MongoId KNIFE = new MongoId("5447e1d04bdc2dff2f8b4567");
public static readonly MongoId AMMO = new MongoId("5485a8684bdc2da71d8b4567");
public static readonly MongoId AMMO_BOX = new MongoId("543be5cb4bdc2deb348b4568");
public static readonly MongoId LOOT_CONTAINER = new MongoId("566965d44bdc2d814c8b4571");
public static readonly MongoId MOB_CONTAINER = new MongoId("5448bf274bdc2dfc2f8b456a");
public static readonly MongoId SEARCHABLE_ITEM = new MongoId("566168634bdc2d144c8b456c");
public static readonly MongoId STASH = new MongoId("566abbb64bdc2d144c8b457d");
public static readonly MongoId SORTING_TABLE = new MongoId("6050cac987d3f925bf016837");
public static readonly MongoId LAUNCHER = new MongoId("55818b014bdc2ddc698b456b");
public static readonly MongoId LIGHT_LASER = new MongoId("55818b0e4bdc2dde698b456e");
public static readonly MongoId LOCKABLE_CONTAINER = new MongoId("5671435f4bdc2d96058b4569");
public static readonly MongoId SIMPLE_CONTAINER = new MongoId("5795f317245977243854e041");
public static readonly MongoId INVENTORY = new MongoId("55d720f24bdc2d88028b456d");
public static readonly MongoId STATIONARY_CONTAINER = new MongoId("567583764bdc2d98058b456e");
public static readonly MongoId POCKETS = new MongoId("557596e64bdc2dc2118b4571");
public static readonly MongoId ARMBAND = new MongoId("5b3f15d486f77432d0509248");
public static readonly MongoId JEWELRY = new MongoId("57864a3d24597754843f8721");
public static readonly MongoId ELECTRONICS = new MongoId("57864a66245977548f04a81f");
public static readonly MongoId BUILDING_MATERIAL = new MongoId("57864ada245977548638de91");
public static readonly MongoId TOOL = new MongoId("57864bb7245977548b3b66c2");
public static readonly MongoId HOUSEHOLD_GOODS = new MongoId("57864c322459775490116fbf");
public static readonly MongoId LOOT_CONTAINER = new MongoId("566965d44bdc2d814c8b4571");
public static readonly MongoId LUBRICANT = new MongoId("57864e4c24597754843f8723");
public static readonly MongoId BATTERY = new MongoId("57864ee62459775490116fc1");
public static readonly MongoId ASSAULT_SCOPE = new MongoId("55818add4bdc2d5b648b456f");
public static readonly MongoId TACTICAL_COMBO = new MongoId("55818b164bdc2ddc698b456c");
public static readonly MongoId FLASHLIGHT = new MongoId("55818b084bdc2d5b648b4571");
public static readonly MongoId MACHINE_GUN = new MongoId("5447bed64bdc2d97278b4568");
public static readonly MongoId MAGAZINE = new MongoId("5448bc234bdc2d3c308b4569");
public static readonly MongoId LIGHT_LASER_DESIGNATOR = new MongoId("55818b0e4bdc2dde698b456e");
public static readonly MongoId FLASH_HIDER = new MongoId("550aa4bf4bdc2dd6348b456b");
public static readonly MongoId COLLIMATOR = new MongoId("55818ad54bdc2ddc698b4569");
public static readonly MongoId IRON_SIGHT = new MongoId("55818ac54bdc2d5b648b456e");
public static readonly MongoId COMPACT_COLLIMATOR = new MongoId("55818acf4bdc2dde698b456b");
public static readonly MongoId COMPENSATOR = new MongoId("550aa4af4bdc2dd4348b456e");
public static readonly MongoId MAP = new MongoId("567849dd4bdc2d150f8b456e");
public static readonly MongoId MARK_OF_UNKNOWN = new MongoId("65ddcc7aef36f6413d0829b9");
public static readonly MongoId MARKSMAN_RIFLE = new MongoId("5447b6194bdc2d67278b4567");
public static readonly MongoId MASTER_MOD = new MongoId("55802f4a4bdc2ddb688b4569");
public static readonly MongoId MED_KIT = new MongoId("5448f39d4bdc2d0a728b4568");
public static readonly MongoId MEDICAL = new MongoId("5448f3ac4bdc2dce718b4569");
public static readonly MongoId MEDICAL_SUPPLIES = new MongoId("57864c8c245977548867e7f1");
public static readonly MongoId MEDS = new MongoId("543be5664bdc2dd4348b4569");
public static readonly MongoId MOB_CONTAINER = new MongoId("5448bf274bdc2dfc2f8b456a");
public static readonly MongoId MOD = new MongoId("5448fe124bdc2da5018b4567");
public static readonly MongoId MONEY = new MongoId("543be5dd4bdc2deb348b4569");
public static readonly MongoId MOUNT = new MongoId("55818b224bdc2dde698b456f");
public static readonly MongoId MULTITOOLS = new MongoId("66abb0743f4d8b145b1612c1");
public static readonly MongoId MUZZLE = new MongoId("5448fe394bdc2d0d028b456c");
public static readonly MongoId MUZZLE_COMBO = new MongoId("550aa4dd4bdc2dc9348b4569");
public static readonly MongoId NIGHT_VISION = new MongoId("5a2c3a9486f774688b05e574");
public static readonly MongoId OPTIC_SCOPE = new MongoId("55818ae44bdc2dde698b456c");
public static readonly MongoId SPECIAL_SCOPE = new MongoId("55818aeb4bdc2ddc698b456a");
public static readonly MongoId OTHER = new MongoId("590c745b86f7743cc433c5f2");
public static readonly MongoId SILENCER = new MongoId("550aa4cd4bdc2dd8348b456c");
public static readonly MongoId PORTABLE_RANGE_FINDER = new MongoId("61605ddea09d851a0a0c1bbc");
public static readonly MongoId ITEM = new MongoId("54009119af1c881c07000029");
public static readonly MongoId CYLINDER_MAGAZINE = new MongoId("610720f290b75a49ff2e5e25");
public static readonly MongoId AUXILIARY_MOD = new MongoId("5a74651486f7744e73386dd1");
public static readonly MongoId BIPOD = new MongoId("55818afb4bdc2dde698b456d");
public static readonly MongoId HEADPHONES = new MongoId("5645bcb74bdc2ded0b8b4578");
public static readonly MongoId RANDOM_LOOT_CONTAINER = new MongoId("62f109593b54472778797866");
public static readonly MongoId STACKABLE_ITEM = new MongoId("5661632d4bdc2d903d8b456b");
public static readonly MongoId BUILT_IN_INSERTS = new MongoId("65649eb40bf0ed77b8044453");
public static readonly MongoId ARMOR_PLATE = new MongoId("644120aa86ffbe10ee032b6f");
public static readonly MongoId CULTIST_AMULET = new MongoId("64b69b0c8f3be32ed22682f8");
public static readonly MongoId RADIO_TRANSMITTER = new MongoId("62e9103049c018f425059f38");
public static readonly MongoId HANDGUARD = new MongoId("55818a104bdc2db9688b4569");
public static readonly MongoId PISTOL = new MongoId("5447b5cf4bdc2d65278b4567");
public static readonly MongoId PISTOL_GRIP = new MongoId("55818a684bdc2ddd698b456d");
public static readonly MongoId PLANTING_KITS = new MongoId("6672e40ebb23210ae87d39eb");
public static readonly MongoId PMS = new MongoId("550ad14d4bdc2dd5348b456c");
public static readonly MongoId POCKETS = new MongoId("557596e64bdc2dc2118b4571");
public static readonly MongoId PORTABLE_RANGE_FINDER = new MongoId("61605ddea09d851a0a0c1bbc");
public static readonly MongoId RADIO_TRANSMITTER = new MongoId("62e9103049c018f425059f38");
public static readonly MongoId RAIL_COVERS = new MongoId("55818b1d4bdc2d5b648b4572");
public static readonly MongoId RANDOM_LOOT_CONTAINER = new MongoId("62f109593b54472778797866");
public static readonly MongoId RECEIVER = new MongoId("55818a304bdc2db5418b457d");
public static readonly MongoId BARREL = new MongoId("555ef6e44bdc2de9068b457e");
public static readonly MongoId CHARGING_HANDLE = new MongoId("55818a6f4bdc2db9688b456b");
public static readonly MongoId COMB_MUZZLE_DEVICE = new MongoId("550aa4dd4bdc2dc9348b4569");
public static readonly MongoId HIDEOUT_AREA_CONTAINER = new MongoId("63da6da4784a55176c018dba");
public static readonly MongoId REPAIR_KITS = new MongoId("616eb7aea207f41933308f46");
public static readonly MongoId REVOLVER = new MongoId("617f1ef5e8b54b0998387733");
public static readonly MongoId ROCKET = new MongoId("677ae5df4be46b83620bf055");
public static readonly MongoId ROCKET_LAUNCHER = new MongoId("67446d4f04141c10630604e7");
public static readonly MongoId SEARCHABLE_ITEM = new MongoId("566168634bdc2d144c8b456c");
public static readonly MongoId SHAFT = new MongoId("55818a604bdc2db5418b457e");
public static readonly MongoId SHOTGUN = new MongoId("5447b6094bdc2dc3278b4567");
public static readonly MongoId SIGHTS = new MongoId("5448fe7a4bdc2d6f028b456b");
public static readonly MongoId SILENCER = new MongoId("550aa4cd4bdc2dd8348b456c");
public static readonly MongoId SIMPLE_CONTAINER = new MongoId("5795f317245977243854e041");
public static readonly MongoId SMG = new MongoId("5447b5e04bdc2d62278b4567");
public static readonly MongoId SNIPER_RIFLE = new MongoId("5447b6254bdc2dc3278b4568");
public static readonly MongoId SORTING_TABLE = new MongoId("6050cac987d3f925bf016837");
public static readonly MongoId SPEC_ITEM = new MongoId("5447e0e74bdc2d3c308b4567");
public static readonly MongoId SPECIAL_SCOPE = new MongoId("55818aeb4bdc2ddc698b456a");
public static readonly MongoId SPECIAL_WEAPON = new MongoId("5447bee84bdc2dc3278b4569");
public static readonly MongoId SPRING_DRIVEN_CYLINDER = new MongoId("627a137bf21bc425b06ab944");
public static readonly MongoId STACKABLE_ITEM = new MongoId("5661632d4bdc2d903d8b456b");
public static readonly MongoId STASH = new MongoId("566abbb64bdc2d144c8b457d");
public static readonly MongoId STATIONARY_CONTAINER = new MongoId("567583764bdc2d98058b456e");
public static readonly MongoId STIMULATOR = new MongoId("5448f3a64bdc2d60728b456a");
public static readonly MongoId STOCK = new MongoId("55818a594bdc2db9688b456a");
public static readonly MongoId TACTICAL_COMBO = new MongoId("55818b164bdc2ddc698b456c");
public static readonly MongoId THERMAL_VISION = new MongoId("5d21f59b6dbe99052b54ef83");
public static readonly MongoId THROW_WEAP = new MongoId("543be6564bdc2df4348b4568");
public static readonly MongoId TOOL = new MongoId("57864bb7245977548b3b66c2");
public static readonly MongoId VEST = new MongoId("5448e5284bdc2dcb718b4567");
public static readonly MongoId VISORS = new MongoId("5448e5724bdc2ddf718b4568");
public static readonly MongoId WEAPON = new MongoId("5422acb9af1c889c16000029");
}
@@ -961,7 +961,7 @@ public class FenceService(
var isMedical = itemHelper.IsOfBaseclasses(
rootItemBeingAdded.Template,
[BaseClasses.MEDICAL, BaseClasses.MEDKIT]
[BaseClasses.MEDICAL, BaseClasses.MED_KIT]
);
var isGearAndHasSlots =
itemHelper.IsOfBaseclasses(
@@ -1566,7 +1566,7 @@ public class FenceService(
if (
(
itemDetails.Parent == BaseClasses.ARMORED_EQUIPMENT
|| itemDetails.Parent == BaseClasses.FACECOVER
|| itemDetails.Parent == BaseClasses.FACE_COVER
|| itemDetails.Parent == BaseClasses.ARMOR_PLATE
)
&& itemDetails.Properties.MaxDurability.GetValueOrDefault(0) > 0
@@ -0,0 +1,138 @@
using System.Text.RegularExpressions;
using MongoIdTplGenerator.Utils;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Utils;
using Path = System.IO.Path;
namespace MongoIdTplGenerator.Generators;
[Injectable]
public class BaseClassesIdGenerator(
ISptLogger<BaseClassesIdGenerator> logger,
DatabaseServer databaseServer,
FileUtil fileUtil,
LocaleUtil localeUtil
) : IMongoIdGenerator
{
private string _enumDir;
private Dictionary<MongoId, TemplateItem> _items;
public Task Run()
{
// Figure out our source and target directories
var projectDir = Directory.GetParent("./").Parent.Parent.Parent.Parent.Parent;
_enumDir = Path.Combine(
projectDir.FullName,
"Libraries",
"SPTarkov.Server.Core",
"Models",
"Enums"
);
_items = databaseServer.GetTables().Templates.Items;
// Generate an object containing all item name to ID associations
var orderedItemsObject = GenerateItemsObject();
// Log any changes to enum values, so the source can be updated as required
LogEnumValueChanges(orderedItemsObject, "BaseClasses", typeof(BaseClasses));
var itemTplOutPath = Path.Combine(_enumDir, "BaseClasses.cs");
WriteEnumsToFile(
itemTplOutPath,
new Dictionary<string, Dictionary<string, MongoId>>
{
{ nameof(BaseClasses), orderedItemsObject },
}
);
logger.Info("Generating items finished");
return Task.CompletedTask;
}
/// <summary>
/// Return an object containing all items in the game with a generated name
/// </summary>
/// <returns>An object containing a generated item name to item ID association</returns>
private Dictionary<string, MongoId> GenerateItemsObject()
{
var itemsObject = new Dictionary<string, MongoId>();
foreach (var item in _items.Values)
{
// Skip invalid items (Non-Item types, and shrapnel)
if (item.Type != "Node")
{
continue;
}
var underscoredName = Regex.Replace(item.Name, @"(?<!_|^)([A-Z])", "_$1");
var itemKey = $"{underscoredName.ToUpperInvariant()}";
// Strip out any remaining special characters
itemKey = localeUtil.SanitizeEnumKey(itemKey);
itemsObject[itemKey] = item.Id;
}
// Sort the items object
var itemList = itemsObject.ToList();
itemList.Sort((kv1, kv2) => kv1.Key.CompareTo(kv2.Key));
var orderedItemsObject = itemList.ToDictionary(kv => kv.Key, kv => kv.Value);
return orderedItemsObject;
}
private void LogEnumValueChanges(
Dictionary<string, MongoId> data,
string enumName,
Type originalEnum
)
{
// First generate a mapping of the original enum values to names
var originalEnumValues = new Dictionary<string, string>();
foreach (var field in originalEnum.GetFields())
{
originalEnumValues.Add(field.GetValue(null)!.ToString()!, field.Name);
}
// Loop through our new data, and find anywhere the given ID's name doesn't match the original enum
foreach (var kv in data)
{
if (originalEnumValues.ContainsKey(kv.Value) && originalEnumValues[kv.Value] != kv.Key)
{
logger.Warning(
$"Enum {enumName} key has changed for {kv.Value}, {originalEnumValues[kv.Value]} => {kv.Key}"
);
}
}
}
private void WriteEnumsToFile(
string outputPath,
Dictionary<string, Dictionary<string, MongoId>> enumEntries
)
{
var enumFileData =
"using SPTarkov.Server.Core.Models.Common;\n\n"
+ "// This is an auto generated file, do not modify. Re-generate by running MongoIdTplGenerator.exe";
foreach (var (enumName, data) in enumEntries)
{
enumFileData += $"\npublic static class {enumName}\n{{\n";
foreach (var (key, value) in data)
{
enumFileData +=
$" public static readonly MongoId {key} = new MongoId(\"{value}\");\n";
}
enumFileData += "}\n";
}
fileUtil.WriteFile(outputPath, enumFileData);
}
}
@@ -4,7 +4,6 @@ using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
@@ -249,7 +248,7 @@ public class ItemTplMongoIdGenerator(
return "BARTER";
}
if (itemHelper.IsOfBaseclass(item.Id, BaseClasses.THROW_WEAPON))
if (itemHelper.IsOfBaseclass(item.Id, BaseClasses.THROW_WEAP))
{
return "GRENADE";
}