miduo_client/Assets/ManagedResources/~Lua/Modules/Incarnation/IncarnationManager.lua

269 lines
8.4 KiB
Lua

IncarnationManager = {}
local this = IncarnationManager
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local ChangingCard = ConfigManager.GetConfig(ConfigName.ChangingCard)
local PassiveSkillConfig = ConfigManager.GetConfig(ConfigName.PlayerSkill)
local PropertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
this.itemDataList = {} --state -1 未拥有 0 已有未激活 1激活未上阵 2上阵
this.SingleIncarnationPro = {}
this.SingleIncarnationProDes = ""
function this.Initialize()
this.InitItemDataList()
end
function this.InitItemDataList()
for k,v in ConfigPairs(ChangingCard) do
this.CreatEmptyItemData(v.ID)
end
local config = ConfigManager.GetConfigData(ConfigName.SpecialConfig,138)
local strs = string.split(config.Value,"|")
for i = 1,#strs do
local str = string.split(strs[i],"#")
local proId = tonumber(str[1])
local proNum = tonumber(str[2])
if not this.SingleIncarnationPro[proId] then
this.SingleIncarnationPro[proId] = 0
end
this.SingleIncarnationPro[proId] = this.SingleIncarnationPro[proId] + proNum
end
this.SingleIncarnationProDes = ""
this.SingleIncarnationProDes = this.GetproDesStr(this.SingleIncarnationProDes,this.SingleIncarnationPro)
Game.GlobalEvent:AddEvent(GameEvent.Bag.GetNewItemIncarnation, this.GetbagIncarnationData)
end
function this.CreatEmptyItemData(id)
if ChangingCard[id].IsOpen == 0 then
return
end
--以state字段来判断状态 pos 字段只是位置,不做判断
if not this.itemDataList[id] then
this.itemDataList[id] = {}
this.itemDataList[id].id = id
this.itemDataList[id].itemId = ChangingCard[id].CardId
this.itemDataList[id].name = itemConfig[ChangingCard[id].CardId].Name
this.itemDataList[id].state = -1
this.itemDataList[id].pos = 0
this.itemDataList[id].property = itemConfig[ChangingCard[id].CardId].PropertyName
this.itemDataList[id].quality = itemConfig[ChangingCard[id].CardId].Quantity
this.itemDataList[id].icon = itemConfig[ChangingCard[id].CardId].ResourceID
--this.itemDataList[id].jump = itemConfig[ChangingCard[id].CardId].Jump[1]
this.itemDataList[id].heroId = ChangingCard[id].desc2
this.itemDataList[id].proDatas = {}
for k,v in ipairs(ChangingCard[id].PropList) do
if not this.itemDataList[id].proDatas[v[1]] then
this.itemDataList[id].proDatas[v[1]] = 0
end
this.itemDataList[id].proDatas[v[1]] = this.itemDataList[id].proDatas[v[1]] + v[2]
end
this.itemDataList[id].proDesList = {}
local str = "激活属性:"
str = this.GetproDesStr(str,this.itemDataList[id].proDatas)
table.insert(this.itemDataList[id].proDesList,str)
this.itemDataList[id].skillDatas = ChangingCard[id].Skill
this.itemDataList[id].skillDes = PassiveSkillConfig[ChangingCard[id].Skill].Desc
table.insert(this.itemDataList[id].proDesList,this.itemDataList[id].skillDes)
end
end
function this.GetproDesStr(_str,dataList)
local str = _str
for k,v in pairs(dataList) do
str = str..PropertyConfig[k].Info.."+"..GetPropertyFormatStrOne(PropertyConfig[k].Style,v).." "
end
return str
end
function this.GetproDesLst(dataList,_color)
local lis1 = {}
for k,v in pairs(dataList) do
table.insert(lis1,{str = string.format("<color=#%s>%s+%s</color>",_color,PropertyConfig[k].Info,GetPropertyFormatStrOne(PropertyConfig[k].Style,v)) ,sort = PropertyConfig[k].SortId})
end
table.sort(lis1,function(a,b)
return a.sort < b.sort
end)
local list = {}
for i = 1,#lis1 do
table.insert(list,lis1[i].str)
end
return list
end
--isBack true 初始化赋值操作 false 其他
function this.SetItemDataList(dataList,isBack)
for i = 1,#dataList do
local state = dataList[i].status
if isBack then
if dataList[i].status == 0 then
state = 1
elseif dataList[i].status == 1 then
state = 2
end
end
this.SetItemDataByid(dataList[i].id,state,dataList[i].index)
end
HeroPropManager.SetFuncPropDirty(Func_Prop_Type.Incarnation)
end
function this.GetbagIncarnationData()
local data = BagManager.GetDataByItemType(ItemType.Incarnation)
for i = 1,#data do
this.SetItemDataByCardId(data[i].id)
end
end
function this.SetItemDataByCardId(id)
local config = ConfigManager.TryGetConfigDataByKey(ConfigName.ChangingCard,"CardId",id)
if config then
if this.itemDataList[config.ID] and this.itemDataList[config.ID].state < 1 then
if BagManager.GetItemCountById(id) > 0 then
this.SetItemDataByid(config.ID,0,0)
else
this.SetItemDataByid(config.ID,-1,0)
end
end
end
end
function this.SetItemDataByid(id,state,pos)
if not this.itemDataList[id] then
this.CreatEmptyItemData(id)
end
this.itemDataList[id].state = state
this.itemDataList[id].pos = pos
CheckRedPointStatus(this.itemDataList[id].property + 43801)
end
function this.GetStatusByItemId(id)
local config = ConfigManager.TryGetConfigDataByKey(ConfigName.ChangingCard,"CardId",id)
if config then
return this.itemDataList[config.ID].state
end
return -1
end
local sortData = {
[-1] = 0,
[0] = 2,
[1] = 1,
[2] = 1,
}
--根据属性获取化身数据
function this.GetItemDataListByPro(property)
local datas = {}
for k,v in pairs(this.itemDataList) do
if v.property == property then
table.insert(datas,v)
end
end
table.sort(datas,function(a,b)
if sortData[a.state] == sortData[b.state] then
if a.quality == b.quality then
return a.id < b.id
else
return a.quality > b.quality
end
else
return sortData[a.state] > sortData[b.state]
end
end)
return datas
end
function this.GetActiveNum()
local num = 0
for k,v in pairs(this.itemDataList) do
if v.state > 0 then
num = num + 1
end
end
return num
end
function this.GetIncarnationPower()
local proList = {}
local num = this.GetActiveNum()
for k,v in pairs(this.SingleIncarnationPro) do
if not proList[k] then
proList[k] = 0
end
proList[k] = proList[k] + (v * num)
end
return proList
end
function this.GetIncarnationTotalPro()
local proList = {}
for k,v in pairs(this.itemDataList) do
if v.state > 0 then
for k,v in pairs(v.proDatas) do
if not proList[k] then
proList[k] = 0
end
proList[k] = proList[k] + v
end
end
end
local proList1 = this.GetIncarnationPower()
for k,v in pairs(proList1) do
if not proList[k] then
proList[k] = 0
end
proList[k] = proList[k] + v
end
return proList
end
--获取已上阵的变身卡 --界面获取
function this.GetIncarnationData1()
local datas = {}
for k,v in pairs(this.itemDataList) do
if v.state == 2 then
datas[v.pos] = v
end
end
return datas
end
--获取已上阵的变身卡 --战斗获取
function this.GetIncarnationData()
local datas = {}
for k,v in pairs(this.itemDataList) do
if v.state == 2 then
table.insert(datas,v.id)
end
end
return datas
end
--获取已上阵的变身卡 --战斗获取
function this.GetIncarnationDataById(id)
for k,v in pairs(this.itemDataList) do
if v.itemId == id then
return v
end
end
return nil
end
function this.CheckRedData(red)
local list = {}
if red == RedPointType.incarnation_people then
list = this.GetItemDataListByPro(1)
elseif red == RedPointType.incarnation_buddish then
list = this.GetItemDataListByPro(2)
elseif red == RedPointType.incarnation_demon then
list = this.GetItemDataListByPro(3)
else
list = this.GetItemDataListByPro(4)
end
for k,v in pairs(list) do
if v.state == 0 then
return true
end
end
return false
end
return this