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

226 lines
6.8 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +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)
-- this.IsNewActivity = false
2021-03-19 15:16:49 +08:00
end
2021-03-22 20:08:18 +08:00
--服务器发来的活动进度条数据
function this.GetActData()
2021-10-15 16:49:00 +08:00
return ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.NiuQi)
2021-03-22 20:08:18 +08:00
end
2021-03-24 20:19:40 +08:00
--牛气值
function this.GetScore()
2021-10-15 16:49:00 +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
2022-03-22 11:57:50 +08:00
function this.GetRewardDataById(id)
for k,v in ipairs(this.rewardData) do
if v.id == id then
return v
end
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)
2022-03-22 11:57:50 +08:00
for k,v in ipairs(temp) do
local data = this.GetRewardDataById(v.missionId)
if data then
data.state = v.state
data.progress = v.progress
end
2021-03-24 17:06:20 +08:00
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
2021-10-15 17:14:27 +08:00
data.actId = sData.ActivityId
2021-03-24 17:06:20 +08:00
data.Text = sData.Text
data.Reward = sData.Reward
data.Sort = sData.Sort
data.Type = sData.Type
data.state = 0
2021-10-15 17:52:05 +08:00
data.jumpId = sData.JumpID
2021-10-16 16:37:44 +08:00
data.value = sData.ValuesII
data.progress = 0
2021-03-24 17:06:20 +08:00
return data
end
--需要显示的任务数据
function this.GetNeedRewardData(sort)
2021-03-22 20:08:18 +08:00
local needData = {}
-- if not this.IsNewActivity then--老的牛气冲天
-- 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
-- if #tempdata == 0 then
-- if v.Sort == sort and v.Type == i then
-- data = v
-- 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
-- end
-- end
-- if data then
-- table.insert(tempdata,data)
-- if #tempdata >= 2 then
-- break
-- end
-- end
-- end
-- end
-- for j = 1,#tempdata do
-- table.insert(needData,tempdata[j])
-- end
-- end
-- table.sort(needData,function (a,b)
-- return a.id < b.id
-- end)
-- else--新的牛气冲天
for k, v in pairs(this.rewardData) do
if v.Sort == sort then
table.insert(needData,v)
end
2021-03-24 17:06:20 +08:00
end
2021-10-15 17:14:27 +08:00
local STATE = {
[0] = 2,
[1] = 3,
[2] = 1,
}
table.sort(needData,function (a,b)
if a.state == b.state then
return a.id < b.id
else
2021-10-15 17:14:27 +08:00
return STATE[a.state] > STATE[b.state]
end
end)
-- end
2021-03-22 20:08:18 +08:00
return needData
end
2021-05-26 18:15:37 +08:00
function this.CheckNiuQiChongTianRedPoint(index)
2021-10-15 16:49:00 +08:00
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.NiuQi)
2021-05-26 18:15:37 +08:00
if not id or id < 1 then
return false
2021-03-24 20:19:40 +08:00
end
2021-10-15 17:14:27 +08:00
for k = #this.rewardData, 1 , -1 do
if this.rewardData[k].actId ~= id then
table.remove( this.rewardData,k)
end
end
2021-05-26 18:15:37 +08:00
local isShow = false
if index == RedPointType.NiuQiChongTian_4 then
isShow = this.NiuQiCheckRedPoint4()
else
local n = 0
if index == RedPointType.NiuQiChongTian_1 then
n = 1
elseif index == RedPointType.NiuQiChongTian_2 then
n = 2
elseif index == RedPointType.NiuQiChongTian_3 then
n = 3
2021-03-24 20:19:40 +08:00
end
2021-05-26 18:15:37 +08:00
isShow = this.NiuQiCheckRedPoint1(n)
2021-03-24 20:19:40 +08:00
end
2021-05-26 18:15:37 +08:00
return isShow
2021-03-24 20:19:40 +08:00
end
2021-05-26 18:15:37 +08:00
function this.NiuQiCheckRedPoint1(index)
2021-03-24 20:19:40 +08:00
for k,v in pairs(this.rewardData) do
2021-05-26 18:15:37 +08:00
if v.state == 1 and (not index or v.Sort == index) then
2021-03-24 20:19:40 +08:00
return true
end
end
return false
end
2021-05-26 18:15:37 +08:00
2021-03-24 20:19:40 +08:00
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-10-15 16:49:00 +08:00
--检查是否为新的牛气冲天
function this.CheckIsNewActivity()
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.NiuQi)
local data = ConfigManager.GetConfigData(ConfigName.GlobalActivity,id)
-- if data.ShowArt == 2 then
-- this.IsNewActivity = true
-- end
2021-10-15 16:49:00 +08:00
end
2021-04-01 18:36:34 +08:00
return this