miduo_client/Assets/ManagedResources/~Lua/Modules/NiuQiChongTian/NiuQiChongTianManager.lua

168 lines
4.8 KiB
Lua
Raw Normal View History

2021-04-01 18:36:34 +08:00
NiuQiChongTianManager = {}
2021-03-19 15:16:49 +08:00
local this = NiuQiChongTianManager
2021-03-24 17:06:20 +08:00
this.rewardData = {}
2021-03-24 20:19:40 +08:00
this.configData = {}
local curScore = 0
local itemId = 0
2021-03-19 15:16:49 +08:00
function this.Initialize()
2021-03-24 17:06:20 +08:00
this.InitAllRewardData()
Game.GlobalEvent:AddEvent(GameEvent.Mission.NiuQiChongTianTask,this.UpdateStatus)
2021-03-19 15:16:49 +08:00
end
2021-03-22 20:08:18 +08:00
--服务器发来的活动进度条数据
function this.GetActData()
return ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.NiuQi)
end
2021-03-24 20:19:40 +08:00
--牛气值
function this.GetScore()
2021-03-22 20:08:18 +08:00
local ActData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.NiuQi)
2021-03-25 11:35:25 +08:00
if not (ActData and ActData.activityId) then return end
2021-03-24 20:19:40 +08:00
if #this.configData == 0 then
local config = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",ActData.activityId)
for i = 1, #config do
local data = {}
itemId = config[i].Values[1][1]
data.missionId = config[i].Id
data.reward = config[i].Reward
data.value = config[i].Values
data.activityId = ActData.activityId
data.state = 0
table.insert(this.configData,data)
end
end
curScore = BagManager.GetTotalItemNum(itemId)
for i = 1, #this.configData do
if curScore >= this.configData[i].value[2][1] then
for key, value in pairs(ActData.mission) do
if value.missionId and value.missionId == this.configData[i].missionId then
2021-03-22 20:08:18 +08:00
if value.state == 0 then
2021-03-24 20:19:40 +08:00
this.configData[i].state = 1--可领的
2021-03-22 20:08:18 +08:00
else
2021-03-24 20:19:40 +08:00
this.configData[i].state = 2--领完的
2021-03-22 20:08:18 +08:00
end
end
end
2021-03-24 20:19:40 +08:00
else
this.configData[i].state = 0--不可领的
2021-03-22 20:08:18 +08:00
end
end
2021-03-24 20:19:40 +08:00
return curScore
2021-03-22 20:08:18 +08:00
end
--所有的任务信息数据
2021-03-24 17:06:20 +08:00
function this.InitAllRewardData()
local ArroGantFly = ConfigManager.GetConfig(ConfigName.ArroGantFly)
for k,v in ConfigPairs(ArroGantFly) do
table.insert(this.rewardData,this.CreatSingleData(v))
2021-03-22 20:08:18 +08:00
end
end
2021-03-24 17:06:20 +08:00
function this.UpdateStatus()
2021-03-24 13:43:56 +08:00
local temp = TaskManager.GetTypeTaskList(TaskTypeDef.NiuQiChongTian)
2021-03-24 17:06:20 +08:00
for k,v in pairs(this.rewardData) do
v.state = temp[v.id].state
end
2021-03-24 20:19:40 +08:00
CheckRedPointStatus(RedPointType.NiuQiChongTian_1)
CheckRedPointStatus(RedPointType.NiuQiChongTian_2)
CheckRedPointStatus(RedPointType.NiuQiChongTian_3)
2021-03-24 17:06:20 +08:00
end
function this.CreatSingleData(sData)
local data = {}
data.id = sData.Id
data.Text = sData.Text
data.Reward = sData.Reward
data.Sort = sData.Sort
data.Type = sData.Type
data.state = 0
return data
end
--需要显示的任务数据
function this.GetNeedRewardData(sort)
2021-03-22 20:08:18 +08:00
local needData = {}
2021-03-24 17:06:20 +08:00
for i = 1, 2 do
local tempdata = {}
for k, v in pairs(this.rewardData) do
if v.Sort == sort and v.Type == i and (v.state == 1 or v.state == 0) then
if #tempdata < 1 then
table.insert(tempdata,v)
else
table.insert(tempdata,v)
break
end
end
end
if #tempdata < 2 then
for k = #this.rewardData, 1 , -1 do
local v = this.rewardData[k]
local data = nil
2021-03-24 20:19:40 +08:00
if #tempdata == 0 then
if v.Sort == sort and v.Type == i then
2021-03-24 17:06:20 +08:00
data = v
2021-03-24 20:19:40 +08:00
end
else
for j = 1, #tempdata do
if tempdata[j].id ~= v.id and v.Sort == sort and v.Type == i then
data = v
break
end
2021-03-24 17:06:20 +08:00
end
end
if data then
table.insert(tempdata,data)
if #tempdata >= 2 then
break
end
2021-03-22 20:08:18 +08:00
end
end
end
2021-03-24 17:06:20 +08:00
for j = 1,#tempdata do
table.insert(needData,tempdata[j])
end
2021-03-22 20:08:18 +08:00
end
2021-03-24 20:19:40 +08:00
table.sort(needData,function (a,b)
return a.id < b.id
end)
2021-03-22 20:08:18 +08:00
return needData
end
2021-03-24 20:19:40 +08:00
function this.NiuQiCheckRedPoint1()
for k,v in pairs(this.rewardData) do
if v.state == 1 and v.Sort == 1 then
return true
end
end
return false
end
function this.NiuQiCheckRedPoint2()
for k,v in pairs(this.rewardData) do
if v.state == 1 and v.Sort == 2 then
return true
end
end
return false
end
function this.NiuQiCheckRedPoint3()
for k,v in pairs(this.rewardData) do
if v.state == 1 and v.Sort == 3 then
return true
end
end
return false
end
function this.NiuQiCheckRedPoint4()
this.GetScore()
for key, value in pairs(this.configData) do
if value.state == 1 then
return true
end
end
return false
end
2021-04-01 18:36:34 +08:00
return this