3 using System.Collections.Immutable;
5 using System.Reflection;
16 private readonly ImmutableHashSet<Identifier> tags;
17 public ImmutableHashSet<Identifier>
Tags => tags;
80 return new EventPrefab(element, file, fallbackIdentifier);
85 : base(file, element.GetAttributeIdentifier(
"identifier", fallbackIdentifier))
94 DebugConsole.ThrowError(
"Could not find an event class of the type \"" +
ConfigElement.
Name +
"\".",
100 DebugConsole.ThrowError(
"Could not find an event class of the type \"" +
ConfigElement.
Name +
"\".",
124 return instance is not
null;
129 ConstructorInfo constructor =
EventType.GetConstructor(
new[] { GetType(), typeof(
int) });
130 Event instance =
null;
133 instance = constructor.Invoke(
new object[] {
this, seed }) as
Event;
137 DebugConsole.ThrowError(ex.InnerException !=
null ? ex.InnerException.ToString() : ex.ToString());
147 return $
"{nameof(EventPrefab)} ({Identifier})";
152 var unlockPathEvents =
Prefabs.OrderBy(p => p.Identifier).Where(e => e.UnlockPathEvent);
153 if (faction !=
null && unlockPathEvents.Any(e => e.Faction == faction.
Prefab.Identifier))
155 unlockPathEvents = unlockPathEvents.Where(e => e.Faction == faction.
Prefab.Identifier);
158 unlockPathEvents.FirstOrDefault(ep => ep.BiomeIdentifier == biomeIdentifier) ??
159 unlockPathEvents.FirstOrDefault(ep => ep.BiomeIdentifier ==
Identifier.Empty);
170 if (!identifier.IsEmpty)
173 if (eventPrefab ==
null)
175 DebugConsole.ThrowError($
"Failed to find an event prefab with the identifier {identifier}.",
176 contentPackage: source);
179 else if (!tag.IsEmpty)
182 if (eventPrefab ==
null)
184 DebugConsole.ThrowError($
"Failed to find an event prefab with the tag {tag}.",
185 contentPackage: source);
190 DebugConsole.ThrowError($
"Failed to find an event prefab: neither an identifier or tag were defined.",
191 contentPackage: source);
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
Identifier NameAsIdentifier()
bool GetAttributeBool(string key, bool def)
int GetAttributeInt(string key, int def)
ImmutableHashSet< Identifier > GetAttributeIdentifierImmutableHashSet(string key, ImmutableHashSet< Identifier >? def, bool trim=true)
Identifier GetAttributeIdentifier(string key, string def)
virtual bool LevelMeetsRequirements()
readonly Identifier BiomeIdentifier
If set, the event set can only be chosen in this biome.
readonly LocalizedString Name
readonly Identifier RequiredLayer
If set, this layer must be present somewhere in the level.
Event CreateInstance(int seed)
readonly bool UnlockPathEvent
If set, this event is used as an event that can unlock a path to the next biome.
readonly string UnlockPathTooltip
Only valid if UnlockPathEvent is set to true. The tooltip displayed on the pathway this event is bloc...
readonly float Commonness
The commonness of the event (i.e. how likely it is for this specific event to be chosen from the even...
EventPrefab(ContentXElement element, RandomEventsFile file, Identifier fallbackIdentifier=default)
override string ToString()
ImmutableHashSet< Identifier > Tags
static EventPrefab Create(ContentXElement element, RandomEventsFile file, Identifier fallbackIdentifier=default)
readonly bool TriggerEventCooldown
When this event occurs, should it trigger the event cooldown during which no new events are triggered...
bool TryCreateInstance< T >(int seed, out T instance)
static EventPrefab FindEventPrefab(Identifier identifier, Identifier tag, ContentPackage source)
Finds an event prefab with the specified identifier, or if it isn't defined, a random event prefab wi...
readonly Identifier RequiredSpawnPointTag
If set, this spawn point tag must be present somewhere in the level.
static EventPrefab GetUnlockPathEvent(Identifier biomeIdentifier, Faction faction)
readonly ContentXElement ConfigElement
readonly Identifier Faction
If set, the event set can only be chosen in locations that belong to this faction.
readonly int UnlockPathReputation
Only valid if UnlockPathEvent is set to true. The reputation requirement displayed on the pathway thi...
readonly float Probability
The probability for the event to do something if it gets selected. For example, the probability for a...
static readonly PrefabCollection< EventPrefab > Prefabs
Event sets are sets of random events that occur within a level (most commonly, monster spawns and scr...
static EventPrefab GetEventPrefab(Identifier identifier)
static List< EventPrefab > GetAllEventPrefabs()
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.
readonly Identifier Identifier