worldbox-observer-mod/IdleSpectator/RelationshipEventCatalog.cs

89 lines
3 KiB
C#

using System;
using System.Collections.Generic;
namespace IdleSpectator;
public sealed class DiscreteEventEntry
{
public string Id = "";
public float EventStrength = 50f;
public string Category = "Event";
public bool CreatesInterest = true;
public string LabelTemplate = "{a}";
public bool IsFallback;
public string MakeLabel(Actor a, Actor b = null)
{
return EventReason.Apply(LabelTemplate, a, b, Id);
}
public string MakeLabel(string a, string b)
{
string template = string.IsNullOrEmpty(LabelTemplate) ? "{id}" : LabelTemplate;
return template
.Replace("{id}", Id ?? "")
.Replace("{a}", a ?? "")
.Replace("{b}", b ?? "");
}
}
/// <summary>Authored discrete relationship lifecycle events (not a live asset library).</summary>
public static class RelationshipEventCatalog
{
private static readonly Dictionary<string, DiscreteEventEntry> Entries =
new Dictionary<string, DiscreteEventEntry>(StringComparer.OrdinalIgnoreCase);
static RelationshipEventCatalog()
{
Add("set_lover", 72f, "Relationship", "{a} became lovers with {b}");
Add("clear_lover", 55f, "Relationship", "{a} parted from a lover");
Add("add_child", 68f, "Relationship", "{a} and {b} have a new child");
Add("new_family", 70f, "Relationship", "{a} starts a new family");
Add("family_removed", 50f, "Relationship", "{a}'s family ends");
Add("find_lover", 45f, "Relationship", "{a} is seeking a lover");
Add("family_group_new", 60f, "Relationship", "{a} forms a family pack");
Add("family_group_join", 36f, "Relationship", "{a} joins a family pack", createsInterest: false);
Add("family_group_leave", 36f, "Relationship", "{a} leaves a family pack", createsInterest: false);
Add("baby_created", 70f, "Relationship", "{a} welcomes a baby");
}
private static void Add(
string id,
float strength,
string category,
string label,
bool createsInterest = true)
{
Entries[id] = new DiscreteEventEntry
{
Id = id,
EventStrength = strength,
Category = category,
CreatesInterest = createsInterest,
LabelTemplate = label
};
}
public static IEnumerable<string> AuthoredIds => Entries.Keys;
public static bool HasAuthored(string id) =>
!string.IsNullOrEmpty(id) && Entries.ContainsKey(id.Trim());
public static DiscreteEventEntry GetOrFallback(string id)
{
if (!string.IsNullOrEmpty(id) && Entries.TryGetValue(id.Trim(), out DiscreteEventEntry entry))
{
return entry;
}
string key = string.IsNullOrEmpty(id) ? "unknown" : id.Trim();
return new DiscreteEventEntry
{
Id = key,
EventStrength = 40f,
Category = "Relationship",
LabelTemplate = "{a} · {id}",
IsFallback = true
};
}
}