342 lines
12 KiB
C#
342 lines
12 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class LuckyADTaskPopupPanel : LuckyTaskPanelBase
|
|
{
|
|
List<LuckyTaskItemData> taskList;
|
|
List<LuckyADTaskItem> taskItems = new List<LuckyADTaskItem>();
|
|
List<LuckyADTaskItemData> taskADList = new List<LuckyADTaskItemData>();
|
|
LuckyADTask luckyTaskItem;
|
|
TMP_Text text_time;
|
|
Timer timer;
|
|
System.DateTime refreshTime;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
luckyTaskItem = transform.Find("root/hook_missions_object").GetComponent<LuckyADTask>();
|
|
text_time = transform.Find("root/text_time").GetComponent<TMP_Text>();
|
|
}
|
|
protected override void SetItem()
|
|
{
|
|
taskList = new List<LuckyTaskItemData>();
|
|
int level = taskData.GetValueOrDefault(-2, 0);
|
|
float inflationRate = taskData.GetValueOrDefault(-3, 0) / 100f;
|
|
foreach (var item in taskData)
|
|
{
|
|
if (item.Key <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
CommonTask commonTask = tables.TbCommonTask.Get(item.Key);
|
|
if (commonTask != null)
|
|
{
|
|
LuckyTaskItemData luckyTaskData = new LuckyTaskItemData();
|
|
luckyTaskData.id = item.Key;
|
|
int dropID = commonTask.TaskReward[level];
|
|
|
|
luckyTaskData.reward = dropID;
|
|
|
|
luckyTaskData.inflationRate = inflationRate;
|
|
string desc = LocalizationMgr.GetText(commonTask.TaskDesc_l10n_key);
|
|
int taskParam = commonTask.TaskParam[level];
|
|
if (commonTask.TaskType == ConditionType.ConsumeEnergy)
|
|
{
|
|
taskParam = GContext.container.Resolve<PlayerItemData>().IntInflation(taskParam, inflationRate);
|
|
}
|
|
luckyTaskData.target = taskParam;
|
|
luckyTaskData.progress = taskParam;
|
|
if (item.Value == -1)
|
|
{
|
|
luckyTaskData.state = -1;
|
|
}
|
|
else if (item.Value >= taskParam)
|
|
{
|
|
luckyTaskData.state = 1;
|
|
}
|
|
else
|
|
{
|
|
luckyTaskData.progress = item.Value;
|
|
luckyTaskData.state = 0;
|
|
}
|
|
desc = desc.SafeFormat(taskParam);
|
|
luckyTaskData.desc = desc;
|
|
taskList.Add(luckyTaskData);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"Task ID {item.Key} not found in CommonTask table.");
|
|
}
|
|
}
|
|
taskList.Sort((a, b) => b.state.CompareTo(a.state)); // 按state排序
|
|
luckyTaskItem.Init(taskList[0], OnClickLuckyTaskItem);
|
|
SetADItem();
|
|
}
|
|
void SetADItem()
|
|
{
|
|
taskADList = SetADItemData();
|
|
for (int i = 0; i < taskADList.Count; i++)
|
|
{
|
|
LuckyADTaskItem luckyTaskItem = Instantiate(itemPrefab, content).AddComponent<LuckyADTaskItem>();
|
|
luckyTaskItem.gameObject.SetActive(true);
|
|
luckyTaskItem.Init(taskADList[i], OnBuySuccess);
|
|
taskItems.Add(luckyTaskItem);
|
|
}
|
|
//设置倒计时
|
|
var nowTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
refreshTime = nowTime.Date.AddDays(1);
|
|
TimeSpan now = refreshTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh",
|
|
ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds));
|
|
double seconds = now.TotalSeconds;
|
|
if (seconds < 1)
|
|
{
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
timer = this.AttachTimer((float)seconds, Refresh,
|
|
(elapsed) =>
|
|
{
|
|
now = refreshTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh",
|
|
ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds));
|
|
}, useRealTime: true);
|
|
}
|
|
}
|
|
void Refresh()
|
|
{
|
|
timer?.Cancel();
|
|
timer = null;
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
}
|
|
List<LuckyADTaskItemData> SetADItemData()
|
|
{
|
|
int round = taskData.GetValueOrDefault(-1, 0);
|
|
float inflationRate = taskData.GetValueOrDefault(-3, 0) / 100f;
|
|
int group = taskData.GetValueOrDefault(-4, 0);
|
|
string adData = PlayFabMgr.Instance.GetLocalData(LuckyTaskData.ADTaskADKey);
|
|
int index = 0;
|
|
int curDay = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
|
if (!string.IsNullOrEmpty(adData))
|
|
{
|
|
string[] strings = adData.Split("|");
|
|
int day = -1;
|
|
if (strings.Length == 2 && int.TryParse(strings[1], out day) && day == curDay)
|
|
{
|
|
int.TryParse(strings[0], out index);
|
|
}
|
|
else
|
|
{
|
|
adData = $"{index}|{curDay}";
|
|
PlayFabMgr.Instance.UpdateUserDataValue(LuckyTaskData.ADTaskADKey, adData);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
adData = $"{index}|{curDay}";
|
|
PlayFabMgr.Instance.UpdateUserDataValue(LuckyTaskData.ADTaskADKey, adData);
|
|
}
|
|
List<LuckyADTaskItemData> taskADList = new List<LuckyADTaskItemData>();
|
|
TbEventLuckyTask eventLuckyTask = LuckyTaskData.GetTbEventLuckyTask(luckyModel.EventId, round, group);
|
|
var adReward = eventLuckyTask.adReward;
|
|
for (int i = 0; i < adReward.Count; i++)
|
|
{
|
|
int dropID = adReward[i];
|
|
LuckyADTaskItemData luckyTaskData = new LuckyADTaskItemData();
|
|
luckyTaskData.reward = dropID;
|
|
luckyTaskData.inflationRate = inflationRate;
|
|
luckyTaskData.index = i;
|
|
if (i < index)
|
|
{
|
|
luckyTaskData.state = -1;
|
|
}
|
|
else if (i == index)
|
|
{
|
|
luckyTaskData.state = 1;
|
|
}
|
|
taskADList.Add(luckyTaskData);
|
|
}
|
|
taskADList.Sort((a, b) => b.state.CompareTo(a.state)); // 按state排序
|
|
return taskADList;
|
|
}
|
|
void OnBuySuccess(LuckyADTaskItem luckyADTaskItem)
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
//领奖
|
|
int dropID = luckyADTaskItem.data.reward;
|
|
|
|
ChangeSource changeSource = new ChangeSource(EventId, "Event_Minigame3", "Event_Minigame3_LuckMagic", "TaskReward");
|
|
if (fishingEvent.SubType == 4)
|
|
{
|
|
changeSource.Source_Type = "Event_Minigame3_LuckyCards";
|
|
}
|
|
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDropLureInflation(luckyTaskItem.data.inflationRate, dropID, changeSource, false);
|
|
|
|
luckyADTaskItem.Play();
|
|
|
|
string adData = PlayFabMgr.Instance.GetLocalData(LuckyTaskData.ADTaskADKey);
|
|
int index = 0;
|
|
int day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
|
if (!string.IsNullOrEmpty(adData))
|
|
{
|
|
string[] strings = adData.Split("|");
|
|
if (strings.Length == 2)
|
|
{
|
|
int.TryParse(strings[0], out index);
|
|
int.TryParse(strings[1], out day);
|
|
}
|
|
}
|
|
//保存进度
|
|
index++;
|
|
adData = $"{index}|{day}";
|
|
PlayFabMgr.Instance.UpdateUserDataValue(LuckyTaskData.ADTaskADKey, adData);
|
|
RefreshADItemState(index);
|
|
canvasGroup.blocksRaycasts = true;
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
void RefreshADItemState(int index)
|
|
{
|
|
for (int i = 0; i < taskADList.Count; i++)
|
|
{
|
|
taskADList[i].state = 0;
|
|
if (taskADList[i].index < index)
|
|
{
|
|
taskADList[i].state = -1;
|
|
}
|
|
else if (taskADList[i].index == index)
|
|
{
|
|
taskADList[i].state = 1;
|
|
}
|
|
taskItems[i].Refresh();
|
|
}
|
|
}
|
|
void RefreshAdItem()
|
|
{
|
|
|
|
}
|
|
public void TaskItemPlay(LuckyADTask luckyTaskItem)
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
try
|
|
{
|
|
luckyTaskItem.data.state = -1; // 更新状态为已领取
|
|
luckyTaskItem.Refresh();
|
|
luckyTaskItem.Play();
|
|
taskList.Sort((a, b) => b.state.CompareTo(a.state)); // 按state排序
|
|
luckyTaskItem.PlayFillAmount(taskList[0]);
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError($"Error during TaskItemPlay: {ex.Message}");
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
|
|
void OnClickLuckyTaskItem(LuckyADTask luckyTaskItem)
|
|
{
|
|
if (IsOpen)
|
|
{
|
|
//奖励补领
|
|
OnClickLuckyTaskItem1(luckyTaskItem);
|
|
return;
|
|
}
|
|
if (luckyTaskItem.data.state == 1)
|
|
{
|
|
bool result = luckyModel.OnGetTaskReward(luckyTaskItem.data.id);
|
|
if (result)
|
|
{
|
|
CommonTask commonTask = tables.TbCommonTask.GetOrDefault(luckyTaskItem.data.id);
|
|
if (commonTask != null)
|
|
{
|
|
// 任务奖励
|
|
int level = taskData.GetValueOrDefault(-2, 0);
|
|
int dropID = commonTask.TaskReward[level];
|
|
|
|
ChangeSource changeSource = new ChangeSource(EventId, "Event_Minigame3", "Event_Minigame3_LuckMagic", "TaskReward");
|
|
if (fishingEvent.SubType == 4)
|
|
{
|
|
changeSource.Source_Type = "Event_Minigame3_LuckyCards";
|
|
}
|
|
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDropLureInflation(luckyTaskItem.data.inflationRate, dropID, changeSource, false);
|
|
if (rewardItem != null)
|
|
{
|
|
TaskItemPlay(luckyTaskItem);
|
|
}
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("event_lucky_task"))
|
|
{
|
|
int round = luckyModel.DicTasks.GetValueOrDefault(-1, 0);
|
|
e.AddContent("task_id", luckyTaskItem.data.id)
|
|
.AddContent("round", round)
|
|
.AddContent("combine_id", round * 100000 + luckyTaskItem.data.id % 10000)
|
|
.AddContent("task_reward", dropID);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("任务奖励领取失败");
|
|
}
|
|
}
|
|
else if (luckyTaskItem.data.state == 0)
|
|
{
|
|
OnClickGo(luckyTaskItem.data.id);
|
|
Debug.Log("任务未完成,无法领取奖励");
|
|
}
|
|
else if (luckyTaskItem.data.state == -1)
|
|
{
|
|
Debug.Log("任务已领取,无法重复领取");
|
|
}
|
|
}
|
|
|
|
void OnClickLuckyTaskItem1(LuckyADTask luckyTaskItem)
|
|
{
|
|
if (luckyTaskItem.data.state == 1)
|
|
{
|
|
CommonTask commonTask = tables.TbCommonTask.GetOrDefault(luckyTaskItem.data.id);
|
|
taskData[luckyTaskItem.data.id] = -1; // 标记为已领取
|
|
if (commonTask != null)
|
|
{
|
|
// 任务奖励
|
|
int level = taskData.GetValueOrDefault(-2, 0);
|
|
int dropID = commonTask.TaskReward[level];
|
|
ChangeSource changeSource = new ChangeSource(EventId, "Event_Minigame3", "Event_Minigame3_LuckMagic", "TaskReward");
|
|
if (fishingEvent.SubType == 4)
|
|
{
|
|
changeSource.Source_Type = "Event_Minigame3_LuckyCards";
|
|
}
|
|
|
|
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDropLureInflation(luckyTaskItem.data.inflationRate, dropID, changeSource, false);
|
|
if (rewardItem != null)
|
|
{
|
|
TaskItemPlay(luckyTaskItem);
|
|
}
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("event_lucky_task"))
|
|
{
|
|
int round = luckyModel.DicTasks.GetValueOrDefault(-1, 0);
|
|
e.AddContent("task_id", luckyTaskItem.data.id)
|
|
.AddContent("round", round)
|
|
.AddContent("combine_id", round * 100000 + luckyTaskItem.data.id % 10000)
|
|
.AddContent("task_reward", dropID);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
}
|
|
}
|
|
|
|
}
|