Add 18.1 mod example

This commit is contained in:
CWX
2025-02-10 17:01:07 +00:00
parent 69e8796035
commit 478ed639aa
5 changed files with 173 additions and 7 deletions
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>_18._1CustomItemServiceLootBox</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<!-- TODO: Change to Nuget Package -->
<ItemGroup>
<Reference Include="Core">
<HintPath>..\TempReferences\Core.dll</HintPath>
<Private>false</Private>
<CopyLocal>false</CopyLocal>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
<Reference Include="SptCommon">
<HintPath>..\TempReferences\SptCommon.dll</HintPath>
<Private>false</Private>
<CopyLocal>false</CopyLocal>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
<Reference Include="SptDependencyInjection">
<HintPath>..\TempReferences\SptDependencyInjection.dll</HintPath>
<Private>false</Private>
<CopyLocal>false</CopyLocal>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
</ItemGroup>
</Project>
@@ -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<CustomItemServiceLootBox> _logger;
private Dictionary<string, TemplateItem> _itemDb;
private InventoryConfig _inventoryConfig;
public CustomItemServiceLootBox(
DatabaseServer databaseServer,
ConfigServer configServer,
ISptLogger<CustomItemServiceLootBox> logger,
CustomItemService customItemService
)
{
_databaseServer = databaseServer;
_configServer = configServer;
_logger = logger;
_customItemService = customItemService;
_inventoryConfig = _configServer.GetConfig<InventoryConfig>();
}
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<string, LocaleDetails>
{
{"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<string, double>
{
{"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");
}
}
@@ -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"
}
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>_18CustomItemService</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>_18CustomItemService</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
</PropertyGroup>
<!-- TODO: Change to Nuget Package -->
<ItemGroup>
+6
View File
@@ -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