Track LocalMods as part of monolith

This commit is contained in:
2026-06-08 18:50:16 +03:00
parent 143f2fed7c
commit 1b214b44c2
1287 changed files with 139255 additions and 1 deletions
@@ -0,0 +1,29 @@
using Barotrauma;
using Barotrauma.Extensions;
using MoreLevelContent.Shared.Generation;
using MoreLevelContent.Shared.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MoreLevelContent.Shared.Store
{
public class BeaconConstStore : StoreBase<BeaconConstStore>
{
private List<OutpostModuleFile> ConstBeacons = new();
public override void Setup() => HasContent = FindConstBeacons();
internal OutpostModuleFile GetBeaconForLevel()
{
Random rand = MLCUtils.GetLevelRandom();
return ConstBeacons.GetRandom(rand);
}
bool FindConstBeacons()
{
ConstBeacons = GetOutpostModuleFilesWithLocation("mlc_BeaconConstruction");
return ConstBeacons.Count() > 0;
// ConstBeacons.Sort();
}
}
}
@@ -0,0 +1,9 @@
namespace MoreLevelContent.Shared.Store
{
public class LevelDataStore : StoreBase<LevelDataStore>
{
public override void Setup() => throw new System.NotImplementedException();
}
}
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Barotrauma;
using Barotrauma.Extensions;
using MoreLevelContent.Shared.Generation;
using static Barotrauma.Level;
namespace MoreLevelContent.Shared.Store
{
public class PirateStore : StoreBase<PirateStore>
{
private List<PirateOutpostDef> pirateOutposts;
private List<PirateNPCSetDef> pirateSets;
public override void Setup()
{
pirateOutposts = new List<PirateOutpostDef>();
pirateSets = new List<PirateNPCSetDef>();
HasContent = FindAndScoreOutpostFiles() && FindAndScoreNPCs();
}
internal PirateOutpostDef FindOutpostWithPath(string path)
{
return pirateOutposts.Find(p => p.SubInfo.FilePath == path);
}
internal void DumpPirateOutposts()
{
if (pirateOutposts.Count == 0)
{
Log.Warn("No pirate outposts found!");
return;
}
foreach (var item in pirateOutposts)
{
Log.Debug(item.SubInfo.FilePath);
}
}
public PirateNPCSetDef GetNPCSetForDiff(float diff, string seed) => GetElementWithPreferedDifficulty(diff, pirateSets, seed);
internal PirateOutpostDef GetPirateOutpostForDiff(float diff, string seed) => GetElementWithPreferedDifficulty(diff, pirateOutposts, seed);
private bool FindAndScoreOutpostFiles()
{
Log.Debug("Collecting pirate outposts...");
var pirateOutpostSets = MissionPrefab.Prefabs.Where(m => m.Tags.Contains("pirateoutpostset"));
Log.Debug($"outposts: {pirateOutpostSets.Count()}");
foreach (var item in pirateOutpostSets)
{
foreach (var outpost in item.ConfigElement.GetChildElements("PirateOutpost"))
{
var path = outpost.GetAttributeContentPath("path");
var min = outpost.GetAttributeInt("mindiff", 0);
var max = outpost.GetAttributeInt("maxdiff", 100);
var placement = outpost.GetAttributeEnum("placement", PlacementType.Bottom);
SubmarineInfo subInfo = new SubmarineInfo(path.Value);
pirateOutposts.Add(new PirateOutpostDef(subInfo, min, max, placement));
}
}
pirateOutposts = pirateOutposts.OrderBy(o => o.SubInfo.Name).ToList();
foreach (var item in pirateOutposts)
{
Log.Verbose(item.DifficultyRange.ToString());
}
if (pirateOutposts.Count > 0)
{
Log.Debug($"Collected {pirateOutposts.Count} pirate outposts");
return true;
}
else
{
Log.Error("Failed to find any pirate outposts!!!");
return false;
}
}
private bool FindAndScoreNPCs()
{
List<MissionPrefab> pirateMissions = MissionPrefab.Prefabs.Where(m => m.Identifier.StartsWith("mlc_mp")).ToList();
foreach (MissionPrefab prefab in pirateMissions)
{
pirateSets.Add(new PirateNPCSetDef(prefab, prefab.Name.Value));
}
Log.Verbose("Sorting sets by their diff ranges...");
pirateSets.Sort();
if (pirateSets.Count == 0)
{
Log.Error("Failed to find pirates to spawn :(");
return false;
}
Log.Verbose($"Collected {pirateSets.Count} pirate NPC sets to choose from.");
return true;
}
}
}
@@ -0,0 +1,67 @@
using Barotrauma;
using Barotrauma.MoreLevelContent.Shared.Utils;
using MoreLevelContent.Shared.Generation;
using MoreLevelContent.Shared.Generation.Pirate;
using MoreLevelContent.Shared.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MoreLevelContent.Shared.Store
{
public abstract class StoreBase<T> : Singleton<T> where T : class
{
public static bool HasContent { get; protected set; }
protected Element GetElementWithPreferedDifficulty<Element>(float preferedDifficulty, List<Element> elements, string seed, float maxDifference = 20f) where Element : DefWithDifficultyRange
{
Log.InternalDebug($"Looking for {typeof(Element).Name} with perfered difficulty of {preferedDifficulty}...");
List<Element> filtered = elements;
try
{
filtered = elements.Where(e => MathF.Abs(e.AverageDifficulty - preferedDifficulty) < maxDifference).ToList();
} catch(Exception e)
{
Log.Error(e.ToString());
}
if (filtered.Count == 0)
{
Log.Warn($"Failed to find element of type '{nameof(Element)}' with prefered difficulty of {preferedDifficulty} with a max differential of {maxDifference}!");
filtered = elements;
}
Log.Verbose($"Filtered sets of '{nameof(Element)}' to choose from {filtered.Count}");
filtered = filtered.OrderBy(e => e.AverageDifficulty).ToList();
var rand = new MTRandom(ToolBox.StringToInt(seed));
Element selectedElement = ToolBox.SelectWeightedRandom(filtered, (elm) =>
{
return elm.AverageDifficulty > preferedDifficulty
? preferedDifficulty / elm.AverageDifficulty
: elm.AverageDifficulty / preferedDifficulty;
}, rand);
return selectedElement;
}
internal List<OutpostModuleFile> GetOutpostModuleFilesWithLocation(string locationType)
{
var outpostModuleFiles = ContentPackageManager.EnabledPackages.All
.SelectMany(p => p.GetFiles<OutpostModuleFile>())
.OrderBy(f => f.UintIdentifier).ToList();
List<OutpostModuleFile> modulesWithTag = new();
foreach (var outpostModuleFile in outpostModuleFiles)
{
SubmarineInfo subInfo = new SubmarineInfo(outpostModuleFile.Path.Value);
if (subInfo.OutpostModuleInfo != null)
{
if (subInfo.OutpostModuleInfo.AllowedLocationTypes.Contains(locationType))
modulesWithTag.Add(outpostModuleFile);
}
}
return modulesWithTag;
}
}
}