public GearRunner(int gearIndex) { SceneLoader instance = SceneLoader.Instance; GearIndex = gearIndex; Config = PersistentSingleton <Economies> .Instance.Gears[gearIndex]; GearState orCreateGearState = GearStateFactory.GetOrCreateGearState(gearIndex); Level = orCreateGearState.Level; Level.Skip(1).Subscribe(delegate { if (PersistentSingleton <GameAnalytics> .Instance != null) { PersistentSingleton <GameAnalytics> .Instance.GearUpgraded.Value = this; } }).AddTo(instance); SalvageRelicAmount = (from lvl in Level select GetSalvageAmount(GearIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty(); SalvageGemCost = SalvageRelicAmount.Select(SalvageRelicsToGems.Evaluate).ToReactiveProperty(); Unlocked = (from lvl in Level select lvl >= 1).TakeUntilDestroy(instance).ToReactiveProperty(); (from pair in Unlocked.Pairwise() where pair.Current && !pair.Previous select pair).Subscribe(delegate { PlayerData.Instance.LifetimeGears.Value++; }).AddTo(instance); SalvageAvailable = PlayerData.Instance.Gems.CombineLatest(SalvageGemCost, (int gems, int cost) => gems >= cost).TakeUntilDestroy(instance).ToReactiveProperty(); UpgradeRequirement = (from lvl in Level select Singleton <EconomyHelpers> .Instance.GetGearUpgradeCost(GearIndex, lvl)).TakeUntilDestroy(instance).ToReactiveProperty(); MaxLevelReached = (from level in Level select level >= Config.MaxLevel).TakeUntilDestroy(instance).ToReactiveProperty(); UniRx.IObservable <CraftingRequirement> left = GearCollectionRunner.CreateBlocksObservable(); UpgradeAvailable = left.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => have.Satisfies(req)).CombineLatest(MaxLevelReached, (bool sat, bool max) => sat && !max).TakeUntilDestroy(instance) .ToReactiveProperty(); UpgradeGemCost = left.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => Singleton <EconomyHelpers> .Instance.GetCraftingGemCost(have, req)).TakeUntilDestroy(instance).ToReactiveProperty(); UpgradeAvailableWithGems = (from comb in UpgradeGemCost.CombineLatest(PlayerData.Instance.Gems, (int cost, int gems) => new { cost, gems }) select(comb.cost <= comb.gems) ? true : false).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); UniRx.IObservable <CraftingRequirement> left2 = GearCollectionRunner.CreateAfterPrestigeBlocksObservable(); UpgradeAfterPrestigeAvailable = left2.CombineLatest(UpgradeRequirement, (CraftingRequirement have, CraftingRequirement req) => have.Satisfies(req)).CombineLatest(MaxLevelReached, (bool sat, bool max) => sat && !max).TakeUntilDestroy(instance) .ToReactiveProperty(); Boost1Amount = Observable.Return(Config.Boost1.Mult.Amount).CombineLatest(CreateGearBonusObservable(Config.Boost1.Mult.BonusType, Config.Boost1.LevelUpAmount), (float sum, Func <float, float> f) => f(sum)).TakeUntilDestroy(instance) .ToReactiveProperty(); Boost2Amount = Observable.Return(Config.Boost2.Mult.Amount).CombineLatest(CreateGearBonusObservable(Config.Boost2.Mult.BonusType, Config.Boost2.LevelUpAmount), (float sum, Func <float, float> f) => f(sum)).TakeUntilDestroy(instance) .ToReactiveProperty(); }
public PlayerGoalActionBigDouble(UniRx.IObservable <BigDouble> rxProperty, UniRx.IObservable <int> rxClaimed, BigDouble[] req) { SceneLoader instance = SceneLoader.Instance; UniRx.IObservable <int> left = (from val in rxProperty select GetStarLevel(val, req)).DistinctUntilChanged(); ClaimedStars = rxClaimed; CompletedStars = left.CombineLatest(ClaimedStars, (int comp, int claim) => Mathf.Min(comp, claim + 1)).TakeUntilDestroy(instance).ToReactiveProperty(); Progress = rxProperty.CombineLatest(ClaimedStars, (BigDouble val, int done) => GetProgress(val, done, req)); ProgressMax = from done in ClaimedStars select GetReq(done, req); ProgressCurrent = rxProperty.CombineLatest(ProgressMax, BigDouble.Min).TakeUntilDestroy(instance).ToReactiveProperty(); }
public static UniRx.IObservable <float> CreateCombineStacking(BonusTypeEnum type, List <UniRx.IObservable <float> > mult1, List <UniRx.IObservable <float> > mult2) { Func <float, float, float> func = CreateFunctionStacking(type); UniRx.IObservable <float> observable = CreateOrigin(type); foreach (UniRx.IObservable <float> item in mult1) { observable = observable.CombineLatest(item, (float left, float right) => func(left, right)); } foreach (UniRx.IObservable <float> item2 in mult2) { observable = observable.CombineLatest(item2, (float left, float right) => func(left, right)); } return(observable); }
public override void AlwaysStart() { SceneLoader instance = SceneLoader.Instance; m_stepIndexes = new int[Steps.Length]; int i; for (i = 0; i < Steps.Length; i++) { m_stepIndexes[i] = PersistentSingleton <Economies> .Instance.TutorialGoals.FindIndex((PlayerGoalConfig goal) => goal.ID == Steps[i]); } UniRx.IObservable <bool> observable = from step in PlayerData.Instance.TutorialStep select IsVisible(step); if (m_delay != 0f) { observable = observable.Delay(TimeSpan.FromSeconds(m_delay)); } UniRx.IObservable <bool> left = from step in PlayerData.Instance.TutorialStep select IsVisible(step); left.CombineLatest(observable, (bool a, bool b) => a && b).DistinctUntilChanged().TakeUntilDestroy(instance) .SubscribeToActiveUntilNull(base.gameObject) .AddTo(this); }
public UniRx.IObservable <int> CreateGearChestsObservable() { UniRx.IObservable <int> observable = Observable.Return(0); foreach (ReactiveProperty <int> item in PlayerData.Instance.GearChestsToCollect) { observable = observable.CombineLatest(item, (int org, int num) => org + num); } return(observable); }
private UniRx.IObservable <bool> CreateUpgradeAfterPrestigeObservable() { UniRx.IObservable <bool> observable = Observable.Return <bool>(value: true); foreach (GearRunner item in Gears()) { observable = observable.CombineLatest(item.UpgradeAfterPrestigeAvailable, (bool old, bool current) => old && !current); } return(observable); }
private UniRx.IObservable <bool> CreateUpgradeObservable() { UniRx.IObservable <bool> observable = Observable.Return <bool>(value: false); foreach (GearRunner item in Gears()) { observable = observable.CombineLatest(item.UpgradeAvailable, (bool old, bool current) => current || old); } return(observable); }
private UniRx.IObservable <int> CreateGearsLevelObservable() { UniRx.IObservable <int> observable = Observable.Return(0); foreach (GearRunner item in Gears()) { observable = observable.CombineLatest(item.Level, (int old, int current) => old + current); } return(observable); }
public PlayerGoalClaimRunner() { SceneLoader instance = SceneLoader.Instance; Singleton <PropertyManager> .Instance.AddRootContext(this); UniRx.IObservable <bool> left = Observable.Return <bool>(value: false); foreach (PlayerGoalRunner playerGoalRunner in Singleton <PlayerGoalCollectionRunner> .Instance.PlayerGoalRunners) { left = left.CombineLatest(playerGoalRunner.ClaimAvailable, (bool acc, bool claim) => acc || claim); } UniRx.IObservable <bool> observable = Observable.Return <bool>(value: false); foreach (PlayerGoalRunner tutorialGoalRunner in Singleton <TutorialGoalCollectionRunner> .Instance.TutorialGoalRunners) { observable = observable.CombineLatest(tutorialGoalRunner.ClaimAvailable, (bool acc, bool claim) => acc || claim); } ClaimAvailable = left.CombineLatest(observable, (bool a, bool b) => a || b).TakeUntilDestroy(instance).ToReactiveProperty(); }
protected void Start() { GearRunner gearRunner = (GearRunner)Singleton <PropertyManager> .Instance.GetContext("GearRunner", base.transform); UniRx.IObservable <CraftingRequirement> left = GearCollectionRunner.CreateBlocksObservable(); left.CombineLatest(gearRunner.UpgradeRequirement, (CraftingRequirement blks, CraftingRequirement req) => req).Subscribe(delegate(CraftingRequirement req) { SetupResources(req); }).AddTo(this); }
public void PlayVideo(CustomController.VideoCtrl videoCtrl, FairyGUI.FillType fillType, UniRx.IObservable <string> videoPath, UniRx.IObservable <float> progress, bool isFullView = false) { var g = gObject; var sub = videoPath.CombineLatest(progress, (a, b) => new UniRx.Tuple <string, float>(a, b)).Sample(videoPath).Subscribe((t) => { videoCtrl.Init(g, fillType, isFullView); videoCtrl.PlayVideo(t.Item1, t.Item2); }); uiBase.AddDisposable(sub); }
private void playVideoWithStartPos(CustomController.VideoCtrl videoCtrl, FairyGUI.FillType fillType, UniRx.IObservable <string> videoPath, UniRx.IObservable <float> startPos) { var g = gObject; var sub = videoPath.CombineLatest(startPos, (a, b) => new UniRx.Tuple <string, float>(a, b)).Sample(videoPath).Subscribe((t) => { videoCtrl.Init(g, fillType); videoCtrl.PlayVideoWithStartPos(t.Item1, t.Item2); }); uiBase.AddDisposable(sub); }
public static UniRx.IObservable <float> CreateCombine(BonusTypeEnum type, List <UniRx.IObservable <float> > multipliers) { Func <float, float, float> func = CreateFunction(type); UniRx.IObservable <float> observable = CreateOrigin(type); foreach (UniRx.IObservable <float> multiplier in multipliers) { observable = observable.CombineLatest(multiplier, (float left, float right) => func(left, right)); } return(observable); }
public HeroNotificaitonRunner() { Singleton <PropertyManager> .Instance.AddRootContext(this); HeroCostRunner orCreateHeroCostRunner = Singleton <HeroTeamRunner> .Instance.GetOrCreateHeroCostRunner(0); SceneLoader instance = SceneLoader.Instance; HeroUpgradeAvailable = orCreateHeroCostRunner.UpgradeAvailable; UniRx.IObservable <bool> observable = Observable.Return <bool>(value: false); foreach (HeroCostRunner item in Singleton <HeroTeamRunner> .Instance.Costs()) { observable = observable.CombineLatest(item.UpgradeAvailable, (bool combined, bool available) => combined || available); } CompanionUpgradeAvailable = observable.TakeUntilDestroy(instance).ToReactiveProperty(); }
public DrillRunner() { SceneLoader instance = SceneLoader.Instance; Singleton <PropertyManager> .Instance.AddRootContext(this); DrillAvailable = (from synced in ServerTimeService.IsSynced select(synced)).TakeUntilDestroy(instance).ToReactiveProperty(); UniRx.IObservable <int> observable = (from upd in TickerService.MasterTicksSlow.CombineLatest(UpdateTimer, (long ticker, bool upd) => upd) where upd select upd into _ select(float) new TimeSpan(PlayerData.Instance.DrillTimeStamp.Value - ServerTimeService.NowTicks()).TotalSeconds into secsLeft select(int) Mathf.Max(0f, secsLeft)).DistinctUntilChanged(); DurationLeft = (from seconds in observable select TextUtils.FormatSecondsShort(seconds)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); DrillCollectable = observable.CombineLatest(PlayerData.Instance.DrillLevel, (int dur, int lvl) => dur == 0 && lvl > 0).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); DrillMaxLevel = (from lvl in PlayerData.Instance.DrillLevel select lvl >= m_maxDrillAds).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); }
public void ImageFromRes(UniRx.IObservable <string> imageSrc, UniRx.IObservable <string> imageAlphaSrc = null) { var g = gObject; if (imageAlphaSrc == null) { var sub = imageSrc.Subscribe((str) => { #if _LOAD_FROM_AB_ #else var img = Resources.Load <Texture2D>(str); if (img != null) { g.texture = new NTexture(img); } #endif }); GetUIBase().AddDisposable(sub); } else { var subAlpha = imageSrc.CombineLatest(imageAlphaSrc, (a, b) => new Tuple <string, string>(a, b)).Subscribe((str) => { #if _LOAD_FROM_AB_ #else var img = Resources.Load <Texture2D>(str.Item1); UnityEngine.Assertions.Assert.IsNotNull(img, "## img at " + str.Item1 + " not found..."); var imgAlpha = Resources.Load <Texture2D>(str.Item2); UnityEngine.Assertions.Assert.IsNotNull(img, "## imgAlpha at " + str.Item2 + " not found..."); #endif NTexture texture = null; if (img != null && imgAlpha == null) { texture = new NTexture(img); } else { texture = new NTexture(img, imgAlpha, 1, 1); } g.texture = texture; }); } }
public override void AlwaysStart() { SceneLoader instance = SceneLoader.Instance; int stepIndex = PersistentSingleton <Economies> .Instance.TutorialGoals.FindIndex((PlayerGoalConfig goal) => goal.ID == Step); UniRx.IObservable <bool> observable = from step in PlayerData.Instance.TutorialStep select step == stepIndex; if (m_delay != 0f) { observable = observable.Delay(TimeSpan.FromSeconds(m_delay)); } UniRx.IObservable <bool> left = from step in PlayerData.Instance.TutorialStep select step == stepIndex; (from turn in left.CombineLatest(observable, (bool a, bool b) => a && b).DistinctUntilChanged() where turn select turn).TakeUntilDestroy(instance).SubscribeToActiveUntilNull(base.gameObject).AddTo(this); }
public override void AlwaysStart() { m_selectable = GetComponent <Toggle>(); SceneLoader instance = SceneLoader.Instance; m_stepIndex = PersistentSingleton <Economies> .Instance.TutorialGoals.FindIndex((PlayerGoalConfig goal) => goal.ID == Step); UniRx.IObservable <bool> observable = from step in PlayerData.Instance.TutorialStep select IsVisible(step); if (m_delay != 0f) { observable = observable.Delay(TimeSpan.FromSeconds(m_delay)); } UniRx.IObservable <bool> left = from step in PlayerData.Instance.TutorialStep select IsVisible(step); left.CombineLatest(observable, (bool a, bool b) => a && b).DistinctUntilChanged().TakeUntilDestroy(instance) .SubscribeToInteractable(m_selectable) .AddTo(this); }
public GearSetRunner(int setIndex) { SceneLoader instance = SceneLoader.Instance; GearRunners = (from gear in Singleton <GearCollectionRunner> .Instance.Gears() where gear.SetIndex == setIndex select gear).ToList(); UniRx.IObservable <int> observable = Observable.Return(int.MaxValue); foreach (GearRunner gearRunner in GearRunners) { observable = observable.CombineLatest(gearRunner.Level, Mathf.Min); } UniRx.IObservable <int> observable2 = Observable.Return(0); foreach (GearRunner gearRunner2 in GearRunners) { observable2 = observable2.CombineLatest(gearRunner2.Level, Mathf.Max); } MaxAllLevel = observable.TakeUntilDestroy(instance).ToReactiveProperty(); MaxAnyLevel = observable2.TakeUntilDestroy(instance).ToReactiveProperty(); GearSet gearSet = PersistentSingleton <Economies> .Instance.GearSets[setIndex]; SetBoostText = new ReactiveProperty <string>(BonusTypeHelper.GetAttributeText(gearSet.Bonus.BonusType, gearSet.Bonus.Amount)); }
public static UniRx.IObservable <BigDouble> ReferenceTaskTarget(PlayerGoalTask target, int parameter) { switch (target) { case PlayerGoalTask.AmountCoins: return(PlayerData.Instance.LifetimeCoins); case PlayerGoalTask.AmountBlocks: { UniRx.IObservable <long> observable = from blocks in PlayerData.Instance.LifetimeBlocksDestroyed[0] select(blocks); for (int i = 1; i < PlayerData.Instance.LifetimeBlocksDestroyed.Count; i++) { observable.CombineLatest(PlayerData.Instance.LifetimeBlocksDestroyed[i], (long total, long blocks) => total + blocks); } return(from blocks in observable select new BigDouble(blocks)); } case PlayerGoalTask.HeroLevel: return(from lvl in Singleton <HeroTeamRunner> .Instance.GetOrCreateHeroRunner(parameter).LifetimeLevel select new BigDouble(lvl)); case PlayerGoalTask.NumCreatures: return(from count in PlayerData.Instance.LifetimeCreatures select new BigDouble(count - 1)); case PlayerGoalTask.NumPrestiges: return(from count in PlayerData.Instance.LifetimePrestiges select new BigDouble(count)); case PlayerGoalTask.AmountSkillUsed: return(from count in Singleton <SkillCollectionRunner> .Instance.GetOrCreateSkillRunner((SkillsEnum)parameter).LifetimeUsed select new BigDouble(count)); case PlayerGoalTask.NumGears: return(from unlocks in PlayerData.Instance.LifetimeGears select new BigDouble(unlocks)); case PlayerGoalTask.AmountRelics: return(from relics in PlayerData.Instance.LifetimeRelics select new BigDouble(relics)); case PlayerGoalTask.HeroTier: return(from lvl in Singleton <HeroTeamRunner> .Instance.GetOrCreateHeroRunner(parameter).Tier select new BigDouble(lvl)); case PlayerGoalTask.Chunk: return(from chunk in PlayerData.Instance.LifetimeChunk select new BigDouble(chunk)); case PlayerGoalTask.OpenChests: return(from chunk in PlayerData.Instance.LifetimeAllOpenedChests select new BigDouble(chunk)); case PlayerGoalTask.TapBlocks: return(from taps in PlayerData.Instance.LifetimeBlocksTaps select new BigDouble(taps)); case PlayerGoalTask.StartAdventure: return(from chunk in PlayerData.Instance.MainChunk where chunk > 0 select chunk into _ select new BigDouble(PlayerData.Instance.LifetimePrestiges.Value)); default: return(null); } }
public static UniRx.IObservable <bool> Or(this UniRx.IObservable <bool> left, UniRx.IObservable <bool> right) { return(left.CombineLatest(right, (bool a, bool b) => a || b)); }
public SkillRunner(SkillsEnum skill) { SceneLoader instance = SceneLoader.Instance; Skill = skill; m_skillState = SkillStateFactory.GetOrCreateSkillState(skill); m_skillConfig = PersistentSingleton <Economies> .Instance.Skills.Find((SkillConfig s) => s.Name == Skill.ToString()); Cost.Value = PersistentSingleton <GameSettings> .Instance.SkillPurchaseCosts[(int)Skill]; LevelReq.Value = m_skillConfig.LevelReq; LifetimeUsed = m_skillState.LifetimeUsed; Locked = (from lvl in Singleton <HeroTeamRunner> .Instance.GetOrCreateHeroRunner(0).LifetimeLevel select lvl < m_skillConfig.LevelReq).TakeUntilDestroy(instance).ToReactiveProperty(); Amount = m_skillState.Amount.CombineLatest(Locked, (int amount, bool locked) => (!locked) ? amount : 0).TakeUntilDestroy(instance).ToReactiveProperty(); UnlockTriggered = (from pair in Locked.Pairwise() where pair.Previous && !pair.Current select pair into _ select Skill).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); m_skillState.CooldownTimeStamp.Subscribe(delegate { if (!Locked.Value) { UpdateCooldown(); } }).AddTo(instance); CanAffordPurchase = (from gems in PlayerData.Instance.Gems select gems >= Cost.Value).TakeUntilDestroy(instance).ToReactiveProperty(); MaxDuration = (from duration in Singleton <CumulativeBonusRunner> .Instance.BonusMult[(int)(8 + Skill)] select SkillsEnumHelper.IsDuration(Skill) ? duration.ToInt() : 0 into duration select m_skillConfig.DurationSeconds + duration).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); TickerService.MasterTicks.Subscribe(delegate(long ticks) { if (m_skillState.ElapsedTime.Value < 1728000000000L) { m_skillState.ElapsedTime.Value += ticks; UpdateCooldown(); } }).AddTo(instance); SecondsLeft = m_skillState.ElapsedTime.CombineLatest(MaxDuration, (long elapsed, int dur) => Mathf.Max(0, dur - (int)(elapsed / 10000000))).DistinctUntilChanged().TakeUntilDestroy(instance) .ToReactiveProperty(); Active = (from secs in SecondsLeft select secs > 0).TakeUntilDestroy(instance).ToReactiveProperty(); (from act in Active.Pairwise() where !act.Current && act.Previous select act).Subscribe(delegate { m_skillState.CooldownTimeStamp.Value = ServerTimeService.NowTicks(); }).AddTo(instance); (from act in Active.Pairwise() where act.Current && act.Previous select act).Subscribe(delegate { if (PersistentSingleton <GameAnalytics> .Instance != null) { PersistentSingleton <GameAnalytics> .Instance.SkillUsed.Value = Skill; } }).AddTo(instance); Cooldown = (from secs in CooldownSeconds select secs > 0).CombineLatest(Active, (bool cooldown, bool active) => cooldown && !active).TakeUntilDestroy(instance).ToReactiveProperty(); UniRx.IObservable <bool> observable = Active.CombineLatest(Cooldown, (bool active, bool cooldown) => !active && !cooldown).CombineLatest(Locked, (bool noTimer, bool locked) => noTimer && !locked); Available = observable.TakeUntilDestroy(instance).ToReactiveProperty(); OutOfStock = observable.CombineLatest(Amount, (bool poss, int amount) => poss && amount <= 0).TakeUntilDestroy(instance).ToReactiveProperty(); LocalizedName = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Skill.Name." + Skill.ToString())); LocalizedDesc = new ReactiveProperty <string>(PersistentSingleton <LocalizationService> .Instance.Text("Skill.Name.Desc." + Skill.ToString())); (from order in Singleton <PrestigeRunner> .Instance.PrestigeTriggered select order == PrestigeOrder.PrestigeStart).Subscribe(delegate { m_skillState.CooldownTimeStamp.Value = 0L; m_skillState.ElapsedTime.Value = 1728000000000L; }).AddTo(instance); (from amount in Amount.Pairwise() where amount.Current > amount.Previous select amount).Subscribe(delegate { ResetCooldown(); }).AddTo(instance); UpdateCooldown(); AdAvailable = Singleton <AdRunner> .Instance.AdReady.TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); (from ad in Singleton <AdRunner> .Instance.AdPlacementFinished where ad.ToString() == Skill.ToString() select ad).Subscribe(delegate { SkillAdFinished(); }).AddTo(instance); (from ad in Singleton <AdRunner> .Instance.AdPlacementSkipped where ad.ToString() == Skill.ToString() select ad).Subscribe(delegate { SkillAdSkipped(); }).AddTo(instance); (from ad in Singleton <AdRunner> .Instance.AdPlacementFailed where ad.ToString() == Skill.ToString() select ad).Subscribe(delegate { SkillAdSkipped(); }).AddTo(instance); }
public BossBattleRunner() { Singleton <PropertyManager> .Instance.AddRootContext(this); SceneLoader instance = SceneLoader.Instance; BossMaxDuration = (from duration in Singleton <CumulativeBonusRunner> .Instance.BonusMult[7] select PersistentSingleton <GameSettings> .Instance.BossDurationSeconds + duration.ToInt()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); UniRx.IObservable <long> left2 = (from dead in (from health in BossCurrentHP select health <= BigDouble.ZERO).DistinctUntilChanged() select(!dead) ? TickerService.MasterTicks : Observable.Never <long>()).Switch(); (from tuple in left2.CombineLatest(BossBattlePaused, (long ticks, bool paused) => new { ticks, paused }) where !tuple.paused select tuple).Subscribe(tuple => { if (ElapsedTime.Value < 864000000000L) { ElapsedTime.Value += tuple.ticks; } }).AddTo(instance); BattleSecondsLeft = (from left in ElapsedTime.CombineLatest(BossMaxDuration, (long elapsed, int dur) => dur - (int)(elapsed / 10000000)) select Mathf.Max(0, left)).TakeUntilDestroy(instance).ToReactiveProperty(); BattleSecondsLeftNormalized = (from secs in BattleSecondsLeft select(float) secs / (float)BossMaxDuration.Value).ToReadOnlyReactiveProperty(); UniRx.IObservable <bool> source = from secs in BattleSecondsLeft.Skip(1) select secs <= 0 into ranOut where ranOut select ranOut; UniRx.IObservable <bool> observable = from killed in (from health in BossCurrentHP select health <= BigDouble.ZERO).DistinctUntilChanged() where killed select killed; observable.Subscribe(delegate { PlayerData.Instance.BossFailedLastTime.Value = false; PersistentSingleton <MainSaver> .Instance.PleaseSave("boss_killed_chunk_" + Singleton <WorldRunner> .Instance.CurrentChunk.Value.Index + "_prestige_" + PlayerData.Instance.LifetimePrestiges.Value); }).AddTo(instance); (from order in Singleton <PrestigeRunner> .Instance.PrestigeTriggered select order == PrestigeOrder.PrestigeStart).Subscribe(delegate { if (BossBattleActive.Value) { ElapsedTime.Value = 85536000000000L; } PlayerData.Instance.BossFailedLastTime.Value = false; }).AddTo(instance); (from seq in Singleton <WorldRunner> .Instance.MapSequence where seq select seq).Subscribe(delegate { PlayerData.Instance.BossFailedLastTime.Value = false; }).AddTo(instance); UniRx.IObservable <bool> observable2 = (from pair in Singleton <ChunkRunner> .Instance.AllBlockAmount.Pairwise() select pair.Current == 1 && pair.Previous > 1).CombineLatest(Singleton <ChunkRunner> .Instance.BossBlock, (bool cleared, BossBlockController boss) => cleared && boss != null).StartWith(value: false); (from activated in observable2 where activated select activated).Subscribe(delegate { StartCountdown(); }).AddTo(instance); BossBattleActive = (from secs in BattleSecondsLeft select secs > 0).CombineLatest(observable2, (bool time, bool block) => time && block).DistinctUntilChanged().TakeUntilDestroy(instance) .ToReadOnlyReactiveProperty(); BossLevelActive = (from boss in Singleton <ChunkRunner> .Instance.BossBlock select boss != null).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); (from pair in BossLevelActive.Pairwise() select pair.Current&& !pair.Previous into start where start select start).Subscribe(delegate { StartBossLevel(); }).AddTo(instance); BossPreludeActive = BossLevelActive.CombineLatest(Singleton <ChunkRunner> .Instance.AllBlockAmount, (bool level, int blocks) => level && blocks > 1).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BossFailedActive = BossLevelActive.CombineLatest(BossPreludeActive, BossBattleActive, (bool level, bool prelude, bool battle) => level && !prelude && !battle).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); TryBossAvailable = PlayerData.Instance.BossFailedLastTime.CombineLatest(BossLevelActive, (bool failed, bool active) => failed && !active).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BossBattlePending = TryBossAvailable.CombineLatest(BossLevelActive, (bool avail, bool level) => avail || level).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BossSuccessNotification = (from _ in observable select Observable.Merge(new UniRx.IObservable <bool>[2] { Observable.Return <bool>(value: true), Observable.Return <bool>(value: false).Delay(TimeSpan.FromSeconds(10.0)) })).Switch().TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BossFailedNotification = (from _ in source select Observable.Merge(new UniRx.IObservable <bool>[2] { Observable.Return <bool>(value: true), Observable.Return <bool>(value: false).Delay(TimeSpan.FromSeconds(10.0)) })).Switch().TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); BossBattleResult = (from _ in source select false).Merge(observable).StartWith(value: false).ToSequentialReadOnlyReactiveProperty(); BossFullHP = (from chunk in Singleton <WorldRunner> .Instance.CurrentChunk select ChunkRunner.IsLastChunkForNode(chunk.Index)).Select(delegate(bool last) { BiomeConfig value = Singleton <WorldRunner> .Instance.CurrentBiomeConfig.Value; return((!last) ? value.MiniBossHP : value.BossHP); }).CombineLatest(Singleton <DrJellyRunner> .Instance.DrJellyBattle, (BigDouble hp, bool dr) => (!dr) ? hp : (hp * PersistentSingleton <GameSettings> .Instance.DrJellyHpMult)).TakeUntilDestroy(instance) .ToReadOnlyReactiveProperty(); BossHealthNormalized = (from hp in BossFullHP select(!(hp > new BigDouble(1.0))) ? new BigDouble(1.0) : hp).CombineLatest(BossCurrentHP, (BigDouble full, BigDouble current) => (current / full).ToFloat()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty(); (from result in BossBattleResult.Skip(1) where !result select result).Subscribe(delegate { AudioController.Instance.QueueEvent(new AudioEvent("BossSequenceFailed", AUDIOEVENTACTION.Play)); }).AddTo(instance); (from result in BossBattleResult.Skip(1) where result select result).Subscribe(delegate { PlayerData.Instance.RetryLevelNumber.Value = 0; }).AddTo(instance); if (PersistentSingleton <GameAnalytics> .Instance != null) { BossBattleResult.Subscribe(delegate(bool result) { PersistentSingleton <GameAnalytics> .Instance.BossBattleResult.Value = result; }).AddTo(instance); } }