Skip to content

生命周期事件参考

本文列出 RitsuLib 提供的全部生命周期事件,介绍订阅方式及可重放事件的行为。

订阅方式

按类型订阅(推荐)

csharp
var sub = RitsuLibFramework.SubscribeLifecycle<GameReadyEvent>(evt =>
{
    Logger.Info($"游戏已就绪:{evt.Game}");
});

// 取消订阅
sub.Dispose();

通过 ILifecycleObserver 订阅多种事件

csharp
public class MyObserver : ILifecycleObserver
{
    public void OnEvent(IFrameworkLifecycleEvent evt)
    {
        if (evt is CombatStartingEvent combat)
            HandleCombatStart(combat);
        else if (evt is RunEndedEvent run)
            HandleRunEnd(run);
    }
}

RitsuLibFramework.SubscribeLifecycle(new MyObserver());

可重放事件(IReplayableFrameworkLifecycleEvent): 若在事件已发生后才订阅,框架会立即以已存储的事件实例回调,无需关心订阅时机。


框架事件

事件可重放携带数据
FrameworkInitializingEventFrameworkModIdFrameworkVersion
FrameworkInitializedEventFrameworkModIdIsActive
ProfileServicesInitializingEvent
ProfileServicesInitializedEventProfileId

游戏引导事件

事件可重放携带数据
EssentialInitializationStartingEvent
EssentialInitializationCompletedEvent
DeferredInitializationStartingEvent
DeferredInitializationCompletedEvent
ContentRegistrationClosedEventReason
ModelRegistryInitializingEvent
ModelRegistryInitializedEventRegisteredModelTypeCount
ModelIdsInitializingEvent
ModelIdsInitializedEvent
ModelPreloadingStartingEvent
ModelPreloadingCompletedEvent
GameTreeEnteredEventGame
GameReadyEventGame
csharp
RitsuLibFramework.SubscribeLifecycle<ModelIdsInitializedEvent>(_ =>
{
    var id = ModelDb.GetId<MyCard>();
});

跑局事件

事件可重放携带数据
RunStartedEventRunStateIsMultiplayerIsDaily
RunLoadedEventRunStateIsMultiplayerIsDaily
RunEndedEventRunIsVictoryIsAbandoned

房间与章节事件

事件携带数据
RoomEnteringEventRunStateRoom
RoomEnteredEventRunStateRoom
RoomExitedEventRunManagerRoom
ActEnteringEventRunManagerTargetActIndexDoTransition
ActEnteredEventRunStateCurrentActIndex
RewardsScreenContinuingEventRunManager

战斗事件

事件携带数据
CombatStartingEventRunStateCombatState?
CombatEndedEventRunStateCombatState?Room
CombatVictoryEventRunStateCombatState?Room
SideTurnStartingEventCombatStateSide
SideTurnStartedEventCombatStateSide
CardPlayingEventCombatStateCardPlay
CardPlayedEventCombatStateCardPlay
CardDrawnEventCombatStateCardFromHandDraw
CardDiscardedEventCombatStateCard
CardExhaustedEventCombatStateCardCausedByEthereal
CardRetainedEventCombatStateCard
CardMovedBetweenPilesEventRunStateCombatState?CardPreviousPileSource

生物事件

事件携带数据
CreatureDyingEventCombatStateCreature
CreatureDiedEventCombatStateCreature
csharp
RitsuLibFramework.SubscribeLifecycle<CardDrawnEvent>(evt =>
{
    if (evt.Card is MyCard myCard)
        myCard.OnDrawn(evt.CombatState);
});

奖励事件

事件携带数据
GoldGainedEventAmount
GoldLostEventAmount
PotionProcuredEventPotion
PotionDiscardedEventPotion
RelicObtainedEventRelic
RelicRemovedEventRelic
RewardTakenEventReward

解锁事件

事件携带数据
EpochObtainedEventEpoch
EpochRevealedEventEpoch
UnlockIncrementedEventUnlockState

存档与持久化事件

Profile 生命周期

事件携带数据
ProfileIdInitializedEventProfileId
ProfileSwitchingEventOldProfileIdNewProfileId
ProfileSwitchedEventProfileId
ProfileDeletingEventProfileId
ProfileDeletedEventProfileId

存档写入

事件携带数据
RunSavingEventRunState
RunSavedEventRunState
ProgressSavingEvent
ProgressSavedEvent

ModDataStore 数据事件

事件说明
ProfileDataReadyEvent存档数据加载完毕,可安全读写
ProfileDataChangedEvent存档数据发生变更
ProfileDataInvalidatedEvent存档数据失效(如切换档案)

游戏结算事件

事件携带数据
GameOverScreenCreatedEventScreen