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