using UnityEngine; namespace IdleSpectator; /// Registers book creation/burn interest candidates. 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 = entry.MakeLabel(EventFeedUtil.SafeName(follow), phase ?? ""); if (!string.IsNullOrEmpty(phase) && phase == "burn") { label = "Book burned: " + EventFeedUtil.SafeName(follow); } string key = "book:" + entry.Id + ":" + (phase ?? "new") + ":" + EventFeedUtil.SafeId(follow); InterestOwnership owns = phase == "burn" ? InterestOwnership.Signal : entry.OwnsCamera; float strength = phase == "burn" ? Mathf.Max(entry.EventStrength, 70f) : entry.EventStrength; EventFeedUtil.Register( key, "book", entry.Category, label, entry.Id, strength, owns, 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); } }