using asap.core;
using cfg;
using game;
using GameCore;
using System.Collections.Generic;
using UnityEngine;
public class LuckyTaskPanelBase : MonoBehaviour
{
///
/// luckyModel 也作为是否自动全部领奖的标志
///
protected ILuckyTaskGetData luckyModel;
protected Tables tables;
protected GameObject itemPrefab;
protected CanvasGroup canvasGroup;
protected Transform content;
protected Dictionary taskData;
protected int EventId;
protected FishingEvent fishingEvent;
protected bool IsOpen;
protected virtual void Awake()
{
canvasGroup = GetComponent();
itemPrefab = transform.Find("root/ScrollView/Viewport/Content/item1").gameObject;
itemPrefab.SetActive(false);
content = transform.Find("root/ScrollView/Viewport/Content");
}
public void Init(ILuckyTaskGetData panelCallTaskData)
{
IsOpen = false;
taskData = panelCallTaskData.DicTasks;
SetData(panelCallTaskData);
}
public void InitOpen(ILuckyTaskGetData panelCallTaskData, Dictionary dicTasks)
{
IsOpen = true;
taskData = dicTasks;
SetData(panelCallTaskData);
}
void SetData(ILuckyTaskGetData panelCallTaskData)
{
tables = GContext.container.Resolve();
luckyModel = panelCallTaskData;
EventId = panelCallTaskData.EventId;
fishingEvent = tables.TbFishingEvent.GetOrDefault(EventId);
SetItem();
}
protected virtual void SetItem()
{
}
async void GetReward()
{
List dropID = new List();
int level = taskData.GetValueOrDefault(-2, 0);
float inflationRate = taskData.GetValueOrDefault(-3, 0) / 100f;
int commonTaskId = 0; ;
foreach (var item in taskData)
{
if (item.Key > 0 && item.Value != -1)
{
CommonTask commonTask = tables.TbCommonTask.Get(item.Key);
if (commonTask != null)
{
commonTaskId = commonTask.Id;
int taskParam = commonTask.TaskParam[level];
int taskReward = commonTask.TaskReward[level];
if (commonTask.TaskType == ConditionType.RechargeAmount)
{
var iap = tables.TbIAPItemList.GetOrDefault(taskParam);
taskParam = iap.VIPPoint;
if (item.Value >= taskParam)
{
dropID.Add(taskReward);
}
}
else
{
if (commonTask.TaskType == ConditionType.ConsumeEnergy)
{
taskParam = GContext.container.Resolve().IntInflation(taskParam, inflationRate);
}
if (item.Value >= taskParam)
{
dropID.Add(taskReward);
}
}
}
}
}
if (dropID.Count > 0)
{
ChangeSource changeSource = new ChangeSource(EventId, "Event_Minigame3", "Event_Minigame3_LuckMagic", "TaskReward");
if (fishingEvent.SubType == 4)
{
changeSource.Source_Type = "Event_Minigame3_LuckyCards";
}
var itemDatas = GContext.container.Resolve().AddItemByDropListLureInflation(inflationRate, dropID, changeSource);
GContext.Publish(new ShowData());
await Awaiters.Seconds(0.5f);
ToastPanel.Show(LocalizationMgr.GetText("UI_COMMON_missions_refreshed"));
}
}
protected async void OnClickGo(int id)
{
await Awaiters.NextFrame;
var task = tables.TbCommonTask.Get(id);
switch (task.TaskType)
{
case ConditionType.Complete1v1Count:
case ConditionType.ConsumeEnergy:
GContext.Publish(new UnloadActToNextAct());
break;
case ConditionType.CollectFishCardCount:
case ConditionType.ConsumeDiamondCount:
await UIManager.Instance.ShowUI(UITypes.FishingShopPanel);
GContext.Publish(new LackOfResourceConfirmEvent() { state = 0 });
break;
case ConditionType.MakeInAppPurchase:
case ConditionType.RechargeAmount:
int packID = luckyModel.GetLuckyPackID();
if (packID <= 0)
{
Debug.LogError("Lucky Pack ID is invalid or not set.");
return;
}
EventPackManager eventPackManager = tables.TbEventPackManager.GetOrDefault(packID);
if (eventPackManager == null)
{
Debug.LogError($"EventPackManager with ID {packID} not found.");
return;
}
GameObject go = await UIManager.Instance.ShowUI(new UIType(eventPackManager.Panel));
if (go != null)
{
EventLuckyTriplePackPanel triple = go.GetComponent();
triple.Init(EventLuckyTriplePackData.Create(EventId, packID));
}
break;
}
UIManager.Instance.DestroyUI(gameObject.name);
}
private void OnDisable()
{
if (IsOpen)
{
GetReward();
}
}
}