Files
Main/Assets/GameAssets/Resources/Lua/Logic/VipZhouChang/ZcTaskData.lua
2025-01-25 04:38:09 +08:00

216 lines
5.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
--作者: 王圣
--日期: 2019-12-16
--文件: ZcTaskData.lua
--模块: ZcTaskData
--描述: vip周常数据
------------------------------------------------
--引用
local ZcTaskData = {
Id = 0,
--任务图标id
IconId = 0,
--总的可以获得的货币
TolCoin = 0,
--总的任务个数
TolTaskNum = 0,
--key:tabId ---任务列表 {Id:任务Id Des : 任务目标 CurNum : 当前达成次数 TotalNum: 需要达成次数 CoinNum:奖励货币数量 IsFinish:是否完成 OpenUI打开的界面Id }
DicTask = Dictionary:New(),
}
function ZcTaskData:New()
local _m = Utils.DeepCopy(self)
return _m
end
--解析数据
function ZcTaskData:ParseCfg(cfg)
if cfg ~= nil then
local types = Utils.SplitStr(cfg.TaskNum, '_')
self.Id = tonumber(types[1])
local key = tonumber(types[2])
--添加任务
local taskId = cfg.Id
local curNum = 0
local condition = Utils.SplitStr(cfg.Condition,'_')
local totalNum = tonumber(condition[#condition])
local coinNum = cfg.Reward
local des = cfg.Desc
local openId = cfg.FunctionId
local isFinish = false
local task = {Id = taskId ,CurNum = curNum,TotalNum = totalNum, CoinNum = coinNum, IsFinish = isFinish, Des = des, OpenUI = openId}
local taskList = nil
if self.DicTask:ContainsKey(key) then
taskList = self.DicTask[key]
taskList:Add(task)
else
taskList = List:New()
taskList:Add(task)
self.DicTask:Add(key,taskList)
end
-- local gCfg = DataConfig.DataGlobal[GlobalName.VIPWeekMoneyIcon]
-- if gCfg ~= nil then
-- self.IconId = tonumber(gCfg.Params)
-- end
self.IconId = cfg.Icon
end
end
function ZcTaskData:ParaseMsg(msg)
if msg ~= nil then
for i = 1,#msg do
self:UpdateTask(msg[i].id,msg[i].prog)
end
end
end
--获取总的货币
function ZcTaskData:GetTotalCoin()
if self.TolCoin == 0 then
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
self.TolCoin = self.TolCoin + list[i].CoinNum
end
end)
else
return self.TolCoin
end
return self.TolCoin
end
--获取剩余可以领取的货币
function ZcTaskData:GetLeftCoin()
local coin = 0
local haveCoin = 0
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
if list[i].IsFinish then
haveCoin = haveCoin + list[i].CoinNum
end
coin = coin + list[i].CoinNum
end
end)
if self.TolCoin == 0 then
self.TolCoin = coin
return coin - haveCoin
else
return self.TolCoin - haveCoin
end
end
--获取已经获得的货币
function ZcTaskData:GetRewardCoin()
local coin = 0
local haveCoin = 0
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
if list[i].IsFinish then
haveCoin = haveCoin + list[i].CoinNum
end
end
end)
return haveCoin
end
--获取总的任务个数
function ZcTaskData:GetTotalTaskNum()
if self.TolTaskNum == 0 then
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
self.TolTaskNum = self.TolTaskNum + 1
end
end)
else
return self.TolTaskNum
end
return self.TolTaskNum
end
--获取当前完成任务的个数
function ZcTaskData:GetFinishTaskNum()
local num = 0
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
if list[i].IsFinish then
num = num + 1
end
end
end)
return num
end
--获取第一个任务
function ZcTaskData:GetFirstTask()
local keys = self.DicTask:GetKeys()
if keys ~= nil and #keys >=1 then
return self.DicTask[keys[1]]
end
return nil
end
--获取任务数据
function ZcTaskData:GetTaskData(taskId)
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
if list[i].Id == taskId then
return list[i]
end
end
end)
return nil
end
--当前key对应的系列任务是否全部做完
function ZcTaskData:IsFinishAllTask(key)
if self.DicTask:ContainsKey(key) then
local list = self.DicTask[key]
if list ~= nil then
for i = 1,#list do
if not list[i].IsFinish then
return false
end
end
end
end
return true
end
function ZcTaskData:ResetTasks()
self.DicTask:Foreach(function(k, v)
local list = v
for i = 1,#list do
list[i].IsFinish = false
list[i].CurNum = 0
end
end)
end
--更新任务
function ZcTaskData:UpdateTask(taskId, process)
local listKey = self.DicTask:GetKeys()
if listKey ~= nil then
for i = 1,#listKey do
local list = self.DicTask[listKey[i]]
for m = 1,#list do
if list[m].Id == taskId then
if list[m].CurNum ~= process and list[m].TotalNum <= process then
--GameCenter.ZhouChangSystem.CurCoinNum = GameCenter.ZhouChangSystem.CurCoinNum + list[m].CoinNum
end
list[m].CurNum = process
if process >= list[m].TotalNum then
list[m].IsFinish = true
return true
end
end
end
end
end
end
return ZcTaskData