調理前チェック/アイテム消費/調理後アイテム追加追加
This commit is contained in:
parent
0afa505a56
commit
7b9a13e0a3
|
|
@ -95,7 +95,8 @@ public class PopcornGameManager : MonoBehaviour
|
||||||
this.CallWaitForSeconds(1.2f, () =>
|
this.CallWaitForSeconds(1.2f, () =>
|
||||||
{
|
{
|
||||||
SetResult(x);
|
SetResult(x);
|
||||||
// 再度画面タップでリセット
|
AddStock();
|
||||||
|
// 画面タップで次へ
|
||||||
this.UpdateAsObservable()
|
this.UpdateAsObservable()
|
||||||
.Select(_ => Input.GetMouseButton(0))
|
.Select(_ => Input.GetMouseButton(0))
|
||||||
.DistinctUntilChanged()
|
.DistinctUntilChanged()
|
||||||
|
|
@ -104,7 +105,8 @@ public class PopcornGameManager : MonoBehaviour
|
||||||
.DelaySubscription(TimeSpan.FromSeconds(1f))
|
.DelaySubscription(TimeSpan.FromSeconds(1f))
|
||||||
.Subscribe(_ =>
|
.Subscribe(_ =>
|
||||||
{
|
{
|
||||||
ResetGame();
|
// ResetGame();
|
||||||
|
TransitionManager.Instance.LoadScene(GameScenes.Main);
|
||||||
}).AddTo(compositeDisposable);
|
}).AddTo(compositeDisposable);
|
||||||
});
|
});
|
||||||
}).AddTo(compositeDisposable);
|
}).AddTo(compositeDisposable);
|
||||||
|
|
@ -162,4 +164,43 @@ public class PopcornGameManager : MonoBehaviour
|
||||||
throw new ArgumentOutOfRangeException(nameof(result), result, null);
|
throw new ArgumentOutOfRangeException(nameof(result), result, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddStock()
|
||||||
|
{
|
||||||
|
var recipe = LocalCacheManager.Load<RecipeData>(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using UniRx;
|
using UniRx;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
@ -42,7 +43,21 @@ public class RecipeDetailView : MonoBehaviour
|
||||||
{
|
{
|
||||||
nextButton.OnClickAsObservable().Subscribe(_ =>
|
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);
|
TransitionManager.Instance.LoadScene(GameScenes.Cooking);
|
||||||
}).AddTo(this);
|
}).AddTo(this);
|
||||||
}
|
}
|
||||||
|
|
@ -55,15 +70,34 @@ public class RecipeDetailView : MonoBehaviour
|
||||||
public void SetRecipe(RecipeData data)
|
public void SetRecipe(RecipeData data)
|
||||||
{
|
{
|
||||||
var gameData = GameDataManager.GameData;
|
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;
|
flavorName.text = data.Name;
|
||||||
flavorPrice.text = data.Price.ToString();
|
flavorPrice.text = data.Price.ToString();
|
||||||
cornAmountText.text = string.Format(cornAmountFormat, gameData.cornSeed, data.CornAmount);
|
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)
|
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);
|
flavor2View.SetActive(true);
|
||||||
flavor2AmountText.text = string.Format(flavorAmountFormat, 0, data.Flavors[1].amount);
|
flavor2AmountText.text = string.Format(flavorAmountFormat, flavor2Amount, data.Flavors[1].amount);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -80,16 +114,50 @@ public class RecipeDetailView : MonoBehaviour
|
||||||
flag = false;
|
flag = false;
|
||||||
cornAmountText.color = Color.red;
|
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;
|
flag = false;
|
||||||
flavor1AmountText.color = Color.red;
|
flavor1AmountText.color = Color.red;
|
||||||
}
|
}
|
||||||
if (data.Flavors.Count == 2 && 0 < data.Flavors[1].amount)
|
if (data.Flavors.Count == 2)
|
||||||
{
|
{
|
||||||
flag = false;
|
var flavorIndex2 = gameData.Material.FindIndex(x => x.id == data.Flavors[1].id);
|
||||||
flavor2AmountText.color = Color.red;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue