252 lines
9.5 KiB
C#
252 lines
9.5 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LuckyTaskPanel : LuckyTaskPanelBase
|
|
{
|
|
/// <summary>
|
|
/// luckyModel 也作为是否自动全部领奖的标志
|
|
/// </summary>
|
|
List<LuckyTaskItem> taskItems = new List<LuckyTaskItem>();
|
|
protected override void SetItem()
|
|
{
|
|
string adData = PlayFabMgr.Instance.GetLocalData(LuckyTaskData.ADTaskADKey);
|
|
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)
|
|
{
|
|
adData = $"{0}|{curDay}";
|
|
PlayFabMgr.Instance.UpdateUserDataValue(LuckyTaskData.ADTaskADKey, adData);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
adData = $"{0}|{curDay}";
|
|
PlayFabMgr.Instance.UpdateUserDataValue(LuckyTaskData.ADTaskADKey, adData);
|
|
}
|
|
List<LuckyTaskItemData> 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);
|
|
string progressText;
|
|
if (commonTask.TaskType == ConditionType.RechargeAmount)
|
|
{
|
|
//sku.ProdPrice
|
|
int iapid = commonTask.TaskParam[level];
|
|
var iap = tables.TbIAPItemList.GetOrDefault(iapid);
|
|
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iap);
|
|
GContext.Publish(sKUDetailDataEvent);
|
|
desc = desc.SafeFormat(sKUDetailDataEvent.price);
|
|
float TaskParam = iap.VIPPoint;
|
|
float value = item.Value;
|
|
float ratio = value / TaskParam;
|
|
float ProdPrice = sKUDetailDataEvent.prodPrice;
|
|
float truncatedPrice = (float)Mathf.Ceil(ratio * ProdPrice * 100) / 100;
|
|
progressText = $"({truncatedPrice:F2}/{ProdPrice})";
|
|
if (item.Value == -1)
|
|
{
|
|
progressText = $"({ProdPrice}/{ProdPrice})";
|
|
luckyTaskData.state = -1;
|
|
}
|
|
else if (value >= TaskParam)
|
|
{
|
|
luckyTaskData.state = 1;
|
|
}
|
|
else
|
|
{
|
|
luckyTaskData.state = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int taskParam = commonTask.TaskParam[level];
|
|
if (commonTask.TaskType == ConditionType.ConsumeEnergy)
|
|
{
|
|
taskParam = GContext.container.Resolve<PlayerItemData>().IntInflation(taskParam, inflationRate);
|
|
}
|
|
progressText = $"({item.Value}/{taskParam})";
|
|
if (item.Value == -1)
|
|
{
|
|
progressText = $"({taskParam}/{taskParam})";
|
|
luckyTaskData.state = -1;
|
|
}
|
|
else if (item.Value >= taskParam)
|
|
{
|
|
luckyTaskData.state = 1;
|
|
}
|
|
else
|
|
{
|
|
luckyTaskData.state = 0;
|
|
}
|
|
desc = desc.SafeFormat(taskParam);
|
|
}
|
|
luckyTaskData.desc = desc + progressText;
|
|
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排序
|
|
for (int i = 0; i < taskList.Count; i++)
|
|
{
|
|
LuckyTaskItem luckyTaskItem = Instantiate(itemPrefab, content).AddComponent<LuckyTaskItem>();
|
|
luckyTaskItem.gameObject.SetActive(true);
|
|
luckyTaskItem.Init(taskList[i], OnClickLuckyTaskItem);
|
|
taskItems.Add(luckyTaskItem);
|
|
}
|
|
}
|
|
|
|
public void TaskItemPlay(LuckyTaskItem luckyTaskItem)
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
try
|
|
{
|
|
luckyTaskItem.data.state = -1; // 更新状态为已领取
|
|
luckyTaskItem.Refresh();
|
|
luckyTaskItem.Play();
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError($"Error during TaskItemPlay: {ex.Message}");
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
|
|
void OnClickLuckyTaskItem(LuckyTaskItem 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(LuckyTaskItem 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);
|
|
}
|
|
}
|
|
}
|
|
public class LuckyTaskItemData
|
|
{
|
|
public int id;
|
|
public string desc;
|
|
public int target;
|
|
public int reward;
|
|
public int progress;
|
|
/// <summary>
|
|
/// // 0:未完成 1:可领取 -1:已领取
|
|
/// </summary>
|
|
public int state;
|
|
public float inflationRate;
|
|
}
|