refactor(mod): renamed project file and made build script zip releases automagically
This commit is contained in:
123
WeebSights/Services/WeebItemService.cs
Normal file
123
WeebSights/Services/WeebItemService.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
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;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
using WeebSights.Models;
|
||||
|
||||
namespace WeebSights.Services;
|
||||
|
||||
[Injectable(TypePriority = OnLoadOrder.PostDBModLoader + 3)]
|
||||
public class WeebItemService(ISptLogger<WeebItemService> logger, JsonUtil jsonUtil, CustomItemService customItemService, DatabaseService databaseService)
|
||||
{
|
||||
public bool TryLoadConfig(string filePath, out List<WeebItemConfig> outputObject)
|
||||
{
|
||||
var json = LoadConfig(filePath);
|
||||
if (json is null)
|
||||
{
|
||||
outputObject = [];
|
||||
return false;
|
||||
}
|
||||
|
||||
outputObject = json;
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<WeebItemConfig>? LoadConfig(string filePath)
|
||||
{
|
||||
return jsonUtil.DeserializeFromFile<List<WeebItemConfig>>(filePath);
|
||||
}
|
||||
|
||||
public void AddIronSightToFilters(WeebItemConfig 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;
|
||||
}
|
||||
#if DEBUG
|
||||
logger.Success($"[Weeb Iron Sights] Added {sight.Id} to filter on item {item.Key}");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<CreateItemResult> GenerateItems(List<WeebItemConfig> items, Dictionary<MongoId, WeebLocaleConfig> locales)
|
||||
{
|
||||
if (items.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!locales.TryGetValue(item.Id, out var localeConfig))
|
||||
{
|
||||
logger.Error($"[Weeb Iron Sights] Failed to load locale for {item.Id}, using IDs for name");
|
||||
localeConfig = new WeebLocaleConfig()
|
||||
{
|
||||
Name = item.Id,
|
||||
Description = "FAILED TO LOAD LOCALES",
|
||||
ShortName = "WEEBSIGHT",
|
||||
};
|
||||
}
|
||||
|
||||
NewItemFromCloneDetails clonedItem = new()
|
||||
{
|
||||
NewId = item.Id,
|
||||
ItemTplToClone = item.CloneFromTpl,
|
||||
ParentId = "55818ac54bdc2d5b648b456e", // Ironsight
|
||||
HandbookParentId = "5b5f746686f77447ec5d7708", // CATEGORY
|
||||
HandbookPriceRoubles = item.Price,
|
||||
OverrideProperties = new TemplateItemProperties()
|
||||
{
|
||||
Ergonomics = item.Ergonomics,
|
||||
CreditsPrice = item.Price,
|
||||
Prefab = new Prefab()
|
||||
{
|
||||
Path = item.BundlePath
|
||||
},
|
||||
},
|
||||
Locales = new Dictionary<string, LocaleDetails>
|
||||
{
|
||||
{
|
||||
"en", new LocaleDetails()
|
||||
{
|
||||
Name = localeConfig.Name,
|
||||
ShortName = localeConfig.ShortName,
|
||||
Description = localeConfig.Description,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var itemCreation = customItemService.CreateItemFromClone(clonedItem);
|
||||
if (itemCreation.Success is false or null)
|
||||
{
|
||||
logger.Error($"[Weeb Iron Sights] Failed to clone item {item.CloneFromTpl} into {item.Id}");
|
||||
itemCreation.Errors?.ForEach(e => logger.Critical("[Weeb Iron Sights] " + e));
|
||||
continue;
|
||||
}
|
||||
|
||||
AddIronSightToFilters(item);
|
||||
yield return itemCreation;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
WeebSights/Services/WeebLocaleService.cs
Normal file
29
WeebSights/Services/WeebLocaleService.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
using WeebSights.Models;
|
||||
|
||||
namespace WeebSights.Services;
|
||||
|
||||
[Injectable]
|
||||
public class WeebLocaleService(JsonUtil jsonUtil)
|
||||
{
|
||||
public bool TryLoadLocales(string filePath, out Dictionary<MongoId, WeebLocaleConfig> outputObject)
|
||||
{
|
||||
var json = LoadLocales(filePath);
|
||||
if (json == null)
|
||||
{
|
||||
outputObject = new Dictionary<MongoId, WeebLocaleConfig>();
|
||||
return false;
|
||||
}
|
||||
|
||||
outputObject = json;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Dictionary<MongoId, WeebLocaleConfig>? LoadLocales(string filePath)
|
||||
{
|
||||
return jsonUtil.DeserializeFromFile<Dictionary<MongoId, WeebLocaleConfig>>(filePath);
|
||||
}
|
||||
}
|
||||
73
WeebSights/Services/WeebTraderService.cs
Normal file
73
WeebSights/Services/WeebTraderService.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Extensions;
|
||||
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.Spt.Mod;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
|
||||
namespace WeebSights.Services;
|
||||
|
||||
[Injectable]
|
||||
public class WeebTraderService(ISptLogger<WeebTraderService> logger, DatabaseService databaseService)
|
||||
{
|
||||
public bool AddToAssortFromItemClone(MongoId traderId, IEnumerable<CreateItemResult> itemCloneResults)
|
||||
{
|
||||
if (!databaseService.GetTables().Traders.TryGetValue(traderId, out var trader))
|
||||
{
|
||||
logger.Error($"[Weeb Iron Sights] Failed to find trader with ID {traderId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var itemResult in itemCloneResults)
|
||||
{
|
||||
var item = databaseService.GetItems().First(i => i.Key == itemResult.ItemId);
|
||||
var traderItem = GenerateItemForTrader(item);
|
||||
var traderBarter = new BarterScheme()
|
||||
{
|
||||
Count = item.Value.Properties?.CreditsPrice ?? 1,
|
||||
Template = CurrencyType.RUB.GetCurrencyTpl()
|
||||
};
|
||||
|
||||
trader.Assort.Items.Add(traderItem);
|
||||
if (!trader.Assort.BarterScheme.TryAdd(traderItem.Id, [[traderBarter]]))
|
||||
{
|
||||
logger.Error(
|
||||
$"[Weeb Iron Sights] Failed to add barter {traderItem.Id} for item {item.Value.Name} with ID {item.Value.Id} in {trader.Base.Name}. Item will not be added");
|
||||
trader.Assort.Items.Remove(traderItem);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!trader.Assort.LoyalLevelItems.TryAdd(traderItem.Id, 1))
|
||||
{
|
||||
logger.Critical(
|
||||
$"[Weeb Iron Sight] Failed to add loyalty requirements for item {item.Value.Name} with ID {item.Value.Id} in {trader.Base.Name}. Item will not be added");
|
||||
trader.Assort.Items.Remove(traderItem);
|
||||
continue;
|
||||
}
|
||||
#if DEBUG
|
||||
logger.Success($"[Weeb Iron Sights] Added item {traderItem.Id} with ID {item.Value.Id} and barter {traderItem.Id} to MECHANIC");
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Item GenerateItemForTrader(KeyValuePair<MongoId, TemplateItem> databaseItem)
|
||||
{
|
||||
return new Item
|
||||
{
|
||||
Id = new MongoId(),
|
||||
Template = databaseItem.Value.Id,
|
||||
ParentId = "hideout",
|
||||
SlotId = "hideout",
|
||||
Upd = new Upd()
|
||||
{
|
||||
UnlimitedCount = true,
|
||||
StackObjectsCount = 99999,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user