备份CatanBuilding瘦身独立工程
This commit is contained in:
266
Assets/Scripts/LuckyTask/LuckyTaskData.cs
Normal file
266
Assets/Scripts/LuckyTask/LuckyTaskData.cs
Normal file
@@ -0,0 +1,266 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// 这是一个处理幸运任务数据的工具类,只有一个监听事件的状态
|
||||
/// </summary>
|
||||
public class LuckyTaskData
|
||||
{
|
||||
ILuckyTaskGetData luckyModel;
|
||||
IDisposable disposables;
|
||||
Tables tables;
|
||||
List<ConditionType> conditionTypeEvents = new List<ConditionType>();
|
||||
public LuckyTaskData(ILuckyTaskGetData luckyModel)
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
this.luckyModel = luckyModel;
|
||||
disposables = GContext.OnEvent<ConditionTypeEvent>().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 (curTasks[taskId] == taskParam || curTasks[taskId] == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
curTasks[taskId] += conditionTypeEvent.count;
|
||||
if (curTasks[taskId] >= taskParam)
|
||||
{
|
||||
curTasks[taskId] = taskParam;
|
||||
}
|
||||
|
||||
isUpdata = true;
|
||||
}
|
||||
}
|
||||
if (isUpdata)
|
||||
{
|
||||
luckyModel.SaveTaskData();
|
||||
SetRedPoint();
|
||||
}
|
||||
}
|
||||
|
||||
public async void OpenTaskPanel(Dictionary<int, int> dicTasks)
|
||||
{
|
||||
GameObject taskPanelName = await UIManager.Instance.ShowUI(new UIType(luckyModel.TaskPanelName));
|
||||
if (taskPanelName != null)
|
||||
{
|
||||
var panel = taskPanelName.GetComponent<LuckyTaskPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
panel.Init(dicTasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为了各个数据类不再重复写这些代码
|
||||
/// 初始化任务数据 , 将任务字典清空并根据传入的任务轮次列表重新填充任务ID,初始进度为0
|
||||
/// </summary>
|
||||
/// <param name="taskRound"></param>
|
||||
public void InitDicTasks(List<int> taskRound)
|
||||
{
|
||||
if (taskRound != null)
|
||||
{
|
||||
var tasks = tables.TbCommonTask;
|
||||
var curTasks = luckyModel.DicTasks;
|
||||
int round = curTasks.GetValueOrDefault(-1, 0);
|
||||
int level = curTasks.GetValueOrDefault(-2, 0);
|
||||
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;
|
||||
}
|
||||
if (item.Value >= taskParam)
|
||||
{
|
||||
Dictionary<int, int> newDicTasks = new Dictionary<int, int>(curTasks);
|
||||
OpenTaskPanel(newDicTasks);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
curTasks.Clear();
|
||||
level = GContext.container.Resolve<PlayerData>().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; // 保留轮次信息
|
||||
luckyModel.SaveTaskData();
|
||||
//SetRedPoint();
|
||||
RedPointManager.Instance.SetRedPointState(luckyModel.LuckyTaskRedPointKey, true);
|
||||
}
|
||||
}
|
||||
public void SetRedPoint()
|
||||
{
|
||||
var tasks = tables.TbCommonTask;
|
||||
var curTasks = luckyModel.DicTasks;
|
||||
//每日任务
|
||||
int count = 0;
|
||||
int level = curTasks.GetValueOrDefault(-2, 0);
|
||||
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;
|
||||
}
|
||||
if (item.Value == taskParam)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
RedPointManager.Instance.SetRedPointState(luckyModel.LuckyTaskRedPointKey, count > 0, count);
|
||||
}
|
||||
/// <summary>
|
||||
/// 为了各个数据类不再重复写这些代码
|
||||
/// 领取任务奖励处理任务数据,将任务状态标记为完成 -1,全部完成后重新初始化任务数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="taskRound2"></param>
|
||||
/// <returns></returns>
|
||||
public bool OnGetTaskReward(int id, List<int> taskRound2)
|
||||
{
|
||||
if (luckyModel.DicTasks.ContainsKey(id))
|
||||
{
|
||||
luckyModel.DicTasks[id] = -1;
|
||||
luckyModel.SaveTaskData();
|
||||
SetRedPoint();
|
||||
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");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 给 LuckyTaskData 使用的接口
|
||||
/// </summary>
|
||||
|
||||
public interface ILuckyTaskGetData
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务进度数据 key:任务ID value:任务进度 -1表示已完成
|
||||
/// key=-1 value=轮次
|
||||
/// key=-2 value=付费等级
|
||||
/// </summary>
|
||||
public Dictionary<int, int> DicTasks { get; set; }
|
||||
public string TaskPanelName { get; }
|
||||
public string LuckyTaskRedPointKey { get; }//luckgame "eventluckmagic.entrance"
|
||||
public void SaveTaskData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 任务面板获取数据接口
|
||||
/// </summary>
|
||||
public interface ILuckyTaskUIGetData
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务进度数据
|
||||
/// </summary>
|
||||
public Dictionary<int, int> DicTasks { get; }
|
||||
/// <summary>
|
||||
/// 领取奖励,标记任务为完成状态 -1
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public bool OnGetTaskReward(int id);
|
||||
/// <summary>
|
||||
/// 获取任务面板名称
|
||||
/// </summary>
|
||||
public string TaskPanelName { get; }
|
||||
/// <summary>
|
||||
/// 获取幸运无限购买礼包ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetLuckyPackID();
|
||||
public int EventId { get; }
|
||||
}
|
||||
|
||||
|
||||
11
Assets/Scripts/LuckyTask/LuckyTaskData.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/LuckyTaskData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68f8129dff34d924e9fe978b0a2d522e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/LuckyTask/UI.meta
Normal file
8
Assets/Scripts/LuckyTask/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b803e1d45f5e95f4caf49e7f2ca08124
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs
Normal file
82
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LuckyTaskBtn : MonoBehaviour, IUIRedPoint
|
||||
{
|
||||
Button btn;
|
||||
ILuckyTaskUIGetData model;
|
||||
|
||||
public string key;
|
||||
public GameObject redPoint;
|
||||
public GameObject redpoint_big;
|
||||
public TMP_Text text_redpoint_big;
|
||||
void Awake()
|
||||
{
|
||||
btn = GetComponent<Button>();
|
||||
btn.onClick.AddListener(OnClick);
|
||||
}
|
||||
public void Init(ILuckyTaskUIGetData model, string key)
|
||||
{
|
||||
this.model = model;
|
||||
this.key = key;
|
||||
SetKey();
|
||||
}
|
||||
async void OnClick()
|
||||
{
|
||||
if (model != null)
|
||||
{
|
||||
GameObject taskPanelName = await UIManager.Instance.ShowUI(new UIType(model.TaskPanelName));
|
||||
if (taskPanelName != null)
|
||||
{
|
||||
var panel = taskPanelName.GetComponent<LuckyTaskPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
panel.Init(model);
|
||||
int count = RedPointManager.Instance.GetRedPointCount(key);
|
||||
RedPointManager.Instance.SetRedPointState(key, count > 0, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(key))
|
||||
{
|
||||
RedPointManager.Instance.RemoveRedPoint(key);
|
||||
key = "";
|
||||
}
|
||||
}
|
||||
public void SetKey()
|
||||
{
|
||||
RedPointManager.Instance.AddRedPoint(key, this);
|
||||
SetRedPointState(RedPointManager.Instance.GetRedPointState(key));
|
||||
}
|
||||
|
||||
public void SetRedPointState(bool state)
|
||||
{
|
||||
int count = RedPointManager.Instance.GetRedPointCount(key);
|
||||
if (count > 1)
|
||||
{
|
||||
redpoint_big.SetActive(true);
|
||||
if (count > 99)
|
||||
{
|
||||
text_redpoint_big.text = "99+";
|
||||
}
|
||||
else
|
||||
{
|
||||
text_redpoint_big.text = count.ToString();
|
||||
}
|
||||
state = false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
redpoint_big.SetActive(false);
|
||||
}
|
||||
redPoint.SetActive(state);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskBtn.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b7ca70f61cc7c74fa993a291c27a535
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
107
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs
Normal file
107
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LuckyTaskItem : MonoBehaviour
|
||||
{
|
||||
public LuckyTaskItemData data { get; private set; }
|
||||
GameObject bg_cliam;
|
||||
Button btn_claim;
|
||||
GameObject bg_normal;
|
||||
Button btnGo;
|
||||
TMP_Text taskDescText;
|
||||
List<RewardItemNew> rewardItemNews = new List<RewardItemNew>();
|
||||
GameObject mask;
|
||||
Action<LuckyTaskItem> action;
|
||||
int count = 0;
|
||||
private void Awake()
|
||||
{
|
||||
bg_cliam = transform.Find("bg_cliam").gameObject;
|
||||
btn_claim = transform.Find("bg_cliam/btn_claim/btn_green_c").GetComponent<Button>();
|
||||
bg_normal = transform.Find("bg_normal").gameObject;
|
||||
btnGo = transform.Find("bg_normal/btn_go/btn_green_c").GetComponent<Button>();
|
||||
taskDescText = transform.Find("text_task").GetComponent<TMP_Text>();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var rewardItem = transform.Find($"reward{i + 1}").GetComponent<RewardItemNew>();
|
||||
if (rewardItem != null)
|
||||
{
|
||||
rewardItemNews.Add(rewardItem);
|
||||
}
|
||||
}
|
||||
mask = transform.Find("bg_done").gameObject;
|
||||
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (btnGo != null)
|
||||
{
|
||||
btnGo.onClick.AddListener(OnClick);
|
||||
}
|
||||
if (btn_claim != null)
|
||||
{
|
||||
btn_claim.onClick.AddListener(OnClick);
|
||||
}
|
||||
}
|
||||
public void Init(LuckyTaskItemData luckyTaskItemData, Action<LuckyTaskItem> action)
|
||||
{
|
||||
this.action = action;
|
||||
this.data = luckyTaskItemData;
|
||||
SetItem();
|
||||
}
|
||||
void SetItem()
|
||||
{
|
||||
Refresh();
|
||||
taskDescText.text = data.desc;
|
||||
var itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(data.reward);
|
||||
if (itemData != null)
|
||||
{
|
||||
count = itemData.Count;
|
||||
if (count > rewardItemNews.Count)
|
||||
{
|
||||
count = rewardItemNews.Count;
|
||||
Debug.LogError($"LuckyTask Reward {data.reward} > PanelItem Count");
|
||||
}
|
||||
for (int i = 0; i < rewardItemNews.Count; i++)
|
||||
{
|
||||
if (count > i)
|
||||
{
|
||||
rewardItemNews[i].gameObject.SetActive(true);
|
||||
rewardItemNews[i].SetData(itemData[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardItemNews[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Play()
|
||||
{
|
||||
data.state = -1; // 更新状态为已领取
|
||||
Refresh();
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
rewardItemNews[i].ParticleAttractor(ignorePack: true);
|
||||
}
|
||||
await rewardItemNews[0].ParticleAttractor(ignorePack: true);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
mask.SetActive(data.state == -1);
|
||||
btnGo.gameObject.SetActive(data.state == 0);
|
||||
bg_normal.gameObject.SetActive(data.state <= 0);
|
||||
bg_cliam.gameObject.SetActive(data.state == 1);
|
||||
}
|
||||
void OnClick()
|
||||
{
|
||||
action?.Invoke(this);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskItem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96c5aec112649fe43a1a1a1e2adbed53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
311
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs
Normal file
311
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs
Normal file
@@ -0,0 +1,311 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LuckyTaskPanel : MonoBehaviour
|
||||
{
|
||||
ILuckyTaskUIGetData luckyModel;
|
||||
Tables tables;
|
||||
GameObject itemPrefab;
|
||||
CanvasGroup canvasGroup;
|
||||
Transform content;
|
||||
List<LuckyTaskItem> taskItems = new List<LuckyTaskItem>();
|
||||
Dictionary<int, int> taskData;
|
||||
private void Awake()
|
||||
{
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
itemPrefab = transform.Find("root/ScrollView/Viewport/Content/item1").gameObject;
|
||||
itemPrefab.SetActive(false);
|
||||
content = transform.Find("root/ScrollView/Viewport/Content");
|
||||
}
|
||||
public void Init(ILuckyTaskUIGetData panelCallTaskData)
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
this.luckyModel = panelCallTaskData;
|
||||
taskData = luckyModel.DicTasks;
|
||||
SetItem();
|
||||
}
|
||||
public void Init(Dictionary<int, int> dicTasks)
|
||||
{
|
||||
tables = GContext.container.Resolve<Tables>();
|
||||
taskData = dicTasks;
|
||||
SetItem();
|
||||
}
|
||||
void SetItem()
|
||||
{
|
||||
List<LuckyTaskItemData> taskList = new List<LuckyTaskItemData>();
|
||||
int level = taskData.GetValueOrDefault(-2, 0);
|
||||
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;
|
||||
luckyTaskData.reward = commonTask.TaskReward;
|
||||
|
||||
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];
|
||||
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 async void TaskItemPlay(LuckyTaskItem luckyTaskItem)
|
||||
{
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
try
|
||||
{
|
||||
await 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 (luckyModel == null)
|
||||
{
|
||||
//奖励补领
|
||||
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)
|
||||
{
|
||||
// 任务奖励
|
||||
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDrop(commonTask.TaskReward, 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", commonTask.TaskReward);
|
||||
}
|
||||
#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)
|
||||
{
|
||||
// 任务奖励
|
||||
List<ItemData> rewardItem = GContext.container.Resolve<PlayerItemData>().AddItemByDrop(commonTask.TaskReward, 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", commonTask.TaskReward);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
async void GetReward()
|
||||
{
|
||||
List<int> dropID = new List<int>();
|
||||
int level = taskData.GetValueOrDefault(-2, 0);
|
||||
foreach (var item in taskData)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (item.Value >= taskParam)
|
||||
{
|
||||
dropID.Add(commonTask.TaskReward);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dropID.Count > 0)
|
||||
{
|
||||
var itemDatas = GContext.container.Resolve<PlayerItemData>().AddItemByDropList(dropID);
|
||||
GContext.Publish(new ShowData());
|
||||
await Awaiters.Seconds(0.5f);
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_COMMON_missions_refreshed"));
|
||||
}
|
||||
}
|
||||
|
||||
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<EventLuckyTriplePackPanel>();
|
||||
triple.Init(EventLuckyTriplePackData.Create(luckyModel.EventId, packID));
|
||||
}
|
||||
break;
|
||||
}
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
if (luckyModel == null)
|
||||
{
|
||||
GetReward();
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
11
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs.meta
Normal file
11
Assets/Scripts/LuckyTask/UI/LuckyTaskPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4424ff39b0f54614f81b4bc6d0a0ec13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user