| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using UnityEngine; |
| | | |
| | | public class FirstChargeManager : GameSystemManager<FirstChargeManager> |
| | | { |
| | | public const int FuncID = 110; |
| | | public int taskID; |
| | | public int nextTaskID; |
| | | public int mainItemId { get { return GetMainItemId(); } } |
| | | public int heroItemID; |
| | | public int maxGiftCount |
| | |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent; |
| | | DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk; |
| | | RechargeManager.Instance.rechargeCountEvent += OnRechargeCountEvent; |
| | | FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent; |
| | | |
| | | TaskManager.Instance.OnTaskUpdate += OnTaskUpdate; |
| | | InitClickTabDict(); |
| | | InitRedPoint(); |
| | | } |
| | | |
| | | public override void Release() |
| | |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent; |
| | | DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk; |
| | | RechargeManager.Instance.rechargeCountEvent -= OnRechargeCountEvent; |
| | | FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent; |
| | | TaskManager.Instance.OnTaskUpdate -= OnTaskUpdate; |
| | | } |
| | | |
| | | private void OnFuncStateChangeEvent(int obj) |
| | | |
| | | public event Action OnFirstChargeTaskUpdateEvent; |
| | | int beforeMainID; |
| | | private void OnTaskUpdate() |
| | | { |
| | | if (FuncID == obj) |
| | | int currentTaskID = TaskManager.Instance.mainTask.TaskID; |
| | | |
| | | if (beforeMainID == taskID && currentTaskID == nextTaskID) |
| | | { |
| | | string key = $"FirstCharge_FirstTime_{FuncID}_{PlayerDatas.Instance.baseData.PlayerID}"; |
| | | string key = $"FirstCharge_FirstTime_{taskID}_{PlayerDatas.Instance.baseData.PlayerID}"; |
| | | if (!LocalSave.HasKey(key)) |
| | | { |
| | | // 第一次开启功能 |
| | | // 第一次完成任务 |
| | | LocalSave.SetBool(key, true); |
| | | PopupWindowsProcessor.Instance.Add("FirstChargeWin"); |
| | | OnFirstChargeTaskUpdateEvent?.Invoke(); |
| | | } |
| | | } |
| | | beforeMainID = currentTaskID; |
| | | } |
| | | |
| | | public void InitClickTabDict() |
| | |
| | | public void OnBeforePlayerDataInitializeEvent() |
| | | { |
| | | firstChargeInfoDict.Clear(); |
| | | |
| | | FuncConfigConfig config = FuncConfigConfig.Get("FirstCharge"); |
| | | taskID = int.Parse(config.Numerical1); |
| | | nextTaskID = int.Parse(config.Numerical2); |
| | | } |
| | | |
| | | public void OnPlayerLoginOk() |
| | | { |
| | | InitClickTabDict(); |
| | | InitRedPoint(); |
| | | if (FuncOpen.Instance.IsFuncOpen(FuncID)&& TryGetUnBuyFirstId(out int firstId)) |
| | | if (IsFuncOpen() && TryGetUnBuyFirstId(out int firstId)) |
| | | { |
| | | PopupWindowsProcessor.Instance.Add("FirstChargeWin"); |
| | | } |
| | | } |
| | | |
| | | public bool TryGetFirstChargeDataByFirstId(int firstId, out FirstChargeData firstChargeData) |
| | | { |
| | | return firstChargeInfoDict.TryGetValue(firstId, out firstChargeData); |
| | | } |
| | | |
| | | //所有的战斗死亡弹首充,置顶在战斗失败界面上即可,若首充充完则无须响应,不会死亡的不需要 |
| | | public void TryPopWin(string battleName) |
| | | { |
| | | if (battleName == null || battleName == string.Empty) |
| | | return; |
| | | if (battleName == "TianziBillboradBattleField") |
| | | return; |
| | | if (!IsFuncOpen()) |
| | | return; |
| | | if (!TryGetUnBuyFirstId(out int firstId)) |
| | | return; |
| | | if (!UIManager.Instance.IsOpened<FirstChargeWin>()) |
| | | { |
| | | UIManager.Instance.OpenWindow<FirstChargeWin>(); |
| | | } |
| | | } |
| | | |
| | | public string loaclKey = "FirstCharge_Fail_"; |
| | | |
| | | public bool GetLocalFail() |
| | | { |
| | | return LocalSave.GetBool(StringUtility.Contact(loaclKey + PlayerDatas.Instance.PlayerId)); |
| | | } |
| | | |
| | | public void SetLocalFail() |
| | | { |
| | | LocalSave.SetBool(StringUtility.Contact(loaclKey + PlayerDatas.Instance.PlayerId), true); |
| | | } |
| | | |
| | | public bool IsFuncOpen() |
| | | { |
| | | if (IsBuyOne()) |
| | | return true; |
| | | if (TaskConfig.HasKey(taskID) && |
| | | TaskManager.Instance.mainTask != null && |
| | | TaskConfig.HasKey(TaskManager.Instance.mainTask.TaskID) && |
| | | TaskManager.Instance.GetNeedFinishTaskCount(taskID) <= 0) |
| | | return true; |
| | | bool isLocalFail = GetLocalFail(); |
| | | return isLocalFail; |
| | | } |
| | | |
| | | // 有一档被购买就返回true |
| | | public bool IsBuyOne() |
| | | { |
| | | var firstChargeList = FirstChargeConfig.GetKeys(); |
| | | if (firstChargeList != null) |
| | | { |
| | | firstChargeList.Sort(); |
| | | foreach (int item in firstChargeList) |
| | | { |
| | | if (TryGetFirstChargeDataByFirstId(item, out FirstChargeData data)) |
| | | { |
| | | if (data.IsUnlock() && data.IsBuy()) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public bool TryGetUnBuyFirstId(out int firstId) |
| | |
| | | UpdateRedPoint(); |
| | | OnUpdateFirstChargeInfo?.Invoke(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 检查是否所有首充奖励都已领取,如果是,则将当前服务器时间保存到本地 |
| | | /// </summary> |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 检查是否所有首充奖励都已经领取 |
| | | public bool IsAllFirstChargeRewardsClaimed() |
| | | { |
| | |
| | | var firstChargeIds = FirstChargeConfig.GetKeys(); |
| | | if (firstChargeIds == null || firstChargeIds.Count == 0) |
| | | return false; |
| | | |
| | | |
| | | foreach (var firstId in firstChargeIds) |
| | | { |
| | | // 尝试获取首充数据 |
| | | if (!TryGetFirstChargeDataByFirstId(firstId, out var firstChargeData)) |
| | | return false; |
| | | |
| | | |
| | | // 检查是否购买 |
| | | if (!firstChargeData.IsBuy()) |
| | | return false; |
| | | |
| | | |
| | | // 检查是否所有奖励都已领取 |
| | | if (!firstChargeData.IsAllHave()) |
| | | return false; |
| | |
| | | // 检查是否已经过了第二天0点 |
| | | return true; |
| | | } |
| | | |
| | | |
| | | // 检查是否已经过了所有奖励领取完毕后的第二天0点 |
| | | public bool IsNextDayAfterAllClaimed() |
| | | { |
| | | // 生成一个唯一的键来获取时间 |
| | | string key = $"FirstCharge_AllRewardsClaimed_Time_{PlayerDatas.Instance.baseData.PlayerID}"; |
| | | |
| | | |
| | | // 检查是否存在记录的时间戳 |
| | | if (!LocalSave.HasKey(key)) |
| | | return false; |
| | | |
| | | |
| | | // 获取记录的时间戳 |
| | | string timeString = LocalSave.GetString(key); |
| | | if (string.IsNullOrEmpty(timeString)) |
| | | return false; |
| | | |
| | | |
| | | // 解析时间戳 |
| | | if (!long.TryParse(timeString, out long ticks)) |
| | | return false; |
| | | |
| | | |
| | | // 将时间戳转换为DateTime |
| | | DateTime allRewardsClaimedTime = new DateTime(ticks); |
| | | |
| | | |
| | | // 计算第二天0点的时间 |
| | | DateTime nextDayStart = allRewardsClaimedTime.Date.AddDays(1); |
| | | |
| | | |
| | | // 判断当前服务器时间是否已经过了第二天0点 |
| | | DateTime serverNow = TimeUtility.ServerNow; |
| | | return serverNow >= nextDayStart; |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // ... existing code ... |
| | | |
| | | // ... existing code ... |
| | | /// <summary> |
| | | /// 获取当前时间是购买这档充值礼包的第几天 |
| | | /// 购买的当天算作第一天,第二天0点后算第二天,以此类推 |
| | |
| | | { |
| | | DateTime serverNow = TimeUtility.ServerNow; |
| | | DateTime chargeTime = TimeUtility.GetTime(ChargeTime); |
| | | |
| | | |
| | | DateTime chargeDate = chargeTime.Date; |
| | | DateTime serverDate = serverNow.Date; |
| | | |
| | | |
| | | // 计算从充值日期到当前日期的完整天数 |
| | | // 购买的当天算第一天,第二天0点后算第二天 |
| | | TimeSpan timeSpan = serverDate - chargeDate; |
| | | int days = (int)timeSpan.TotalDays + 1; // +1 因为当天算第一天 |
| | | |
| | | |
| | | int maxDay = FirstChargeManager.Instance.maxDay; |
| | | |
| | | return Mathf.Min(maxDay, Mathf.Max(1, days)); |