Marketを設定クラスに対応

This commit is contained in:
kimura 2021-11-29 15:01:36 +09:00
parent 594a285814
commit cb6601de8a
2 changed files with 11 additions and 35 deletions

View File

@ -46,7 +46,7 @@ public class Title : MonoBehaviour
.Subscribe(t =>
{
// 一般客orセレブ
var (isSpecial, orderCount) = Market.GetCustomerData(false);
var (isSpecial, orderCount) = Market.Instance.GetCustomerData(false);
// 複数パターンある場合ChooseRandom
var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab();

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using MyGame.Scenes.marketing.Scripts;
using TMPro;
using UniRx;
using UniRx.Triggers;
@ -18,21 +19,15 @@ public enum ShopState
public class Market : SingletonMonoBehaviour<Market>
{
public static readonly int ShopStockCount = 20;
private static readonly int SpecialOrderCount = 5;
private static readonly (int want, float weight)[] CustomerWeightTable = {
(1, 75f),
(2, 15f),
(3, 3.5f),
(4, 1.25f),
(5, .25f),
(0, 5f),
};
private static readonly float walkerSpecialRate = .01f;
private static readonly float customerSpecialRate = .01f;
// 購入時アニメーションタイミング
private static readonly float waitSellTime = 1.5f;
private static readonly float waitRefillTime = 1f;
[SerializeField] private CustomerFlow customerFlow;
[SerializeField] private GameObject orderPosisionObject;
[SerializeField] private CustomerData customerData;
[SerializeField] private CustomerSetting customerSetting;
[SerializeField] private CustomerController customerControllerPrefab;
public List<ProductStockData> DisplayFlavors => displayFlavors;
@ -229,13 +224,13 @@ public class Market : SingletonMonoBehaviour<Market>
}
}
this.CallWaitForSeconds(1.5f, () =>
this.CallWaitForSeconds(waitSellTime, () =>
{
sellObservable.OnNext(coin);
sellOrderSubject.OnNext(orders);
CheckStock(gameData.ShopStock);
this.CallWaitForSeconds(1f, () =>
this.CallWaitForSeconds(waitRefillTime, () =>
{
refillSubject.OnNext((isReorder, refillList));
foreach (var controller in customers)
@ -341,28 +336,9 @@ public class Market : SingletonMonoBehaviour<Market>
}
public static (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer)
public (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer)
{
var specialRate = isCustomer ? walkerSpecialRate : customerSpecialRate;
var isSpecial = Random.value < specialRate;
// セレブは5個購入固定
return isSpecial ? (true, specialOrderCount: SpecialOrderCount) : (false, GetOrderCount());
}
// お客さん出現パターン確率計算と行動パターン計算
private static int GetOrderCount()
{
var randomPoint = Random.value * CustomerWeightTable.Sum(x => x.weight);
foreach (var value in CustomerWeightTable)
{
if (randomPoint < value.weight)
{
return value.want;
}
randomPoint -= value.weight;
}
return CustomerWeightTable.Last().want;
return customerSetting.GetCustomerData(isCustomer);
}
private CustomerController SpawnCustomer()