Marketクラスリファクタ
This commit is contained in:
parent
2bb250d135
commit
0ba6b6fc01
|
|
@ -18,6 +18,14 @@ public enum ShopState
|
|||
public class Market : SingletonMonoBehaviour<Market>
|
||||
{
|
||||
public static readonly int ShopStockCount = 20;
|
||||
private static readonly (int want, float weight)[] customerWeightTable = {
|
||||
(1, 70f),
|
||||
(2, 20f),
|
||||
(3, 3f),
|
||||
(4, 1.5f),
|
||||
(5, .5f),
|
||||
(0, 5f),
|
||||
};
|
||||
|
||||
[SerializeField] private CustomerFlow customerFlow;
|
||||
[SerializeField] private GameObject orderPosisionObject;
|
||||
|
|
@ -189,14 +197,7 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
|
||||
// 商品補充
|
||||
RefillShopStockData();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
StockFlavorLog();
|
||||
Debug.Log($"ShopStock{gameData.ShopStock.Count}, {shuffledOrder.Count + orders.Count}");
|
||||
Debug.Log($"displayCount:{displayFlavors.Count}\n" +
|
||||
$"shuffled:{shuffledOrder.Count} {string.Join(",", shuffledOrder)}\n" +
|
||||
$"orders:{orders.Count} {string.Join(",", orders)}");
|
||||
#endif
|
||||
|
||||
// 表示データ更新
|
||||
var isReorder = false;
|
||||
var refillList = new List<int>();
|
||||
|
|
@ -261,6 +262,7 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
controller.ChangeCustomerState(CustomerState.Wait);
|
||||
}).AddTo(this);
|
||||
|
||||
// 客湧き
|
||||
customerFlow.Flow.Subscribe(isCustomer =>
|
||||
{
|
||||
if (IsPause.Value)
|
||||
|
|
@ -271,58 +273,14 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
var (isSpecial, orderCount) = GetCustomerData(isCustomer);
|
||||
|
||||
// 複数パターンある場合ChooseRandom
|
||||
CustomerAnimator prefab;
|
||||
if (isSpecial)
|
||||
{
|
||||
prefab = customerData.ChooseSpecialPrefab();
|
||||
}
|
||||
else
|
||||
{
|
||||
prefab = customerData.ChooseNormalPrefab();
|
||||
}
|
||||
|
||||
var customerController = Instantiate(customerControllerPrefab, transform);
|
||||
var prefab = isSpecial ? customerData.ChooseSpecialPrefab() : customerData.ChooseNormalPrefab();
|
||||
var customerController = SpawnCustomer();
|
||||
customerController.Setup(orderPosisionObject.transform.GetComponentsInChildren<Transform>().ToList().Skip(1).ToList());
|
||||
customerController.OrderCount = orderCount;
|
||||
customerController.CustomerPrefab = prefab;
|
||||
customerControllerList.Add(customerController);
|
||||
|
||||
IsPause.Subscribe(x =>
|
||||
{
|
||||
customerController.IsPause = x;
|
||||
}).AddTo(customerController);
|
||||
|
||||
|
||||
customerController.MoveEndObservable
|
||||
.SkipLatestValueOnSubscribe()
|
||||
.DistinctUntilChanged()
|
||||
.Subscribe(prevMovingType =>
|
||||
{
|
||||
// Debug.Log($"move end {type} {customerController.GetHashCode()}");
|
||||
switch (prevMovingType)
|
||||
{
|
||||
case CustomerMovingType.WalkSide:
|
||||
case CustomerMovingType.WalkSideEat:
|
||||
customerList.Remove(customerController);
|
||||
customerControllerList.Remove(customerController);
|
||||
Destroy(customerController.gameObject);
|
||||
break;
|
||||
case CustomerMovingType.WalkCenter:
|
||||
if (customerController.State.Value == CustomerState.WalkShop)
|
||||
{
|
||||
customerList.Add(customerController);
|
||||
}
|
||||
break;
|
||||
case CustomerMovingType.WalkBackHalf:
|
||||
waitCustomerList.Add(customerController);
|
||||
break;
|
||||
case CustomerMovingType.StayBackOrder:
|
||||
requestSubject.OnNext(customerController);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}).AddTo(customerController);
|
||||
|
||||
if (isCustomer)
|
||||
{
|
||||
// 近くまで歩く(タップされたらcustomerList.Add()
|
||||
|
|
@ -361,24 +319,19 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
}
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
|
||||
private (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer)
|
||||
{
|
||||
var isSpecial = isCustomer ? Random.value < .01f : Random.value < .03f;
|
||||
|
||||
// セレブは5個購入固定
|
||||
return isSpecial ? (true, 5) : (false, GetOrderCount());
|
||||
}
|
||||
|
||||
// お客さん出現パターン確率計算と行動パターン計算
|
||||
private int GetOrderCount(bool isSpecial)
|
||||
private int GetOrderCount()
|
||||
{
|
||||
if (isSpecial)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
var customerWeightTable = new (int want, float weight)[]{
|
||||
(1, 70f),
|
||||
(2, 20f),
|
||||
(3, 3f),
|
||||
(4, 1.5f),
|
||||
(5, .5f),
|
||||
(0, 5f),
|
||||
};
|
||||
|
||||
var randomPoint = Random.value * customerWeightTable.Sum(x => x.weight);
|
||||
foreach (var value in customerWeightTable)
|
||||
{
|
||||
|
|
@ -390,27 +343,43 @@ public class Market : SingletonMonoBehaviour<Market>
|
|||
}
|
||||
return customerWeightTable.Last().want;
|
||||
}
|
||||
|
||||
private (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer)
|
||||
|
||||
private CustomerController SpawnCustomer()
|
||||
{
|
||||
var isSpecial = false;
|
||||
|
||||
if (isCustomer)
|
||||
{
|
||||
isSpecial = Random.value < .01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
isSpecial = Random.value < .03f;
|
||||
}
|
||||
|
||||
// セレブは5個購入固定
|
||||
if (isSpecial)
|
||||
{
|
||||
return (true, GetOrderCount(true));
|
||||
}
|
||||
|
||||
return (false, GetOrderCount(false));
|
||||
var customerController = Instantiate(customerControllerPrefab, transform);
|
||||
IsPause.Subscribe(x => customerController.IsPause = x).AddTo(customerController);
|
||||
|
||||
customerController.MoveEndObservable
|
||||
.SkipLatestValueOnSubscribe()
|
||||
.DistinctUntilChanged()
|
||||
.Subscribe(prevMovingType =>
|
||||
{
|
||||
// Debug.Log($"move end {type} {customerController.GetHashCode()}");
|
||||
switch (prevMovingType)
|
||||
{
|
||||
case CustomerMovingType.WalkSide:
|
||||
case CustomerMovingType.WalkSideEat:
|
||||
customerList.Remove(customerController);
|
||||
customerControllerList.Remove(customerController);
|
||||
Destroy(customerController.gameObject);
|
||||
break;
|
||||
case CustomerMovingType.WalkCenter:
|
||||
if (customerController.State.Value == CustomerState.WalkShop)
|
||||
{
|
||||
customerList.Add(customerController);
|
||||
}
|
||||
break;
|
||||
case CustomerMovingType.WalkBackHalf:
|
||||
waitCustomerList.Add(customerController);
|
||||
break;
|
||||
case CustomerMovingType.StayBackOrder:
|
||||
requestSubject.OnNext(customerController);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}).AddTo(customerController);
|
||||
return customerController;
|
||||
}
|
||||
|
||||
private int SellPopcorn(List<ProductStockData> stockDataList)
|
||||
|
|
|
|||
Loading…
Reference in New Issue