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

361 lines
13 KiB
Lua
Raw Normal View History

2021-12-20 16:50:51 +08:00
HomeLandManager = {}
local this = HomeLandManager
2021-12-23 14:38:02 +08:00
local HomeLand = ConfigManager.GetConfig(ConfigName.HomeLand)
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.HomeLandLevel)
local HomeLandTask = ConfigManager.GetConfig(ConfigName.HomeLandTask)
2021-12-28 11:54:08 +08:00
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
2021-12-29 20:17:45 +08:00
local EquipStrengthen = ConfigManager.GetConfig(ConfigName.EquipStrengthen)
local EquipRankUp = ConfigManager.GetConfig(ConfigName.EquipRankUp)
2021-12-20 16:50:51 +08:00
function this.Initialize()
2021-12-23 14:38:02 +08:00
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
2021-12-29 20:17:45 +08:00
this.EquipData = {}
this.levelProId = 0
for i = 1, 4 do
this.EquipData[i] = {}
this.EquipData[i].Id = 1001
2022-01-05 11:05:11 +08:00
this.EquipData[i].configData = EquipStrengthen[1001]
2021-12-29 20:17:45 +08:00
end
this.curEquip = 1--当前停留的装备
2021-12-31 18:13:10 +08:00
this.activePrivilege = false
this.priviLeftTime = 0
2021-12-29 20:17:45 +08:00
end
--获取家园和装备强化信息
function this.GetData(func)
2022-01-14 14:14:48 +08:00
NetManager.HomeInfoRequest(function ()
2022-09-01 17:30:15 +08:00
if func then
func()
end
2022-01-14 14:14:48 +08:00
end)
2021-12-23 14:38:02 +08:00
end
--接收服务器信息
function this.GetServerData(msg,func)
2021-12-24 18:20:18 +08:00
if msg.infos and #msg.infos > 0 then
for index, value in ipairs(msg.infos) do
2022-01-06 14:23:41 +08:00
-- LogGreen("Id:"..tostring(value.id).." startTime:"..tostring(TimeStampToDateStr4(value.productionStartTime)).." endTime:"..tostring(TimeStampToDateStr4(value.upLvEndTime)))
2021-12-24 18:20:18 +08:00
if value.id and value.id > 0 then
local data = HomeLandLevel[value.id]
2022-01-06 10:56:59 +08:00
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
2021-12-24 18:20:18 +08:00
end
2021-12-23 14:38:02 +08:00
end
end
if msg.drop then
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1)
end
if func then
func()
end
2021-12-20 16:50:51 +08:00
end
2022-09-01 17:30:15 +08:00
---获取英雄武器摘星阁属性加成
function this.GetHeroEquipPropAdd(_heroId,_equipPos)
local heroDId= string.gsub(_heroId, "TEMP_", "")--不知道为什么有狗屁临时id
local heroData=HeroManager.GetSingleHeroData(heroDId)
2022-09-01 18:26:30 +08:00
if heroData.equipStrong==nil or heroData.equipStrong[_equipPos]==nil then
2022-09-01 17:30:15 +08:00
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
2021-12-29 20:17:45 +08:00
--获取服务器装备信息
function this.GetServerEquipData(msg,func)
2022-01-06 10:56:59 +08:00
this.levelProId = msg.equipRankUp > 0 and msg.equipRankUp or 1
2021-12-30 11:00:27 +08:00
-- this.levelProId = msg.equipRankUp + 1
2021-12-29 20:17:45 +08:00
-- this.levelProId = 1
if msg.infos and #msg.infos > 0 then
for index, value in ipairs(msg.infos) do
-- value.lvId = 1022
2022-01-06 14:23:41 +08:00
-- LogYellow("Location:"..tostring(value.location).." lvId:"..tostring(value.lvId).." 突破等级Id"..tostring(this.levelProId))
2021-12-29 20:17:45 +08:00
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
2021-12-28 11:54:08 +08:00
--升级材料和前置浮生殿等级检测
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--立即完成
2022-01-06 11:45:28 +08:00
-- LogGreen(tostring(_data.Time).." "..tostring(tonumber(_str[1])).." "..tonumber(_str[3]))
2021-12-28 18:27:31 +08:00
data[16] = math.ceil(_data.Time/tonumber(_str[1]))*tonumber(_str[3])
2021-12-28 11:54:08 +08:00
end
for key, value in pairs(data) do
2022-01-06 11:45:28 +08:00
-- LogGreen(string.format("需要%s: %s,现有:%s",key,value,BagManager.GetTotalItemNum(key)))
2021-12-28 11:54:08 +08:00
if BagManager.GetTotalItemNum(key) < value then
PopupTipPanel.ShowTip(string.format("%s不足",ItemConfig[key].Name))
return
end
end
2021-12-28 18:27:31 +08:00
func(data[16])
2021-12-28 11:54:08 +08:00
end
2021-12-29 14:03:16 +08:00
--设置任务
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
2021-12-29 20:17:45 +08:00
--检测当前停留
function this.GetCurIndex()
for i = 1, 4 do
if this.EquipData[i].configData.Limit2 == EquipRankUp[this.levelProId].Level then
2022-01-08 11:36:31 +08:00
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
2021-12-29 20:17:45 +08:00
end
end
end
--检测按钮显示
function this.GetCurIndexBtnsShow()
return this.EquipData[this.curEquip].configData.Limit2 == EquipRankUp[this.levelProId].Level
end
--检测是否全部可以突破
2022-09-01 17:30:15 +08:00
function this.GetAllCanUpgrade(_heroData)
2021-12-29 20:17:45 +08:00
local num = 0
for i = 1, 4 do
2022-09-02 13:15:24 +08:00
local curLv=_heroData.equipStrong[i] and _heroData.equipStrong[i] or 0
2022-09-01 17:30:15 +08:00
local equipStrengthenConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",curLv)
if equipStrengthenConfig.Limit2 > _heroData.equipAdvanceLv then
2021-12-29 20:17:45 +08:00
num = num + 1
end
end
if num == 4 then
return true
end
return false
end
--检测是否全部可以突破并提示
2022-09-01 17:30:15 +08:00
function this.GetAllCanUpgradeWithPopup(_heroData)
2021-12-29 20:17:45 +08:00
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
2022-09-02 13:15:24 +08:00
local curLv=_heroData.equipStrong[i] and _heroData.equipStrong[i] or 0
2022-09-01 17:30:15 +08:00
local equipStrengthenConfig=ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen,"Level",curLv)
if equipStrengthenConfig.Limit2 == _heroData.equipAdvanceLv then
2021-12-29 20:17:45 +08:00
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
2021-12-31 18:13:10 +08:00
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
2021-12-31 18:13:10 +08:00
if func then
func()
end
end
2022-01-06 14:23:41 +08:00
--==============================红点检测==============================
2022-01-04 15:10:35 +08:00
--烦人的红点检测我决定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
2022-01-05 10:12:23 +08:00
if data[i].dataMain.IsOpen == 1 and (this.singleUpgrade(i) or this.singleGet(i)) then
2022-01-04 15:10:35 +08:00
return true
end
end
return false
end
--1-5建筑的单个升级
function this.singleUpgrade(id)
local data = this.BuildData[id].dataSingle
2022-01-05 14:17:53 +08:00
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
2022-01-06 10:33:08 +08:00
if data.Cost and BagManager.GetTotalItemNum(data.Cost[1][1]) >= data.Cost[1][2] then--所需材料够
2022-01-05 14:17:53 +08:00
if not data.Rule or (this.BuildData[data.Rule[1]].level >= data.Rule[2]) then--到达升级条件
2022-01-05 16:21:20 +08:00
if this.BuildData[id].endTime <= GetTimeStamp() then
return true
end
2022-01-05 14:17:53 +08:00
end
2022-01-04 15:10:35 +08:00
end
end
return false
end
--1-4建筑的单个领取
function this.singleGet(id)
local data = this.BuildData[id]
2022-01-05 14:17:53 +08:00
if data.dataMain.Type == 1 and data.dataSingle.Gain and this.BuildData[5].level > data.dataMain.UnlockLevel[2] then
2022-01-04 15:10:35 +08:00
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()
2022-09-01 17:30:15 +08:00
-- 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
2022-01-04 15:10:35 +08:00
return false
end
--摘星阁单个装备检测
function this.CheckSingleEquipUpgrade(id)
local bool = false
local data = this.EquipData[id]
2022-01-06 17:59:25 +08:00
if data.configData.Cost and BagManager.GetTotalItemNum(data.configData.Cost[1][1]) >= data.configData.Cost[1][2] then--所需材料够
2022-01-04 18:58:34 +08:00
if this.BuildData[data.configData.Limit[1]].level >= data.configData.Limit[2] then--到达升级条件
2022-01-04 15:10:35 +08:00
bool = true
end
end
return bool
end
2022-01-06 14:23:41 +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
2022-01-06 15:28:41 +08:00
-- LogRed(tostring(Obj.transform:GetChild(i-1).gameObject.activeInHierarchy))
2022-01-06 14:23:41 +08:00
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
2021-12-20 16:50:51 +08:00
return HomeLandManager