Lifecycle Events

Subscribe

Use lifecycle events when a mod needs game timing but does not need to own a Harmony patch.

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

Dispose the returned subscription when the handler is temporary.

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

Replayable events are delivered immediately to late subscribers by default. Pass replayCurrentState: false when you only want future events.

订阅

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

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

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

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

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

Common Events

TimingEvents
Framework bootFrameworkInitializingEvent, FrameworkInitializedEvent
Model setupContentRegistrationClosedEvent, ModelRegistryInitializedEvent, ModelIdsInitializedEvent, ModelPreloadingCompletedEvent
Game nodeGameTreeEnteredEvent, GameReadyEvent
Profiles and savesProfileIdInitializedEvent, ProfileSwitchingEvent, ProfileSwitchedEvent, RunSavingEvent, RunSavedEvent, ProgressSavingEvent, ProgressSavedEvent, ProfileDeletingEvent, ProfileDeletedEvent
Run flowRunStartedEvent, RunLoadedEvent, RunEndedEvent, RoomEnteringEvent, RoomEnteredEvent, RoomExitedEvent, ActEnteringEvent, ActEnteredEvent
CombatCombatStartingEvent, CombatEndedEvent, CombatVictoryEvent, SideTurnStartingEvent, SideTurnStartedEvent, CardPlayingEvent, CardPlayedEvent
CardsCardMovedBetweenPilesEvent, CardDrawnEvent, CardDiscardedEvent, CardExhaustedEvent, BeforeFlushEvent, CardsFlushedEvent
Rewards and inventoryGoldGainedEvent, GoldLostEvent, PotionProcuredEvent, PotionDiscardedEvent, RelicObtainedEvent, RelicRemovedEvent, RewardTakenEvent
UnlocksEpochObtainedEvent, EpochRevealedEvent, UnlockIncrementedEvent

常用事件

时机事件
框架启动FrameworkInitializingEventFrameworkInitializedEvent
模型设置ContentRegistrationClosedEventModelRegistryInitializedEventModelIdsInitializedEventModelPreloadingCompletedEvent
游戏节点GameTreeEnteredEventGameReadyEvent
档位与存档ProfileIdInitializedEventProfileSwitchingEventProfileSwitchedEventRunSavingEventRunSavedEventProgressSavingEventProgressSavedEventProfileDeletingEventProfileDeletedEvent
Run 流程RunStartedEventRunLoadedEventRunEndedEventRoomEnteringEventRoomEnteredEventRoomExitedEventActEnteringEventActEnteredEvent
战斗CombatStartingEventCombatEndedEventCombatVictoryEventSideTurnStartingEventSideTurnStartedEventCardPlayingEventCardPlayedEvent
卡牌CardMovedBetweenPilesEventCardDrawnEventCardDiscardedEventCardExhaustedEventBeforeFlushEventCardsFlushedEvent
奖励与物品栏GoldGainedEventGoldLostEventPotionProcuredEventPotionDiscardedEventRelicObtainedEventRelicRemovedEventRewardTakenEvent
解锁EpochObtainedEventEpochRevealedEventUnlockIncrementedEvent

Version Notes

CardRetainedEvent is obsolete on newer host APIs. Use CardsFlushedEvent when you need retained and flushed cards together.

For game API differences that affect event availability, check Diagnostics and compatibility.

版本注意点

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

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