sk-client/Assets/ManagedResources/~Lua/Modules/PowerCenter/PowerCenterManager.lua

289 lines
9.3 KiB
Lua
Raw Permalink Normal View History

2024-07-03 18:38:10 +08:00
PowerCenterManager = {}
local this = PowerCenterManager
local SpecialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
local PowerCenterConfig = ConfigManager.GetConfig(ConfigName.PowerCenterConfig)
this.maxField = tonumber(SpecialConfig[561].Value)
this.cd = tonumber(SpecialConfig[562].Value)
this.powerCenterIsActivate = false
function this.Initialize()
this.allData = {level = 0, hero = {}, linkPos = {}, equip = {}}
for i = 1, PowerCenterManager.maxField do
this.allData.linkPos[i] = {position = i, heroId = "", readyTime = -1, heroLevel = 0, heroBreakId = 0, state = 2}
end
this.speedUpCdCost = {}
local reward = string.split(SpecialConfig[563].Value, "|")
for i = 1, #reward do
local data = string.split(reward[i], "#")
this.speedUpCdCost[i] = {tonumber(data[1]), tonumber(data[2])}
end
end
--请求异能中心信息
function PowerCenterManager.GetPowerCenterInfo(func)
--[[
level
active
strongestHero = {}
linkPos = {
[1] = {
position
heroId = 英雄唯一ID
readyTime = 冷却完成时间
heroLevel = 原等级
heroBreakId = 原阶数
}
}
equip = {
[1] = {
position
equipId
heroId
}
}
]]
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.PowerCenter) then
if func then
func()
end
return
end
NetManager.GetPowerCenterInfo(function (msg)
this.SetInfo(msg)
if func then
func(msg)
end
end)
end
function this.SetInfo(msg)
this.powerCenterIsActivate = msg.active
for i = 1, #msg.strongestHero do
this.allData.hero[i] = HeroManager.GetSingleHeroData(msg.strongestHero[i])
-- if HeroManager.GetSingleHeroData(msg.strongestHero[i]) == nil then
-- LogError(msg.strongestHero[i])
-- end
end
for i = 1, PowerCenterManager.maxField do
local data
for m = 1, #msg.linkPos do
if msg.linkPos[m].position == i then
data = msg.linkPos[m]
end
end
if data then
local state = 0
if data.readyTime > 0 then
if data.readyTime/1000 - GetTimeStamp() > 0 then
state = 1
end
end
this.allData.linkPos[i] = {
position = data.position,
heroId = data.heroId,
readyTime = data.readyTime,
heroLevel = data.heroLevel,
heroBreakId = data.heroBreakId,
state = state
}
else
local state = 2
if i == #msg.linkPos+1 then
if this.PowerCenterUnLockRedpoint() then
state = 3
end
end
this.allData.linkPos[i] = {position = i, heroId = "", readyTime = -1, heroLevel = 0, heroBreakId = 0, state = state}
end
end
for i = 1, #msg.equip do
this.allData.equip[i] = msg.equip[i]
end
this.allData.level = msg.level
end
--异能中心链接&取消链接 type--0:取消链接,1:链接
function PowerCenterManager.GetPowerCenterLinkHero(position, heroId, type, func)
--[[
linkHeroInfo = {
heroId
heroLevel
heroBreakId = 阶数
equip
}
]]
local data = HeroManager.GetSingleHeroData(heroId)
local allAddProVal = HeroManager.CalculateHeroAllProValList(1, data.dynamicId, false)
local cur = {
lv = data.lv,
dynamicId = data.dynamicId,
hp = allAddProVal[HeroProType.Hp],
attack = allAddProVal[HeroProType.Attack],
pDef = allAddProVal[HeroProType.PhysicalDefence],
speed = allAddProVal[HeroProType.Speed],
}
NetManager.GetPowerCenterLinkHero(position, heroId, type, function (msg)
this.RefreshHeroData(msg)
if type == 0 then
this.allData.linkPos[position] = {position = position, heroId = "", readyTime = (GetTimeStamp()+this.cd)*1000, heroLevel = 0, heroBreakId = 0, state = 1}
if func then
func(msg)
end
elseif type == 1 then
UIManager.OpenPanel(UIName.PowerCenterLinkWinPanel, cur, function ()
this.allData.linkPos[position] = {position = position, heroId = msg.heroId, readyTime = 0, heroLevel = cur.lv, heroBreakId = msg.heroBreakId, state = 0}
if func then
func(msg)
end
end)
end
end)
end
--异能中心解锁链接栏位
function PowerCenterManager.GetPowerCenterUnlockPos(func)
if not this.PowerCenterUnLockRedpoint() then
PopupTipPanel.ShowTip(GetLanguageStrById("材料不足"))
return
end
NetManager.GetPowerCenterUnlockPos(function (msg)
local index = 0
for i = 1, PowerCenterManager.maxField do
if this.allData.linkPos[i].state == 3 then
index = i
break
end
end
this.allData.linkPos[index] = {position = index, heroId = "", readyTime = 0, state = 0}
local state = 2
if this.PowerCenterUnLockRedpoint() then
state = 3
end
this.allData.linkPos[index+1] = {position = index+1, heroId = "", readyTime = 0, state = state}
if func then
func(msg)
end
end)
end
--异能中心加速栏位冷却
function PowerCenterManager.GetPowerCenterSpeedUpLinkPos(position, costType, func)
NetManager.GetPowerCenterSpeedUpLinkPos(position, costType, function (msg)
this.allData.linkPos[position] = {position = position, heroId = "", readyTime = 0, heroLevel = 0, heroBreakId = 0, state = 0}
if func then
func(msg)
end
end)
end
function this.EventPowerCenterInfoIndication(msg)
--[[
powerCenterInfo
linkHeroInfo = {
[1] = {
heroId
heroLevel
heroBreakId = 阶数
equip
}
}
]]
-- LogError("EventPowerCenterInfoIndication")
this.SetInfo(msg.powerCenterInfo)
for i = 1, #msg.linkHeroInfo do
this.RefreshHeroData(msg.linkHeroInfo[i])
end
Game.GlobalEvent:DispatchEvent(GameEvent.PowerCenter.RefreshLinkList)
end
--刷新背包英雄数据
function this.RefreshHeroData(data)
local hero = HeroManager.GetSingleHeroData(data.heroId)
HeroManager.UpdateSingleHeroDatas(data.heroId, data.heroLevel, hero.star, data.heroBreakId, hero.upStarId, false)
--移除装备
local equipList = {}
for e = 1, #data.equip do
table.insert(equipList, data.equip[e].equipId)
EquipManager.SetEquipUpHeroDid(data.equip[e].equipId, data.heroId)
end
HeroManager.SetHeroEquipIdList(data.heroId, equipList)
--移除戒指
if hero.planList and #hero.planList > 0 then
for p = 1, #hero.planList do
if not this.CheckUnlockCombatPlan(data.heroLevel, hero.star, hero.planList[p].position) then
CombatPlanManager.DownPlanData(data.heroId, hero.planList[p].planId)
table.remove(hero.planList, p)
end
end
end
end
function this.CheckUnlockCombatPlan(lv, star, slot)
local s_type = 0
local s_value = 0
local specialConfig = ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig, "Key", "CombatPlanUnlock")
local valueArray = string.split(specialConfig.Value, "|")
local a = string.split(valueArray[slot], "#")
s_type = a[2]
s_value = a[3]
if tonumber(s_type) == 1 then
return lv >= tonumber(s_value)
elseif tonumber(s_type) == 2 then
return star >= tonumber(s_value)
end
return false
end
--可解锁红点
function PowerCenterManager.PowerCenterUnLockRedpoint()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.PowerCenter) then
return false
end
if not this.powerCenterIsActivate then
return false
end
local index = 1
for i = 1, #this.allData.linkPos do
if this.allData.linkPos[i].state == 2 or this.allData.linkPos[i].state == 3 then
index = i
break
end
end
if index == 1 or index == this.maxField then
return false
end
local cost = PowerCenterConfig[index].Cost
if BagManager.GetItemCountById(cost[1][1]) >= cost[1][2] then
this.allData.linkPos[index] = {position = index, heroId = "", readyTime = 0, state = 3}
return true
end
return false
end
--查找英雄是否是链接英雄
function PowerCenterManager.FindHeroIsLinkHeroForDynamicId(dynamicId)
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.PowerCenter) then
return false
end
for i = 1, #this.allData.linkPos do
if this.allData.linkPos[i].heroId == dynamicId then
return true
end
end
return false
end
--获取解锁栏位消耗
function PowerCenterManager.GetUnlockCost()
local index = 0
for i = 1, #PowerCenterManager.allData.linkPos do
if PowerCenterManager.allData.linkPos[i].state == 2 or PowerCenterManager.allData.linkPos[i].state == 3 then
index = i
break
end
end
return PowerCenterConfig[index].Cost
end
return PowerCenterManager