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) local EquipStrengthen = ConfigManager.GetConfig(ConfigName.EquipStrengthen) local EquipRankUp = ConfigManager.GetConfig(ConfigName.EquipRankUp) 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 this.EquipData = {} this.levelProId = 0 for i = 1, 4 do this.EquipData[i] = {} this.EquipData[i].Id = 1001 this.EquipData[i].configData = EquipStrengthen[1001] end this.curEquip = 1--当前停留的装备 this.activePrivilege = false this.priviLeftTime = 0 end --获取家园和装备强化信息 function this.GetData(func) NetManager.HomeInfoRequest(function () if func then func() 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] if data then 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 end if msg.drop then UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1) end if func then func() end end ---获取英雄武器摘星阁属性加成 function this.GetHeroEquipPropAdd(_heroId,_equipPos) local heroDId= string.gsub(_heroId, "TEMP_", "")--不知道为什么有狗屁临时id local heroData=HeroManager.GetSingleHeroData(heroDId) if heroData.equipStrong==nil or heroData.equipStrong[_equipPos]==nil then return 0 end local lv=heroData.equipStrong[_equipPos] local equipRankUpLv=heroData.equipAdvanceLv local equipStrengthenConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",lv) local equipRankUpConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipRankUp,"Level",equipRankUpLv) local addProp=equipStrengthenConfig.Rate+equipRankUpConfig.Rate[_equipPos] return addProp end --获取服务器装备信息 function this.GetServerEquipData(msg,func) this.levelProId = msg.equipRankUp > 0 and msg.equipRankUp or 1 -- this.levelProId = msg.equipRankUp + 1 -- this.levelProId = 1 if msg.infos and #msg.infos > 0 then for index, value in ipairs(msg.infos) do -- value.lvId = 1022 -- LogYellow("Location:"..tostring(value.location).." lvId:"..tostring(value.lvId).." 突破等级Id:"..tostring(this.levelProId)) if value.location and value.location > 0 and value.location < 5 then this.EquipData[value.location].Id = value.lvId this.EquipData[value.location].configData = EquipStrengthen[value.lvId] this.EquipData[value.location].configPro = EquipRankUp[this.levelProId] end end 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.GetCurIndex() for i = 1, 4 do if this.EquipData[i].configData.Limit2 == EquipRankUp[this.levelProId].Level then if this.EquipData[i].configData.Cost and this.EquipData[i].configData.Cost[1][2] <= BagManager.GetTotalItemNum(this.EquipData[i].configData.Cost[1][1]) then this.curEquip = i return end end end end --检测按钮显示 function this.GetCurIndexBtnsShow() return this.EquipData[this.curEquip].configData.Limit2 == EquipRankUp[this.levelProId].Level end --检测是否全部可以突破 function this.GetAllCanUpgrade(_heroData) local num = 0 for i = 1, 4 do local curLv=_heroData.equipStrong[i] and _heroData.equipStrong[i] or 0 local equipStrengthenConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",curLv) if equipStrengthenConfig.Limit2 > _heroData.equipAdvanceLv then num = num + 1 end end if num == 4 then return true end return false end --检测是否全部可以突破并提示 function this.GetAllCanUpgradeWithPopup(_heroData) local TEXT = { [1] = {"武器","r_Equip_GuardianWeapon_0004"}, [2] = {"战甲","r_Equip_Coat_0005"}, [3] = {"头饰","r_Equip_HeadAccessory_0005"}, [4] = {"战靴","r_equip_Shoes_0005"}, } for i = 1, 4 do local curLv=_heroData.equipStrong[i] and _heroData.equipStrong[i] or 0 local equipStrengthenConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",curLv) if equipStrengthenConfig.Limit2 == _heroData.equipAdvanceLv then PopupTipPanel.ShowTip(string.format("%s未达到最大等级,不可突破!",TEXT[i][1])) this.curEquip = i return true end end return false end --通过两个id计算两个等级 function this.IdToLevel(id1,id2) local lv1 = EquipStrengthen[id1] and EquipStrengthen[id1].Level or 0 local lv2 = EquipRankUp[id2] and EquipRankUp[id2].Level or 0 return {lv1, lv2} end function this.LevelToId() local num1 = ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",self.equipData.homeEquipLv[1]).Id local num2 = ConfigManager.GetConfigDataByKey(ConfigName.EquipRankUp,"Level",self.equipData.homeEquipLv[2]).Id return {num1,num2} end --通过两个等级计算加成 function this.LevelToValue(ids,position) local num1 = ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",ids[1]).Rate local num2 = ConfigManager.GetConfigDataByKey(ConfigName.EquipRankUp,"Level",ids[2]).Rate[position] return num1 + num2 end function this.CheckPrivilege(func) local data = PrivilegeManager.GetSerData(4022) if data and data.endTime - GetTimeStamp() > 0 then this.activePrivilege = true this.priviLeftTime = PrivilegeManager.GetPrivilegeRemainValue(4021) else this.activePrivilege = false this.priviLeftTime = 0 end if func then func() end end --==============================红点检测============================== --烦人的红点检测(我决定1-4写一个、5写一个,6写一个、任务写一个、7移植过来,然后写个总的检测跑一遍所有) function this.CheckRedMain() if this.Check1to5Building() then return true end if this.CheckMission() then return true end if this.CheckEquipUpgrade() then return true end return false end function this.Check1to5Building() local data = this.BuildData for i = 1, 5 do if data[i].dataMain.IsOpen == 1 and (this.singleUpgrade(i) or this.singleGet(i)) then return true end end return false end --1-5建筑的单个升级 function this.singleUpgrade(id) local data = this.BuildData[id].dataSingle if HomeLand[id].UnlockLevel[1] == 1 and PlayerManager.level < HomeLand[id].UnlockLevel[2] then elseif HomeLand[id].UnlockLevel[1] == 2 and HomeLandManager.BuildData[5].level < HomeLand[id].UnlockLevel[2] then elseif HomeLand[id].UnlockLevel[1] == 3 and PlayerManager.level < GlobalSystemConfig[HomeLand[id].UnlockLevel[2]].OpenRules[2] then else if data.Cost and BagManager.GetTotalItemNum(data.Cost[1][1]) >= data.Cost[1][2] then--所需材料够 if not data.Rule or (this.BuildData[data.Rule[1]].level >= data.Rule[2]) then--到达升级条件 if this.BuildData[id].endTime <= GetTimeStamp() then return true end end end end return false end --1-4建筑的单个领取 function this.singleGet(id) local data = this.BuildData[id] if data.dataMain.Type == 1 and data.dataSingle.Gain and this.BuildData[5].level > data.dataMain.UnlockLevel[2] then return (GetTimeStamp() - data.startTime)/60*data.dataSingle.Gain[2] >= data.dataSingle.Storage[1][2] end return false end --检测任务 function this.CheckMission() local data = this.SetRewardData() for index, value in ipairs(data) do if value.state == 1 then return true end end return false end --摘星阁 function this.CheckEquipUpgrade() -- if this.BuildData[5].level >= HomeLand[6].UnlockLevel[2] then -- if this.GetAllCanUpgrade() then -- local configData = EquipRankUp[this.levelProId] -- local isEnough=true -- for i = 1, #configData.Cost do -- if BagManager.GetTotalItemNum(configData.Cost[i][1]) < configData.Cost[i][2] then -- isEnough=false -- end -- end -- if configData.Cost and isEnough then -- return true -- else -- return false -- end -- end -- for i = 1, 4 do -- if this.CheckSingleEquipUpgrade(i) then -- return true -- end -- end -- end return false end --摘星阁单个装备检测 function this.CheckSingleEquipUpgrade(id) local bool = false local data = this.EquipData[id] if data.configData.Cost and BagManager.GetTotalItemNum(data.configData.Cost[1][1]) >= data.configData.Cost[1][2] then--所需材料够 if this.BuildData[data.configData.Limit[1]].level >= data.configData.Limit[2] then--到达升级条件 bool = true end end return bool 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 HomeLandManager