|
|
@@ -27,93 +27,112 @@ EQUIP_QUALITY_WEIGHT = 10000
|
|
|
EQUIP_QUALITY_BASE_RATE = { 7000, 8000, 9000, 10000, 12000 }
|
|
|
|
|
|
|
|
|
--- 随机属性
|
|
|
-local attrCheck = {}
|
|
|
-function checkAttr(equipGrid)
|
|
|
- local quality = equipGrid.quality
|
|
|
- local len = 0
|
|
|
+-- 转换装备洗练数据格式
|
|
|
+function AttrHashToArray(attrData)
|
|
|
+ local _, attrInfo = next(attrData)
|
|
|
+ if type(attrInfo) == "table" then
|
|
|
+ return attrData
|
|
|
+ end
|
|
|
|
|
|
- for key, value in pairs(equipGrid.attr) do
|
|
|
- len = len + 1
|
|
|
- attrCheck[len] = {key, value}
|
|
|
- end
|
|
|
|
|
|
- -- 砍掉后面的
|
|
|
- if quality < len then
|
|
|
- equipGrid.attr = {}
|
|
|
- for z = 1, quality do
|
|
|
- equipGrid.attr[attrCheck[z][1]] = attrCheck[z][2]
|
|
|
- end
|
|
|
- end
|
|
|
+ local len = 0
|
|
|
+ local attrArray = {}
|
|
|
+ for attrType, attrVal in pairs(attrData) do
|
|
|
+ len = len + 1
|
|
|
+ attrArray[len] = {attrType, attrVal, EquipLogicGrid.EQUIP_COLOR_3}
|
|
|
+ end
|
|
|
+ return attrArray
|
|
|
end
|
|
|
|
|
|
--- 随机属性
|
|
|
-function randomAttr(itemID, isRandom, otherData)
|
|
|
- local equipConfig = EquipExcel[itemID]
|
|
|
- if not equipConfig then return end
|
|
|
|
|
|
- -- 固定属性
|
|
|
- local quality = 1
|
|
|
- local attr = { }
|
|
|
- if equipConfig.random == 1 and not isRandom then
|
|
|
- quality = #equipConfig.randomAttr
|
|
|
- if quality > EQUIP_QUALITY_MAX then
|
|
|
- quality = EQUIP_QUALITY_MAX
|
|
|
- end
|
|
|
+-- 随出单条洗练属性的品质 和 倍数
|
|
|
+local function randAttrValMul()
|
|
|
+ local totalWeight = 0
|
|
|
+ for _, weight in ipairs(EquipLogicGrid.EQUIPWASH_COLOR_WEIGHT) do
|
|
|
+ totalWeight = totalWeight + weight
|
|
|
+ end
|
|
|
|
|
|
- for i = 1, quality do
|
|
|
- local key = equipConfig.randomAttr[i][1]
|
|
|
- local value = equipConfig.randomAttr[i][2]
|
|
|
- attr[key] = attr[key] or 0
|
|
|
- attr[key] = attr[key] + value
|
|
|
+ local color = 0
|
|
|
+ local mul = 0
|
|
|
+ local randNum = math.random(1, totalWeight)
|
|
|
+
|
|
|
+ local weight = 0
|
|
|
+ for k, v in ipairs(EquipLogicGrid.EQUIPWASH_COLOR_WEIGHT) do
|
|
|
+ weight = weight + v
|
|
|
+ if randNum <= weight then
|
|
|
+ color = k
|
|
|
+ break
|
|
|
end
|
|
|
- return attr, quality
|
|
|
end
|
|
|
|
|
|
- if not otherData then
|
|
|
- -- 随机品质
|
|
|
- local random = math.random(1, EQUIP_QUALITY_WEIGHT)
|
|
|
- for i = 1, #EQUIP_QUALITY do
|
|
|
- local weight = EQUIP_QUALITY[i]
|
|
|
- if random <= weight then
|
|
|
- quality = i > #equipConfig.randomAttr and #equipConfig.randomAttr or i
|
|
|
- break
|
|
|
- else
|
|
|
- random = random - weight
|
|
|
- end
|
|
|
- end
|
|
|
- else
|
|
|
- if type(otherData) == "number" then
|
|
|
- otherData = otherData < 0 and 1 or otherData
|
|
|
- quality = otherData > #equipConfig.randomAttr and #equipConfig.randomAttr or otherData
|
|
|
- end
|
|
|
- end
|
|
|
+ assert(color > 0, "============装备洗练配置错误===============")
|
|
|
|
|
|
- if quality > EQUIP_QUALITY_MAX then
|
|
|
- quality = EQUIP_QUALITY_MAX
|
|
|
+ local mulTbl = EquipLogicGrid.EQUIPWASH_COLOR_MUL[color]
|
|
|
+ mul = math.random(mulTbl[1], mulTbl[2]) / 100
|
|
|
+ return color, mul
|
|
|
+end
|
|
|
+
|
|
|
+-- 随机装备品质
|
|
|
+local function randColor(randomAttrCfg)
|
|
|
+ local color = 0
|
|
|
+ local random = math.random(1, EQUIP_QUALITY_WEIGHT)
|
|
|
+ for i = 1, #EQUIP_QUALITY do
|
|
|
+ local weight = EQUIP_QUALITY[i]
|
|
|
+ if random <= weight then
|
|
|
+ color = i > #randomAttrCfg and #randomAttrCfg or i
|
|
|
+ break
|
|
|
+ else
|
|
|
+ random = random - weight
|
|
|
+ end
|
|
|
end
|
|
|
+ return color
|
|
|
+end
|
|
|
+
|
|
|
|
|
|
+-- 随机出装备洗练属性
|
|
|
+local function randAttrArray(randomAttrCfg, equipColor)
|
|
|
+ --品质
|
|
|
+ equipColor = equipColor or randColor(randomAttrCfg)
|
|
|
|
|
|
-- 计算总权重
|
|
|
local totalWeight = 0
|
|
|
- for k, v in pairs(equipConfig.randomAttr) do
|
|
|
+ for k, v in pairs(randomAttrCfg) do
|
|
|
totalWeight = totalWeight + v[3]
|
|
|
end
|
|
|
|
|
|
- -- 随机条目属性
|
|
|
+ local len = 0
|
|
|
+ local attr = {}
|
|
|
local MathRandom = math.random
|
|
|
- local randomAttr = Util.copyTable(equipConfig.randomAttr)
|
|
|
-
|
|
|
- for z = 1, quality do
|
|
|
+
|
|
|
+ -- for i = 1, equipColor do
|
|
|
+ -- local weight = 0
|
|
|
+ -- local randmWeight = MathRandom(1, totalWeight)
|
|
|
+ -- for _, v in ipairs(randomAttrCfg) do
|
|
|
+ -- weight = weight + v[3]
|
|
|
+ -- if randmWeight <= weight then
|
|
|
+ -- len = len + 1
|
|
|
+ -- local attrColor, mul = randAttrValMul()
|
|
|
+ -- local finalVal = math.floor(v[2] * mul)
|
|
|
+ -- attr[len] = {v[1], finalVal, attrColor}
|
|
|
+ -- break
|
|
|
+ -- end
|
|
|
+ -- end
|
|
|
+ -- end
|
|
|
+
|
|
|
+ for z = 1, equipColor do
|
|
|
local randmWeight = MathRandom(1, totalWeight)
|
|
|
- for k, v in pairs(randomAttr) do
|
|
|
+ for k, v in pairs(randomAttrCfg) do
|
|
|
local key = v[1]
|
|
|
local value = v[2]
|
|
|
local weight = v[3]
|
|
|
if randmWeight <= weight then
|
|
|
- attr[key] = attr[key] or 0
|
|
|
- attr[key] = attr[key] + value
|
|
|
- randomAttr[k] = nil
|
|
|
+ len = len + 1
|
|
|
+
|
|
|
+ local attrColor, mul = randAttrValMul()
|
|
|
+ local finalVal = math.floor(value * mul)
|
|
|
+ attr[len] = {key, finalVal, attrColor}
|
|
|
+
|
|
|
+ randomAttrCfg[k] = nil
|
|
|
-- 排除这个权重
|
|
|
totalWeight = totalWeight - weight
|
|
|
break
|
|
|
@@ -123,9 +142,121 @@ function randomAttr(itemID, isRandom, otherData)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ return attr
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+-- 随机属性
|
|
|
+local attrCheck = {}
|
|
|
+function checkAttr(equipGrid)
|
|
|
+ local quality = equipGrid.quality
|
|
|
+ local len = 0
|
|
|
+
|
|
|
+-- for key, value in pairs(equipGrid.attr) do
|
|
|
+-- len = len + 1
|
|
|
+-- attrCheck[len] = {key, value}
|
|
|
+-- end
|
|
|
+
|
|
|
+ for k, v in ipairs(equipGrid.attr) do
|
|
|
+ len = len + 1
|
|
|
+ attrCheck[len] = {v[1], v[2], v[3]}
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ -- 砍掉后面的
|
|
|
+ if quality < len then
|
|
|
+ equipGrid.attr = {}
|
|
|
+ for z = 1, quality do
|
|
|
+ -- equipGrid.attr[attrCheck[z][1]] = attrCheck[z][2]
|
|
|
+ equipGrid.attr[z] = {
|
|
|
+ attrCheck[z][1],
|
|
|
+ attrCheck[z][2],
|
|
|
+ attrCheck[z][3],
|
|
|
+ }
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 随机属性
|
|
|
+function randomAttr(itemID, isRandom, otherData)
|
|
|
+ local equipConfig = EquipExcel[itemID]
|
|
|
+ if not equipConfig then return end
|
|
|
+
|
|
|
+ -- 固定属性
|
|
|
+ local quality = 1
|
|
|
+ -- local attr = {}
|
|
|
+
|
|
|
+ -- 所有装备的随机属性使用同一套规则
|
|
|
+ -- if equipConfig.random == 1 and not isRandom then
|
|
|
+ -- quality = #equipConfig.randomAttr
|
|
|
+ -- if quality > EQUIP_QUALITY_MAX then
|
|
|
+ -- quality = EQUIP_QUALITY_MAX
|
|
|
+ -- end
|
|
|
+
|
|
|
+ -- for i = 1, quality do
|
|
|
+ -- local key = equipConfig.randomAttr[i][1]
|
|
|
+ -- local value = equipConfig.randomAttr[i][2]
|
|
|
+ -- attr[key] = attr[key] or 0
|
|
|
+ -- attr[key] = attr[key] + value
|
|
|
+ -- end
|
|
|
+ -- return attr, quality
|
|
|
+ -- end
|
|
|
+
|
|
|
+ if not otherData then
|
|
|
+ -- 随机品质
|
|
|
+ quality = randColor(equipConfig.randomAttr)
|
|
|
+ else
|
|
|
+ if type(otherData) == "number" then
|
|
|
+ otherData = otherData < 0 and 1 or otherData
|
|
|
+ quality = otherData > #equipConfig.randomAttr and #equipConfig.randomAttr or otherData
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ if quality > EQUIP_QUALITY_MAX then
|
|
|
+ quality = EQUIP_QUALITY_MAX
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ -- 计算总权重
|
|
|
+ -- local totalWeight = 0
|
|
|
+ -- for k, v in pairs(equipConfig.randomAttr) do
|
|
|
+ -- totalWeight = totalWeight + v[3]
|
|
|
+ -- end
|
|
|
+
|
|
|
+ -- 随机条目属性
|
|
|
+ -- local MathRandom = math.random
|
|
|
+ local randomAttr = Util.copyTable(equipConfig.randomAttr)
|
|
|
+
|
|
|
+ -- for z = 1, quality do
|
|
|
+ -- local randmWeight = MathRandom(1, totalWeight)
|
|
|
+ -- for k, v in pairs(randomAttr) do
|
|
|
+ -- local key = v[1]
|
|
|
+ -- local value = v[2]
|
|
|
+ -- local weight = v[3]
|
|
|
+ -- if randmWeight <= weight then
|
|
|
+ -- attr[key] = attr[key] or 0
|
|
|
+ -- attr[key] = attr[key] + value
|
|
|
+ -- randomAttr[k] = nil
|
|
|
+ -- -- 排除这个权重
|
|
|
+ -- totalWeight = totalWeight - weight
|
|
|
+ -- break
|
|
|
+ -- else
|
|
|
+ -- randmWeight = randmWeight - weight
|
|
|
+ -- end
|
|
|
+ -- end
|
|
|
+ -- end
|
|
|
+
|
|
|
+ local attr = randAttrArray(randomAttr, quality)
|
|
|
+
|
|
|
return attr, quality
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
-- 检查背包空间
|
|
|
function checkEmptyCnt(human, itemCnt)
|
|
|
if itemCnt > getEmptyCnt(human) then
|
|
|
@@ -156,11 +287,13 @@ end
|
|
|
|
|
|
-- 获取装备附加属性
|
|
|
function getEquipTzAttr(equipConfig)
|
|
|
- if not equipConfig.randomAttr then return end
|
|
|
- if equipConfig.random == 1 then
|
|
|
- return equipConfig.randomAttr
|
|
|
- end
|
|
|
- return nil
|
|
|
+ -- if not equipConfig.randomAttr then return end
|
|
|
+ -- if equipConfig.random == 1 then
|
|
|
+ -- return equipConfig.randomAttr
|
|
|
+ -- end
|
|
|
+ local attr = randAttrArray(Util.copyTable(equipConfig.randomAttr))
|
|
|
+
|
|
|
+ return attr
|
|
|
end
|
|
|
|
|
|
-- 返回装备背包空余格子数
|
|
|
@@ -220,6 +353,25 @@ function modifyEquip(human, equipGrid)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+-- 兼容老数据处理 : 修改装备的 wash 和 attr 的数据格式
|
|
|
+function TransformEuipAttrData(human)
|
|
|
+ for index = 1, EQUIP_BAG_MAX_CNT do
|
|
|
+ local equipGrid = human.db.equipBag[index]
|
|
|
+ if equipGrid then
|
|
|
+ if equipGrid.attr then
|
|
|
+ equipGrid.attr = AttrHashToArray(equipGrid.attr)
|
|
|
+ end
|
|
|
+
|
|
|
+ if equipGrid.washAttr then
|
|
|
+ equipGrid.washAttr = AttrHashToArray(equipGrid.washAttr)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
-- 推送装备背包信息
|
|
|
function sendEquipBagList(human)
|
|
|
local msgRet = Msg.gc.GC_EQUIP_BAG_LIST
|