Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -6,12 +6,25 @@ using Microsoft.Xna.Framework;
namespace Barotrauma
{
class EventManagerSettings
class EventManagerSettings : PrefabWithUintIdentifier
{
public static readonly List<EventManagerSettings> List = new List<EventManagerSettings>();
public static readonly PrefabCollection<EventManagerSettings> Prefabs = new PrefabCollection<EventManagerSettings>();
public static IOrderedEnumerable<EventManagerSettings> OrderedByDifficulty
{
get
{
return Prefabs.OrderBy(p => (p.MinLevelDifficulty + p.MaxLevelDifficulty) * 0.5f)
.ThenBy(p => p.UintIdentifier);
}
}
public readonly string Identifier;
public readonly string Name;
public static EventManagerSettings GetByDifficultyPercentile(float p)
{
EventManagerSettings[] settings = OrderedByDifficulty.ToArray();
return settings[Math.Clamp((int)(settings.Length * p), 0, settings.Length - 1)];
}
public readonly LocalizedString Name;
//How much the event threshold increases per second. 0.0005f = 0.03f per minute
public readonly float EventThresholdIncrease = 0.0005f;
@@ -26,61 +39,19 @@ namespace Barotrauma
public readonly float FreezeDurationWhenCrewAway = 60.0f * 10.0f;
public static void Init()
public override void Dispose() { }
public EventManagerSettings(XElement element, EventManagerSettingsFile file) : base(file, element.NameAsIdentifier())
{
List.Clear();
foreach (ContentFile file in GameMain.Instance.GetFilesOfType(ContentType.EventManagerSettings))
{
Load(file);
}
}
Name = TextManager.Get("difficulty." + Identifier).Fallback(Identifier.Value);
EventThresholdIncrease = element.GetAttributeFloat("EventThresholdIncrease", EventThresholdIncrease);
DefaultEventThreshold = element.GetAttributeFloat("DefaultEventThreshold", DefaultEventThreshold);
EventCooldown = element.GetAttributeFloat("EventCooldown", EventCooldown);
private static void Load(ContentFile file)
{
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
if (doc == null) { return; }
var mainElement = doc.Root;
bool allowOverriding = false;
if (doc.Root.IsOverride())
{
mainElement = doc.Root.FirstElement();
allowOverriding = true;
}
foreach (XElement subElement in mainElement.Elements())
{
var element = subElement.IsOverride() ? subElement.FirstElement() : subElement;
string identifier = element.Name.ToString();
var duplicate = List.FirstOrDefault(e => e.Identifier.ToString().Equals(identifier, StringComparison.OrdinalIgnoreCase));
if (duplicate != null)
{
if (allowOverriding || subElement.IsOverride())
{
DebugConsole.NewMessage($"Overriding the existing preset '{identifier}' in the event manager settings using the file '{file.Path}'", Color.Yellow);
List.Remove(duplicate);
}
else
{
DebugConsole.ThrowError($"Error in '{file.Path}': Another element with the name '{identifier}' found! Each element must have a unique name. Use <override></override> tags if you want to override an existing preset.");
continue;
}
}
List.Add(new EventManagerSettings(element));
}
List.Sort((x, y) => { return Math.Sign((x.MinLevelDifficulty + x.MaxLevelDifficulty) / 2.0f - (y.MinLevelDifficulty + y.MaxLevelDifficulty) / 2.0f); });
}
MinLevelDifficulty = element.GetAttributeFloat("MinLevelDifficulty", MinLevelDifficulty);
MaxLevelDifficulty = element.GetAttributeFloat("MaxLevelDifficulty", MaxLevelDifficulty);
public EventManagerSettings(XElement element)
{
Identifier = element.Name.ToString();
Name = TextManager.Get("difficulty." + Identifier, returnNull: true) ?? Identifier;
EventThresholdIncrease = element.GetAttributeFloat("EventThresholdIncrease", 0.0005f);
DefaultEventThreshold = element.GetAttributeFloat("DefaultEventThreshold", 0.2f);
EventCooldown = element.GetAttributeFloat("EventCooldown", 360.0f);
MinLevelDifficulty = element.GetAttributeFloat("MinLevelDifficulty", 0.0f);
MaxLevelDifficulty = element.GetAttributeFloat("MaxLevelDifficulty", 100.0f);
FreezeDurationWhenCrewAway = element.GetAttributeFloat("FreezeDurationWhenCrewAway", 10.0f * 60.0f);
FreezeDurationWhenCrewAway = element.GetAttributeFloat("FreezeDurationWhenCrewAway", FreezeDurationWhenCrewAway);
}
}
}