Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -1,4 +1,6 @@
using System;
using Barotrauma.Extensions;
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
@@ -11,6 +13,9 @@ namespace Barotrauma
public readonly ContentXElement ConfigElement;
public readonly Type EventType;
private readonly ImmutableHashSet<Identifier> tags;
public ImmutableHashSet<Identifier> Tags => tags;
/// <summary>
/// The probability for the event to do something if it gets selected. For example, the probability for a MonsterEvent to spawn the monster(s).
/// </summary>
@@ -37,6 +42,11 @@ namespace Barotrauma
/// </summary>
public readonly Identifier RequiredLayer;
/// <summary>
/// If set, this spawn point tag must be present somewhere in the level.
/// </summary>
public readonly Identifier RequiredSpawnPointTag;
/// <summary>
/// If set, the event set can only be chosen in locations that belong to this faction.
/// </summary>
@@ -93,6 +103,7 @@ namespace Barotrauma
Name = TextManager.Get($"eventname.{Identifier}").Fallback(Identifier.ToString());
tags = ConfigElement.GetAttributeIdentifierImmutableHashSet(nameof(tags), ImmutableHashSet<Identifier>.Empty);
BiomeIdentifier = ConfigElement.GetAttributeIdentifier("biome", Identifier.Empty);
Faction = ConfigElement.GetAttributeIdentifier("faction", Identifier.Empty);
Commonness = element.GetAttributeFloat("commonness", 1.0f);
@@ -100,6 +111,7 @@ namespace Barotrauma
TriggerEventCooldown = element.GetAttributeBool("triggereventcooldown", EventType != typeof(ScriptedEvent));
RequiredLayer = element.GetAttributeIdentifier(nameof(RequiredLayer), Identifier.Empty);
RequiredSpawnPointTag = element.GetAttributeIdentifier(nameof(RequiredSpawnPointTag), Identifier.Empty);
UnlockPathEvent = element.GetAttributeBool("unlockpathevent", false);
UnlockPathTooltip = element.GetAttributeString("unlockpathtooltip", "lockedpathtooltip");
@@ -146,5 +158,39 @@ namespace Barotrauma
unlockPathEvents.FirstOrDefault(ep => ep.BiomeIdentifier == biomeIdentifier) ??
unlockPathEvents.FirstOrDefault(ep => ep.BiomeIdentifier == Identifier.Empty);
}
/// <summary>
/// Finds an event prefab with the specified identifier, or if it isn't defined, a random event prefab with the specified tag.
/// </summary>
/// <param name="source">Which content package is trying to find the event (if any)? Only used for logging error messages.</param>
/// <returns></returns>
public static EventPrefab FindEventPrefab(Identifier identifier, Identifier tag, ContentPackage source)
{
EventPrefab eventPrefab = null;
if (!identifier.IsEmpty)
{
eventPrefab = EventSet.GetEventPrefab(identifier);
if (eventPrefab == null)
{
DebugConsole.ThrowError($"Failed to find an event prefab with the identifier {identifier}.",
contentPackage: source);
}
}
else if (!tag.IsEmpty)
{
eventPrefab = EventSet.GetAllEventPrefabs().Where(e => e.Tags.Contains(tag)).GetRandomUnsynced();
if (eventPrefab == null)
{
DebugConsole.ThrowError($"Failed to find an event prefab with the tag {tag}.",
contentPackage: source);
}
}
else
{
DebugConsole.ThrowError($"Failed to find an event prefab: neither an identifier or tag were defined.",
contentPackage: source);
}
return eventPrefab;
}
}
}