From 594a285814a862dfd7bedf2083febeaa98d86ce3 Mon Sep 17 00:00:00 2001 From: kimura Date: Mon, 29 Nov 2021 14:55:40 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=8A=E5=AE=A2=E3=81=95=E3=82=93=E9=87=8F?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=82=AF=E3=83=A9=E3=82=B9=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marketing/Scripts/CustomerSetting.cs | 45 +++++++++++++++++++ .../marketing/Scripts/CustomerSetting.cs.meta | 3 ++ 2 files changed, 48 insertions(+) create mode 100644 popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs create mode 100644 popcorn/Assets/MyGame/Scenes/marketing/Scripts/CustomerSetting.cs.meta 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