miduo_client/Assets/ManagedResources/~Lua/Modules/HomeLand/TrainBuildManager.lua

249 lines
9.6 KiB
Lua
Raw Normal View History

2023-11-20 10:35:47 +08:00
TrainBuildManager = {}
local this = TrainBuildManager
local HomeLand = ConfigManager.GetConfig(ConfigName.TrainBuild)
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.TrainBuildLevel)
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
2023-11-21 15:35:30 +08:00
local trainConfig=ConfigManager.GetConfig(ConfigName.Train)
2023-11-21 17:26:43 +08:00
local heroConfig=ConfigManager.GetConfig(ConfigName.HeroConfig)
2023-11-27 18:04:43 +08:00
--所有正在特训的英雄id
local trainHeroId={}
2023-11-20 10:35:47 +08:00
function this.Initialize()
this.BuildData = {}
2023-11-27 18:04:43 +08:00
2023-11-20 10:35:47 +08:00
for _, configData in ConfigPairs(HomeLand) do
this.BuildData[configData.Id] = {}
this.BuildData[configData.Id].dataMain = configData--HomeLand中数据
if configData.LvupCostPool > 0 then
2023-11-20 16:14:02 +08:00
this.BuildData[configData.Id].id=configData.Id
2023-11-22 18:38:49 +08:00
this.BuildData[configData.Id].level = 0 --等级
2023-11-20 16:14:02 +08:00
local singledata = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainBuildLevel,"PoolID",configData.Id,"level",this.BuildData[configData.Id].level)
2023-11-20 10:35:47 +08:00
this.BuildData[configData.Id].dataSingle = singledata--HomeLandLevel中数据
this.BuildData[configData.Id].startTime = 0 --资源开始积攒的时间
this.BuildData[configData.Id].endTime = 0 --建筑升级的结束时间
this.BuildData[configData.Id].heroId =nil --特训英雄
this.BuildData[configData.Id].heroStarTime =0
this.BuildData[configData.Id].isOpen = this.CheckBuildIsOpen(configData.UnlockLevel)
end
end
2023-11-21 15:35:30 +08:00
--所有可以特训的英雄静态id
this.allHeroId={}
for _, configData in ConfigPairs(trainConfig) do
if CheckListIsContainValue1(this.allHeroId,configData.HeroID)==false then
table.insert(this.allHeroId,configData.HeroID)
end
end
2023-11-27 18:04:43 +08:00
2023-11-21 15:35:30 +08:00
end
2023-11-20 10:35:47 +08:00
2023-11-21 15:35:30 +08:00
--获取所有可以特修的英雄数据
function this.GetAllCanTrainHero()
local heros={}
local list=HeroManager.GetAllHeroList()
LogError("list len============================="..#list)
for k, v in pairs(list) do
local hero=v
if CheckListIsContainValue1(this.allHeroId,hero.id) then
table.insert(heros,v)
end
end
LogError("#heros len==============="..#heros)
if #heros>0 then
table.sort(heros,function(a,b)
if a.star==b.star then
return a.lv>b.lv
else
return a.star>b.star
end
end)
end
return heros
2023-11-20 10:35:47 +08:00
end
2024-01-03 15:24:49 +08:00
--检测英雄是否正在特训
function this.CheckHeroIsTraining(_did)
return CheckListIsContainValue1(trainHeroId,_did)
end
2023-11-21 15:35:30 +08:00
2023-11-20 10:35:47 +08:00
---检测功能开启方法
function this.CheckBuildIsOpen(str)
if not str then
return false
end
local type=str[1]
local value=str[2]
if type==1 then
return PlayerManager.level>=value
elseif type==2 then
return this.BuildData[1].level>=value
end
return true
end
--接收服务器信息
function this.GetServerData(msg,func)
2023-11-27 18:04:43 +08:00
trainHeroId={}
2023-11-20 10:35:47 +08:00
if msg.infos and #msg.infos > 0 then
for index, value in ipairs(msg.infos) do
2023-11-20 16:14:02 +08:00
LogGreen("Id:"..tostring(value.id).." startTime:"..tostring(TimeStampToDateStr4(value.startTime)).." value.lv:"..value.lv)
2023-11-20 10:35:47 +08:00
if value.id and value.id > 0 then
2023-11-20 16:14:02 +08:00
--local data = HomeLandLevel[value.id]
--if data then
this.BuildData[value.id].level = value.lv
this.BuildData[value.id].startTime = value.startTime
this.BuildData[value.id].endTime=0
this.BuildData[value.id].heroId = value.heroId
this.BuildData[value.id].heroStarTime = value.heroStartTime
2023-11-24 11:46:47 +08:00
LogError("value.lv===================="..value.lv.." value.id====="..value.id.." startime====="..value.startTime)
2023-11-20 16:14:02 +08:00
local singledata = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainBuildLevel,"PoolID",value.id,"level",value.lv)
if value.startTime>0 then
this.BuildData[value.id].endTime=value.startTime+singledata.Time
end
this.BuildData[value.id].dataSingle = singledata
2023-11-22 18:38:49 +08:00
if value.heroId and value.heroId~="" then
2023-11-27 18:04:43 +08:00
table.insert(trainHeroId,value.heroId)
2023-11-21 17:26:43 +08:00
end
2023-11-20 16:14:02 +08:00
--end
2023-11-20 10:35:47 +08:00
end
end
end
if msg.drop then
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
end
if func then
func()
end
end
2023-11-27 14:40:54 +08:00
function this.RemoveTrainHero(_heroId)
2023-11-27 18:04:43 +08:00
if CheckListIsContainValue1(trainHeroId,_heroId) then
--table.removebyvalue(this.trainHeroId,_heroId)
for i=1,#trainHeroId do
if trainHeroId[i]==_heroId then
LogError("i==========================="..i)
table.remove(trainHeroId,i)
end
end
LogError("this.trainHeroId len==================="..#trainHeroId)
2023-11-27 14:40:54 +08:00
LogError("成功移除特训英雄")
end
end
2023-11-20 10:35:47 +08:00
2023-11-27 18:04:43 +08:00
function this.AddTrainHero(_heroId)
table.insert(trainHeroId,_heroId)
end
function this.GetTrainHeroIds()
return trainHeroId
end
2023-11-20 16:14:02 +08:00
--设置特训点信息
function this.SetBuildInfo(_info)
if _info and this.BuildData[_info.id] then
this.BuildData[_info.id].level = _info.lv
this.BuildData[_info.id].startTime = _info.startTime
this.BuildData[_info.id].heroId = _info.heroId
this.BuildData[_info.id].heroStarTime = _info.heroStartTime
LogError("_info.startTime==================".._info.startTime.." _info.lv===".._info.lv)
local singledata = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainBuildLevel,"PoolID",_info.id,"level",_info.lv)
2023-11-24 11:46:47 +08:00
if _info.startTime>0 then
2023-11-27 14:40:54 +08:00
2023-11-24 11:46:47 +08:00
this.BuildData[_info.id].endTime = _info.startTime+singledata.Time
2023-11-27 14:40:54 +08:00
LogError("singledata.time==========="..singledata.Time.." endtime===="..this.BuildData[_info.id].endTime)
2023-11-24 11:46:47 +08:00
else
this.BuildData[_info.id].endTime=0
end
2023-11-20 16:14:02 +08:00
this.BuildData[_info.id].dataSingle = singledata
end
end
2023-11-20 10:35:47 +08:00
--升级材料和前置浮生殿等级检测
function this.ResumeCost(_data,_str,func)
if _data.Rule and #_data.Rule>0 and type(_data.Rule[1])~="userdata" 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]))
2023-11-22 18:38:49 +08:00
data[16] = math.ceil(_data.Time/60)*tonumber(_str[2])
2023-11-20 10:35:47 +08:00
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
--==============================红点检测==============================
--烦人的红点检测我决定1-4写一个、5写一个6写一个、任务写一个、7移植过来,然后写个总的检测跑一遍所有)
function this.CheckRedMain()
2023-11-24 11:46:47 +08:00
LogError("检测 家园建筑 红点------------------------")
2023-11-22 18:38:49 +08:00
for k, v in pairs(this.BuildData) do
if v.heroId and v.heroId~="" and v.heroStarTime then
local pos=k
local max=0
local curValue=0
local heroData=HeroManager.GetSingleHeroData(v.heroId)
local train=ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.Train,"HeroID",heroData.heroConfig.Id,"Level",heroData.HeroTraining.trainingLv)
if train then
local aaa=ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainSetting,"PoolID",train.TrainSettingID,"Level",heroData.HeroTraining.trainingLv)
if pos==1 then
max=aaa.TrainExp1
curValue=heroData.HeroTraining.attackExp
elseif pos==2 then
max=aaa.TrainExp2
curValue=heroData.HeroTraining.defenseExp
elseif pos==3 then
max=aaa.TrainExp3
curValue=heroData.HeroTraining.hpExp
end
end
2023-11-24 11:46:47 +08:00
LogError("check trainbuild red point")
2023-11-22 18:38:49 +08:00
local endTime=v.heroStarTime+math.ceil((max-curValue)/v.dataSingle.Gain)*60
local leftTime=endTime-GetTimeStamp()
if leftTime<=0 then
return true
end
end
2023-11-20 10:35:47 +08:00
end
return false
end
2023-11-21 17:26:43 +08:00
2023-11-20 10:35:47 +08:00
--===============设置按钮位置=================
local POS = {
[1] = {Vector3.New(0,110,0)},
[2] = {Vector3.New(-75,80,0),Vector3.New(75,80,0)},
[3] = {Vector3.New(0,110,0),Vector3.New(-100,30,0),Vector3.New(100,30,0)},
[4] = {Vector3.New(55,90,0),Vector3.New(110,0,0),Vector3.New(-55,90,0),Vector3.New(-110,0,0)},
}
function this.SetButtonPosition(Obj)
local objList = {}
for i = 1, Obj.transform.childCount do
-- LogRed(tostring(Obj.transform:GetChild(i-1).gameObject.activeInHierarchy))
if Obj.transform:GetChild(i-1).gameObject.activeInHierarchy then
table.insert(objList,Obj.transform:GetChild(i-1).gameObject)
end
end
-- LogError("#objList"..tostring(#objList))
for index, value in ipairs(objList) do
value:GetComponent("RectTransform").localPosition = POS[#objList][index]
end
end
return TrainBuildManager