add utils
This commit is contained in:
parent
fdd8c08596
commit
147394f70d
|
@ -0,0 +1,61 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace MyGame.Scripts
|
||||
{
|
||||
public static class GameDataUtils
|
||||
{
|
||||
public static int GetPartTimerHeart(int cityId)
|
||||
{
|
||||
var cityDataList = GameDataManager.GameData.CityGameDataDict.Values;
|
||||
var fundedList = cityDataList.Where(data => data.IsFundingCompleted).ToList();
|
||||
|
||||
// 初期店舗の場合リスト内で1店舗解放済みであればOK
|
||||
if (cityId == Const.DefaultCityId && fundedList.Count == 1)
|
||||
{
|
||||
return fundedList[0].Heart;
|
||||
}
|
||||
|
||||
// バイト開放には店舗が2つ以上必要
|
||||
if (fundedList.Count < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 最新の店舗ハート数+1つ前の店舗のBrotherHeart
|
||||
var cities = fundedList.TakeLast(2).ToArray();
|
||||
var prevCityBrotherHeart = cities[0].BrotherHeart;
|
||||
var latestCityHeart = cities[1].Heart;
|
||||
// 都市開放時のハート取得
|
||||
var baseBrotherHeart = GameDataManager.GetCityGameData(cityId).BrotherHeart;
|
||||
return prevCityBrotherHeart + latestCityHeart - baseBrotherHeart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 都市が最新店舗かどうか判定
|
||||
/// 資金調達済みの都市データ内で最後尾なら最新店舗
|
||||
/// </summary>
|
||||
/// <param name="cityId"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CheckLatestCity(int cityId)
|
||||
{
|
||||
if (cityId == Const.DefaultCityId)
|
||||
{
|
||||
return !GameDataManager.GameData.CityGameDataDict.Values.Any(data => data.IsFundingCompleted);
|
||||
}
|
||||
return GameDataManager.GameData.CityGameDataDict.LastOrDefault(pair => pair.Value.IsFundingCompleted).Key == cityId;
|
||||
}
|
||||
|
||||
public static GameData CreateCityData(int cityId)
|
||||
{
|
||||
var dict = GameDataManager.GameData.CityGameDataDict;
|
||||
if (dict.ContainsKey(cityId))
|
||||
{
|
||||
return dict[cityId];
|
||||
}
|
||||
var newCityData = new GameData();
|
||||
newCityData.OnDeserialized();
|
||||
dict.Add(cityId, newCityData);
|
||||
return dict[cityId];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5c1a064cc6f4254b2b637b24478c58e
|
||||
timeCreated: 1663307584
|
Loading…
Reference in New Issue