miduo_client/Assets/ManagedResources/~Lua/Modules/Pokemon/PokemonManager.lua

236 lines
8.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

PokemonManager = {}
local this = PokemonManager
local spiritAnimal = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
local spiritAnimalBook = ConfigManager.GetConfig(ConfigName.SpiritAnimalBook)
local pokemons = {}--灵兽数据
local pokemonFetter = {}--灵兽羁绊
local pokemonFormatipn = {}--灵兽编队
function this.Initialize()
end
---------------------------------------------
--初始化灵兽数据
---------------------------------------------
function this.InitPokemonsData(_msgPokemonList)
--Log("初始化灵兽数据" .. #_msgPokemonList)
pokemons = {}
for i = 1, #_msgPokemonList do
this.UpdatePokemonDatas(_msgPokemonList[i])
end
end
--刷新本地数据v 掉落时调用
function this.UpdatePokemonDatas(_msgPokemonData,isRefreshFetter)
local singPokemonData = {}
singPokemonData.heroBackData = _msgPokemonData
singPokemonData.id = _msgPokemonData.sId
singPokemonData.dynamicId = _msgPokemonData.id
singPokemonData.star = _msgPokemonData.star
singPokemonData.lv = _msgPokemonData.level
singPokemonData.isZhen = _msgPokemonData.isZhen
pokemons[singPokemonData.dynamicId] = singPokemonData
if isRefreshFetter then
this.GetPokemonRefreshFetter(singPokemonData.id)
end
end
--获取当前灵兽数据
function this.GetSinglePokemonData(_did)
if not _did then return nil end
if pokemons[_did] then
return pokemons[_did]
else
return nil
end
end
--获取当前可上阵的所有灵兽数据
function this.GetCanUpZhenPokemonDatas()
local upZhenSidList = this.GetAllPokemonFormationSids()
local curAllPokemonList = {}
for key, value in pairs(pokemons) do
if value.isZhen == false and not upZhenSidList[value.id] then
table.insert(curAllPokemonList,value)
end
end
return curAllPokemonList
end
--移除灵兽数据
function this.RemoveSinglePokemonData(_did)
if not _did then return end
if pokemons[_did] then
pokemons[_did] = nil
end
end
--前端刷新单个灵兽数据
function this.UpdateSinglePokemonData(_did,_lv,_star)
if not _did then return end
if pokemons[_did] then
pokemons[_did].lv = _lv
pokemons[_did].star = _star
end
end
--获取当前所有可吞卡灵兽数据
function this.GetNoUpLvPokemonData(_id)
local curAllPokemonList = {}
for key, value in pairs(pokemons) do
if value.isZhen == false and value.star <= 0 and value.lv <= 1 then
table.insert(curAllPokemonList,value)
end
end
return curAllPokemonList
end
--获取单个灵兽属性 (灵兽属性/编队人数 灵兽属性会平分给上阵的所有神将)
function this.GetSinglePokemonAddProData(_did)
if not pokemons[_did] then return end
local addAllProVal = {}
local curPokeonData = pokemons[_did]
local curPokemonConFig = ConfigManager.GetConfigData(ConfigName.SpiritAnimal,curPokeonData.id)
local curPokemonLvConFig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalLevel,"Quality",curPokemonConFig.Quality,"Level",curPokeonData.lv)
local curPokemonStarConFig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalStar,"Quality",curPokemonConFig.Quality,"Star",curPokeonData.star)
--基础
addAllProVal[HeroProType.Hp] = curPokemonConFig.Hp
addAllProVal[HeroProType.Attack] = curPokemonConFig.Attack
addAllProVal[HeroProType.PhysicalDefence] = curPokemonConFig.PhysicalDefence
addAllProVal[HeroProType.MagicDefence] = curPokemonConFig.MagicDefence
--升级
for i = 1, #curPokemonLvConFig.CharacterLevelPara do
local curPro = curPokemonLvConFig.CharacterLevelPara[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
--升星 属性=(基础属性+等级属性)*1+星级倍率)
local StarPara = curPokemonStarConFig.StarPara/10000
local addEndAllProVal = {}
for key, value in pairs(addAllProVal) do
addEndAllProVal[key] = value * (1 + StarPara)
end
return addEndAllProVal
end
---------------------------------------------
--灵兽羁绊 (羁绊属性直接就是团队属性)
---------------------------------------------
function this.InitPokemonsFetterData(_msgPokemonFetterList)
--Log("灵兽羁绊" .. #_msgPokemonFetterList)
pokemonFetter = {}
for i = 1, #_msgPokemonFetterList do
this.UpdatePokemonFetterDatas(_msgPokemonFetterList[i])
end
end
--刷新本地灵兽羁绊数据
function this.UpdatePokemonFetterDatas(_msgPokemonFetter)
local singPokemonFetterData = {}
singPokemonFetterData.id = _msgPokemonFetter.id
pokemonFetter[singPokemonFetterData.id] = singPokemonFetterData
end
function this.GetAllPokemonFetterDatas()
return pokemonFetter
end
--判断是否激活新的灵兽羁绊数据
function this.GetPokemonRefreshFetter(_sid)
local curPokemonSidList = this.GetCurPokemonSidList()
local allActivityFetterIds = {}
for key, configInfo in ConfigPairs(ConfigManager.GetConfig(ConfigName.SpiritAnimalBook)) do
if pokemonFetter[key] then--已有的羁绊去掉
return
end
local stateNum = 0
for i = 1, #configInfo.Teamers do
if configInfo.Teamers[i] == _sid then
stateNum = stateNum + 1
else
if curPokemonSidList[configInfo.Teamers[i]] then
stateNum = stateNum + 1
end
end
end
if stateNum >= #configInfo.Teamers then
table.insert(allActivityFetterIds,configInfo)
end
end
if #allActivityFetterIds > 0 then
for i = 1, #allActivityFetterIds do
PopupTipPanel.ShowTip("已激活灵兽羁绊—【".. allActivityFetterIds[i].Name .."】!")
local curBackData = {}
curBackData.id = allActivityFetterIds[i].Id
this.UpdatePokemonFetterDatas(curBackData)
end
end
end
--获取所有的灵兽种类
function this.GetCurPokemonSidList()
local curPokemonSidList = {}
for key, value in pairs(pokemons) do
curPokemonSidList[value.id] = value
end
return curPokemonSidList
end
--获取所有灵兽羁绊总和属性 (羁绊属性直接加在团队属性上)
function this.GetAllPokemonFetterAddPros()
local addAllProVal = {}
for key, value in pairs(pokemonFetter) do
local curspiritAnimalBook = spiritAnimalBook[key]
if curspiritAnimalBook and #curspiritAnimalBook.ActivePara > 0 then
for i = 1, #curspiritAnimalBook.ActivePara do
local curPro = curspiritAnimalBook.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.UpdatePokemonFormationDatas(_msgPokemonFormationList)
pokemonFormatipn = {}
for i = 1, #_msgPokemonFormationList do
local teamInfo = {}
teamInfo.pokemonDid = _msgPokemonFormationList[i].pokemonDid
teamInfo.position = _msgPokemonFormationList[i].position
table.insert(pokemonFormatipn, teamInfo)
end
end
--获取编队灵兽静态id list
function this.GetAllPokemonFormationSids()
local formationSids = {}
for i = 1, #pokemonFormatipn do
if pokemons[pokemonFormatipn[i].pokemonDid] then
formationSids[pokemons[pokemonFormatipn[i].pokemonDid].id] = pokemons[pokemonFormatipn[i].pokemonDid]
end
end
return formationSids
end
--获取灵兽编队属性
function this.GetPokemonFormationAddPro()
local allPro = {}
for key, value in pairs(pokemonFormatipn) do
if pokemons[key] then
local curPokemonAddPro = this.GetNoUpLvPokemonData(key)
HeroManager.DoubleTableCompound(allPro, curPokemonAddPro)
end
end
return allPro
end
return this