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

181 lines
5.7 KiB
Lua
Raw Normal View History

2021-11-11 16:48:15 +08:00
IncarnationManager = {}
local this = IncarnationManager
2021-11-16 15:24:17 +08:00
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
2021-11-18 11:55:26 +08:00
local ChangingCard = ConfigManager.GetConfig(ConfigName.ChangingCard)
local PassiveSkillConfig = ConfigManager.GetConfig(ConfigName.PassiveSkillConfig)
local PropertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
2021-11-16 15:24:17 +08:00
this.itemDataList = {} --state -1 未拥有 0 已有未激活 1激活未上阵 2上阵
2021-11-11 16:48:15 +08:00
function this.Initialize()
2021-11-16 15:24:17 +08:00
this.InitItemDataList()
2021-11-11 16:48:15 +08:00
end
2021-11-16 15:24:17 +08:00
function this.InitItemDataList()
2021-11-18 11:55:26 +08:00
for k,v in ConfigPairs(ChangingCard) do
this.CreatEmptyItemData(v.ID)
2021-11-16 15:24:17 +08:00
end
2021-11-18 11:55:26 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Bag.GetNewItem, this.SetItemDataByCardId)
2021-11-16 15:24:17 +08:00
end
function this.CreatEmptyItemData(id)
2021-11-18 11:55:26 +08:00
if ChangingCard[id].IsOpen == 0 then
return
end
--以state字段来判断状态 pos 字段只是位置,不做判断
2021-11-16 15:24:17 +08:00
if not this.itemDataList[id] then
this.itemDataList[id] = {}
2021-11-18 11:55:26 +08:00
this.itemDataList[id].id = id
this.itemDataList[id].itemId = ChangingCard[id].CardId
this.itemDataList[id].name = itemConfig[ChangingCard[id].CardId].Name
2021-11-16 15:24:17 +08:00
this.itemDataList[id].state = -1
2021-11-18 11:55:26 +08:00
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].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].skillDatas = GetSkillConfigDesc(PassiveSkillConfig[ChangingCard[id].Skill])
this.itemDataList[id].proDesList = {}
local str = "激活属性:"
for k,v in pairs(this.itemDataList[id].proDatas) do
str = str..PropertyConfig[k].Info.."+"..GetEquipPropertyFormatStr(PropertyConfig[k].Style,v).." "
end
table.insert(this.itemDataList[id].proDesList,str)
table.insert(this.itemDataList[id].proDesList,this.itemDataList[id].skillDatas)
2021-11-16 15:24:17 +08:00
end
end
2021-11-18 11:55:26 +08:00
--isBack true 初始化赋值操作 false 其他
function this.SetItemDataList(dataList,isBack)
2021-11-16 15:24:17 +08:00
for i = 1,#dataList do
2021-11-18 11:55:26 +08:00
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 < 0 then
this.SetItemDataByid(config.ID,0,0)
end
2021-11-16 15:24:17 +08:00
end
end
2021-11-18 11:55:26 +08:00
function this.SetItemDataByid(id,state,pos)
2021-11-16 15:24:17 +08:00
if not this.itemDataList[id] then
this.CreatEmptyItemData(id)
end
this.itemDataList[id].state = state
2021-11-18 11:55:26 +08:00
this.itemDataList[id].pos = pos
CheckRedPointStatus(this.itemDataList[id].property + 43801)
2021-11-16 15:24:17 +08:00
end
2021-11-18 11:55:26 +08:00
local sortData = {
[-1] = 0,
[0] = 2,
[1] = 1,
[2] = 1,
}
2021-11-16 15:24:17 +08:00
--根据属性获取化身数据
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
2021-11-18 11:55:26 +08:00
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)
2021-11-16 15:24:17 +08:00
return datas
end
2021-11-18 11:55:26 +08:00
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
return proList
2021-11-16 15:24:17 +08:00
end
2021-11-18 11:55:26 +08:00
--获取已上阵的变身卡 --界面获取
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
2021-11-16 15:24:17 +08:00
2021-11-18 11:55:26 +08:00
--获取已上阵的变身卡 --战斗获取
2021-11-16 15:24:17 +08:00
function this.GetIncarnationData()
local datas = {}
for k,v in pairs(this.itemDataList) do
if v.state == 2 then
2021-11-18 11:55:26 +08:00
table.insert(datas,v.id)
2021-11-16 15:24:17 +08:00
end
end
return datas
2021-11-11 16:48:15 +08:00
end
2021-11-18 11:55:26 +08:00
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
2021-11-11 16:48:15 +08:00
return this