From 478ed639aa849dd891619ece14ebeadd6833f047 Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 10 Feb 2025 17:01:07 +0000 Subject: [PATCH] Add 18.1 mod example --- .../18.1CustomItemServiceLootBox.csproj | 32 +++++ .../CustomItemServiceLootBox.cs | 115 ++++++++++++++++++ .../18.1CustomItemServiceLootBox/package.json | 13 ++ .../18CustomItemService.csproj | 14 +-- ModExamples/ModExamples.sln | 6 + 5 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 ModExamples/18.1CustomItemServiceLootBox/18.1CustomItemServiceLootBox.csproj create mode 100644 ModExamples/18.1CustomItemServiceLootBox/CustomItemServiceLootBox.cs create mode 100644 ModExamples/18.1CustomItemServiceLootBox/package.json diff --git a/ModExamples/18.1CustomItemServiceLootBox/18.1CustomItemServiceLootBox.csproj b/ModExamples/18.1CustomItemServiceLootBox/18.1CustomItemServiceLootBox.csproj new file mode 100644 index 00000000..acd88995 --- /dev/null +++ b/ModExamples/18.1CustomItemServiceLootBox/18.1CustomItemServiceLootBox.csproj @@ -0,0 +1,32 @@ + + + + net9.0 + _18._1CustomItemServiceLootBox + enable + enable + Library + + + + + + ..\TempReferences\Core.dll + false + false + false + + + ..\TempReferences\SptCommon.dll + false + false + false + + + ..\TempReferences\SptDependencyInjection.dll + false + false + false + + + diff --git a/ModExamples/18.1CustomItemServiceLootBox/CustomItemServiceLootBox.cs b/ModExamples/18.1CustomItemServiceLootBox/CustomItemServiceLootBox.cs new file mode 100644 index 00000000..0a4bb1d4 --- /dev/null +++ b/ModExamples/18.1CustomItemServiceLootBox/CustomItemServiceLootBox.cs @@ -0,0 +1,115 @@ +using Core.Models.Eft.Common.Tables; +using Core.Models.External; +using Core.Models.Spt.Config; +using Core.Models.Spt.Mod; +using Core.Models.Utils; +using Core.Servers; +using Core.Services.Mod; + +namespace _18._1CustomItemServiceLootBox; + +public class CustomItemServiceLootBox : IPostDBLoadMod, IPostSptLoadMod +{ + private CustomItemService _customItemService; + private DatabaseServer _databaseServer; + private ConfigServer _configServer; + private readonly ISptLogger _logger; + private Dictionary _itemDb; + + private InventoryConfig _inventoryConfig; + + public CustomItemServiceLootBox( + DatabaseServer databaseServer, + ConfigServer configServer, + ISptLogger logger, + CustomItemService customItemService + ) + { + _databaseServer = databaseServer; + _configServer = configServer; + _logger = logger; + _customItemService = customItemService; + + _inventoryConfig = _configServer.GetConfig(); + } + + public void PostDBLoad() + { + _itemDb = _databaseServer.GetTables().Templates.Items; + + // Example of adding new item by cloning existing item using createclonedetails + var crateId = "new_crate_with_randomized_content"; + var exampleCloneItem = new NewItemFromCloneDetails + { + // The item we want to clone, in this example i will cloning the sealed weapon crate + ItemTplToClone = "6489b2b131a2135f0d7d0fcb", + // ParentId refers to the Node item the container will be under, you can check it in https://db.sp-tarkov.com/search + ParentId = "62f109593b54472778797866", + // The new id of our cloned item + NewId = crateId, + FleaPriceRoubles = 50000, + HandbookPriceRoubles = 42500, + // Handbook Parent Id refers to the category the container will be under + // Handbook parent can be found in SPT_Data\Server\database\templates. + HandbookParentId = "62f109593b54472778797866", + Locales = new Dictionary + { + {"en", new LocaleDetails + { + Name = "Custom Lootbox", + ShortName = "Custom Lootbox", + Description = "A custom lootbox container" + } + } + }, + OverrideProperties = new Props + { + Name = "Custom Lootbox", + ShortName = "Custom Lootbox", + Description = "A custom lootbox container", + Weight = 15 + }, + }; + + // Basically calls the function and tell the server to add our Cloned new item into the server + _customItemService.CreateItemFromClone(exampleCloneItem); + + // Change item _name to remove it from the *actual* sealed weapon crate logic, this removes it from airdrops and allows easier access to change the contents + + var customItemInDb = _itemDb.GetValueOrDefault(crateId); + customItemInDb.Name = crateId; + + // Add to inventory config with custom item pool + _inventoryConfig.RandomLootContainers[crateId] = new RewardDetails + { + RewardCount = 6, + FoundInRaid = true, + RewardTplPool = new Dictionary + { + {"57514643245977207f2c2d09", 1}, + {"544fb62a4bdc2dfb738b4568", 1}, + {"57513f07245977207e26a311", 1}, + {"57513f9324597720a7128161", 1}, + {"57513fcc24597720a31c09a6", 1}, + {"5e8f3423fd7471236e6e3b64", 1}, + {"60b0f93284c20f0feb453da7", 1}, + {"5734773724597737fd047c14", 1}, + {"59e3577886f774176a362503", 1}, + {"57505f6224597709a92585a9", 1}, + {"544fb6cc4bdc2d34748b456e", 1} + } + }; + } + + // Check if our item is in the server or not + public void PostSptLoad() + { + if (_itemDb.TryGetValue("new_crate_with_randomized_content", out var crate)) + { + _logger.LogWithColor("Item Exists in DB"); + return; + } + + _logger.LogWithColor("Item Doesn't Exist in DB"); + } +} diff --git a/ModExamples/18.1CustomItemServiceLootBox/package.json b/ModExamples/18.1CustomItemServiceLootBox/package.json new file mode 100644 index 00000000..64c28a96 --- /dev/null +++ b/ModExamples/18.1CustomItemServiceLootBox/package.json @@ -0,0 +1,13 @@ +{ + "Name": "18.1CustomItemServiceLootBox", + "Version": "1.0.0", + "SptVersion": "~4.0", + "LoadBefore": [], + "LoadAfter": [], + "IncompatibileMods": [], + "Url": "https://github.com/sp-tarkov/server-csharp/tree/develop/ExampleMods/Mods", + "IsBundleMod": false, + "Author": "SPT", + "Contributors": [], + "Licence": "MIT" +} diff --git a/ModExamples/18CustomItemService/18CustomItemService.csproj b/ModExamples/18CustomItemService/18CustomItemService.csproj index 3a793a15..209bcf8e 100644 --- a/ModExamples/18CustomItemService/18CustomItemService.csproj +++ b/ModExamples/18CustomItemService/18CustomItemService.csproj @@ -1,12 +1,12 @@  - - net9.0 - _18CustomItemService - enable - enable - Library - + + net9.0 + _18CustomItemService + enable + enable + Library + diff --git a/ModExamples/ModExamples.sln b/ModExamples/ModExamples.sln index 7475d4c6..3d47b25a 100644 --- a/ModExamples/ModExamples.sln +++ b/ModExamples/ModExamples.sln @@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "15HttpListenerExample", "15 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18CustomItemService", "18CustomItemService\18CustomItemService.csproj", "{ADE10F29-58D6-4C13-B217-7C737DFB413A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18.1CustomItemServiceLootBox", "18.1CustomItemServiceLootBox\18.1CustomItemServiceLootBox.csproj", "{B870C285-B435-4C40-89C4-0220D34CB9BE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -105,6 +107,10 @@ Global {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Debug|Any CPU.Build.0 = Debug|Any CPU {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Release|Any CPU.ActiveCfg = Release|Any CPU {ADE10F29-58D6-4C13-B217-7C737DFB413A}.Release|Any CPU.Build.0 = Release|Any CPU + {B870C285-B435-4C40-89C4-0220D34CB9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B870C285-B435-4C40-89C4-0220D34CB9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B870C285-B435-4C40-89C4-0220D34CB9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B870C285-B435-4C40-89C4-0220D34CB9BE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE