World対応
This commit is contained in:
parent
b98f2aeadc
commit
60ccfc860e
|
@ -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<CustomerType> vipCustomerObservable;
|
||||
private readonly Subject<IObservable<Unit>> vipCustomerSubject = new Subject<IObservable<Unit>>();
|
||||
private IObservable<CustomerType> tastingCustomerObservable;
|
||||
private readonly Subject<Unit> 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<CustomerType> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
adStartObservable.AddTo(this);
|
||||
vipCustomerSubject.AddTo(this);
|
||||
resetSubject.AddTo(this);
|
||||
|
||||
var shopLevelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(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<Unit> 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;
|
||||
|
||||
/// <summary>
|
||||
/// 特定フローの停止
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
/*
|
||||
* 通常宣伝
|
||||
* Vip宣伝
|
||||
* 試食
|
||||
* これらを停止
|
||||
*/
|
||||
resetSubject.OnNext(Unit.Default);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue