Track LocalMods as part of monolith
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Barotrauma;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MoreLevelContent.Shared.Data
|
||||
{
|
||||
class Character_MLCData
|
||||
{
|
||||
public XElement NPCElement;
|
||||
public bool IsDistressShuttle;
|
||||
public bool IsDistressDiver;
|
||||
}
|
||||
|
||||
public static partial class MLCData
|
||||
{
|
||||
private static readonly ConditionalWeakTable<Character, Character_MLCData> character_data = new();
|
||||
|
||||
internal static Character_MLCData MLC(this Character characterData) => character_data.GetOrCreateValue(characterData);
|
||||
|
||||
internal static void AddData(this Character characterData, Character_MLCData additional)
|
||||
{
|
||||
try
|
||||
{
|
||||
character_data.Add(characterData, additional);
|
||||
}
|
||||
catch (Exception e) { Log.Error(e.ToString()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Barotrauma;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MoreLevelContent.Shared.Data
|
||||
{
|
||||
public class DataBase
|
||||
{
|
||||
public void SaveData(XElement saveFile)
|
||||
{
|
||||
var saveFields = GetSaveFields();
|
||||
foreach (var field in saveFields)
|
||||
{
|
||||
saveFile.SetAttributeValue(field.Name, field.GetValue(this));
|
||||
}
|
||||
SaveSpecific(saveFile);
|
||||
}
|
||||
|
||||
public void LoadData(XElement saveFile)
|
||||
{
|
||||
var saveFields = GetSaveFields();
|
||||
foreach (var field in saveFields)
|
||||
{
|
||||
XAttribute attr = saveFile.GetAttribute(field.Name);
|
||||
if (attr != null)
|
||||
{
|
||||
if (field.FieldType.IsEnum)
|
||||
{
|
||||
field.SetValue(this, Enum.Parse(field.FieldType, attr.Value));
|
||||
continue;
|
||||
}
|
||||
field.SetValue(this, Convert.ChangeType(attr.Value, field.FieldType));
|
||||
}
|
||||
else
|
||||
{
|
||||
field.SetValue(this, ((AttributeSaveData)field.GetCustomAttribute(typeof(AttributeSaveData))).DefaultFieldValue);
|
||||
}
|
||||
}
|
||||
LoadSpecific(saveFile);
|
||||
}
|
||||
|
||||
protected virtual void LoadSpecific(XElement saveFile) { }
|
||||
protected virtual void SaveSpecific(XElement saveFile) { }
|
||||
|
||||
private IEnumerable<FieldInfo> GetSaveFields() => GetType().GetFields().Where(f => f.IsDefined(typeof(AttributeSaveData), false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple data that can be stringified into an xml attribute
|
||||
/// </summary>
|
||||
public class AttributeSaveData : Attribute
|
||||
{
|
||||
public AttributeSaveData(object defaultValue) => DefaultFieldValue = defaultValue;
|
||||
|
||||
public object DefaultFieldValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
using Barotrauma;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using MoreLevelContent.Shared.Generation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MoreLevelContent.Shared.Data
|
||||
{
|
||||
public class LevelData_MLCData : DataBase
|
||||
{
|
||||
[AttributeSaveData(false)]
|
||||
public bool HasBeaconConstruction;
|
||||
|
||||
[AttributeSaveData(false)]
|
||||
public bool HasDistress;
|
||||
|
||||
[AttributeSaveData(7)]
|
||||
public int DistressStepsLeft;
|
||||
|
||||
[AttributeSaveData(false)]
|
||||
public bool HasPirateActivity;
|
||||
|
||||
[AttributeSaveData(false)]
|
||||
public bool HasBlackMarket;
|
||||
|
||||
[AttributeSaveData(RelayStationStatus.None)]
|
||||
public RelayStationStatus RelayStationStatus;
|
||||
|
||||
[AttributeSaveData(false)]
|
||||
public bool HasLostCargo;
|
||||
|
||||
[AttributeSaveData(4)]
|
||||
public int CargoStepsLeft;
|
||||
|
||||
[AttributeSaveData(0)]
|
||||
public int RequestedU;
|
||||
|
||||
[AttributeSaveData(0)]
|
||||
public int RequestedS;
|
||||
|
||||
[AttributeSaveData(0)]
|
||||
public int RequestedE;
|
||||
|
||||
[AttributeSaveData(TriangulationTarget.None)]
|
||||
public TriangulationTarget TriangulationTarget;
|
||||
|
||||
public MapFeatureData MapFeatureData;
|
||||
|
||||
internal PirateData PirateData;
|
||||
|
||||
public LevelData_MLCData()
|
||||
{
|
||||
MapFeatureData = new MapFeatureData();
|
||||
PirateData = new PirateData();
|
||||
}
|
||||
|
||||
public bool HasRelayStation => RelayStationStatus != RelayStationStatus.None;
|
||||
|
||||
public LocalizedString GetRequestedSupplies()
|
||||
{
|
||||
List<LocalizedString> requestedSuppliesList = new();
|
||||
|
||||
// Utility
|
||||
if (RequestedU > 0)
|
||||
{
|
||||
requestedSuppliesList.Add(TextManager.GetWithVariable("mlc.beaconconstutility", "[count]", RequestedU.ToString()));
|
||||
}
|
||||
|
||||
// Structural
|
||||
if (RequestedS > 0)
|
||||
{
|
||||
requestedSuppliesList.Add(TextManager.GetWithVariable("mlc.beaconconststructural", "[count]", RequestedS.ToString()));
|
||||
}
|
||||
|
||||
// Electrical
|
||||
if (RequestedE > 0)
|
||||
{
|
||||
requestedSuppliesList.Add(TextManager.GetWithVariable("mlc.beaconconstelectrical", "[count]", RequestedE.ToString()));
|
||||
}
|
||||
switch (requestedSuppliesList.Count)
|
||||
{
|
||||
case 1:
|
||||
return TextManager.GetWithVariable("mlc.beaconconstone", "[supply1]", requestedSuppliesList[0]);
|
||||
case 2:
|
||||
return TextManager.GetWithVariables("mlc.beaconconsttwo", ("[supply1]", requestedSuppliesList[0]), ("[supply2]", requestedSuppliesList[1]));
|
||||
case 3:
|
||||
return TextManager.GetWithVariables("mlc.beaconconstthree", ("[supply1]", requestedSuppliesList[0]), ("[supply2]", requestedSuppliesList[1]), ("[supply3]", requestedSuppliesList[2]));
|
||||
default:
|
||||
Log.Error($"Invalid amount of requested supplies {requestedSuppliesList.Count}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void LoadSpecific(XElement saveFile)
|
||||
{
|
||||
var pirateData = saveFile.GetChildElement("PirateData");
|
||||
if (pirateData != null)
|
||||
{
|
||||
PirateData = new PirateData()
|
||||
{
|
||||
Status = pirateData.GetAttributeEnum("status", PirateOutpostStatus.None),
|
||||
Difficulty = pirateData.GetAttributeFloat("difficulty", 0),
|
||||
Revealed = pirateData.GetAttributeBool("revealed", false)
|
||||
};
|
||||
}
|
||||
var mapFeatureData = saveFile.GetChildElement("MapFeatureData");
|
||||
if (mapFeatureData != null)
|
||||
{
|
||||
MapFeatureData = new MapFeatureData()
|
||||
{
|
||||
Name = mapFeatureData.GetAttributeIdentifier("name", null),
|
||||
Revealed = mapFeatureData.GetAttributeBool("revealed", false)
|
||||
};
|
||||
if (MapFeatureModule.TryGetFeature(MapFeatureData.Name, out MapFeature feature))
|
||||
{
|
||||
MapFeatureData.Feature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SaveSpecific(XElement saveFile)
|
||||
{
|
||||
var pirateData = new XElement("PirateData",
|
||||
new XAttribute("status", PirateData.Status),
|
||||
new XAttribute("difficulty", PirateData.Difficulty),
|
||||
new XAttribute("revealed", PirateData.Revealed));
|
||||
|
||||
var mapFeatureData = new XElement("MapFeatureData",
|
||||
new XAttribute("name", MapFeatureData.Name),
|
||||
new XAttribute("revealed", MapFeatureData.Revealed));
|
||||
|
||||
saveFile.Add(pirateData);
|
||||
saveFile.Add(mapFeatureData);
|
||||
}
|
||||
}
|
||||
|
||||
public class MapFeatureData
|
||||
{
|
||||
public Identifier Name;
|
||||
public bool Revealed;
|
||||
internal MapFeature Feature;
|
||||
public bool HasFeature => Feature != null;
|
||||
}
|
||||
|
||||
public static partial class MLCData
|
||||
{
|
||||
private static readonly ConditionalWeakTable<LevelData, LevelData_MLCData> levelData_data = new();
|
||||
|
||||
internal static LevelData_MLCData MLC(this LevelData levelData) => levelData_data.GetOrCreateValue(levelData);
|
||||
|
||||
internal static void AddData(this LevelData levelData, LevelData_MLCData additional)
|
||||
{
|
||||
try
|
||||
{
|
||||
levelData_data.Add(levelData, additional);
|
||||
} catch(Exception e) { Log.Error(e.ToString()); }
|
||||
}
|
||||
}
|
||||
|
||||
public enum PirateOutpostStatus
|
||||
{
|
||||
None,
|
||||
Active,
|
||||
Destroyed,
|
||||
Husked
|
||||
}
|
||||
|
||||
public enum RelayStationStatus
|
||||
{
|
||||
None,
|
||||
Inactive,
|
||||
Active
|
||||
}
|
||||
|
||||
public enum TriangulationTarget
|
||||
{
|
||||
None,
|
||||
MapFeature,
|
||||
PirateBase,
|
||||
Treasure
|
||||
}
|
||||
|
||||
internal class PirateData
|
||||
{
|
||||
public PirateData()
|
||||
{
|
||||
Status = PirateOutpostStatus.None;
|
||||
Difficulty = 0;
|
||||
Revealed = false;
|
||||
}
|
||||
|
||||
public PirateData(PirateSpawnData spawnData)
|
||||
{
|
||||
Difficulty = 0;
|
||||
Status = PirateOutpostStatus.None;
|
||||
Revealed = false;
|
||||
|
||||
if (spawnData.WillSpawn)
|
||||
{
|
||||
Status = PirateOutpostStatus.Active;
|
||||
Difficulty = spawnData.PirateDifficulty;
|
||||
|
||||
if (spawnData.Husked)
|
||||
{
|
||||
Status = PirateOutpostStatus.Husked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PirateOutpostStatus Status;
|
||||
public float Difficulty;
|
||||
public bool Revealed;
|
||||
|
||||
public bool HasPirateBase => Status != PirateOutpostStatus.None;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Barotrauma;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MoreLevelContent.Shared.Data
|
||||
{
|
||||
class Level_MLCData : DataBase
|
||||
{
|
||||
public ContentFile RelayStationFile;
|
||||
public Submarine BeaconConstructionStation;
|
||||
public Submarine RelayStation;
|
||||
public Item DropOffPoint;
|
||||
|
||||
public bool CheckSuppliesDelivered()
|
||||
{
|
||||
if (DropOffPoint == null)
|
||||
{
|
||||
Log.Error("No drop off point specified!!");
|
||||
return false;
|
||||
}
|
||||
int uCount = DropOffPoint.ContainedItems.Where(it => it.Tags.Contains("supply_utility")).Count();
|
||||
int sCount = DropOffPoint.ContainedItems.Where(it => it.Tags.Contains("supply_structural")).Count();
|
||||
int eCount = DropOffPoint.ContainedItems.Where(it => it.Tags.Contains("supply_electrical")).Count();
|
||||
return
|
||||
uCount >= Level.Loaded.LevelData.MLC().RequestedU && // electrical
|
||||
sCount >= Level.Loaded.LevelData.MLC().RequestedS && // structural
|
||||
eCount >= Level.Loaded.LevelData.MLC().RequestedE; // electrical
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class MLCData
|
||||
{
|
||||
private static readonly ConditionalWeakTable<Level, Level_MLCData> level_data = new();
|
||||
|
||||
internal static Level_MLCData MLC(this Level levelData) => level_data.GetOrCreateValue(levelData);
|
||||
|
||||
internal static void AddData(this Level levelData, Level_MLCData additional)
|
||||
{
|
||||
try
|
||||
{
|
||||
level_data.Add(levelData, additional);
|
||||
}
|
||||
catch (Exception e) { Log.Error(e.ToString()); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user