diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs new file mode 100644 index 00000000..c7d0495c --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs.meta b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs.meta new file mode 100644 index 00000000..fb06dcd3 --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 573c945685b348baa1a1ba6aeeb38714 +timeCreated: 1638163510 \ No newline at end of file