Project_WL/Assets/Script/Util/DataCheckMgr.cs

175 lines
6.8 KiB
C#

using System.Collections;
using UnityEngine;
using System;
using Random = UnityEngine.Random;
using System.Globalization;
#if UNITY_ANDROID
//using Google.Play.Review;
#elif UNITY_IOS
using UnityEngine.iOS;
#endif
public class DataCheckMgr : MyCoroutine
{
private static DataCheckMgr _ins;
public static DataCheckMgr Ins { get { if (_ins == null) { _ins = new GameObject("DataCheckMgr").AddComponent<DataCheckMgr>(); DontDestroyOnLoad(_ins.gameObject); } return _ins; } }
public int NewChapter { get; set; } = 0;
int AppRunTimeMin = 0, NewsGetTime = -1;
bool CheckMail = false;
public void Set()
{
StartCoroutine(Co_1Min());
StartCoroutine(Co_1Sec());
}
IEnumerator Co_1Min()
{
var sdata = ServerInfo.Ins.m_ServerData;
while (true)
{
// 매시간 뉴스 체크
if (NewsGetTime != ServerInfo.ServerTime.Hour)
{
ServerInfo.Ins.Get_News(news =>
{
NewsGetTime = ServerInfo.ServerTime.Hour;
NoticeUI.list_news = news;
});
}
yield return new WaitForSeconds(60f);
++AppRunTimeMin;
}
}
int[] arr_cloverid = new int[] { 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 26, 27, 28 };
IEnumerator Co_1Sec()
{
var sdata = ServerInfo.Ins.m_ServerData;
while (true)
{
// 다음날이 됐을 때, 일일 데이터 초기화
if (sdata.Get_Common(eCommon.DOY_Day) != ServerInfo.ServerTime.DayOfYear)
sdata.Init_Daily();
// 다음주가 됐을 때, 주간 데이터 초기화
int weekNum = SamplesCalendar.Get_WeekOfYear(ServerInfo.ServerTime);
if (sdata.Get_Common(eCommon.DOY_Week) != weekNum)
sdata.Init_Week(weekNum);
// 다음달이 됐을 때, 주간 데이터 초기화
if (sdata.Get_Common(eCommon.Month) != ServerInfo.ServerTime.Month)
sdata.Init_Month();
yield return new WaitForSeconds(1f);
sdata.Sub_AllFarmSlotTime(); // 실제 사용 데이터
sdata.Sub_AllFarmShopTime(); // 실제 사용 데이터
sdata.Sub_ShopADTime(-1);
sdata.Add_Common(eCommon.PlayTime);
sdata.Add_MissionCount(MyValue.arr_Mission[0], 13);
sdata.Add_MissionCount(MyValue.arr_Mission[1], 11);
sdata.Sub_AllPotionTime();
sdata.Sub_Common(eCommon.CloverShopResetTime);
sdata.Buff.Sub_Time();
}
}
public void Reset_CloverItems()
{
var sdata = ServerInfo.Ins.m_ServerData;
sdata.Set_Common(eCommon.CloverShopResetTime, 3600);
for (int i = 0; i < 7; i++)
sdata.Set_Common(eCommon.CloverShopID_Weapon + i, arr_cloverid[Random.Range(0, arr_cloverid.Length)]);
}
#region
bool showReview;
public void Show_Review(Action _act)
{
if (showReview) return;
showReview = true;
Set_Coroutine(_act, 1f);
#if UNITY_ANDROID
#if FGB_OneStore
WebViewInfo.Ins.Show_WebView(MyValue.OnestoreURL);
#else
//var reviewManager = new ReviewManager();
//// start preloading the review prompt in the background
//var playReviewInfoAsyncOperation = reviewManager.RequestReviewFlow();
//// define a callback after the preloading is done
//playReviewInfoAsyncOperation.Completed += playReviewInfoAsync =>
//{
// if (playReviewInfoAsync.Error == ReviewErrorCode.NoError)
// {
// // display the review prompt
// var playReviewInfo = playReviewInfoAsync.GetResult();
// reviewManager.LaunchReviewFlow(playReviewInfo);
// }
// else
// {
// // handle error when loading review prompt
// }
//};
#endif
#else
#if UNITY_IOS
Device.RequestStoreReview();
#endif
#endif
}
#endregion
}
public class SamplesCalendar
{
public static int Get_WeekOfYear(DateTime _dt)
{
// Gets the Calendar instance associated with a CultureInfo.
CultureInfo myCI = new CultureInfo("ko-KR");
Calendar myCal = myCI.Calendar;
// Gets the DTFI properties required by GetWeekOfYear.
CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
DayOfWeek myFirstDOW = DayOfWeek.Monday;
//Debug.LogFormat("The CalendarWeekRule used for the ko-KR culture is {0}.", myCWR);
//Debug.LogFormat("The FirstDayOfWeek used for the ko-KR culture is {0}.", myFirstDOW);
//Debug.LogFormat("Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear(_dt, myCWR, myFirstDOW));
//DateTime LastDay = new DateTime(_dt.Year, 1, 1);
//Debug.LogFormat("(1,1) There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 1, 2);
//Debug.LogFormat("(1,2) There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 6, 30);
//Debug.LogFormat("(6,30)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 7, 1);
//Debug.LogFormat("(7,1)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 7, 2);
//Debug.LogFormat("(7,2)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 7, 3);
//Debug.LogFormat("(7,3)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//// Displays the total number of weeks in the current year.
//LastDay = new DateTime(_dt.Year, 12, 30);
//Debug.LogFormat("(12,30)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year, 12, 31);
//Debug.LogFormat("(12,31)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year + 1, 1, 1);
//Debug.LogFormat("(1,1)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
//LastDay = new DateTime(_dt.Year + 1, 1, 2);
//Debug.LogFormat("(1,2)There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year);
return myCal.GetWeekOfYear(_dt, myCWR, myFirstDOW);
}
}