public override void SyncData(IDataStore dataStore) { using var scopedJsonSync = new ScopedJsonSync(dataStore, nameof(BLTTournamentQueueBehavior)); if (dataStore.IsSaving) { var usedHeroList = TournamentQueue.Select(t => t.Hero).ToList(); dataStore.SyncData("UsedHeroObjectList", ref usedHeroList); var queue = TournamentQueue.Select(e => new TournamentQueueEntrySavable { HeroIndex = usedHeroList.IndexOf(e.Hero), IsSub = e.IsSub, EntryFee = e.EntryFee, }).ToList(); scopedJsonSync.SyncDataAsJson("Queue2", ref queue); } else { List <Hero> usedHeroList = null; dataStore.SyncData("UsedHeroObjectList", ref usedHeroList); List <TournamentQueueEntrySavable> queue = null; scopedJsonSync.SyncDataAsJson("Queue2", ref queue); if (usedHeroList != null && queue != null) { TournamentQueue = queue.Select(e => new TournamentQueueEntry { Hero = usedHeroList[e.HeroIndex], IsSub = e.IsSub, EntryFee = e.EntryFee, }).ToList(); } } TournamentQueue ??= new(); TournamentQueue.RemoveAll(e => e.Hero == null || e.Hero.IsDead); TournamentHub.UpdateEntrants(); }
public override void RegisterEvents() { CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, (_, _, _, _) => { TournamentQueue.RemoveAll(e => e.Hero == null || e.Hero.IsDead); }); }