feat(sights): added sights to the filters

This commit is contained in:
Yui
2025-11-04 00:29:53 -03:00
parent 9103b884f2
commit 99c737c672
3 changed files with 42 additions and 9 deletions

View File

@@ -4,15 +4,17 @@ using moe.yuyui.weebsights_port.Interfaces;
using moe.yuyui.weebsights_port.Models;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Spt.Mod;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Services.Mod;
namespace moe.yuyui.weebsights_port.Items;
[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 2)]
public class ItemGenerator(ISptLogger<ItemGenerator> logger, CustomItemService customItemService)
public class ItemGenerator(ISptLogger<ItemGenerator> logger, CustomItemService customItemService, DatabaseService databaseService)
{
public IEnumerable<CreateItemResult> GenerateWeebSights<T>() where T : IWeebSightEnum
{
@@ -61,7 +63,34 @@ public class ItemGenerator(ISptLogger<ItemGenerator> logger, CustomItemService c
itemCreation.Errors?.ForEach(e => logger.Critical("[Weeb Iron Sights] " + e));
continue;
}
AddItemToFilters(sight);
yield return itemCreation;
}
}
private void AddItemToFilters(WeebSight sight)
{
var itemsWithSlots = databaseService.GetTemplates().Items.Where(i => i.Value.Properties?.Slots?.Count() > 0);
foreach (var item in itemsWithSlots)
{
var backIronSightSlot = item.Value.Properties?.Slots?.FirstOrDefault(s => s.Name == "mod_sight_rear");
if (backIronSightSlot == null)
{
continue;
}
var slotFilter = backIronSightSlot?.Properties?.Filters?.FirstOrDefault(f => f.Filter?.Contains(sight.CloneFromTpl) ?? false);
if (slotFilter == null)
{
continue;
}
if (slotFilter.Filter?.Add(sight.Id) is false)
{
logger.Error("[Weeb Iron Sights] Failed to add filter to item " + item.Key);
continue;
}
logger.Success($"[Weeb Iron Sights] Added {sight.Id} to filter on item {item.Key}");
}
}
}

View File

@@ -1,23 +1,23 @@
using moe.yuyui.weebsights_port.Assorts;
using System.Diagnostics;
using moe.yuyui.weebsights_port.Assorts;
using moe.yuyui.weebsights_port.Enums;
using moe.yuyui.weebsights_port.Items;
using moe.yuyui.weebsights_port.Locales;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Services;
namespace moe.yuyui.weebsights_port;
[Injectable(TypePriority = OnLoadOrder.PostSptModLoader + 1)]
public class Mod(ISptLogger<Mod> logger, EnglishLocale englishLocale, MechanicAssort mechanicAssort, ItemGenerator itemGenerator): IOnLoad
public class Mod(ISptLogger<Mod> logger,
MechanicAssort mechanicAssort,
ItemGenerator itemGenerator): IOnLoad
{
public Task OnLoad()
{
if (!englishLocale.LoadLocales())
{
logger.Error("[Weeb Iron Sights] Failed to load locales, you may see garbled text");
}
var stopWatch = Stopwatch.StartNew();
var sightsMbus = itemGenerator.GenerateWeebSights<ESightsMbus>();
var sightsMcx = itemGenerator.GenerateWeebSights<ESightsMcx>();
if (!mechanicAssort.InjectAssortFromItemClone(sightsMbus))
@@ -25,10 +25,14 @@ public class Mod(ISptLogger<Mod> logger, EnglishLocale englishLocale, MechanicAs
logger.Critical("[Weeb Iron Sights] Failed to inject MBUS Sights");
}
if (!mechanicAssort.InjectAssortFromItemClone(sightsMcx))
{
logger.Critical("[Weeb Iron Sights] Failed to inject MCX Sights");
}
stopWatch.Stop();
logger.Success($"[Weeb Iron Sights] Loaded in {stopWatch.ElapsedMilliseconds} ms");
return Task.CompletedTask;
}
}

View File

@@ -2,4 +2,4 @@ using SPTarkov.Server.Core.Models.Common;
namespace moe.yuyui.weebsights_port.Models;
public record WeebSight(MongoId Id, string Asset, MongoId? CloneFromTpl);
public record WeebSight(MongoId Id, string Asset, MongoId CloneFromTpl);