60 lines
2.2 KiB
Lua
60 lines
2.2 KiB
Lua
GemManager = {}
|
|
local this = GemManager
|
|
local gemConfig = ConfigManager.GetConfig(ConfigName.GemConfig)
|
|
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
|
|
|
|
return this |