お客さん量設定クラス追加
This commit is contained in:
parent
4b29abaf4c
commit
594a285814
|
|
@ -0,0 +1,45 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MyGame.Scenes.marketing.Scripts
|
||||
{
|
||||
public class CustomerSetting : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int specialOrderCount = 5;
|
||||
[SerializeField] private float walkerSpecialRate = .01f;
|
||||
[SerializeField] private float customerSpecialRate = .01f;
|
||||
|
||||
private static readonly (int want, float weight)[] CustomerWeightTable = {
|
||||
(1, 75f),
|
||||
(2, 15f),
|
||||
(3, 3.5f),
|
||||
(4, 1.25f),
|
||||
(5, .25f),
|
||||
(0, 5f),
|
||||
};
|
||||
|
||||
public (bool isSpecial, int orderCount) GetCustomerData (bool isCustomer)
|
||||
{
|
||||
var specialRate = isCustomer ? walkerSpecialRate : customerSpecialRate;
|
||||
var isSpecial = Random.value < specialRate;
|
||||
|
||||
// セレブは5個購入固定
|
||||
return isSpecial ? (true, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 573c945685b348baa1a1ba6aeeb38714
|
||||
timeCreated: 1638163510
|
||||
Loading…
Reference in New Issue