feat(sights): added sights to the filters
This commit is contained in:
@@ -4,15 +4,17 @@ using moe.yuyui.weebsights_port.Interfaces;
|
|||||||
using moe.yuyui.weebsights_port.Models;
|
using moe.yuyui.weebsights_port.Models;
|
||||||
using SPTarkov.DI.Annotations;
|
using SPTarkov.DI.Annotations;
|
||||||
using SPTarkov.Server.Core.DI;
|
using SPTarkov.Server.Core.DI;
|
||||||
|
using SPTarkov.Server.Core.Models.Common;
|
||||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||||
using SPTarkov.Server.Core.Models.Spt.Mod;
|
using SPTarkov.Server.Core.Models.Spt.Mod;
|
||||||
using SPTarkov.Server.Core.Models.Utils;
|
using SPTarkov.Server.Core.Models.Utils;
|
||||||
|
using SPTarkov.Server.Core.Services;
|
||||||
using SPTarkov.Server.Core.Services.Mod;
|
using SPTarkov.Server.Core.Services.Mod;
|
||||||
|
|
||||||
namespace moe.yuyui.weebsights_port.Items;
|
namespace moe.yuyui.weebsights_port.Items;
|
||||||
|
|
||||||
[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 2)]
|
[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
|
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));
|
itemCreation.Errors?.ForEach(e => logger.Critical("[Weeb Iron Sights] " + e));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
AddItemToFilters(sight);
|
||||||
yield return itemCreation;
|
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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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.Enums;
|
||||||
using moe.yuyui.weebsights_port.Items;
|
using moe.yuyui.weebsights_port.Items;
|
||||||
using moe.yuyui.weebsights_port.Locales;
|
using moe.yuyui.weebsights_port.Locales;
|
||||||
using SPTarkov.DI.Annotations;
|
using SPTarkov.DI.Annotations;
|
||||||
using SPTarkov.Server.Core.DI;
|
using SPTarkov.Server.Core.DI;
|
||||||
using SPTarkov.Server.Core.Models.Utils;
|
using SPTarkov.Server.Core.Models.Utils;
|
||||||
|
using SPTarkov.Server.Core.Services;
|
||||||
|
|
||||||
namespace moe.yuyui.weebsights_port;
|
namespace moe.yuyui.weebsights_port;
|
||||||
|
|
||||||
[Injectable(TypePriority = OnLoadOrder.PostSptModLoader + 1)]
|
[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()
|
public Task OnLoad()
|
||||||
{
|
{
|
||||||
if (!englishLocale.LoadLocales())
|
var stopWatch = Stopwatch.StartNew();
|
||||||
{
|
|
||||||
logger.Error("[Weeb Iron Sights] Failed to load locales, you may see garbled text");
|
|
||||||
}
|
|
||||||
|
|
||||||
var sightsMbus = itemGenerator.GenerateWeebSights<ESightsMbus>();
|
var sightsMbus = itemGenerator.GenerateWeebSights<ESightsMbus>();
|
||||||
var sightsMcx = itemGenerator.GenerateWeebSights<ESightsMcx>();
|
var sightsMcx = itemGenerator.GenerateWeebSights<ESightsMcx>();
|
||||||
if (!mechanicAssort.InjectAssortFromItemClone(sightsMbus))
|
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");
|
logger.Critical("[Weeb Iron Sights] Failed to inject MBUS Sights");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!mechanicAssort.InjectAssortFromItemClone(sightsMcx))
|
if (!mechanicAssort.InjectAssortFromItemClone(sightsMcx))
|
||||||
{
|
{
|
||||||
logger.Critical("[Weeb Iron Sights] Failed to inject MCX Sights");
|
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;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,4 +2,4 @@ using SPTarkov.Server.Core.Models.Common;
|
|||||||
|
|
||||||
namespace moe.yuyui.weebsights_port.Models;
|
namespace moe.yuyui.weebsights_port.Models;
|
||||||
|
|
||||||
public record WeebSight(MongoId Id, string Asset, MongoId? CloneFromTpl);
|
public record WeebSight(MongoId Id, string Asset, MongoId CloneFromTpl);
|
||||||
|
|||||||
Reference in New Issue
Block a user