249 lines
9.6 KiB
Lua
249 lines
9.6 KiB
Lua
TrainBuildManager = {}
|
||
local this = TrainBuildManager
|
||
local HomeLand = ConfigManager.GetConfig(ConfigName.TrainBuild)
|
||
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.TrainBuildLevel)
|
||
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local trainConfig=ConfigManager.GetConfig(ConfigName.Train)
|
||
local heroConfig=ConfigManager.GetConfig(ConfigName.HeroConfig)
|
||
--所有正在特训的英雄id
|
||
local trainHeroId={}
|
||
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].id=configData.Id
|
||
this.BuildData[configData.Id].level = 0 --等级
|
||
local singledata = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainBuildLevel,"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 --建筑升级的结束时间
|
||
this.BuildData[configData.Id].heroId =nil --特训英雄
|
||
this.BuildData[configData.Id].heroStarTime =0
|
||
this.BuildData[configData.Id].isOpen = this.CheckBuildIsOpen(configData.UnlockLevel)
|
||
end
|
||
end
|
||
--所有可以特训的英雄静态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
|
||
|
||
end
|
||
|
||
|
||
--获取所有可以特修的英雄数据
|
||
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
|
||
end
|
||
--检测英雄是否正在特训
|
||
function this.CheckHeroIsTraining(_did)
|
||
return CheckListIsContainValue1(trainHeroId,_did)
|
||
end
|
||
|
||
---检测功能开启方法
|
||
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)
|
||
trainHeroId={}
|
||
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.startTime)).." value.lv:"..value.lv)
|
||
if value.id and value.id > 0 then
|
||
--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
|
||
LogError("value.lv===================="..value.lv.." value.id====="..value.id.." startime====="..value.startTime)
|
||
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
|
||
if value.heroId and value.heroId~="" then
|
||
table.insert(trainHeroId,value.heroId)
|
||
end
|
||
--end
|
||
end
|
||
end
|
||
end
|
||
if msg.drop then
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
|
||
end
|
||
if func then
|
||
func()
|
||
end
|
||
end
|
||
function this.RemoveTrainHero(_heroId)
|
||
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)
|
||
LogError("成功移除特训英雄")
|
||
end
|
||
end
|
||
|
||
function this.AddTrainHero(_heroId)
|
||
table.insert(trainHeroId,_heroId)
|
||
end
|
||
|
||
function this.GetTrainHeroIds()
|
||
return trainHeroId
|
||
end
|
||
--设置特训点信息
|
||
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)
|
||
if _info.startTime>0 then
|
||
|
||
this.BuildData[_info.id].endTime = _info.startTime+singledata.Time
|
||
LogError("singledata.time==========="..singledata.Time.." endtime===="..this.BuildData[_info.id].endTime)
|
||
else
|
||
this.BuildData[_info.id].endTime=0
|
||
end
|
||
|
||
this.BuildData[_info.id].dataSingle = singledata
|
||
end
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
--升级材料和前置浮生殿等级检测
|
||
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]))
|
||
data[16] = math.ceil(_data.Time/60)*tonumber(_str[2])
|
||
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()
|
||
LogError("检测 家园建筑 红点------------------------")
|
||
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
|
||
LogError("check trainbuild red point")
|
||
local endTime=v.heroStarTime+math.ceil((max-curValue)/v.dataSingle.Gain)*60
|
||
local leftTime=endTime-GetTimeStamp()
|
||
if leftTime<=0 then
|
||
return true
|
||
end
|
||
end
|
||
end
|
||
return false
|
||
end
|
||
|
||
|
||
|
||
--===============设置按钮位置=================
|
||
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 |