miduo_client/Assets/ManagedResources/~Lua/Modules/Gem/GemManager.lua

84 lines
3.0 KiB
Lua

GemManager = {}
local this = GemManager
local gemConfig = ConfigManager.GetConfig(ConfigName.GemConfig)
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
function this.Initialize()
this.myGemList = {}--我穿戴命石的id
this.typeGemList = {}
end
--获取服务器发来的背包中的命石数据信息
function this.GetGemsFromBagByType(_type)
local data = {}
local bagdata = BagManager.GetBagAllDataByItemType(ItemType.Gem)
for i = 1, #bagdata do
local tempdata = {}
tempdata.id = bagdata[i].id
tempdata.num = bagdata[i].num
tempdata.type = gemConfig[bagdata[i].id].Type
tempdata.name = gemConfig[bagdata[i].id].Name
if tempdata.type == _type or _type == 0 and tempdata.num > 0 then
table.insert(data,tempdata)
end
end
table.sort(data,function (a,b)
return a.id > b.id
end)
return data
end
function this.UpdateSingleGem(msg)
if msg and msg.lifeGridInfo and msg.lifeGridInfo.gridId and msg.lifeGridInfo.gridId > 0 then
if not this.myGemList[msg.lifeGridInfo.gridId] then
this.myGemList[msg.lifeGridInfo.gridId] = {}
end
if not this.myGemList[msg.lifeGridInfo.gridId][msg.lifeGridInfo.gridIndex] then
this.myGemList[msg.lifeGridInfo.gridId][msg.lifeGridInfo.gridIndex] = nil
end
LogPink(string.format( "修改的位置[%s][%s] ID:%s",msg.lifeGridInfo.gridId,msg.lifeGridInfo.gridIndex,tostring(msg.lifeGridInfo.itemId)))
this.myGemList[msg.lifeGridInfo.gridId][msg.lifeGridInfo.gridIndex] = msg.lifeGridInfo.itemId
end
end
--获取穿戴着的命石
function this.GetWearedGem(_GemList)
for i,v in ipairs(_GemList) do
LogPink(string.format("命格:%s index:%s ID:%s",v.gridId,v.gridIndex,v.itemId))
if v and v.gridId then
if not this.myGemList[v.gridId] then
this.myGemList[v.gridId] = {}
end
if not this.myGemList[v.gridId][v.gridIndex] then
this.myGemList[v.gridId][v.gridIndex] = nil
end
if v.itemId and v.itemId > 0 then
this.myGemList[v.gridId][v.gridIndex] = v.itemId
end
end
end
end
function this.GetAllAttri()
local data = {}
for i = 1, 8 do
for j = 1, 3 do
if this.myGemList[i] and this.myGemList[i][j] and this.myGemList[i][j] > 0 then
local pro = gemConfig[this.myGemList[i][j]].Property
for k = 1, #pro do
if not data[pro[k][1]] then
data[pro[k][1]] = {}
data[pro[k][1]].id = pro[k][1]
data[pro[k][1]].num = 0
end
data[pro[k][1]].num = data[pro[k][1]].num + pro[k][2]
end
end
end
end
-- table.sort(data,function (a,b)
-- return propertyConfig[a.id].SortId < propertyConfig[b.id].SortId
-- end)
return data
end
return this