458 lines
19 KiB
C#
458 lines
19 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using GUPS.AntiCheat.Protected;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
public class SaveMgr : MonoBehaviourSingletonTemplate<SaveMgr>
|
|
{
|
|
public SaveData m_SaveData;
|
|
|
|
IEnumerator Start()
|
|
{
|
|
while (true)
|
|
{
|
|
yield return null;
|
|
if (TableChecker.Ins == null) continue;
|
|
if (TableChecker.Ins.CheckAllLoad())
|
|
break;
|
|
}
|
|
Load();
|
|
yield return null;
|
|
SoundInfo.Ins.Play_BGM(eBGM.b008_Title);
|
|
SoundInfo.Ins.Play_OneShot(eSound.s012_Title);
|
|
while (!LobbyUI.Ins) yield return null;
|
|
LobbyUI.Ins.Set_Money();
|
|
}
|
|
|
|
public bool isLoad() { return m_SaveData != null; }
|
|
|
|
public void Load()
|
|
{
|
|
m_SaveData = CryptoUtil.Load<SaveData>("SaveData");
|
|
if (m_SaveData == null)
|
|
{
|
|
m_SaveData = new SaveData
|
|
{
|
|
bSound = true,
|
|
bBgm = true,
|
|
|
|
Attendance = 0,
|
|
MoneyChatCoin = 0,
|
|
MoneyGacha = 100,
|
|
MoneyHeart = 0,
|
|
MoneyLucky = table_GlobalValue.Ins.Get_Int("LuckyPoint"),
|
|
SelectGirlID = 1,
|
|
LastDoY = 0,
|
|
AttendanceDoY = 0,
|
|
MiniGameHP = table_GlobalValue.Ins.Get_Int("MiniGame_TotalEnterMoney")
|
|
};
|
|
|
|
Open_Album(table_album.Ins.Get_DataList()[0]);
|
|
}
|
|
}
|
|
|
|
public string Get_SaveDataJson() { return JsonConvert.SerializeObject(m_SaveData); }
|
|
public void Save()
|
|
{
|
|
if (m_SaveData != null)
|
|
CryptoUtil.Save(m_SaveData, "SaveData");
|
|
}
|
|
|
|
public void Set_Option(eOption option)
|
|
{
|
|
switch (option)
|
|
{
|
|
case eOption.Sound: m_SaveData.bSound = !m_SaveData.bSound; break;
|
|
case eOption.Bgm: m_SaveData.bBgm = !m_SaveData.bBgm; break;
|
|
}
|
|
Save();
|
|
}
|
|
public bool Get_Option(eOption option)
|
|
{
|
|
switch (option)
|
|
{
|
|
case eOption.Sound: return m_SaveData.bSound;
|
|
case eOption.Bgm: return m_SaveData.bBgm;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int Get_DoY() { return m_SaveData.LastDoY; }
|
|
public int Get_WOY() { return m_SaveData.WeekOfYear; }
|
|
|
|
public void Add_Money(eMoney money, int add = 1)
|
|
{
|
|
switch (money)
|
|
{
|
|
case eMoney.AlbumOpen:
|
|
m_SaveData.MoneyHeart += add;
|
|
m_SaveData.MoneyHeart = Mathf.Max(m_SaveData.MoneyHeart, 0);
|
|
break;
|
|
|
|
case eMoney.Chat:
|
|
m_SaveData.MoneyChatCoin += add;
|
|
m_SaveData.MoneyChatCoin = Mathf.Max(m_SaveData.MoneyChatCoin, 0);
|
|
break;
|
|
|
|
case eMoney.Gacha:
|
|
m_SaveData.MoneyGacha += add;
|
|
m_SaveData.MoneyGacha = Mathf.Max(m_SaveData.MoneyGacha, 0);
|
|
break;
|
|
|
|
case eMoney.Lucky:
|
|
m_SaveData.MoneyLucky += add;
|
|
m_SaveData.MoneyLucky = Mathf.Max(m_SaveData.MoneyLucky, 0);
|
|
break;
|
|
|
|
case eMoney.MiniGameHP:
|
|
m_SaveData.MiniGameHP += add;
|
|
m_SaveData.MiniGameHP = Mathf.Max(m_SaveData.MiniGameHP, 0);
|
|
break;
|
|
|
|
//case eMoney.ItemBomb: m_SaveData.ItemBomb += add; m_SaveData.ItemBomb = Mathf.Max(m_SaveData.ItemBomb, 0); break;
|
|
//case eMoney.ItemUmbrella: m_SaveData.ItemUmbrella += add; m_SaveData.ItemUmbrella = Mathf.Max(m_SaveData.ItemUmbrella, 0); break;
|
|
//case eMoney.ItemDildo: m_SaveData.ItemDildo += add; m_SaveData.ItemDildo = Mathf.Max(m_SaveData.ItemDildo, 0); break;
|
|
}
|
|
|
|
LobbyUI.Ins.Set_Money();
|
|
}
|
|
|
|
public void Set_Money(eMoney money, int val)
|
|
{
|
|
switch (money)
|
|
{
|
|
case eMoney.AlbumOpen: m_SaveData.MoneyHeart = val; break;
|
|
case eMoney.Chat: m_SaveData.MoneyChatCoin = val; break;
|
|
case eMoney.Gacha: m_SaveData.MoneyGacha = val; break;
|
|
case eMoney.Lucky: m_SaveData.MoneyLucky = val; break;
|
|
case eMoney.MiniGameHP: m_SaveData.MiniGameHP = val; break;
|
|
//case eMoney.ItemBomb: m_SaveData.ItemBomb = val; break;
|
|
//case eMoney.ItemUmbrella: m_SaveData.ItemUmbrella = val; break;
|
|
//case eMoney.ItemDildo: m_SaveData.ItemDildo = val; break;
|
|
}
|
|
|
|
LobbyUI.Ins.Set_Money();
|
|
}
|
|
public int Get_Money(eMoney money)
|
|
{
|
|
switch (money)
|
|
{
|
|
case eMoney.AlbumOpen: return m_SaveData.MoneyHeart;
|
|
case eMoney.Chat: return m_SaveData.MoneyChatCoin;
|
|
case eMoney.Gacha: return m_SaveData.MoneyGacha;
|
|
case eMoney.Lucky: return m_SaveData.MoneyLucky;
|
|
case eMoney.MiniGameHP: return m_SaveData.MiniGameHP;
|
|
//case eMoney.ItemBomb: return m_SaveData.ItemBomb;
|
|
//case eMoney.ItemUmbrella: return m_SaveData.ItemUmbrella;
|
|
//case eMoney.ItemDildo: return m_SaveData.ItemDildo;
|
|
}
|
|
return 0;
|
|
}
|
|
public bool Check_Money(eMoney money, int amount, bool showToast = true, float toasty = 0f)
|
|
{
|
|
var enough = Get_Money(money) >= amount;
|
|
if (!enough && showToast)
|
|
{
|
|
switch (money)
|
|
{
|
|
case eMoney.AlbumOpen:
|
|
LobbyUI.Ins.m_ToastUI.Set("하트가 부족합니다.", toasty);
|
|
break;
|
|
case eMoney.Chat:
|
|
LobbyUI.Ins.m_ToastUI.Set("채팅 코인이 부족합니다.", toasty);
|
|
break;
|
|
case eMoney.Gacha:
|
|
LobbyUI.Ins.m_ToastUI.Set("별 코인이 부족합니다.", toasty);
|
|
break;
|
|
case eMoney.Lucky:
|
|
LobbyUI.Ins.m_ToastUI.Set("럭키 포인트가 부족합니다.", toasty);
|
|
break;
|
|
case eMoney.MiniGameHP:
|
|
LobbyUI.Ins.m_ToastUI.Set("생명력이 부족합니다.", toasty);
|
|
break;
|
|
case eMoney.ItemBomb:
|
|
case eMoney.ItemUmbrella:
|
|
case eMoney.ItemDildo:
|
|
LobbyUI.Ins.m_ToastUI.Set("재화가 부족합니다.", toasty);
|
|
break;
|
|
}
|
|
}
|
|
return enough;
|
|
}
|
|
|
|
public DateTime Get_MiniGameTime() { return m_SaveData.MiniGameHPTime; }
|
|
public void Set_MiniGameTime()
|
|
{
|
|
m_SaveData.MiniGameHPTime = InternetTime.Ins.Time.AddSeconds(table_GlobalValue.Ins.Get_Int("MiniGame_EnterMoney_Time"));
|
|
}
|
|
|
|
public void DailyCheck()
|
|
{
|
|
m_SaveData.LastDoY = InternetTime.Ins.Time.DayOfYear;
|
|
|
|
if (m_SaveData.Attendance >= 7)
|
|
m_SaveData.Attendance = 0;
|
|
|
|
m_SaveData.list_ShopLimit.ForEach(f => f.Count = 0);
|
|
|
|
Save();
|
|
}
|
|
public void WeeklyCheck(int woy)
|
|
{
|
|
m_SaveData.WeekOfYear = woy;
|
|
|
|
m_SaveData.BuyShopWeekly = false;
|
|
|
|
Save();
|
|
}
|
|
public void Add_AttendanceDay() { ++m_SaveData.Attendance; }
|
|
public int Get_AttendanceDay() { return m_SaveData.Attendance; }
|
|
public bool CanGet_Attandance(int day) { return Get_AttendanceDay() < day && m_SaveData.AttendanceDoY != m_SaveData.LastDoY; }
|
|
public bool CanGet_Attandance()
|
|
{
|
|
var lst = table_attandance.Ins.Get_DataList();
|
|
for (int i = 0; i < lst.Count; i++)
|
|
{
|
|
if (CanGet_Attandance(lst[i].n_Day))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public void Get_AttandanceReward()
|
|
{
|
|
Add_AttendanceDay();
|
|
var curDay = Get_AttendanceDay();
|
|
var data = table_attandance.Ins.Get_Data(curDay);
|
|
Add_Money(eMoney.Chat, data.n_GachaAmount);
|
|
m_SaveData.AttendanceDoY = InternetTime.Ins.Time.DayOfYear;
|
|
Save();
|
|
}
|
|
|
|
public void Open_Album(albumtabledata data)
|
|
{
|
|
if (!m_SaveData.dic_ablumopen.ContainsKey(data.n_GirlID))
|
|
m_SaveData.dic_ablumopen.Add(data.n_GirlID, new List<int>());
|
|
if (!m_SaveData.dic_ablumopen[data.n_GirlID].Contains(data.n_Index))
|
|
m_SaveData.dic_ablumopen[data.n_GirlID].Add(data.n_Index);
|
|
}
|
|
public int Get_SelectGirlID() { return m_SaveData.SelectGirlID; }
|
|
public void Set_SelectGirlID(int id)
|
|
{
|
|
if (IsObtainGirl(id))
|
|
{
|
|
m_SaveData.SelectGirlID = id;
|
|
Save();
|
|
}
|
|
}
|
|
public bool IsObtainGirl(int id)
|
|
{
|
|
var pregirl = id - 1;
|
|
if (pregirl > 0)
|
|
{
|
|
var lst = table_album.Ins.Get_DataList(pregirl);
|
|
return lst.Count == Get_ImageCount(pregirl) && Get_ImageCount(id) > 0;
|
|
}
|
|
return true;
|
|
}
|
|
public bool IsOpenAlbum(albumtabledata data)
|
|
{
|
|
return m_SaveData.dic_ablumopen.ContainsKey(data.n_GirlID) &&
|
|
m_SaveData.dic_ablumopen[data.n_GirlID].Contains(data.n_Index);
|
|
}
|
|
public int Get_ImageCount(int girlid)
|
|
{
|
|
return m_SaveData.dic_ablumopen.ContainsKey(girlid) ? m_SaveData.dic_ablumopen[girlid].Count : 0;
|
|
}
|
|
|
|
public void Set_ShopReward(shoptabledata data)
|
|
{
|
|
Add_Money(eMoney.AlbumOpen, data.n_RewardHeart);
|
|
Add_Money(eMoney.Chat, data.n_RewardChatCoin);
|
|
Add_Money(eMoney.Gacha, data.n_RewardGacha);
|
|
Set_ShopInit(data.e_InAppInitType);
|
|
|
|
if (!m_SaveData.NoAD && data.b_AdRemove)
|
|
{
|
|
m_SaveData.NoAD = data.b_AdRemove;
|
|
ADInfo.Ins.Set_Banner(false);
|
|
SetBannerPos.Run();
|
|
}
|
|
|
|
m_SaveData.BonusGameRefill += data.n_BonusGameRefill;
|
|
|
|
if (!m_SaveData.InfinityMiniGame && data.b_InfinityMiniGame)
|
|
m_SaveData.InfinityMiniGame = data.b_InfinityMiniGame;
|
|
|
|
if (!m_SaveData.LuckyGameCharge && data.b_LuckyGameCharge)
|
|
m_SaveData.LuckyGameCharge = data.b_LuckyGameCharge;
|
|
|
|
if (data.n_Limit > 0)
|
|
{
|
|
var adData = m_SaveData.list_ShopLimit.Find(f => f.ShopID.Equals(data.s_ID));
|
|
if (adData == null)
|
|
m_SaveData.list_ShopLimit.Add(new ShopADSaveData { ShopID = data.s_ID, Count = 1 });
|
|
else
|
|
++adData.Count;
|
|
}
|
|
|
|
Save();
|
|
}
|
|
public bool CanShowPreviewAD(bool showtoast = true)
|
|
{
|
|
var cal = m_SaveData.PreviewADTime - InternetTime.Ins.Time;
|
|
var canshow = cal.TotalSeconds <= 0;
|
|
if (!canshow && showtoast) LobbyUI.Ins.m_ToastUI.Set($"{cal} 남음");
|
|
return canshow;
|
|
}
|
|
public void Add_PreviewADTime(int sec)
|
|
{
|
|
m_SaveData.PreviewADTime = InternetTime.Ins.Time.AddSeconds(sec);
|
|
Save();
|
|
}
|
|
public bool CanShowGachaAD(bool showtoast = true)
|
|
{
|
|
var cal = m_SaveData.GachaADTime - InternetTime.Ins.Time;
|
|
var canshow = cal.TotalSeconds <= 0;
|
|
if (!canshow && showtoast) LobbyUI.Ins.m_ToastUI.Set($"{cal} 남음");
|
|
return canshow;
|
|
}
|
|
public void Add_GachaADTime(int sec)
|
|
{
|
|
m_SaveData.GachaADTime = InternetTime.Ins.Time.AddSeconds(sec);
|
|
Save();
|
|
}
|
|
public bool CanShowShopAD(bool showtoast = true)
|
|
{
|
|
var cal = m_SaveData.ShopADTime - InternetTime.Ins.Time;
|
|
var canshow = cal.TotalSeconds <= 0;
|
|
if (!canshow && showtoast) LobbyUI.Ins.m_ToastUI.Set($"{cal} 남음");
|
|
return canshow;
|
|
}
|
|
public void Add_ShopADTime(int sec)
|
|
{
|
|
m_SaveData.ShopADTime = InternetTime.Ins.Time.AddSeconds(sec);
|
|
Save();
|
|
}
|
|
public bool CanBuyShopPackage(shoptabledata data)
|
|
{
|
|
switch (data.e_InAppInitType)
|
|
{
|
|
default: if (data.b_AdRemove) return !m_SaveData.NoAD; else return true;
|
|
case eInAppInitType.Week: return !m_SaveData.BuyShopWeekly;
|
|
case eInAppInitType.One1: return !m_SaveData.BuyShopOne1;
|
|
case eInAppInitType.One2: return !m_SaveData.BuyShopOne2;
|
|
case eInAppInitType.Disable_Buy1: return !m_SaveData.BuyShopDisableOne1;
|
|
case eInAppInitType.Disable_Buy2: return !m_SaveData.BuyShopDisableOne2;
|
|
}
|
|
}
|
|
public void Set_ShopInit(eInAppInitType inittype)
|
|
{
|
|
switch (inittype)
|
|
{
|
|
case eInAppInitType.Week: m_SaveData.BuyShopWeekly = true; break;
|
|
case eInAppInitType.One1: m_SaveData.BuyShopOne1 = true; break;
|
|
case eInAppInitType.One2: m_SaveData.BuyShopOne2 = true; break;
|
|
case eInAppInitType.Disable_Buy1: m_SaveData.BuyShopDisableOne1 = true; break;
|
|
case eInAppInitType.Disable_Buy2: m_SaveData.BuyShopDisableOne2 = true; break;
|
|
}
|
|
}
|
|
public bool Get_ShopNoAD() { return m_SaveData.NoAD; }
|
|
public int Get_ShopLimitCount(string id)
|
|
{
|
|
var data = m_SaveData.list_ShopLimit.Find(f => f.ShopID.Equals(id));
|
|
return data != null ? data.Count : 0;
|
|
}
|
|
public bool Shop_FullPackage_Active()
|
|
{
|
|
if (m_SaveData.BuyShopOne1 && m_SaveData.BuyShopOne2) return false;
|
|
return true;
|
|
}
|
|
public bool Shop_SalePackage_Active()
|
|
{
|
|
if (m_SaveData.BuyShopDisableOne1 && m_SaveData.BuyShopDisableOne2) return false;
|
|
return true;
|
|
}
|
|
public bool GachaChargeTime_Reduce() { return m_SaveData.LuckyGameCharge; }
|
|
public bool IsInfinityMiniGame() { return m_SaveData.InfinityMiniGame; }
|
|
public int Get_LuckyGameRefill() { return m_SaveData.BonusGameRefill; }
|
|
|
|
public void Add_ChatData(int girlid, string converid, ChatHistory history)
|
|
{
|
|
var data = m_SaveData.list_ChatSaveData.Find(f=>f.GirlID == girlid);
|
|
if (data == null)
|
|
{
|
|
data = new ChatSaveData { GirlID = girlid };
|
|
m_SaveData.list_ChatSaveData.Add(data);
|
|
}
|
|
if (!string.IsNullOrEmpty(converid)) data.conversationId = converid;
|
|
data.histories.Add(history);
|
|
if (data.histories.Count > 20) data.histories.RemoveAt(0);
|
|
|
|
Save();
|
|
}
|
|
public ChatSaveData Get_ChatSaveData_orNull(int girlid)
|
|
{
|
|
return m_SaveData.list_ChatSaveData.Find(f => f.GirlID == girlid);
|
|
}
|
|
public void Del_ChatSaveData(int girlid)
|
|
{
|
|
var data = Get_ChatSaveData_orNull(girlid);
|
|
if (data != null) m_SaveData.list_ChatSaveData.Remove(data);
|
|
Save();
|
|
}
|
|
|
|
|
|
public class SaveData
|
|
{
|
|
public bool bSound, bBgm;
|
|
|
|
ProtectedInt32 _LastDoY; public int LastDoY { get { return _LastDoY; } set { _LastDoY = value; _LastDoY.Obfuscate(); } }
|
|
ProtectedInt32 _WeekOfYear; public int WeekOfYear { get { return _WeekOfYear; } set { _WeekOfYear = value; _WeekOfYear.Obfuscate(); } }
|
|
ProtectedInt32 _GirlSelectIndex; public int SelectGirlID { get { return _GirlSelectIndex; } set { _GirlSelectIndex = value; _GirlSelectIndex.Obfuscate(); } }
|
|
ProtectedInt32 _AttendanceDoY; public int AttendanceDoY { get { return _AttendanceDoY; } set { _AttendanceDoY = value; _AttendanceDoY.Obfuscate(); } }
|
|
ProtectedInt32 _Attendance; public int Attendance { get { return _Attendance; } set { _Attendance = value; _Attendance.Obfuscate(); } }
|
|
|
|
ProtectedInt32 _MoneyHeart; public int MoneyHeart { get { return _MoneyHeart; } set { _MoneyHeart = value; _MoneyHeart.Obfuscate(); } }
|
|
ProtectedInt32 _MoneyChatCoin; public int MoneyChatCoin { get { return _MoneyChatCoin; } set { _MoneyChatCoin = value; _MoneyChatCoin.Obfuscate(); } }
|
|
ProtectedInt32 _MoneyGacha; public int MoneyGacha { get { return _MoneyGacha; } set { _MoneyGacha = value; _MoneyGacha.Obfuscate(); } }
|
|
ProtectedInt32 _MoneyLucky; public int MoneyLucky { get { return _MoneyLucky; } set { _MoneyLucky = value; _MoneyLucky.Obfuscate(); } }
|
|
ProtectedInt32 _MiniGameHP; public int MiniGameHP { get { return _MiniGameHP; } set { _MiniGameHP = value; _MiniGameHP.Obfuscate(); } }
|
|
ProtectedInt32 _BonusGameRefill; public int BonusGameRefill { get { return _BonusGameRefill; } set { _BonusGameRefill = value; _BonusGameRefill.Obfuscate(); } }
|
|
//ProtectedInt32 _ItemBomb; public int ItemBomb { get { return _ItemBomb; } set { _ItemBomb = value; _ItemBomb.Obfuscate(); } }
|
|
//ProtectedInt32 _ItemUmbrella; public int ItemUmbrella { get { return _ItemUmbrella; } set { _ItemUmbrella = value; _ItemUmbrella.Obfuscate(); } }
|
|
//ProtectedInt32 _ItemDildo; public int ItemDildo { get { return _ItemDildo; } set { _ItemDildo = value; _ItemDildo.Obfuscate(); } }
|
|
|
|
ProtectedDateTime _MiniGameHPTime; public DateTime MiniGameHPTime { get { return _MiniGameHPTime; } set { _MiniGameHPTime = value; _MiniGameHPTime.Obfuscate(); } }
|
|
ProtectedDateTime _GachaADTime; public DateTime GachaADTime { get { return _GachaADTime; } set { _GachaADTime = value; _GachaADTime.Obfuscate(); } }
|
|
ProtectedDateTime _ShopADTime; public DateTime ShopADTime { get { return _ShopADTime; } set { _ShopADTime = value; _ShopADTime.Obfuscate(); } }
|
|
ProtectedDateTime _PreviewADTime; public DateTime PreviewADTime { get { return _PreviewADTime; } set { _PreviewADTime = value; _PreviewADTime.Obfuscate(); } }
|
|
|
|
ProtectedBool _NoAD; public bool NoAD { get { return _NoAD; } set { _NoAD = value; _NoAD.Obfuscate(); } }
|
|
ProtectedBool _InfinityMiniGame; public bool InfinityMiniGame { get { return _InfinityMiniGame; } set { _InfinityMiniGame = value; _InfinityMiniGame.Obfuscate(); } }
|
|
ProtectedBool _LuckyGameCharge; public bool LuckyGameCharge { get { return _LuckyGameCharge; } set { _LuckyGameCharge = value; _LuckyGameCharge.Obfuscate(); } }
|
|
ProtectedBool _BuyShopWeekly; public bool BuyShopWeekly { get { return _BuyShopWeekly; } set { _BuyShopWeekly = value; _BuyShopWeekly.Obfuscate(); } }
|
|
ProtectedBool _BuyShopOne1; public bool BuyShopOne1 { get { return _BuyShopOne1; } set { _BuyShopOne1 = value; _BuyShopOne1.Obfuscate(); } }
|
|
ProtectedBool _BuyShopOne2; public bool BuyShopOne2 { get { return _BuyShopOne2; } set { _BuyShopOne2 = value; _BuyShopOne2.Obfuscate(); } }
|
|
ProtectedBool _BuyShopDisableOne1; public bool BuyShopDisableOne1 { get { return _BuyShopDisableOne1; } set { _BuyShopDisableOne1 = value; _BuyShopDisableOne1.Obfuscate(); } }
|
|
ProtectedBool _BuyShopDisableOne2; public bool BuyShopDisableOne2 { get { return _BuyShopDisableOne2; } set { _BuyShopDisableOne2 = value; _BuyShopDisableOne2.Obfuscate(); } }
|
|
|
|
public Dictionary<int, List<int>> dic_ablumopen = new Dictionary<int, List<int>>();
|
|
public List<ShopADSaveData> list_ShopLimit = new List<ShopADSaveData>();
|
|
public List<ChatSaveData> list_ChatSaveData = new List<ChatSaveData>();
|
|
}
|
|
|
|
public class ShopADSaveData
|
|
{
|
|
public string ShopID;
|
|
ProtectedInt32 _Count; public int Count { get { return _Count; } set { _Count = value; _Count.Obfuscate(); } }
|
|
}
|
|
|
|
public class ChatSaveData
|
|
{
|
|
public int GirlID;
|
|
public string conversationId;
|
|
public List<ChatHistory> histories = new List<ChatHistory>();
|
|
}
|
|
} |