From 7b9a13e0a3ec997eb6e7d6c4d105c63f7412908c Mon Sep 17 00:00:00 2001 From: kimura Date: Fri, 6 Aug 2021 17:50:29 +0900 Subject: [PATCH] =?UTF-8?q?=E8=AA=BF=E7=90=86=E5=89=8D=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF/=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0?= =?UTF-8?q?=E6=B6=88=E8=B2=BB/=E8=AA=BF=E7=90=86=E5=BE=8C=E3=82=A2?= =?UTF-8?q?=E3=82=A4=E3=83=86=E3=83=A0=E8=BF=BD=E5=8A=A0=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cooking/Scripts/PopcornGameManager.cs | 45 +++++++++- .../Scenes/recipe/Scripts/RecipeDetailView.cs | 86 +++++++++++++++++-- 2 files changed, 120 insertions(+), 11 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/PopcornGameManager.cs b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/PopcornGameManager.cs index 3a70b7fd..adea4aeb 100644 --- a/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/PopcornGameManager.cs +++ b/popcorn/Assets/MyGame/Scenes/Cooking/Scripts/PopcornGameManager.cs @@ -95,7 +95,8 @@ public class PopcornGameManager : MonoBehaviour this.CallWaitForSeconds(1.2f, () => { SetResult(x); - // 再度画面タップでリセット + AddStock(); + // 画面タップで次へ this.UpdateAsObservable() .Select(_ => Input.GetMouseButton(0)) .DistinctUntilChanged() @@ -104,7 +105,8 @@ public class PopcornGameManager : MonoBehaviour .DelaySubscription(TimeSpan.FromSeconds(1f)) .Subscribe(_ => { - ResetGame(); + // ResetGame(); + TransitionManager.Instance.LoadScene(GameScenes.Main); }).AddTo(compositeDisposable); }); }).AddTo(compositeDisposable); @@ -162,4 +164,43 @@ public class PopcornGameManager : MonoBehaviour throw new ArgumentOutOfRangeException(nameof(result), result, null); } } + + private void AddStock() + { + var recipe = LocalCacheManager.Load(RecipeDetailView.DetailRecipeTag); + var gameData = GameDataManager.GameData; + // 店頭の空きに追加 + if (21 >= gameData.ShopStock.Count + recipe.Volume) + { + for (int i = 0; i < recipe.Volume; i++) + { + gameData.ShopStock.Add(recipe.RecipeId); + } + GameDataManager.SaveGameData(); + return; + } + // 空のタンクに追加 + var emptyTankIndex = gameData.StorageTanks.FindIndex(x => x.Stock == 0); + if (emptyTankIndex != -1) + { + gameData.StorageTanks[emptyTankIndex].FlavorId = recipe.RecipeId; + gameData.StorageTanks[emptyTankIndex].Stock = recipe.Volume; + GameDataManager.SaveGameData(); + return; + } + // 同じフレーバーのタンクを確認 + var index = gameData.StorageTanks.FindIndex(x => x.FlavorId == recipe.RecipeId); + if (index != -1) + { + // 同じフレーバーのタンクの空きに追加 + var tank = gameData.StorageTanks[index]; + if (tank.Capacity >= tank.Stock + recipe.Volume) + { + tank.Stock += recipe.Volume; + gameData.StorageTanks[index] = tank; + GameDataManager.SaveGameData(); + return; + } + } + } } diff --git a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs index c12fa3c7..87a397ab 100644 --- a/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs +++ b/popcorn/Assets/MyGame/Scenes/recipe/Scripts/RecipeDetailView.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using UniRx; using UnityEngine; using UnityEngine.UI; @@ -42,7 +43,21 @@ public class RecipeDetailView : MonoBehaviour { nextButton.OnClickAsObservable().Subscribe(_ => { - + var gameData = GameDataManager.GameData; + gameData.cornSeed -= data.CornAmount; + var flavorIndex1 = gameData.Material.FindIndex(x => x.id == data.Flavors[0].id); + var stockMaterial1 = gameData.Material[flavorIndex1]; + stockMaterial1.amount -= data.Flavors[0].amount; + gameData.Material[flavorIndex1] = stockMaterial1; + if (data.Flavors.Count == 2) + { + var flavorIndex2 = gameData.Material.FindIndex(x => x.id == data.Flavors[0].id); + var stockMaterial2 = gameData.Material[flavorIndex2]; + stockMaterial2.amount -= data.Flavors[0].amount; + gameData.Material[flavorIndex2] = stockMaterial2; + } + + GameDataManager.SaveGameData(); TransitionManager.Instance.LoadScene(GameScenes.Cooking); }).AddTo(this); } @@ -55,15 +70,34 @@ public class RecipeDetailView : MonoBehaviour public void SetRecipe(RecipeData data) { var gameData = GameDataManager.GameData; - flavorStock.text = string.Format(flavorStockFormat, 9999); + + // 在庫 + // 店頭の空きがない + var shopStock = gameData.ShopStock.FindAll(x => x == data.RecipeId).Count; + var tankStock = gameData.StorageTanks.FindAll(x => x.FlavorId == data.RecipeId).Sum(x => x.Stock); + flavorStock.text = string.Format(flavorStockFormat, shopStock + tankStock); flavorName.text = data.Name; flavorPrice.text = data.Price.ToString(); cornAmountText.text = string.Format(cornAmountFormat, gameData.cornSeed, data.CornAmount); - flavor1AmountText.text = string.Format(flavorAmountFormat, 999, data.Flavors[0].amount); + + var flavor1Amount = 0; + var flavorIndex1 = gameData.Material.FindIndex(x => x.id == data.Flavors[0].id); + if (flavorIndex1 != -1) + { + flavor1Amount = gameData.Material[flavorIndex1].amount; + } + flavor1AmountText.text = string.Format(flavorAmountFormat, flavor1Amount, data.Flavors[0].amount); + + var flavor2Amount = 0; if (data.Flavors.Count == 2) { + var flavorIndex2 = gameData.Material.FindIndex(x => x.id == data.Flavors[0].id); + if (flavorIndex2 != -1) + { + flavor2Amount = gameData.Material[flavorIndex2].amount; + } flavor2View.SetActive(true); - flavor2AmountText.text = string.Format(flavorAmountFormat, 0, data.Flavors[1].amount); + flavor2AmountText.text = string.Format(flavorAmountFormat, flavor2Amount, data.Flavors[1].amount); } else { @@ -80,16 +114,50 @@ public class RecipeDetailView : MonoBehaviour flag = false; cornAmountText.color = Color.red; } - if (999 < data.Flavors[0].amount) + var flavorIndex1 = gameData.Material.FindIndex(x => x.id == data.Flavors[0].id); + if (flavorIndex1 == -1 || gameData.Material[flavorIndex1].amount < data.Flavors[0].amount) { flag = false; flavor1AmountText.color = Color.red; } - if (data.Flavors.Count == 2 && 0 < data.Flavors[1].amount) + if (data.Flavors.Count == 2) { - flag = false; - flavor2AmountText.color = Color.red; + var flavorIndex2 = gameData.Material.FindIndex(x => x.id == data.Flavors[1].id); + if (flavorIndex2 == -1 || gameData.Material[flavorIndex2].amount < data.Flavors[1].amount) + { + flag = false; + flavor2AmountText.color = Color.red; + } } - return flag; + + if (!flag) + { + return false; + } + + // 店頭の空きがない + // 店頭の空きに追加 + if (21 >= gameData.ShopStock.Count + data.Volume) + { + return true; + } + // 空のタンクに追加 + if (gameData.StorageTanks.FindIndex(x => x.Stock == 0) != -1) + { + return true; + } + // 同じフレーバーのタンクを確認 + var index = gameData.StorageTanks.FindIndex(x => x.FlavorId == data.RecipeId); + if (index != -1) + { + // 同じフレーバーのタンクの空きに追加 + var tank = gameData.StorageTanks[index]; + if (tank.Capacity >= tank.Stock + data.Volume) + { + return true; + } + } + + return false; } } \ No newline at end of file