using asap.core; using cfg; using GameCore; using System; using System.Collections.Generic; using System.Linq; using UniRx; using UnityEngine; public class TbEventLuckyTask { public List taskID = new List(); public List adReward = new List(); } /// /// 这是一个处理幸运任务数据的工具类,只有一个监听事件的状态 /// public class LuckyTaskData { public const string ADTaskADKey = "LuckyTaskADKey"; ILuckyTaskGetData luckyModel; IDisposable disposables; Tables tables; int _redCount; public int RedCount { get { return _redCount; } } List conditionTypeEvents = new List(); public LuckyTaskData(ILuckyTaskGetData luckyModel) { tables = GContext.container.Resolve(); this.luckyModel = luckyModel; disposables = GContext.OnEvent().Subscribe(UpdateTaskData); SetRedPoint(); } void UpdateTaskData(ConditionTypeEvent conditionTypeEvent) { if (conditionTypeEvents.Count > 0 && !conditionTypeEvents.Contains(conditionTypeEvent.type)) { return; } //Debug.Log($"[LuckyTaskData] UpdateTaskData {conditionTypeEvent.type} {conditionTypeEvent.count}"); var tasks = tables.TbCommonTask; var curTasks = luckyModel.DicTasks; var curTasksId = curTasks.Keys.ToList(); bool isUpdata = false; int level = curTasks.GetValueOrDefault(-2, 0); //每日任务 foreach (var taskId in curTasksId) { if (taskId <= 0) { continue; } var task = tasks.GetOrDefault(taskId); if (task == null) continue; if (!conditionTypeEvents.Contains(task.TaskType)) { conditionTypeEvents.Add(task.TaskType); } if (task.TaskType == conditionTypeEvent.type) { int taskParam = task.TaskParam[level]; if (task.TaskType == ConditionType.RechargeAmount) { var iap = tables.TbIAPItemList.GetOrDefault(taskParam); taskParam = iap.VIPPoint; } if (task.TaskType == ConditionType.ConsumeEnergy) { float inflationRate = curTasks.GetValueOrDefault(-3, 0) / 100f; taskParam = GContext.container.Resolve().IntInflation(taskParam, inflationRate); } if (curTasks[taskId] == taskParam || curTasks[taskId] == -1) { continue; } curTasks[taskId] += conditionTypeEvent.count; if (curTasks[taskId] >= taskParam) { curTasks[taskId] = taskParam; } isUpdata = true; } } if (isUpdata) { SetRedPoint(); luckyModel.SaveTaskData(); } } public async void OpenTaskPanel(Dictionary dicTasks) { GameObject taskPanelName = await UIManager.Instance.ShowUI(new UIType(luckyModel.TaskPanelName)); if (taskPanelName != null) { var panel = taskPanelName.GetComponent(); if (panel != null) { panel.InitOpen(luckyModel, dicTasks); } } } public void RefreshTasks() { InitDicTasks(); } public void InitTasks() { int inflationRate = (int)(GContext.container.Resolve().InflationRate * 100); int group = FishingEventData.Condition_NoRechargeDay() ? 1 : 0; luckyModel.DicTasks[-3] = inflationRate; // 保留轮次信息 luckyModel.DicTasks[-4] = group; // 保留轮次信息 InitDicTasks(); } /// /// 为了各个数据类不再重复写这些代码 /// 初始化任务数据 , 将任务字典清空并根据传入的任务轮次列表重新填充任务ID,初始进度为0 /// void InitDicTasks() { var tasks = tables.TbCommonTask; var curTasks = luckyModel.DicTasks; int round = curTasks.GetValueOrDefault(-1, 0); int level = curTasks.GetValueOrDefault(-2, 0); int inflationRate = curTasks.GetValueOrDefault(-3, 0); int group = curTasks.GetValueOrDefault(-4, 0); TbEventLuckyTask eventLuckyTask = GetTbEventLuckyTask(luckyModel.EventId, round + 1, group); var taskRound = eventLuckyTask.taskID; if (curTasks.Count > 0 && round > 0) { foreach (var item in curTasks) { if (item.Key > 0 && item.Value != -1) { CommonTask commonTask = tables.TbCommonTask.Get(item.Key); if (commonTask != null) { int taskParam = commonTask.TaskParam[level]; if (commonTask.TaskType == ConditionType.RechargeAmount) { var iap = tables.TbIAPItemList.GetOrDefault(taskParam); taskParam = iap.VIPPoint; } else if (commonTask.TaskType == ConditionType.ConsumeEnergy) { taskParam = GContext.container.Resolve().IntInflation(taskParam, inflationRate / 100f); } if (item.Value >= taskParam) { Dictionary newDicTasks = new Dictionary(curTasks); OpenTaskPanel(newDicTasks); break; } } } } } curTasks.Clear(); level = GContext.container.Resolve().PriceLv; if (level >= tables.TbCommonTask.DataList[0].TaskParam.Count) { level = tables.TbCommonTask.DataList[0].TaskParam.Count - 1; } curTasks[-2] = level; conditionTypeEvents.Clear(); for (int i = 0; i < taskRound.Count; i++) { var taskId = taskRound[i]; if (taskId > 0 && !curTasks.ContainsKey(taskId)) { curTasks[taskId] = 0; // 初始化任务进度为0 var task = tasks.GetOrDefault(taskId); if (!conditionTypeEvents.Contains(task.TaskType)) { conditionTypeEvents.Add(task.TaskType); } } } curTasks[-1] = ++round; // 保留轮次信息 curTasks[-3] = inflationRate; // 保留轮次信息 curTasks[-4] = group; // 保留轮次信息 _redCount = 0; luckyModel.SaveTaskData(); RedPointManager.Instance.SetRedPointState(luckyModel.LuckyTaskRedPointKey, true); } public void SetRedPoint() { var tasks = tables.TbCommonTask; var curTasks = luckyModel.DicTasks; //每日任务 _redCount = 0; int level = curTasks.GetValueOrDefault(-2, 0); float inflationRate = curTasks.GetValueOrDefault(-3, 0) / 100f; foreach (var item in curTasks) { if (item.Key <= 0 || item.Value <= 0) { continue; } var task = tasks.GetOrDefault(item.Key); if (task == null) continue; int taskParam = task.TaskParam[level]; if (task.TaskType == ConditionType.RechargeAmount) { var iap = tables.TbIAPItemList.GetOrDefault(taskParam); taskParam = iap.VIPPoint; } else if (task.TaskType == ConditionType.ConsumeEnergy) { taskParam = GContext.container.Resolve().IntInflation(taskParam, inflationRate); } if (item.Value == taskParam) { _redCount++; } } RedPointManager.Instance.SetRedPointState(luckyModel.LuckyTaskRedPointKey, _redCount > 0, _redCount); } /// /// 为了各个数据类不再重复写这些代码 /// 领取任务奖励处理任务数据,将任务状态标记为完成 -1,全部完成后重新初始化任务数据 /// /// /// public bool OnGetTaskReward(int id) { if (luckyModel.DicTasks.ContainsKey(id)) { luckyModel.DicTasks[id] = -1; SetRedPoint(); luckyModel.SaveTaskData(); return true; } else { Debug.LogError($" The current task list does not include ID : {id} "); return false; } } public void Dispose() { if (disposables != null) { disposables.Dispose(); disposables = null; } Debug.Log($"[LuckyTaskData] {this.GetType().Name} Dispose"); } /// /// /// /// /// /// key=1 value=广告组完成ID /// key=-1 value=轮次 /// key=-2 value=付费等级 /// key=-3 value=体力膨胀系数 /// key=-4 value=普通组还是广告组 /// public static TbEventLuckyTask GetTbEventLuckyTask(int eventID, int round, int group) { TbEventLuckyTask tbEventLuckyTask = new TbEventLuckyTask(); Tables tables = GContext.container.Resolve(); FishingEvent fishingEvent = tables.TbFishingEvent.GetOrDefault(eventID); if (fishingEvent.Type == 8) { if (round > 2) { round = 2; } switch (fishingEvent.SubType) { case 3: return GetTbEventLuckMagicTask(round, group); case 4: return GetTbEventLuckyCardsTask(round, group); default: break; } } return tbEventLuckyTask; } static TbEventLuckyTask GetTbEventLuckMagicTask(int round, int group) { TbEventLuckyTask tbEventLuckyTask = new TbEventLuckyTask(); Tables tables = GContext.container.Resolve(); List taskDataList = tables.TbEventLuckMagicTask.DataList; var taskList = taskDataList.Where(t => t.Round == round && t.Type == group).ToList(); tbEventLuckyTask.taskID = taskList.Where(t => t.CommonTask > 0).Select(t => t.CommonTask).ToList(); tbEventLuckyTask.adReward = taskDataList.Where(t => t.AdReward > 0).Select(t => t.AdReward).ToList(); return tbEventLuckyTask; } static TbEventLuckyTask GetTbEventLuckyCardsTask(int round, int group) { TbEventLuckyTask tbEventLuckyTask = new TbEventLuckyTask(); Tables tables = GContext.container.Resolve(); List taskDataList = tables.TbEventLuckyCardsTask.DataList; var taskList = taskDataList.Where(t => t.Round == round && t.Type == group).ToList(); tbEventLuckyTask.taskID = taskList.Where(t => t.CommonTask > 0).Select(t => t.CommonTask).ToList(); tbEventLuckyTask.adReward = taskDataList.Where(t => t.AdReward > 0).Select(t => t.AdReward).ToList(); return tbEventLuckyTask; } } /// /// 给 LuckyTaskData 使用的接口 /// public interface ILuckyTaskGetData { /// /// 任务进度数据 key:任务ID value:任务进度 -1表示已完成 /// key=-1 value=轮次 /// key=-2 value=付费等级 /// key=-3 value=体力膨胀系数 /// key=-4 value=普通组还是广告组 /// public Dictionary DicTasks { get; set; } public string TaskPanelName { get; } public string LuckyTaskRedPointKey { get; }//luckgame "eventluckmagic.entrance" public void SaveTaskData(); public int EventId { get; } /// /// 领取奖励,标记任务为完成状态 -1 /// /// /// public bool OnGetTaskReward(int id); /// /// 获取幸运无限购买礼包ID /// /// public int GetLuckyPackID(); }