miduo_client/Assets/ManagedResources/~Lua/Modules/TianShuMiJuan/TianShuMiJuanManger.lua

173 lines
5.6 KiB
Lua
Raw Normal View History

2021-03-17 14:29:34 +08:00
TianShuMiJuanManger = {}
2021-03-16 17:37:32 +08:00
local this = TianShuMiJuanManger
2021-03-22 15:16:29 +08:00
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
2021-03-16 17:37:32 +08:00
--读表
function this.Initialize()
this.fetterData = {}
for k,v in ConfigPairs(ConfigManager.GetConfig(ConfigName.SpiritAnimalBook)) do
local configData = this.CreatSingleConfigData(v)
2021-03-17 14:29:34 +08:00
if not this.fetterData[v.Id] then
this.fetterData[v.Id] = {}
end
this.fetterData[v.Id] = configData
2021-03-16 17:37:32 +08:00
end
2021-03-19 14:37:24 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Player.OnLevelChange, this.OnLevelChange)
end
function this.OnLevelChange()
2021-03-22 15:16:29 +08:00
for k,v in pairs(this.fetterData) do
if v.enabled == -2 then
v.enabled = this.CheckOpenFetter(v.openLevel) and -1 or -2
end
end
2021-03-22 17:05:00 +08:00
this.CheckFetterStatus(1)
this.CheckFetterStatus(2)
this.CheckFetterStatus(3)
2021-03-16 17:37:32 +08:00
end
2021-03-23 14:13:02 +08:00
function this.CheckRedPointType(redType)
if redType == RedPointType.Hero_Fetter then
this.CheckRedPoint(1)
elseif redType == RedPointType.SoulPrint_Fetter then
this.CheckRedPoint(2)
elseif redType == RedPointType.TianShuPokemon_Fetter then
this.CheckRedPoint(3)
end
end
2021-03-16 17:37:32 +08:00
function this.CreatSingleConfigData(configData)
local data = {}
2021-03-22 15:16:29 +08:00
data.id = configData.Id
2021-03-16 17:37:32 +08:00
data.name = GetLanguageStrById(configData.Name)
data.teamers = configData.Teamers
data.activePara = configData.ActivePara
2021-03-22 15:16:29 +08:00
data.activeParaTip = "激活属性:"
for i = 1, #data.activePara do
local config = propertyConfig[data.activePara[i][1]]
local value= GetEquipPropertyFormatStr(config.Style,data.activePara[i][2])
data.activeParaTip = data.activeParaTip..config.Info.."+"..value .. " "
end
data.activeParaTip = rtrim(data.activeParaTip)
2021-03-16 17:37:32 +08:00
data.activeForce = configData.ActiveForce
2021-03-22 15:16:29 +08:00
data.fetterType = configData.FetterType
2021-03-16 17:37:32 +08:00
data.reward = configData.Reward
data.openLevel = configData.OpenLevel
2021-03-22 15:16:29 +08:00
data.enabled = this.CheckOpenFetter(data.openLevel) and -1 or -2 -- -2 未开启 -1 不可激活 0 可激活 1已激活
2021-03-16 17:37:32 +08:00
return data
end
--刷新已经激活的羁绊
function this.UpdateFetterId(ids)
for i = 1, #ids do
if this.fetterData[ids[i]] then
this.fetterData[ids[i]].enabled = 1
end
end
end
--检测条件变化,判断羁绊是否可激活
function this.CheckFetterStatus(fetterType)
if fetterType == 1 then
local curPokemonSidList = PlayerManager.heroHandBook
this.GetAllPokemonFetterDatas(fetterType,curPokemonSidList)
CheckRedPointStatus(RedPointType.Hero_Fetter)
elseif fetterType == 2 then
local curPokemonSidList = SoulPrintManager.GetAllHavedSoulPrint()
this.GetAllPokemonFetterDatas(fetterType,curPokemonSidList)
CheckRedPointStatus(RedPointType.SoulPrint_Fetter)
elseif fetterType == 3 then
local curPokemonSidList = PokemonManager.GetAllPokemonGetDatas()
this.GetAllPokemonFetterDatas(fetterType,curPokemonSidList)
CheckRedPointStatus(RedPointType.Pokemon_Fetter)
CheckRedPointStatus(RedPointType.TianShuPokemon_Fetter)
end
end
--刷新羁绊状态
function this.GetAllPokemonFetterDatas(fetterType,curPokemonSidList)
local SpiritAnimalBookList = {}
for k,v in pairs(this.fetterData) do
2021-03-17 14:29:34 +08:00
if v.fetterType == fetterType and v.enabled == -1 then
2021-03-16 17:37:32 +08:00
if this.IsCompound(v.teamers,curPokemonSidList) then
v.enabled = 0
end
end
end
end
2021-03-22 15:16:29 +08:00
function this.CheckRedPoint(fetterType)
for k,v in pairs(this.fetterData) do
if v.fetterType == fetterType and v.enabled == 0 then
2021-03-23 14:13:02 +08:00
LogGreen("fetterType:"..fetterType.." 红点亮了")
2021-03-16 17:37:32 +08:00
return true
end
end
2021-03-23 14:13:02 +08:00
LogGreen("fetterType:"..fetterType.." 红点灰了")
return false
2021-03-16 17:37:32 +08:00
end
function this.IsCompound(Teamers,curPokemonSidList)
local isCompound = true
for k,v in ipairs(Teamers) do
if curPokemonSidList[v] == nil then
if isCompound then
isCompound = false
break
end
end
end
return isCompound
end
--根据type获取羁绊数据
function this.GetFetterDataByFetterType(fetterType)
local data = {}
for k,v in pairs(this.fetterData) do
2021-03-22 15:16:29 +08:00
if v.fetterType == fetterType and v.enabled ~= -2 then
2021-03-16 17:37:32 +08:00
table.insert(data,v)
end
end
return data
end
2021-03-19 14:37:24 +08:00
function this.CheckOpenFetter(openLevel)
if openLevel > PlayerManager.level then
return false
end
return true
end
2021-03-16 17:37:32 +08:00
--获取所有羁绊总和属性 (羁绊属性直接加在团队属性上)
function this.GetAllFetterAddProsBy(fetterType)
local fetterData = this.GetFetterDataByFetterType(fetterType)
local addAllProVal = {}
for key, value in pairs(fetterData) do
if value.enabled == 1 and #value.activePara > 0 then
for i = 1, #value.activePara do
local curPro = value.activePara[i]
if curPro[2] > 0 then
if addAllProVal[curPro[1]] then
addAllProVal[curPro[1]]=addAllProVal[curPro[1]]+curPro[2]
else
addAllProVal[curPro[1]]=curPro[2]
end
end
end
end
end
return addAllProVal
end
----获取所有羁绊总和静态战力
function this.GetAllPokemonFetterAddProsSWarPower(fetterType)
local fetterData = this.GetFetterDataByFetterType(fetterType)
local addPowerVal = 0
for key, value in pairs(fetterData) do
if value.enabled == 1 and value.activeForce > 0 then
addPowerVal = addPowerVal + value.ActiveForce
end
end
return addPowerVal
end
return this