82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>Registers book creation/burn interest candidates.</summary>
|
|
public static class BookInterestFeed
|
|
{
|
|
public static void Emit(string bookTypeId, Actor subject, string phase)
|
|
{
|
|
if (AgentHarness.Busy)
|
|
{
|
|
return;
|
|
}
|
|
|
|
DiscreteEventEntry entry = BookInterestCatalog.GetOrFallback(bookTypeId);
|
|
if (!entry.CreatesInterest)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Actor follow = subject;
|
|
if (follow == null || !follow.isAlive())
|
|
{
|
|
// Book without a living author: skip rather than invent a stranger.
|
|
return;
|
|
}
|
|
|
|
string label = EventReason.Apply(entry.LabelTemplate, follow, id: entry.Id);
|
|
if (!string.IsNullOrEmpty(phase) && phase == "burn")
|
|
{
|
|
label = EventFeedUtil.SafeName(follow) + " burns a book";
|
|
}
|
|
|
|
string key = "book:" + entry.Id + ":" + (phase ?? "new") + ":" + EventFeedUtil.SafeId(follow);
|
|
float strength = phase == "burn" ? Mathf.Max(entry.EventStrength, 70f) : entry.EventStrength;
|
|
EventFeedUtil.Register(
|
|
key,
|
|
"book",
|
|
entry.Category,
|
|
label,
|
|
entry.Id,
|
|
strength,
|
|
follow.current_position,
|
|
follow);
|
|
}
|
|
|
|
public static void EmitFromBook(object book, string phase)
|
|
{
|
|
if (book == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string typeId = "unknown";
|
|
Actor author = null;
|
|
try
|
|
{
|
|
object asset = book.GetType().GetField("asset")?.GetValue(book)
|
|
?? book.GetType().GetProperty("asset")?.GetValue(book, null)
|
|
?? book.GetType().GetMethod("getAsset")?.Invoke(book, null);
|
|
if (asset != null)
|
|
{
|
|
object id = asset.GetType().GetField("id")?.GetValue(asset)
|
|
?? asset.GetType().GetProperty("id")?.GetValue(asset, null);
|
|
if (id != null)
|
|
{
|
|
typeId = id.ToString();
|
|
}
|
|
}
|
|
|
|
author = book.GetType().GetField("author")?.GetValue(book) as Actor
|
|
?? book.GetType().GetProperty("author")?.GetValue(book, null) as Actor
|
|
?? book.GetType().GetMethod("getAuthor")?.Invoke(book, null) as Actor;
|
|
}
|
|
catch
|
|
{
|
|
// ignore
|
|
}
|
|
|
|
Emit(typeId, author, phase);
|
|
}
|
|
}
|