跳转到内容

生命周期事件

Mod 需要游戏时机但不需要自己拥有 Harmony patch 时,使用生命周期事件。

var subscription = RitsuLibFramework.SubscribeLifecycle<GameReadyEvent>(evt =>
{
Logger.Info($"Game ready: {evt.Game.Name}");
});

临时 handler 用完后 dispose 返回的 subscription。

RitsuLibFramework.SubscribeLifecycle<CombatStartingEvent>((evt, sub) =>
{
PrepareForCombat(evt.RunState);
sub.Dispose();
});

可重放事件默认会立即补发给后订阅者。只想接收未来事件时,传 replayCurrentState: false。

时机事件
框架启动FrameworkInitializingEvent、FrameworkInitializedEvent
模型设置ContentRegistrationClosedEvent、ModelRegistryInitializedEvent、ModelIdsInitializedEvent、ModelPreloadingCompletedEvent
游戏节点GameTreeEnteredEvent、GameReadyEvent
档位与存档ProfileIdInitializedEvent、ProfileSwitchingEvent、ProfileSwitchedEvent、RunSavingEvent、RunSavedEvent、ProgressSavingEvent、ProgressSavedEvent、ProfileDeletingEvent、ProfileDeletedEvent
Run 流程RunStartedEvent、RunLoadedEvent、RunEndedEvent、RoomEnteringEvent、RoomEnteredEvent、RoomExitedEvent、ActEnteringEvent、ActEnteredEvent
战斗CombatStartingEvent、CombatEndedEvent、CombatVictoryEvent、SideTurnStartingEvent、SideTurnStartedEvent、CardPlayingEvent、CardPlayedEvent
卡牌CardMovedBetweenPilesEvent、CardDrawnEvent、CardDiscardedEvent、CardExhaustedEvent、BeforeFlushEvent、CardsFlushedEvent
奖励与物品栏GoldGainedEvent、GoldLostEvent、PotionProcuredEvent、PotionDiscardedEvent、RelicObtainedEvent、RelicRemovedEvent、RewardTakenEvent
解锁EpochObtainedEvent、EpochRevealedEvent、UnlockIncrementedEvent

CardRetainedEvent 在较新 host API 上已过时。需要同时观察 retained 和 flushed cards 时,使用 CardsFlushedEvent。

影响事件可用性的游戏 API 差异见 诊断与兼容。