2021-12-06 15:07:34 +08:00
|
|
|
|
GemManager = {}
|
|
|
|
|
local this = GemManager
|
2021-12-08 09:29:08 +08:00
|
|
|
|
local gemConfig = ConfigManager.GetConfig(ConfigName.GemConfig)
|
2021-12-08 17:27:22 +08:00
|
|
|
|
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
|
2021-12-06 14:24:24 +08:00
|
|
|
|
function this.Initialize()
|
2021-12-07 11:50:03 +08:00
|
|
|
|
this.myGemList = {}--我穿戴命石的id
|
2021-12-08 09:29:08 +08:00
|
|
|
|
this.typeGemList = {}
|
2021-12-07 11:50:03 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-08 09:29:08 +08:00
|
|
|
|
--获取服务器发来的背包中的命石数据信息
|
2021-12-08 15:40:43 +08:00
|
|
|
|
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
|
2021-12-08 09:29:08 +08:00
|
|
|
|
end
|
2021-12-08 15:40:43 +08:00
|
|
|
|
table.sort(data,function (a,b)
|
|
|
|
|
return a.id > b.id
|
|
|
|
|
end)
|
|
|
|
|
return data
|
2021-12-08 09:29:08 +08:00
|
|
|
|
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
|
2021-12-07 11:50:03 +08:00
|
|
|
|
end
|
2021-12-08 15:40:43 +08:00
|
|
|
|
LogPink(string.format( "修改的位置[%s][%s] ID:%s",msg.lifeGridInfo.gridId,msg.lifeGridInfo.gridIndex,tostring(msg.lifeGridInfo.itemId)))
|
2021-12-08 09:29:08 +08:00
|
|
|
|
this.myGemList[msg.lifeGridInfo.gridId][msg.lifeGridInfo.gridIndex] = msg.lifeGridInfo.itemId
|
2021-12-07 11:50:03 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-08 09:29:08 +08:00
|
|
|
|
--获取穿戴着的命石
|
2021-12-07 11:50:03 +08:00
|
|
|
|
function this.GetWearedGem(_GemList)
|
2021-12-07 14:03:02 +08:00
|
|
|
|
for i,v in ipairs(_GemList) do
|
2021-12-07 11:50:03 +08:00
|
|
|
|
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
|
2021-12-08 09:29:08 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-08 17:27:22 +08:00
|
|
|
|
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
|
2021-12-08 18:21:28 +08:00
|
|
|
|
data[pro[k][1]] = 0
|
2021-12-08 17:27:22 +08:00
|
|
|
|
end
|
2021-12-08 18:21:28 +08:00
|
|
|
|
data[pro[k][1]] = data[pro[k][1]] + pro[k][2]
|
2021-12-08 17:27:22 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return data
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-10 11:40:15 +08:00
|
|
|
|
function this.GetSortAttri()
|
|
|
|
|
local tempData = {}
|
|
|
|
|
local data = this.GetAllAttri()
|
|
|
|
|
for key, value in pairs(data) do
|
|
|
|
|
local t = {}
|
|
|
|
|
t.id = key
|
|
|
|
|
t.num = value
|
|
|
|
|
t.sort = propertyConfig[key].SortId
|
|
|
|
|
table.insert( tempData,t )
|
|
|
|
|
end
|
|
|
|
|
table.sort(tempData,function (a,b)
|
|
|
|
|
return a.sort < b.sort
|
|
|
|
|
end )
|
|
|
|
|
return tempData
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-09 20:17:37 +08:00
|
|
|
|
--========================一键合成============================
|
|
|
|
|
--获取表中所有命石(data[类型1-8][等级1-10]=表数据),组成map
|
|
|
|
|
function this.GetMapOfBagData()
|
|
|
|
|
local data = {}
|
|
|
|
|
local bagdata = BagManager.GetBagAllDataByItemType(ItemType.Gem)
|
|
|
|
|
for _, configInfo in ConfigPairs(gemConfig) do
|
|
|
|
|
if not data[configInfo.Type] then
|
|
|
|
|
data[configInfo.Type] = {}
|
|
|
|
|
end
|
|
|
|
|
if not data[configInfo.Type][configInfo.Level] then
|
|
|
|
|
data[configInfo.Type][configInfo.Level] = {}
|
|
|
|
|
end
|
|
|
|
|
-- LogPink("type:"..tostring(configInfo.Type).." Level:"..tostring(configInfo.Level))
|
|
|
|
|
data[configInfo.Type][configInfo.Level] = configInfo
|
|
|
|
|
end
|
|
|
|
|
return data
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-09 13:29:16 +08:00
|
|
|
|
function this.OneKeyConpound()
|
2021-12-09 20:17:37 +08:00
|
|
|
|
--获取表中所有命石,组成map
|
|
|
|
|
local totalMoney = 0
|
|
|
|
|
local finalList = {}
|
|
|
|
|
local configMap = this.GetMapOfBagData()
|
|
|
|
|
--1-8的外部循环
|
|
|
|
|
for i = 1, #configMap do
|
|
|
|
|
local bool,money = this.DoCircle1(finalList,configMap[i])
|
|
|
|
|
totalMoney = totalMoney + money
|
|
|
|
|
if not bool then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return finalList,totalMoney
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--一键合成循环
|
|
|
|
|
function this.DoCircle1(finalList,data)
|
|
|
|
|
local totalMoney = 0
|
|
|
|
|
local lastGNum = 0--上一次合成出来的数量
|
|
|
|
|
for i = 1, #data do
|
|
|
|
|
local tempData = data[i]
|
|
|
|
|
--判断是否满级
|
|
|
|
|
if not tempData.NextGem or tempData.NextGem == 0 then
|
|
|
|
|
if lastGNum > 0 then
|
|
|
|
|
finalList[tempData.Id] = lastGNum
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local bagGemNum = BagManager.GetTotalItemNum(tempData.Id)--当前背包中数量
|
|
|
|
|
local curGemNum = 0--当前可使用合成的该等级的Gem数量
|
|
|
|
|
if bagGemNum > 0 then
|
|
|
|
|
curGemNum = bagGemNum + lastGNum--当前一共拥有命石数量(包括已经合成的数量)
|
|
|
|
|
end
|
|
|
|
|
--命石不足
|
|
|
|
|
if curGemNum < tempData.UpgradeNum then
|
|
|
|
|
if lastGNum > 0 then
|
|
|
|
|
finalList[tempData.Id] = lastGNum
|
|
|
|
|
lastGNum = 0
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local remainNum = curGemNum%tempData.UpgradeNum--如果合成到下一级,本级所剩余的数量
|
|
|
|
|
if remainNum ~= 0 then
|
|
|
|
|
curGemNum = curGemNum - remainNum--此处curGemNum变为实际花费的命石数量
|
|
|
|
|
end
|
|
|
|
|
if curGemNum > 0 then
|
|
|
|
|
local needMoneyNum = curGemNum/tempData.UpgradeNum * tempData.UpgradeCost[2]--按照命石可合成的数量,要花费的金币
|
|
|
|
|
local curMoneyNum = BagManager.GetTotalItemNum(tempData.UpgradeCost[1])--当前金币数量
|
|
|
|
|
if needMoneyNum + totalMoney > curMoneyNum then--如果当前金币不足要花费的数量,计算可以合成几个
|
|
|
|
|
local upNum = (curMoneyNum - totalMoney)/tempData.UpgradeCost[2]--实际真的合成了几个
|
|
|
|
|
totalMoney = totalMoney + upNum*tempData.UpgradeCost[2]--金币计入总数
|
|
|
|
|
local endCostNum = upNum*tempData.UpgradeNum--例如命石数量可消耗6,实际合成2,要把未使用的4加入最终list
|
|
|
|
|
if lastGNum > endCostNum then
|
|
|
|
|
finalList[tempData.Id] = lastGNum - endCostNum--要把未使用的加入最终list
|
|
|
|
|
end
|
|
|
|
|
finalList[tempData.NextGem] = upNum
|
|
|
|
|
return false,totalMoney
|
|
|
|
|
else--如果金币足额
|
|
|
|
|
totalMoney = totalMoney + needMoneyNum--金币计入总数
|
|
|
|
|
if bagGemNum > 0 then
|
|
|
|
|
if remainNum - bagGemNum > 0 then--如果扣除给下一次循环所需要的,本次剩余如果大于0,则全部加入最终list
|
|
|
|
|
finalList[tempData.NextGem] = remainNum - bagGemNum
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
lastGNum = curGemNum/tempData.UpgradeNum
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return true,totalMoney
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--=========================快速合成================================
|
|
|
|
|
function this.FastConpound(id)
|
|
|
|
|
local totalMoney = 0
|
|
|
|
|
local finalList = {}
|
|
|
|
|
local configMap = this.GetMapOfBagData()[gemConfig[id].Type]
|
|
|
|
|
local selectLv = gemConfig[id].Level
|
|
|
|
|
local lastGNum = 0--上一次合成出来的数量
|
|
|
|
|
for i = 1, #configMap do
|
|
|
|
|
local tempData = configMap[i]
|
|
|
|
|
if tempData.Level >= selectLv then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
local bagGemNum = BagManager.GetTotalItemNum(tempData.Id)--当前背包中数量
|
|
|
|
|
local curGemNum = 0--当前可使用合成的该等级的Gem数量
|
|
|
|
|
if bagGemNum > 0 then
|
|
|
|
|
curGemNum = bagGemNum + lastGNum--当前一共拥有命石数量(包括已经合成的数量)
|
|
|
|
|
end
|
|
|
|
|
if curGemNum < tempData.UpgradeNum then--如果出现断层,需要清空数据继续遍历,
|
|
|
|
|
finalList = {}
|
|
|
|
|
totalMoney = 0
|
|
|
|
|
lastGNum = 0
|
|
|
|
|
else
|
|
|
|
|
local needNum = this.DoCircle2(tempData.Type,tempData.Level,selectLv)
|
|
|
|
|
local remainNum = curGemNum%tempData.UpgradeNum
|
|
|
|
|
if curGemNum > needNum then
|
|
|
|
|
remainNum = curGemNum - needNum
|
|
|
|
|
curGemNum = needNum
|
|
|
|
|
end
|
|
|
|
|
lastGNum = math.floor(curGemNum/tempData.UpgradeNum)
|
|
|
|
|
totalMoney = totalMoney + lastGNum*tempData.UpgradeCost[2]
|
|
|
|
|
if bagGemNum > 0 then
|
|
|
|
|
finalList[tempData.Id] = bagGemNum - remainNum
|
|
|
|
|
end
|
|
|
|
|
local haveGoldNum= BagManager.GetTotalItemNum(tempData.UpgradeCost[1])
|
|
|
|
|
if totalMoney>haveGoldNum then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
totalMoney = totalMoney + gemConfig[id].UpgradeCost[2]
|
|
|
|
|
return true,lastGNum==1,finalList,totalMoney
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function this.DoCircle2(type,curLevel,targetLevel)
|
|
|
|
|
local needNum = 1
|
|
|
|
|
local configMap = this.GetMapOfBagData()[type]
|
|
|
|
|
for i = 1, #configMap do
|
|
|
|
|
if configMap[i].Level >= curLevel then
|
|
|
|
|
if configMap[i].Level == targetLevel then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
needNum = needNum*configMap[i].UpgradeNum
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return needNum
|
2021-12-09 13:29:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
2021-12-06 14:24:24 +08:00
|
|
|
|
return this
|