151 lines
5.1 KiB
C#
151 lines
5.1 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
|
|
public class EventRechargeBenefitsPanel : MonoBehaviour
|
|
{
|
|
TMP_Text text_time;
|
|
RechargeItem[] items;
|
|
PlayerShopData playerShopData;
|
|
Tables tables;
|
|
EventTotalRecharge eventTotalRecharge;
|
|
private DateTime endDateTime;
|
|
CanvasGroup root;
|
|
TotalRechargeData totalRechargeData;
|
|
TotalRechargeManager totalRechargeManager;
|
|
private void Awake()
|
|
{
|
|
totalRechargeManager = new TotalRechargeManager();
|
|
playerShopData = GContext.container.Resolve<PlayerShopData>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
root = transform.Find("root").GetComponent<CanvasGroup>();
|
|
text_time = transform.Find("root/bg_time/text_time").GetComponent<TMP_Text>();
|
|
items = transform.Find("root/Content").GetComponentsInChildren<RechargeItem>();
|
|
totalRechargeData = totalRechargeManager.GetEventData();
|
|
if (!totalRechargeManager.CheckTotalRechargeOpen(totalRechargeData))
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
if (!totalRechargeManager.CheckTotalRechargeOpen(totalRechargeData))
|
|
{
|
|
OnClickClose();
|
|
return;
|
|
}
|
|
int fishingEventID = totalRechargeData.eventID;
|
|
FishingEvent fishingEvent = tables.TbFishingEvent[fishingEventID];
|
|
endDateTime = DateTime.Parse((fishingEvent.TimeDefinition as LimitedTime)?.EndTime);
|
|
eventTotalRecharge = tables.TbEventTotalRecharge[fishingEvent.RedirectID];
|
|
List<RechargeItemData> taskList = new List<RechargeItemData>();
|
|
|
|
//显示任务
|
|
var taskIds = eventTotalRecharge.TaskList;
|
|
var vip = totalRechargeData.vip;
|
|
int oldProgress = totalRechargeData.oldProgress;
|
|
int newProgress = totalRechargeData.progress;
|
|
int taskCount = taskIds.Count;
|
|
for (int i = 0; i < taskCount; i++)
|
|
{
|
|
int taskId = taskIds[i];
|
|
CommonTask commonTask = tables.TbCommonTask.GetOrDefault(taskId);
|
|
if (commonTask != null)
|
|
{
|
|
RechargeItemData taskData = new RechargeItemData();
|
|
taskData.id = taskId;
|
|
taskData.reward = commonTask.TaskReward[vip];
|
|
|
|
string desc = LocalizationMgr.GetText(commonTask.TaskDesc_l10n_key);
|
|
int iapid = commonTask.TaskParam[vip];
|
|
var iap = tables.TbIAPItemList.GetOrDefault(iapid);
|
|
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iap);
|
|
GContext.Publish(sKUDetailDataEvent);
|
|
desc = desc.SafeFormat(sKUDetailDataEvent.price);
|
|
int TaskParam = iap.VIPPoint;
|
|
taskData.rewardState = 0;
|
|
float newvalue = newProgress;
|
|
if (newvalue >= TaskParam)
|
|
{
|
|
taskData.rewardState = 1;
|
|
newvalue = TaskParam;
|
|
}
|
|
float value = oldProgress;
|
|
if (value >= TaskParam)
|
|
{
|
|
taskData.rewardState = 2;
|
|
value = TaskParam;
|
|
}
|
|
taskData.progress = value / TaskParam;
|
|
taskData.newProgress = newvalue / TaskParam;
|
|
taskData.desc = desc;
|
|
taskList.Add(taskData);
|
|
}
|
|
else
|
|
{
|
|
UnityEngine.Debug.LogError($"Task ID {taskId} not found in CommonTask table.");
|
|
}
|
|
}
|
|
int itemCount = items.Length;
|
|
if (taskCount != itemCount)
|
|
{
|
|
Debug.LogError($"[EventRechargeBenefitsPanel] taskCount{(taskCount)} != itemCount{(itemCount)} ");
|
|
}
|
|
for (int i = 0; i < itemCount; i++)
|
|
{
|
|
RechargeItem taskItem = items[i];
|
|
taskItem.gameObject.SetActive(true);
|
|
taskItem.Init(taskList[i]);
|
|
}
|
|
if (oldProgress != newProgress)
|
|
{
|
|
//播动画,领奖
|
|
GetReward();
|
|
}
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
UpdateTimer(0);
|
|
}
|
|
async void GetReward()
|
|
{
|
|
root.blocksRaycasts = false;
|
|
|
|
await Awaiters.Seconds(0.5f);
|
|
//进度条涨
|
|
for (int i = 0; i < items.Length; i++)
|
|
{
|
|
items[i].Play();
|
|
}
|
|
await Awaiters.Seconds(1);
|
|
totalRechargeManager.GetTotalReward(RewardType.Normal, "");
|
|
GContext.Publish(new ShowData());
|
|
root.blocksRaycasts = true;
|
|
}
|
|
private void UpdateTimer(long obj)
|
|
{
|
|
TimeSpan tmpAll = GetRemainingTime(endDateTime);
|
|
if (tmpAll.TotalSeconds <= 0)
|
|
{
|
|
OnClickClose();
|
|
}
|
|
else
|
|
{
|
|
text_time.text = ConvertTools.ConvertTime2(tmpAll);
|
|
}
|
|
}
|
|
private void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
}
|
|
private TimeSpan GetRemainingTime(DateTime endDateTime)
|
|
{
|
|
return endDateTime - ZZTimeHelper.UtcNow();
|
|
}
|
|
}
|