ポップコーン完成時の保存場所の計算を修正

This commit is contained in:
kimura 2021-08-10 15:59:19 +09:00
parent 97d2022741
commit af3bf40a65
1 changed files with 30 additions and 14 deletions

View File

@ -95,7 +95,10 @@ public class PopcornGameManager : MonoBehaviour
this.CallWaitForSeconds(1.2f, () =>
{
SetResult(x);
AddStock();
if (x != CornResult.Failure)
{
AddStock();
}
// 画面タップで次へ
this.UpdateAsObservable()
.Select(_ => Input.GetMouseButton(0))
@ -170,21 +173,19 @@ public class PopcornGameManager : MonoBehaviour
var recipe = LocalCacheManager.Load<RecipeData>(RecipeDetailView.DetailRecipeTag);
var gameData = GameDataManager.GameData;
// 店頭の空きに追加
if (21 >= gameData.ShopStock.Count + recipe.Volume)
var remain = recipe.Volume;
var shopSpace = Market.ShopStockCount - gameData.ShopStock.Count;
if (shopSpace > 0)
{
for (int i = 0; i < recipe.Volume; i++)
var stockCount = Mathf.Min(shopSpace, remain);
for (int i = 0; i < stockCount; i++)
{
gameData.ShopStock.Add(recipe.RecipeId);
}
GameDataManager.SaveGameData();
return;
remain -= stockCount;
}
// 空のタンクに追加
var emptyTankIndex = gameData.StorageTanks.FindIndex(x => x.Stock == 0);
if (emptyTankIndex != -1)
if (remain == 0)
{
gameData.StorageTanks[emptyTankIndex].FlavorId = recipe.RecipeId;
gameData.StorageTanks[emptyTankIndex].Stock = recipe.Volume;
GameDataManager.SaveGameData();
return;
}
@ -194,13 +195,28 @@ public class PopcornGameManager : MonoBehaviour
{
// 同じフレーバーのタンクの空きに追加
var tank = gameData.StorageTanks[index];
if (tank.Capacity >= tank.Stock + recipe.Volume)
var tankSpace = tank.Capacity - tank.Stock;
if (tankSpace > 0)
{
tank.Stock += recipe.Volume;
var stockCount = Mathf.Min(tankSpace, remain);
tank.Stock += stockCount;
gameData.StorageTanks[index] = tank;
GameDataManager.SaveGameData();
return;
remain -= stockCount;
}
}
if (remain == 0)
{
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 = remain;
GameDataManager.SaveGameData();
return;
}
}
}