From 60ccfc860e49e963c5b8cb1b647e76776ee665de Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 7 Oct 2022 15:37:36 +0900 Subject: [PATCH] =?UTF-8?q?World=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/marketing/Scripts/CustomerFlow.cs | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs index 8da67230..37d59f2d 100644 --- a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerFlow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using MyGame.Scripts; using UniRx; using UnityEngine; @@ -20,6 +21,7 @@ public class CustomerFlow : MonoBehaviour private IObservable vipCustomerObservable; private readonly Subject> vipCustomerSubject = new Subject>(); private IObservable tastingCustomerObservable; + private readonly Subject resetSubject = new(); private static readonly float CheckHeartInterval = 1f; private static readonly float TenMinutes = 60f * 10; @@ -45,24 +47,27 @@ public class CustomerFlow : MonoBehaviour private int customerBonus; private int adWalkerBonus; + private GameData cityGameData; + public IObservable Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable); private void Awake() { adStartObservable.AddTo(this); vipCustomerSubject.AddTo(this); + resetSubject.AddTo(this); var shopLevelList = SpreadsheetDataManager.Instance.GetBaseDataList(Const.ShopLevelDataSheet); shopLevelList = shopLevelList.Where(data => data.shopLevel != Const.SpecialShopLevel).ToList(); // 1秒間隔でハートを確認 var changeCustomerFlowObservable = Observable.Interval(TimeSpan.FromSeconds(CheckHeartInterval)) - .Select(_ => GameDataManager.GameData.Heart); + .Select(_ => GameDataUtils.GetTotalHeart()) + .DistinctUntilChanged() + .Select(heart => TenMinutes / (shopLevelList.Last(x => x.heart <= heart).customer + customerBonus)); // 10分間期待値を来客の間隔に変換 // お客さん出現タイマー customerObservable = changeCustomerFlowObservable - .DistinctUntilChanged() - .Select(heart => TenMinutes / (shopLevelList.Last(x => x.heart <= heart).customer + customerBonus)) // 10分間期待値を来客の間隔に変換 .DistinctUntilChanged() // .Do(x => Debug.Log($"changeInterval:{x}")) .Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval))) @@ -95,44 +100,49 @@ public class CustomerFlow : MonoBehaviour // 試食 // tastingCustomerInterval毎にTastingCountを確認 var tastingTimer = Observable.Interval(TimeSpan.FromSeconds(tastingCustomerInterval)) + .SkipWhile(_ => cityGameData is null) .Where(_ => adActiveCount <= 0) // 宣伝中判定 - .Where(_ => GameDataManager.GameData.ShopStock.Count > 0) // 在庫ゼロ判定 - .Where(_ => GameDataManager.GameData.TastingCount > 0) // 試食残り判定 + .Where(_ => cityGameData.ShopStock.Count > 0) // 在庫ゼロ判定 + .Where(_ => cityGameData.TastingCount > 0) // 試食残り判定 .Publish() .RefCount(); // 試食残りカウントを減らす tastingTimer.Subscribe(_ => { - GameDataManager.GameData.TastingCount--; + cityGameData.TastingCount--; }); tastingCustomerObservable = tastingTimer - // .Do(_ => Debug.Log($"tastingCustomer remain:{GameDataManager.GameData.TastingCount}")) + // .Do(_ => Debug.Log($"tastingCustomer remain:{cityGameData.TastingCount}")) .Select(_ => CustomerType.Customer); } public void StartAdWalker(Action onComplete = null) { - var timerObservable = AdWalkerTimer().Publish().RefCount(); + var timerObservable = AdWalkerTimer(); adStartObservable.OnNext(timerObservable); adActiveCount++; - timerObservable.Subscribe(_ => { }, () => - { - adActiveCount--; - onComplete?.Invoke(); - }).AddTo(this); + timerObservable + .Subscribe(_ => { }, () => + { + adActiveCount--; + onComplete?.Invoke(); + }).AddTo(this); } private IObservable AdWalkerTimer() { return Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(adWalkerDuration/(adWalkerCount + adWalkerBonus))) .Take(TimeSpan.FromSeconds(adWalkerDuration)) - .AsUnitObservable(); + .AsUnitObservable() + .TakeUntil(resetSubject) + .Publish().RefCount(); } public void StartVip() { vipCustomerSubject.OnNext(Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(vipCustomerInterval)) .Take(vipCustomerCount) + .TakeUntil(resetSubject) .AsUnitObservable()); } @@ -141,4 +151,20 @@ public class CustomerFlow : MonoBehaviour customerBonus = bonusList[ShopCustomizeBonusCategory.Customer].value; adWalkerBonus = bonusList[ShopCustomizeBonusCategory.AdWalker].value; } + + public void SetCityGameData(GameData newGameData) => cityGameData = newGameData; + + /// + /// 特定フローの停止 + /// + public void Stop() + { + /* + * 通常宣伝 + * Vip宣伝 + * 試食 + * これらを停止 + */ + resetSubject.OnNext(Unit.Default); + } }