34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System;
|
|
|
|
namespace Jovian.EncounterSystem {
|
|
/// <summary>
|
|
/// Cross-table reference to an <see cref="IEncounter"/>. Stores the owning
|
|
/// <see cref="EncounterTable"/> asset and the target encounter's <see cref="EncounterDefinition.internalId"/>.
|
|
/// Rename-safe because the stored key is a GUID.
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct EncounterLink {
|
|
/// <summary>The table that owns the linked encounter.</summary>
|
|
public EncounterTable table;
|
|
|
|
/// <summary>The target encounter's stable GUID (<see cref="EncounterDefinition.internalId"/>).</summary>
|
|
public string internalId;
|
|
|
|
/// <summary>Look up the referenced encounter, or <c>null</c> if the table is missing or the id
|
|
/// no longer exists in it.</summary>
|
|
public IEncounter Resolve() {
|
|
if(table == null || table.encounters == null || string.IsNullOrEmpty(internalId)) {
|
|
return null;
|
|
}
|
|
|
|
foreach(var encounter in table.encounters) {
|
|
if(encounter?.EncounterDefinition?.internalId == internalId) {
|
|
return encounter;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|