104 lines
3.9 KiB
Lua
104 lines
3.9 KiB
Lua
HomeLandManager = {}
|
||
local this = HomeLandManager
|
||
local HomeLand = ConfigManager.GetConfig(ConfigName.HomeLand)
|
||
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.HomeLandLevel)
|
||
local HomeLandTask = ConfigManager.GetConfig(ConfigName.HomeLandTask)
|
||
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
function this.Initialize()
|
||
this.BuildData = {}
|
||
for _, configData in ConfigPairs(HomeLand) do
|
||
this.BuildData[configData.Id] = {}
|
||
this.BuildData[configData.Id].dataMain = configData--HomeLand中数据
|
||
if configData.LvupCostPool > 0 then
|
||
this.BuildData[configData.Id].level = 1 --等级
|
||
local singledata = ConfigManager.GetConfigDataByDoubleKey(ConfigName.HomeLandLevel,"PoolID",configData.Id,"level",this.BuildData[configData.Id].level)
|
||
this.BuildData[configData.Id].dataSingle = singledata--HomeLandLevel中数据
|
||
this.BuildData[configData.Id].startTime = 0 --资源开始积攒的时间
|
||
this.BuildData[configData.Id].endTime = 0 --建筑升级的结束时间
|
||
end
|
||
end
|
||
end
|
||
|
||
--接收服务器信息
|
||
function this.GetServerData(msg,func)
|
||
if msg.infos and #msg.infos > 0 then
|
||
for index, value in ipairs(msg.infos) do
|
||
LogGreen("Id:"..tostring(value.id).." startTime:"..tostring(TimeStampToDateStr4(value.productionStartTime)).." endTime:"..tostring(TimeStampToDateStr4(value.upLvEndTime)))
|
||
if value.id and value.id > 0 then
|
||
local data = HomeLandLevel[value.id]
|
||
this.BuildData[data.PoolID].level = data.level
|
||
this.BuildData[data.PoolID].startTime = value.productionStartTime
|
||
this.BuildData[data.PoolID].endTime = value.upLvEndTime
|
||
this.BuildData[data.PoolID].dataSingle = HomeLandLevel[value.id]
|
||
end
|
||
end
|
||
end
|
||
if msg.drop then
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
|
||
end
|
||
if func then
|
||
func()
|
||
end
|
||
end
|
||
|
||
--升级材料和前置浮生殿等级检测
|
||
function this.ResumeCost(_data,_str,func)
|
||
if _data.Rule and this.BuildData[_data.Rule[1]].level < _data.Rule[2] then
|
||
PopupTipPanel.ShowTip(string.format("%s到达%s级可升级!",this.BuildData[_data.Rule[1]].dataMain.Name,_data.Rule[2]))
|
||
return
|
||
end
|
||
|
||
local data = {}
|
||
for i = 1, #_data.Cost do
|
||
if not data[_data.Cost[i][1]] then
|
||
data[_data.Cost[i][1]] = 0
|
||
end
|
||
data[_data.Cost[i][1]] = data[_data.Cost[i][1]] + _data.Cost[i][2]
|
||
end
|
||
if _str then--立即完成
|
||
LogGreen(tostring(_data.Time).." "..tostring(tonumber(_str[1])).." "..tonumber(_str[3]))
|
||
data[16] = math.ceil(_data.Time/tonumber(_str[1]))*tonumber(_str[3])
|
||
end
|
||
for key, value in pairs(data) do
|
||
LogGreen(string.format("需要%s: %s,现有:%s",key,value,BagManager.GetTotalItemNum(key)))
|
||
if BagManager.GetTotalItemNum(key) < value then
|
||
PopupTipPanel.ShowTip(string.format("%s不足!",ItemConfig[key].Name))
|
||
return
|
||
end
|
||
end
|
||
func(data[16])
|
||
end
|
||
|
||
--设置任务
|
||
function this.SetRewardData()
|
||
local dataList = {}
|
||
local transform = {
|
||
[0] = 2,
|
||
[1] = 1,
|
||
[2] = 0,
|
||
}
|
||
for k,v in ConfigPairs(ConfigManager.GetConfig(ConfigName.HomeLandTask)) do
|
||
local data = {}
|
||
data.Id = v.Id
|
||
local taskData = TaskManager.GetTypeTaskInfo(TaskTypeDef.HomeLandTask,v.Id)
|
||
data.info = string.format("%s(%s/%s)",v.ContentsShow,taskData.progress,v.Values[2][1])
|
||
data.BoxReward = v.Reward
|
||
data.state = transform[taskData.state]
|
||
table.insert(dataList,data)
|
||
end
|
||
return dataList
|
||
end
|
||
|
||
--等级总和
|
||
-- function this.GetLevelNum()
|
||
-- local num = 0
|
||
-- for index, value in ipairs(this.BuildData) do
|
||
-- if value.level then
|
||
-- num = num + value.level
|
||
-- end
|
||
-- end
|
||
-- LogYellow("等级总和:"..num)
|
||
-- return num
|
||
-- end
|
||
|
||
return HomeLandManager |