World対応
This commit is contained in:
parent
b98f2aeadc
commit
60ccfc860e
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MyGame.Scripts;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ public class CustomerFlow : MonoBehaviour
|
||||||
private IObservable<CustomerType> vipCustomerObservable;
|
private IObservable<CustomerType> vipCustomerObservable;
|
||||||
private readonly Subject<IObservable<Unit>> vipCustomerSubject = new Subject<IObservable<Unit>>();
|
private readonly Subject<IObservable<Unit>> vipCustomerSubject = new Subject<IObservable<Unit>>();
|
||||||
private IObservable<CustomerType> tastingCustomerObservable;
|
private IObservable<CustomerType> tastingCustomerObservable;
|
||||||
|
private readonly Subject<Unit> resetSubject = new();
|
||||||
private static readonly float CheckHeartInterval = 1f;
|
private static readonly float CheckHeartInterval = 1f;
|
||||||
private static readonly float TenMinutes = 60f * 10;
|
private static readonly float TenMinutes = 60f * 10;
|
||||||
|
|
||||||
|
@ -45,24 +47,27 @@ public class CustomerFlow : MonoBehaviour
|
||||||
private int customerBonus;
|
private int customerBonus;
|
||||||
private int adWalkerBonus;
|
private int adWalkerBonus;
|
||||||
|
|
||||||
|
private GameData cityGameData;
|
||||||
|
|
||||||
public IObservable<CustomerType> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable);
|
public IObservable<CustomerType> Flow => walkerObservable.Merge(customerObservable, adWalkerObservable, vipCustomerObservable, tastingCustomerObservable);
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
adStartObservable.AddTo(this);
|
adStartObservable.AddTo(this);
|
||||||
vipCustomerSubject.AddTo(this);
|
vipCustomerSubject.AddTo(this);
|
||||||
|
resetSubject.AddTo(this);
|
||||||
|
|
||||||
var shopLevelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(Const.ShopLevelDataSheet);
|
var shopLevelList = SpreadsheetDataManager.Instance.GetBaseDataList<ShopLevelData>(Const.ShopLevelDataSheet);
|
||||||
shopLevelList = shopLevelList.Where(data => data.shopLevel != Const.SpecialShopLevel).ToList();
|
shopLevelList = shopLevelList.Where(data => data.shopLevel != Const.SpecialShopLevel).ToList();
|
||||||
|
|
||||||
// 1秒間隔でハートを確認
|
// 1秒間隔でハートを確認
|
||||||
var changeCustomerFlowObservable = Observable.Interval(TimeSpan.FromSeconds(CheckHeartInterval))
|
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
|
customerObservable = changeCustomerFlowObservable
|
||||||
.DistinctUntilChanged()
|
|
||||||
.Select(heart => TenMinutes / (shopLevelList.Last(x => x.heart <= heart).customer + customerBonus)) // 10分間期待値を来客の間隔に変換
|
|
||||||
.DistinctUntilChanged()
|
.DistinctUntilChanged()
|
||||||
// .Do(x => Debug.Log($"changeInterval:{x}"))
|
// .Do(x => Debug.Log($"changeInterval:{x}"))
|
||||||
.Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval)))
|
.Select(customerInterval => Observable.Interval(TimeSpan.FromSeconds(customerInterval)))
|
||||||
|
@ -95,44 +100,49 @@ public class CustomerFlow : MonoBehaviour
|
||||||
// 試食
|
// 試食
|
||||||
// tastingCustomerInterval毎にTastingCountを確認
|
// tastingCustomerInterval毎にTastingCountを確認
|
||||||
var tastingTimer = Observable.Interval(TimeSpan.FromSeconds(tastingCustomerInterval))
|
var tastingTimer = Observable.Interval(TimeSpan.FromSeconds(tastingCustomerInterval))
|
||||||
|
.SkipWhile(_ => cityGameData is null)
|
||||||
.Where(_ => adActiveCount <= 0) // 宣伝中判定
|
.Where(_ => adActiveCount <= 0) // 宣伝中判定
|
||||||
.Where(_ => GameDataManager.GameData.ShopStock.Count > 0) // 在庫ゼロ判定
|
.Where(_ => cityGameData.ShopStock.Count > 0) // 在庫ゼロ判定
|
||||||
.Where(_ => GameDataManager.GameData.TastingCount > 0) // 試食残り判定
|
.Where(_ => cityGameData.TastingCount > 0) // 試食残り判定
|
||||||
.Publish()
|
.Publish()
|
||||||
.RefCount();
|
.RefCount();
|
||||||
// 試食残りカウントを減らす
|
// 試食残りカウントを減らす
|
||||||
tastingTimer.Subscribe(_ =>
|
tastingTimer.Subscribe(_ =>
|
||||||
{
|
{
|
||||||
GameDataManager.GameData.TastingCount--;
|
cityGameData.TastingCount--;
|
||||||
});
|
});
|
||||||
tastingCustomerObservable = tastingTimer
|
tastingCustomerObservable = tastingTimer
|
||||||
// .Do(_ => Debug.Log($"tastingCustomer remain:{GameDataManager.GameData.TastingCount}"))
|
// .Do(_ => Debug.Log($"tastingCustomer remain:{cityGameData.TastingCount}"))
|
||||||
.Select(_ => CustomerType.Customer);
|
.Select(_ => CustomerType.Customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartAdWalker(Action onComplete = null)
|
public void StartAdWalker(Action onComplete = null)
|
||||||
{
|
{
|
||||||
var timerObservable = AdWalkerTimer().Publish().RefCount();
|
var timerObservable = AdWalkerTimer();
|
||||||
adStartObservable.OnNext(timerObservable);
|
adStartObservable.OnNext(timerObservable);
|
||||||
adActiveCount++;
|
adActiveCount++;
|
||||||
timerObservable.Subscribe(_ => { }, () =>
|
timerObservable
|
||||||
{
|
.Subscribe(_ => { }, () =>
|
||||||
adActiveCount--;
|
{
|
||||||
onComplete?.Invoke();
|
adActiveCount--;
|
||||||
}).AddTo(this);
|
onComplete?.Invoke();
|
||||||
|
}).AddTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IObservable<Unit> AdWalkerTimer()
|
private IObservable<Unit> AdWalkerTimer()
|
||||||
{
|
{
|
||||||
return Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(adWalkerDuration/(adWalkerCount + adWalkerBonus)))
|
return Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(adWalkerDuration/(adWalkerCount + adWalkerBonus)))
|
||||||
.Take(TimeSpan.FromSeconds(adWalkerDuration))
|
.Take(TimeSpan.FromSeconds(adWalkerDuration))
|
||||||
.AsUnitObservable();
|
.AsUnitObservable()
|
||||||
|
.TakeUntil(resetSubject)
|
||||||
|
.Publish().RefCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartVip()
|
public void StartVip()
|
||||||
{
|
{
|
||||||
vipCustomerSubject.OnNext(Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(vipCustomerInterval))
|
vipCustomerSubject.OnNext(Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(vipCustomerInterval))
|
||||||
.Take(vipCustomerCount)
|
.Take(vipCustomerCount)
|
||||||
|
.TakeUntil(resetSubject)
|
||||||
.AsUnitObservable());
|
.AsUnitObservable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,4 +151,20 @@ public class CustomerFlow : MonoBehaviour
|
||||||
customerBonus = bonusList[ShopCustomizeBonusCategory.Customer].value;
|
customerBonus = bonusList[ShopCustomizeBonusCategory.Customer].value;
|
||||||
adWalkerBonus = bonusList[ShopCustomizeBonusCategory.AdWalker].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