1037 lines
32 KiB
C#
1037 lines
32 KiB
C#
using BansheeGz.BGDatabase;
|
||
using CodeJay.Classes;
|
||
using CodeJay.Defines;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
|
||
namespace CodeJay
|
||
{
|
||
namespace Classes
|
||
{
|
||
[System.Serializable]
|
||
public class SaveData
|
||
{
|
||
public long Gold;
|
||
public long Heart;
|
||
public long Key;
|
||
|
||
public long BuyKeyCount;
|
||
|
||
public bool Sound_Toggle;
|
||
public bool SFX_Toggle;
|
||
|
||
public bool IsRemoveADS;
|
||
|
||
/// <summary> Normalized Speed. 0 ~ 1
|
||
/// <para>In reality, 'GameSpeed' * 1.8 + 0.2 is the speed of the game.</para></summary>
|
||
public float GameSpeed;
|
||
|
||
/// <summary>Number of Watched Ad In Store(Ad Heart Product).</summary>
|
||
public int ProductAdWatchedNumber, ShopADDia;
|
||
public DateTime ProductAdWatchedTime, ShopADDiaTime;
|
||
public int FreeHeartCount, FreeKeyCount;
|
||
public int InterstitialADCount;
|
||
|
||
public bool[] ImageOpenStates_Left, ImageOpenStates_Right;
|
||
public bool[] HeartImageOpen;
|
||
public long[] UnlockProgress;
|
||
|
||
public int NormalGameLevel;
|
||
/// <summary>The Amount of Gold Taken From Current level AI.</summary>
|
||
public long NormalGame_GetGold;
|
||
|
||
public long BuyShopAccumulatedMoney;
|
||
public float MissionAddRate;
|
||
|
||
public int Month;
|
||
public int TotalCashPerMonth;
|
||
|
||
public void Initialize()
|
||
{
|
||
this.Gold = 10000;
|
||
this.Heart = 0;
|
||
this.Key = 0;
|
||
this.BuyKeyCount = 0;
|
||
this.Sound_Toggle = false;
|
||
this.SFX_Toggle = false;
|
||
this.IsRemoveADS = false;
|
||
this.GameSpeed = 1.5f;
|
||
ShopADDia = this.ProductAdWatchedNumber = Constants.ADS_REWARD_COUNT;
|
||
this.FreeHeartCount = Constants.FREE_HEART_DAY;
|
||
FreeKeyCount = Constants.FREE_HEART_DAY;
|
||
this.InterstitialADCount = Constants.INTERSTITIAL_AD_CYCLE;
|
||
this.NormalGameLevel = 1;
|
||
this.NormalGame_GetGold = 0;
|
||
this.BuyShopAccumulatedMoney = 0;
|
||
MissionAddRate = 0f;
|
||
Month = 0;
|
||
TotalCashPerMonth = 0;
|
||
|
||
if (ImageOpenStates_Left == null) ImageOpenStates_Left = new bool[DB_HuntingData.CountEntities >> 1];
|
||
if (ImageOpenStates_Right == null) ImageOpenStates_Right = new bool[DB_HuntingData.CountEntities >> 1];
|
||
if (HeartImageOpen == null) HeartImageOpen = new bool[DB_HuntingData.CountEntities >> 1];
|
||
|
||
for (int i = 0; i < ImageOpenStates_Left.Length; i++) ImageOpenStates_Left[i] = false;
|
||
ImageOpenStates_Left[0] = true; // 최초 앨범 오픈
|
||
for (int i = 0; i < ImageOpenStates_Right.Length; i++) ImageOpenStates_Right[i] = false;
|
||
for (int i = 0; i < HeartImageOpen.Length; i++) HeartImageOpen[i] = false;
|
||
|
||
if (this.UnlockProgress == null)
|
||
this.UnlockProgress = new long[Defines.Constants.AI_IMAGE_NUMBER];
|
||
|
||
for (int i = 0; i < UnlockProgress.Length; i++)
|
||
UnlockProgress[i] = 0;
|
||
}
|
||
|
||
public void Overwrite(SaveData data)
|
||
{
|
||
if (data == null)
|
||
throw new System.Exception("Overwrite Data Never Be Null");
|
||
else
|
||
{
|
||
this.Gold = data.Gold;
|
||
this.Heart = data.Heart;
|
||
this.Key = data.Key;
|
||
this.BuyKeyCount = data.BuyKeyCount;
|
||
this.Sound_Toggle = data.Sound_Toggle;
|
||
this.SFX_Toggle = data.SFX_Toggle;
|
||
this.IsRemoveADS = data.IsRemoveADS;
|
||
this.GameSpeed = data.GameSpeed;
|
||
this.ProductAdWatchedNumber = data.ProductAdWatchedNumber;
|
||
ProductAdWatchedTime = data.ProductAdWatchedTime;
|
||
ShopADDiaTime = data.ShopADDiaTime;
|
||
ShopADDiaTime = data.ShopADDiaTime;
|
||
this.FreeHeartCount = data.FreeHeartCount;
|
||
FreeKeyCount = data.FreeKeyCount;
|
||
this.InterstitialADCount = data.InterstitialADCount;
|
||
this.NormalGameLevel = data.NormalGameLevel;
|
||
this.NormalGame_GetGold = data.NormalGame_GetGold;
|
||
this.BuyShopAccumulatedMoney = data.BuyShopAccumulatedMoney;
|
||
MissionAddRate = data.MissionAddRate;
|
||
Month = data.Month;
|
||
TotalCashPerMonth = data.TotalCashPerMonth;
|
||
|
||
if (NormalGameLevel <= 0)
|
||
NormalGameLevel = 1;
|
||
|
||
if (data.ImageOpenStates_Left != null)
|
||
for (int i = 0; i < ImageOpenStates_Left.Length; i++)
|
||
if (data.ImageOpenStates_Left.Length > i)
|
||
ImageOpenStates_Left[i] = data.ImageOpenStates_Left[i];
|
||
if (data.ImageOpenStates_Right != null)
|
||
for (int i = 0; i < ImageOpenStates_Right.Length; i++)
|
||
if (data.ImageOpenStates_Right.Length > i)
|
||
ImageOpenStates_Right[i] = data.ImageOpenStates_Right[i];
|
||
if (data.HeartImageOpen != null)
|
||
for (int i = 0; i < HeartImageOpen.Length; i++)
|
||
if (data.HeartImageOpen.Length > i)
|
||
HeartImageOpen[i] = data.HeartImageOpen[i];
|
||
|
||
if (data.UnlockProgress != null)
|
||
{
|
||
for (int i = 0; i < UnlockProgress.Length; i++)
|
||
{
|
||
if (data.UnlockProgress.Length > i)
|
||
UnlockProgress[i] = data.UnlockProgress[i];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
[System.Serializable]
|
||
public class HuntingData
|
||
{
|
||
// Data Index
|
||
// 100<30><30><EFBFBD><EFBFBD><EFBFBD> 50<35><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD>.
|
||
public int Index, n_Group;
|
||
|
||
public Sprite HuntingImage()
|
||
{
|
||
return DB_HuntingData.GetEntity(new BGId(HuntingDataID)).DBF_HuntingImage;
|
||
}
|
||
public Sprite UnlockImage()
|
||
{
|
||
return DB_HuntingData.GetEntity(new BGId(HuntingDataID)).DBF_UnlockImage;
|
||
}
|
||
|
||
public int Stake;
|
||
public int TextureIndex;
|
||
public long ClearConditionMoney;
|
||
|
||
public int n_AlbumType, NeedKey, NeedHeart, NeedLv;
|
||
|
||
public string Name;
|
||
public string Description;
|
||
public string Script;
|
||
|
||
public string HuntingDataID;
|
||
|
||
/*public HuntingData(int index, int stake, int textureIndex, long clearMoney, string name, string desc, string script)
|
||
{
|
||
this.Index = index;
|
||
this.Stake = stake;
|
||
this.TextureIndex = textureIndex;
|
||
this.ClearConditionMoney = clearMoney;
|
||
this.Name = name;
|
||
this.Description = desc;
|
||
this.Script = script;
|
||
}*/
|
||
|
||
//public HuntingData(int index, int stake, long clearMoney, string name, string desc, string huntingDataID)
|
||
//{
|
||
// this.Index = index;
|
||
// this.Stake = stake;
|
||
// this.ClearConditionMoney = clearMoney;
|
||
// this.Name = name;
|
||
// this.Description = desc;
|
||
// this.HuntingDataID = huntingDataID;
|
||
//}
|
||
|
||
public HuntingData(int index, DB_HuntingData data)
|
||
{
|
||
Index = index;
|
||
n_Group = data.DBF_n_Group;
|
||
Stake = data.DBF_Stake;
|
||
ClearConditionMoney = data.DBF_ClearConditionMoney;
|
||
Name = data.DBF_name;
|
||
Description = data.DBF_Description;
|
||
HuntingDataID = data.Id.ToString();
|
||
n_AlbumType = data.DBF_n_AlbumType;
|
||
NeedKey = data.DBF_NeedKey;
|
||
NeedHeart = data.DBF_NeedHeart;
|
||
NeedLv = data.DBF_NeedLv;
|
||
}
|
||
}
|
||
|
||
public class HuntingUIData
|
||
{
|
||
public HuntingData m_Left, m_Right;
|
||
}
|
||
}
|
||
|
||
namespace Defines
|
||
{
|
||
[System.Serializable]
|
||
public class Constants
|
||
{
|
||
public const int AI_IMAGE_NUMBER = 100;
|
||
|
||
public const int ADS_TIMER_COUNT = 3600;
|
||
|
||
public const int ADS_REWARD_COUNT = 3;
|
||
|
||
public const int FREE_HEART_DAY = 1;
|
||
|
||
public const int INTERSTITIAL_AD_CYCLE = 3;
|
||
}
|
||
}
|
||
}
|
||
|
||
public partial class DBManager : MonoBehaviour
|
||
{
|
||
private const string SAVE_KEY = "GSProject";
|
||
public const int NORMAL_GAME_CONDITION_PER_LEVEL = 10000;
|
||
public const int NORMAL_GAME_STAKE_PER_LEVEL = 100;
|
||
|
||
#region Fields
|
||
private CodeJay.Classes.SaveData saveData;
|
||
private List<HuntingData> _lstHuntindData;
|
||
#endregion
|
||
|
||
#region Properties
|
||
|
||
public bool CompleteDataLoad { get; private set; } = false;
|
||
public bool BGMMute { get => saveData.Sound_Toggle; set => saveData.Sound_Toggle = value; }
|
||
public bool SFXMute { get => saveData.SFX_Toggle; set => saveData.SFX_Toggle = value; }
|
||
|
||
public long Gold { get => saveData.Gold; }
|
||
public long Heart { get => saveData.Heart; }
|
||
public long Key { get => saveData.Key; }
|
||
public long BuyKeyCount { get => saveData.BuyKeyCount; }
|
||
public float GameSpeed { get => saveData.GameSpeed; set => saveData.GameSpeed = value; }
|
||
public int ProductAdWatchedNumber { get => saveData.ProductAdWatchedNumber; }
|
||
public DateTime ProductAdWatchedTime { get => saveData.ProductAdWatchedTime; }
|
||
public int ShopADDia { get => saveData.ShopADDia; }
|
||
public DateTime ShopADDiaTime { get => saveData.ShopADDiaTime; }
|
||
public int FreeHeartCount { get => saveData.FreeHeartCount; }
|
||
public int FreeKeyCount { get => saveData.FreeKeyCount; }
|
||
public int NormalGameLevel { get => saveData.NormalGameLevel; }
|
||
public int InterstitialADCount { get => saveData.InterstitialADCount; }
|
||
public bool IsRemoveADS { get => saveData.IsRemoveADS; }
|
||
public long BuyShopAccumulatedMoney { get => saveData.BuyShopAccumulatedMoney; }
|
||
public float MissionAddRate { get => saveData.MissionAddRate; }
|
||
public int TotalCashPerMonth { get => saveData.TotalCashPerMonth; }
|
||
|
||
public UnityAction OnResetFreeHeartCountEvent, OnResetFreeKeyCountEvent;
|
||
public UnityAction OnResetADSRewardActionCountEvent;
|
||
#endregion
|
||
|
||
private Coroutine DayResetCoroutine = null;
|
||
|
||
private void Awake()
|
||
{
|
||
saveData = new CodeJay.Classes.SaveData();
|
||
this.LoadDatas();
|
||
}
|
||
|
||
#if UNITY_EDITOR
|
||
private void Update()
|
||
{
|
||
if (Input.GetKeyDown(KeyCode.U))
|
||
{
|
||
string str = "\n<><6E>ȭ<EFBFBD><C8AD>";
|
||
str += "\nŰ : " + saveData.Key.ToString();
|
||
str += "\n<><6E>Ʈ : " + saveData.Heart.ToString();
|
||
str += "\n<><6E><EFBFBD> : " + saveData.Gold.ToString();
|
||
Debug.Log(str);
|
||
}
|
||
else if (Input.GetKeyDown(KeyCode.I))
|
||
{
|
||
this.AddGold(100000, this.name);
|
||
this.AddHeart(1, this.name);
|
||
this.AddKey(1, this.name);
|
||
|
||
string str = "\n<><6E>ȭ<EFBFBD><C8AD>";
|
||
str += "\nŰ : " + saveData.Key.ToString();
|
||
str += "\n<><6E>Ʈ : " + saveData.Heart.ToString();
|
||
str += "\n<><6E><EFBFBD> : " + saveData.Gold.ToString();
|
||
Debug.Log(str);
|
||
}
|
||
else if (Input.GetKeyDown(KeyCode.O))
|
||
{
|
||
this.SubGold(saveData.Gold, this.name);
|
||
this.SubHeart(saveData.Heart, this.name);
|
||
this.SubKey(saveData.Key, this.name);
|
||
|
||
string str = "\n<><6E>ȭ<EFBFBD><C8AD>";
|
||
str += "\nŰ : " + saveData.Key.ToString();
|
||
str += "\n<><6E>Ʈ : " + saveData.Heart.ToString();
|
||
str += "\n<><6E><EFBFBD> : " + saveData.Gold.ToString();
|
||
Debug.Log(str);
|
||
}
|
||
else if (Input.GetKeyDown(KeyCode.T))
|
||
{
|
||
saveData.FreeKeyCount = 1;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
private void OnDestroy()
|
||
{
|
||
if(DayResetCoroutine != null)
|
||
{
|
||
StopCoroutine(DayResetCoroutine);
|
||
DayResetCoroutine = null;
|
||
}
|
||
}
|
||
|
||
public string Get_SaveDataJson() { return JsonConvert.SerializeObject(saveData); }
|
||
public void Set_SaveData(SaveData saveData) { this.saveData = saveData; SaveDatas(); }
|
||
public SaveData Get_SaveData() { return saveData; }
|
||
|
||
private void LoadDatas()
|
||
{
|
||
StartCoroutine(eLoadDatas());
|
||
}
|
||
|
||
private System.Collections.IEnumerator eLoadDatas()
|
||
{
|
||
|
||
this.saveData = new SaveData();
|
||
saveData.Initialize();
|
||
|
||
SaveData loadData = ES3.Load<SaveData>(SAVE_KEY, defaultValue: null, new ES3Settings()
|
||
{
|
||
encryptionType = ES3.EncryptionType.AES, // AES 또는 XOR 사용 가능
|
||
encryptionPassword = "MyStrongPassword123" // 원하는 암호
|
||
});
|
||
|
||
if (loadData != null)
|
||
{
|
||
this.saveData.Overwrite(loadData);
|
||
}
|
||
|
||
this.SetHuntingData();
|
||
|
||
yield return null;
|
||
CompleteDataLoad = true;
|
||
}
|
||
|
||
private void SetHuntingData()
|
||
{
|
||
_lstHuntindData = new List<HuntingData>();
|
||
|
||
DB_HuntingData data = null;
|
||
for (int i = 0; i < DB_HuntingData.CountEntities; i++)
|
||
{
|
||
data = DB_HuntingData.GetEntity(i);
|
||
if (data != null)
|
||
{
|
||
//_lstHuntindData.Add(new HuntingData(i, data.DBF_Stake, data.DBF_ClearConditionMoney, data.DBF_Name, data.DBF_Description, data.Id.ToString()));
|
||
_lstHuntindData.Add(new HuntingData(i, data));
|
||
}
|
||
}
|
||
}
|
||
|
||
public void SaveDatas()
|
||
{
|
||
if (CompleteDataLoad)
|
||
{
|
||
ES3.Save(SAVE_KEY, this.saveData, new ES3Settings()
|
||
{
|
||
encryptionType = ES3.EncryptionType.AES, // AES 또는 XOR 사용 가능
|
||
encryptionPassword = "MyStrongPassword123" // 원하는 암호
|
||
});
|
||
}
|
||
}
|
||
|
||
public bool ExistSaveData()
|
||
{
|
||
if (CompleteDataLoad)
|
||
{
|
||
return ES3.KeyExists(SAVE_KEY, new ES3Settings()
|
||
{
|
||
encryptionType = ES3.EncryptionType.AES,
|
||
encryptionPassword = "MyStrongPassword123" // 원하는 암호
|
||
});
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public void Set_Mission(bool add)
|
||
{
|
||
if (add) saveData.MissionAddRate += 0.03f;
|
||
else saveData.MissionAddRate = 0f;
|
||
SaveDatas();
|
||
}
|
||
|
||
public void AddGold(long amount, string objectName)
|
||
{
|
||
saveData.Gold += amount;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Gold", "Gold", amount, saveData.Gold, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold);
|
||
}
|
||
|
||
public void MinGold(long min, string objectName)
|
||
{
|
||
saveData.Gold -= min;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Gold", "Gold", min, saveData.Gold, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold);
|
||
}
|
||
|
||
public bool AddNormalGameProgress(long goldAmount)
|
||
{
|
||
saveData.NormalGame_GetGold += goldAmount;
|
||
|
||
if (GetRemainigNormalGameAIGold() <= 0)
|
||
{
|
||
NormalGameWin();
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void SubGold(long amount, string objectName)
|
||
{
|
||
saveData.Gold -= amount;
|
||
|
||
if (saveData.Gold < 0)
|
||
saveData.Gold = 0;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Gold", "Gold", amount, saveData.Gold, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold);
|
||
}
|
||
public void SubNormalGameGetGold(long goldAmount)
|
||
{
|
||
saveData.NormalGame_GetGold -= goldAmount;
|
||
|
||
if (saveData.NormalGame_GetGold < 0)
|
||
saveData.NormalGame_GetGold = 0;
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
}
|
||
|
||
public void SubKey(long amount, string objectName)
|
||
{
|
||
saveData.Key -= amount;
|
||
|
||
if (saveData.Key < 0)
|
||
saveData.Key = 0;
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Key", "Key", amount, saveData.Key, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeKey);
|
||
}
|
||
|
||
public void AddHeart(long amount, string objectName)
|
||
{
|
||
saveData.Heart += amount;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Heart", "Heart", amount, saveData.Heart, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeHeart);
|
||
}
|
||
|
||
public void SubHeart(long amount, string objectName)
|
||
{
|
||
saveData.Heart -= amount;
|
||
|
||
if (saveData.Heart < 0)
|
||
saveData.Heart = 0;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Heart", "Heart", amount, saveData.Heart, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeHeart);
|
||
}
|
||
|
||
public void AddKey(long amount, string objectName)
|
||
{
|
||
saveData.Key += amount;
|
||
|
||
//GameManager.Flamingo.Flamingo.ChangeAssetAmount("Key", "Key", amount, saveData.Key, GameManager.Account.GetUserID(), GameManager.Account.GetUserEmail(), objectName, objectName, "");
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeKey);
|
||
}
|
||
|
||
public void UnlockLastAIImage(bool left)
|
||
{
|
||
if (IsAllUnlocked(left))
|
||
return;
|
||
|
||
var lst = left ? saveData.ImageOpenStates_Left : saveData.ImageOpenStates_Right;
|
||
for (int i = 0; i < lst.Length; i++)
|
||
{
|
||
if (lst[i] == false)
|
||
{
|
||
lst[i] = true;
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (left) ++saveData.NormalGameLevel;
|
||
|
||
//FirebaseAnalytics.LogEvent("UnlockHunting_" + GameManager.DB.GetUnlockTargetIndex(left).ToString(), new Firebase.Analytics.Parameter("Unlock", GameManager.DB.GetUnlockTargetIndex(left)));
|
||
}
|
||
|
||
public bool IsAllUnlocked(bool left)
|
||
{
|
||
if (left) return saveData.ImageOpenStates_Left[saveData.ImageOpenStates_Left.Length - 1];
|
||
else return saveData.ImageOpenStates_Right[saveData.ImageOpenStates_Right.Length - 1];
|
||
}
|
||
|
||
public int GetUnlockTargetIndex(bool left)
|
||
{
|
||
if (IsAllUnlocked(left))
|
||
return left ? saveData.ImageOpenStates_Left.Length - 1 : saveData.ImageOpenStates_Right.Length - 1;
|
||
|
||
var lst = left ? saveData.ImageOpenStates_Left : saveData.ImageOpenStates_Right;
|
||
for (int i = 0; i < lst.Length; i++)
|
||
{
|
||
if (lst[i] == false)
|
||
return i;
|
||
}
|
||
|
||
return saveData.ImageOpenStates_Left.Length - 1;
|
||
}
|
||
|
||
public bool CanBuyHeartImage(int group)
|
||
{
|
||
return saveData.HeartImageOpen[group] == false;
|
||
}
|
||
public void UnlockHeartImage(int group)
|
||
{
|
||
saveData.HeartImageOpen[group] = true;
|
||
}
|
||
|
||
public int GetUnlockHuntingCount()
|
||
{
|
||
for (int i = 0; i < saveData.ImageOpenStates_Left.Length; i++)
|
||
{
|
||
if (saveData.ImageOpenStates_Left[i] == false)
|
||
return i;
|
||
}
|
||
|
||
return saveData.ImageOpenStates_Left.Length;
|
||
}
|
||
|
||
public int GetHuntingListLength()
|
||
{
|
||
return saveData.ImageOpenStates_Left.Length;
|
||
}
|
||
|
||
public int LastClearedIndex()
|
||
{
|
||
if (saveData.ImageOpenStates_Left[0] == false)
|
||
return 0;
|
||
|
||
for (int i = 0; i < saveData.ImageOpenStates_Left.Length; i++)
|
||
{
|
||
if (saveData.ImageOpenStates_Left[i] == false)
|
||
return i - 1;
|
||
}
|
||
|
||
return saveData.ImageOpenStates_Left.Length - 1;
|
||
}
|
||
|
||
public long GetUnlockTargetProgress(bool left)
|
||
{
|
||
return saveData.UnlockProgress[GetUnlockTargetIndex(left)];
|
||
}
|
||
|
||
public HuntingData GetHuntingData(int index)
|
||
{
|
||
if (index < 0)
|
||
return _lstHuntindData[0];
|
||
else if (index >= _lstHuntindData.Count)
|
||
return _lstHuntindData[_lstHuntindData.Count - 1];
|
||
else
|
||
{
|
||
return _lstHuntindData[index];
|
||
}
|
||
}
|
||
public List<HuntingData> Get_HuntingDatas(int type)
|
||
{
|
||
return _lstHuntindData.FindAll(f => f.n_AlbumType == type);
|
||
}
|
||
|
||
public List<HuntingUIData> Get_AlbumDatas()
|
||
{
|
||
var rtn = new List<HuntingUIData>();
|
||
var lst = _lstHuntindData;
|
||
for (int i = 0; i < lst.Count; i++)
|
||
{
|
||
rtn.Add(new HuntingUIData { m_Left = lst[i], m_Right = lst[i + 1] });
|
||
++i;
|
||
}
|
||
|
||
return rtn;
|
||
}
|
||
public List<HuntingUIData> Get_AlbumDatas(int type)
|
||
{
|
||
var rtn = new List<HuntingUIData>();
|
||
var lst = _lstHuntindData.FindAll(f => f.n_AlbumType == type);
|
||
for (int i = 0; i < lst.Count; i++)
|
||
{
|
||
rtn.Add(new HuntingUIData { m_Left = lst[i], m_Right = lst[i + 1] });
|
||
++i;
|
||
}
|
||
|
||
return rtn;
|
||
}
|
||
|
||
public bool AddCurrentChallengeCondition(long amount, bool left)
|
||
{
|
||
int targetIndex = GetUnlockTargetIndex(left);
|
||
saveData.UnlockProgress[targetIndex] += amount;
|
||
|
||
if (saveData.ImageOpenStates_Left[targetIndex] == false)
|
||
{
|
||
if (saveData.UnlockProgress[targetIndex] >= _lstHuntindData[targetIndex].ClearConditionMoney)
|
||
{
|
||
saveData.UnlockProgress[targetIndex] = _lstHuntindData[targetIndex].ClearConditionMoney;
|
||
this.UnlockLastAIImage(left);
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public long GetReaminingTargetCondition(bool left)
|
||
{
|
||
int index = GetUnlockTargetIndex(left);
|
||
long result = _lstHuntindData[index].ClearConditionMoney - saveData.UnlockProgress[index];
|
||
|
||
if (result < 0)
|
||
result = 0;
|
||
|
||
return result;
|
||
}
|
||
|
||
public string GetReaminingTargetConditionString(int index)
|
||
{
|
||
long result = _lstHuntindData[index].ClearConditionMoney - saveData.UnlockProgress[index];
|
||
return result <= 0 ? "" : CodeJay.CodeJayUtility.Converter.MoneyToString(result);
|
||
}
|
||
|
||
public int GetHuntingDataLength() => _lstHuntindData.Count;
|
||
public long GetRemainigNormalGameAIGold()
|
||
{
|
||
//long result = (saveData.NormalGameLevel * NORMAL_GAME_CONDITION_PER_LEVEL) - saveData.NormalGame_GetGold;
|
||
var data = DB_HuntingData.GetEntity(GameManager.DB.GetUnlockTargetIndex(true) << 1);
|
||
long result = data.DBF_ClearConditionMoney - saveData.NormalGame_GetGold;
|
||
if (result < 0)
|
||
result = 0;
|
||
return result;
|
||
}
|
||
|
||
public void NormalGameWin()
|
||
{
|
||
//if (GameManager.DB.GetUnlockTargetIndex() <= 5)
|
||
//{
|
||
// //GameManager.Flamingo.Flamingo.FinishTutorial(GameManager.DB.NormalGameLevel.ToString(), "Level" + GameManager.DB.NormalGameLevel.ToString(), "Normal");
|
||
//}
|
||
|
||
if (GamePanel.Instance.IsChallengeMode == false)
|
||
{
|
||
//FirebaseAnalytics.LogEvent("NormalLevel_" + GameManager.DB.NormalGameLevel.ToString());
|
||
}
|
||
|
||
saveData.NormalGame_GetGold = 0;
|
||
UnlockLastAIImage(true);
|
||
SaveDatas();
|
||
GameManager.UI.ShowNStackPopup(EPopupType.AlbumOpenPopup);
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
}
|
||
|
||
/// <summary>if AI won</summary>
|
||
public void AddGoldToAI(bool isChallengeMode, long amount)
|
||
{
|
||
if (isChallengeMode)
|
||
{
|
||
int index = this.GetUnlockTargetIndex(true);
|
||
saveData.UnlockProgress[index] -= amount;
|
||
|
||
if (saveData.UnlockProgress[index] < 0)
|
||
saveData.UnlockProgress[index] = 0;
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
}
|
||
else
|
||
{
|
||
saveData.NormalGame_GetGold -= amount;
|
||
if (saveData.NormalGame_GetGold < 0)
|
||
saveData.NormalGame_GetGold = 0;
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
}
|
||
}
|
||
|
||
public void DonwloadUnlockDataCount(int count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
for (int i = 0; i < saveData.ImageOpenStates_Left.Length; i++)
|
||
{
|
||
if (i < count)
|
||
{
|
||
saveData.ImageOpenStates_Left[i] = true;
|
||
}
|
||
else
|
||
{
|
||
saveData.ImageOpenStates_Left[i] = false;
|
||
}
|
||
}
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
||
}
|
||
}
|
||
|
||
public void DonwloadGoldData(long count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.Gold = count;
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeGold);
|
||
}
|
||
}
|
||
|
||
public void DonwloadHeartData(long count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.Heart = count;
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeHeart);
|
||
}
|
||
}
|
||
|
||
public void DonwloadKeyData(long count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.Key = count;
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeKey);
|
||
}
|
||
}
|
||
|
||
public void DonwloadBuyKeyCountData(long count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.BuyKeyCount = count;
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeKey);
|
||
}
|
||
}
|
||
|
||
public void DownloadLevel(int count)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.NormalGameLevel = count;
|
||
SaveDatas();
|
||
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeNormalGameData);
|
||
}
|
||
}
|
||
|
||
public void DownloadIsRemoveADS(bool isRemoveADS)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.IsRemoveADS = isRemoveADS;
|
||
SaveDatas();
|
||
|
||
// 사실 이 코드는 옳은 코드는 아니다.
|
||
GameManager.ADS.HideBanner();
|
||
}
|
||
}
|
||
|
||
public void DownloadBuyShopAccumulatedMoney(long money)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.BuyShopAccumulatedMoney = money;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void AddBuyKeyCount(int add)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.BuyKeyCount += add;
|
||
}
|
||
}
|
||
|
||
public void ResetADSRewardActionCount()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.ProductAdWatchedNumber = Constants.ADS_REWARD_COUNT;
|
||
saveData.ShopADDia = Constants.ADS_REWARD_COUNT;
|
||
OnResetADSRewardActionCountEvent?.Invoke();
|
||
}
|
||
}
|
||
|
||
public int MinProductAdWatchedNumber(int min)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.ProductAdWatchedNumber -= min;
|
||
if (saveData.ProductAdWatchedNumber < 0)
|
||
saveData.ProductAdWatchedNumber = 0;
|
||
if (saveData.ProductAdWatchedNumber == 0)
|
||
saveData.ProductAdWatchedTime = InternetTime.Ins.Time.AddHours(1);
|
||
SaveDatas();
|
||
|
||
return saveData.ProductAdWatchedNumber;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
public void ProductAdWatchedNumber_Plus()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.ProductAdWatchedNumber = 1;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public int MinProductAdDia(int min)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.ShopADDia -= min;
|
||
if (saveData.ShopADDia < 0)
|
||
saveData.ShopADDia = 0;
|
||
if (saveData.ShopADDia == 0)
|
||
saveData.ShopADDiaTime = InternetTime.Ins.Time.AddHours(1);
|
||
SaveDatas();
|
||
|
||
return saveData.ShopADDia;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
public void ProductAdDia_Plus()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.ShopADDia = 1;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void ResetFreeHeartCount()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.FreeHeartCount = Constants.FREE_HEART_DAY;
|
||
OnResetFreeHeartCountEvent?.Invoke();
|
||
}
|
||
}
|
||
|
||
public int MinFreeHeartCount(int min)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.FreeHeartCount -= min;
|
||
SaveDatas();
|
||
|
||
return saveData.FreeHeartCount;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
public void ResetFreeKeyCount()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.FreeKeyCount = Constants.FREE_HEART_DAY;
|
||
OnResetFreeKeyCountEvent?.Invoke();
|
||
}
|
||
}
|
||
|
||
public int MinFreeKeyCount(int min)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.FreeKeyCount -= min;
|
||
SaveDatas();
|
||
|
||
return saveData.FreeKeyCount;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
public int MinInterstitialADCount(int min)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.InterstitialADCount -= min;
|
||
SaveDatas();
|
||
|
||
return saveData.InterstitialADCount;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
public void ResetInterstitialADCount()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.InterstitialADCount = CodeJay.Defines.Constants.INTERSTITIAL_AD_CYCLE;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void RemoveADS()
|
||
{
|
||
if(saveData != null)
|
||
{
|
||
saveData.IsRemoveADS = true;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void AddBuyShopAccumulatedMoney(int money)
|
||
{
|
||
if(saveData != null)
|
||
{
|
||
saveData.BuyShopAccumulatedMoney += money;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void Set_Month(int month)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.Month = month;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
public void ResetTotalCashPerMonth()
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.TotalCashPerMonth = 0;
|
||
SaveDatas();
|
||
}
|
||
}
|
||
public void AddTotalCashPerMonth(int cash)
|
||
{
|
||
if (saveData != null)
|
||
{
|
||
saveData.TotalCashPerMonth += cash;
|
||
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeKey);
|
||
SaveDatas();
|
||
}
|
||
}
|
||
|
||
public void CheckDayReset()
|
||
{
|
||
if(DayResetCoroutine != null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DateTime now = InternetTime.Ins.Time;
|
||
DateTime midnightToday = DateTime.Today.AddDays(1).AddTicks(-1);
|
||
if (now.Hour == 23 && now.Minute >= 30)
|
||
{
|
||
float Minute = midnightToday.Minute - now.Minute;
|
||
DayResetCoroutine = StartCoroutine(DayRest(Minute * 60));
|
||
}
|
||
}
|
||
|
||
private IEnumerator DayRest(float delayInSeconds)
|
||
{
|
||
yield return null;
|
||
yield return new WaitForSecondsRealtime(delayInSeconds);
|
||
|
||
ResetADSRewardActionCount();
|
||
ResetFreeHeartCount();
|
||
ResetFreeKeyCount();
|
||
|
||
if (GameManager.DB.Get_SaveData().Month != InternetTime.Ins.Time.Month)
|
||
{
|
||
GameManager.DB.Set_Month(InternetTime.Ins.Time.Month);
|
||
GameManager.DB.ResetTotalCashPerMonth();
|
||
}
|
||
|
||
DayResetCoroutine = null;
|
||
}
|
||
}
|