Ver código fonte

装备洗练修改

gitxsm 11 meses atrás
pai
commit
112f338813

+ 6 - 0
script/core/ObjHuman.lua

@@ -737,6 +737,12 @@ function onLogin(human, isNew)
 		
 	BagLogic.sendBagList(human)
 	FuwenLogic.sendFuwenBagList(human)
+
+	if Config.IS_USE_GM_CMD then
+		HeroLogic.TransformHeroEquipAttr(human)
+		EquipLogic.TransformEuipAttrData(human)
+	end
+
     EquipLogic.sendEquipBagList(human)
 	HeroLogic.sendHeroBagCap(human)
 	HeroLogic.sendHeroBagList(human)

+ 37 - 17
script/module/bag/Grid.lua

@@ -178,25 +178,45 @@ function makeItemEquip(net, itemConfig, equipGrid, equipIndex, shuijingAttrID, e
         local attrLen = 0
 		net.equip[1].tzAttr = net.equip[1].tzAttr or {}
         if equipGrid then
-           EquipLogic.checkAttr(equipGrid)
-		   for key, value in pairs(equipGrid.attr) do
-              attrLen = attrLen + 1
-			  net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {}
-		   	  net.equip[1].tzAttr[attrLen].key = key
-		   	  net.equip[1].tzAttr[attrLen].value = math.floor(value * baseRate) 
-		   end
+			EquipLogic.checkAttr(equipGrid)
+		--    for key, value in pairs(equipGrid.attr) do
+        --       attrLen = attrLen + 1
+		-- 	  net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {}
+		--    	  net.equip[1].tzAttr[attrLen].attr.key = key
+		--    	  net.equip[1].tzAttr[attrLen].value = math.floor(value * baseRate)
+		--    end
+
+			for idx, v in ipairs(equipGrid.attr) do
+				net.equip[1].tzAttr[idx] = net.equip[1].tzAttr[idx] or {}
+				net.equip[1].tzAttr[idx].attr.key = v[1]
+				net.equip[1].tzAttr[idx].attr.value = math.floor(v[2] * baseRate)
+				net.equip[1].tzAttr[idx].color = v[3] or 1
+
+				net.equip[1].tzAttr[0] = idx
+			end
+
         else
-           local randomAttr = EquipLogic.getEquipTzAttr(itemConfig)
-           if randomAttr then
-		      for _, attr in pairs(randomAttr) do
-                attrLen = attrLen + 1
-				net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {}
-		      	net.equip[1].tzAttr[attrLen].key = attr[1]
-		      	net.equip[1].tzAttr[attrLen].value = attr[2]
-		      end
-           end
+			local randomAttr = EquipLogic.getEquipTzAttr(itemConfig)
+			if randomAttr then
+				-- for _, attr in pairs(randomAttr) do
+				-- 	attrLen = attrLen + 1
+				-- 	net.equip[1].tzAttr[attrLen] = net.equip[1].tzAttr[attrLen] or {}
+				-- 	net.equip[1].tzAttr[attrLen].key = attr[1]
+				-- 	net.equip[1].tzAttr[attrLen].value = attr[2]
+				-- end
+
+				for idx, v in ipairs(randomAttr) do
+					net.equip[1].tzAttr[idx] = net.equip[1].tzAttr[idx] or {}
+					net.equip[1].tzAttr[idx].attr.key = v[1]
+					net.equip[1].tzAttr[idx].attr.value = v[2]
+					net.equip[1].tzAttr[idx].color = v[3] or 1
+
+					net.equip[1].tzAttr[0] = idx
+				end
+			end
+			-- net.equip[1].tzAttr[0] = attrLen
         end
-        net.equip[1].tzAttr[0] = attrLen
+        -- net.equip[1].tzAttr[0] = attrLen
 	end
 	if itemConfig.subType == ItemDefine.EQUIP_SUBTYPE_SHENQI then
 		local shenqiUpNeedConfig = EquipExcel.shenqiUpNeed[net.id]

+ 9 - 1
script/module/bag/Proto.lua

@@ -18,6 +18,14 @@ SuitNet = {
 	{"gemAttr",     4,     Attr},           -- 宝石套装加成
 }
 
+
+EQUIP_WASH_ATTR_DATA = {
+	{"attr",       1,       Attr},  --属性
+	{"color",      1,       "byte"}, --品质, 1~5 绿, 蓝, 紫, 橙, 红
+}
+
+
+
 Equip = {
     {"uuid",       1,       "string"},   -- 唯一标识
     {"putUuid",    1,   	"string"},   -- 穿戴者uuid
@@ -26,7 +34,7 @@ Equip = {
 	{"exp",        1,       "int"},   	 -- 神器的经验值
     {"star",       1,   	"byte"},     -- 穿戴星级
 	{"baseAttr",   4,       Attr},    	 -- 基础性能
-    {"tzAttr",     5,       Attr},    	 -- 拓展属性
+    {"tzAttr",     5,       EQUIP_WASH_ATTR_DATA}, -- 拓展属性
 	{"suit",       2,       SuitNet},    -- 套装信息
 	{"job",        1,       "byte"},     -- 职业专属
 	{"jobAttr",    10,      Attr},    	 -- 职业专属属性

+ 220 - 68
script/module/equip/EquipLogic.lua

@@ -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

+ 34 - 5
script/module/equip/EquipLogicGrid.lua

@@ -1,10 +1,39 @@
 local lua_mongo = _G.lua_mongo
-local Msg = require("core.Msg")
-local Util = require("common.Util")
-local Grid = require("bag.Grid")
-local ItemDefine = require("bag.ItemDefine")
+-- local Msg = require("core.Msg")
+-- local Util = require("common.Util")
+-- local Grid = require("bag.Grid")
+-- local ItemDefine = require("bag.ItemDefine")
 local EquipExcel = require("excel.equip").equip
-local EquipLogic = require("equip.EquipLogic")
+-- local EquipLogic = require("equip.EquipLogic")
+
+
+-- 装备品质
+EQUIP_COLOR_1 = 1   -- 绿
+EQUIP_COLOR_2 = 2   -- 蓝
+EQUIP_COLOR_3 = 3   -- 紫
+EQUIP_COLOR_4 = 4   -- 橙
+EQUIP_COLOR_5 = 5   -- 红
+
+-- 装备洗练时, 品质权重
+EQUIPWASH_COLOR_WEIGHT = {
+   [EQUIP_COLOR_1] = 30,
+   [EQUIP_COLOR_2] = 25,
+   [EQUIP_COLOR_3] = 20,
+   [EQUIP_COLOR_4] = 15,
+   [EQUIP_COLOR_5] = 10,
+}
+
+-- 装备洗练时, 品质与属性值的倍数范围(需要除以100)
+EQUIPWASH_COLOR_MUL = {
+   [EQUIP_COLOR_1] = {61, 75},
+   [EQUIP_COLOR_2] = {76, 90},
+   [EQUIP_COLOR_3] = {91, 105},
+   [EQUIP_COLOR_4] = {106, 120},
+   [EQUIP_COLOR_5] = {121, 135},
+}
+
+
+
 
 -- 创建装备
 function createGrid(id)

+ 1 - 1
script/module/equip/EquipWash.lua

@@ -237,7 +237,7 @@ function randomDo(human, bagIndex, heroUuid, pos)
     TriggerLogic.PublishEvent(TriggerDefine.EQUIP_REFINEMENT, human.db._id, 1)
 end
 
--- 洗练查询
+-- 洗练保存
 function randomSave(human, bagIndex, heroUuid, pos)
     local equipGrid, heroGrid, heroIndex = getEquipGrid(human, bagIndex, heroUuid, pos)
     if not equipGrid then return end

+ 6 - 2
script/module/hero/HeroEquip.lua

@@ -319,8 +319,12 @@ function doCalcHero(obj,attrs)
 				end
 
                 -- 随机属性
-                for key, value in pairs(equipGrid.attr) do
-					RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
+                -- for key, value in pairs(equipGrid.attr) do
+				-- 	RoleAttr.updateValue(key, mathFloor(value * baseRate) ,attrs)
+				-- end
+
+				for _, attrData in ipairs(equipGrid.attr) do
+					RoleAttr.updateValue(attrData[1], mathFloor(attrData[2] * baseRate) ,attrs)
 				end
 				
 				local heroID = obj.id

+ 31 - 0
script/module/hero/HeroLogic.lua

@@ -206,6 +206,37 @@ local function sortZhanli(a, b)
 	return a[2] > b[2]
 end
 
+
+function TransformHeroEquipAttr(human)
+	for index = 1, human.db.heroBag[0] do
+        local heroGrid = human.db.heroBag[index]
+        if heroGrid and heroGrid.lv >= 2 then
+
+			for i = 1, ItemDefine.EQUIP_MAX_CNT do
+				local equipGrid = heroGrid.equip and heroGrid.equip[i]
+				if equipGrid then
+					if equipGrid.attr then
+						local _, attrInfo = next(equipGrid.attr)
+						if type(attrInfo) == "table" then
+							return
+						end
+
+						equipGrid.attr = EquipLogic.AttrHashToArray(equipGrid.attr)
+					end
+
+					if equipGrid.washAttr then
+						equipGrid.washAttr = EquipLogic.AttrHashToArray(equipGrid.washAttr)
+					end
+				end
+			end
+		end
+	end
+end
+
+
+
+
+
 -- 下发英雄背包列表
 function sendHeroBagList(human)
 	local msgRet = Msg.gc.GC_HERO_BAG_LIST