Browse Source

修改合成逻辑:增加,根据装备强化等级以及追加次数提现不同的成功率

huangyuhao 2 months ago
parent
commit
2478e049f9
1 changed files with 115 additions and 31 deletions
  1. 115 31
      meta/userapi/lua/ItemSynthesis.lua

+ 115 - 31
meta/userapi/lua/ItemSynthesis.lua

@@ -1,4 +1,3 @@
1
-
2
 ItemSynthesis = {}
1
 ItemSynthesis = {}
3
 local this = {}
2
 local this = {}
4
 
3
 
@@ -8,13 +7,13 @@ local SYNTHESIS_CFG_TYPE = {
8
 }
7
 }
9
 function testsynthesis(actor)
8
 function testsynthesis(actor)
10
     local msgData = {30001}
9
     local msgData = {30001}
11
-    ItemSynthesis.synthesis(actor,msgData)
10
+    ItemSynthesis.synthesis(actor, msgData)
12
 end
11
 end
13
 
12
 
14
 -- 道具合成
13
 -- 道具合成
15
-function ItemSynthesis.synthesis(actor,msgData)
14
+function ItemSynthesis.synthesis(actor, msgData)
16
     local synthesisCfgId = msgData[1]
15
     local synthesisCfgId = msgData[1]
17
-    local arbitrarily = ConfigDataManager.getTableValue("cfg_synthesis","arbitrarily","id",synthesisCfgId)
16
+    local arbitrarily = ConfigDataManager.getTableValue("cfg_synthesis", "arbitrarily", "id", synthesisCfgId)
18
 
17
 
19
     local special = nil
18
     local special = nil
20
     local count = 1
19
     local count = 1
@@ -27,20 +26,23 @@ function ItemSynthesis.synthesis(actor,msgData)
27
             return
26
             return
28
         end
27
         end
29
     end
28
     end
29
+    -- 辅助消耗道具
30
+    local assistantItem = msgData[3]
30
 
31
 
31
-    local synthesisType = tonumber(ConfigDataManager.getTableValue("cfg_synthesis","synthesisType","id",synthesisCfgId))
32
-    jprint("synthesisType",synthesisType)
32
+    local synthesisType =
33
+        tonumber(ConfigDataManager.getTableValue("cfg_synthesis", "synthesisType", "id", synthesisCfgId))
34
+    jprint("synthesisType", synthesisType)
33
     if synthesisType == SYNTHESIS_CFG_TYPE.special and count > 10 then
35
     if synthesisType == SYNTHESIS_CFG_TYPE.special and count > 10 then
34
         return
36
         return
35
     end
37
     end
36
 
38
 
37
-    local needLevel = ConfigDataManager.getTableValue("cfg_synthesis","level","id",synthesisCfgId)
38
-    local currentLevel = getbaseinfo(actor,"level")
39
+    local needLevel = ConfigDataManager.getTableValue("cfg_synthesis", "level", "id", synthesisCfgId)
40
+    local currentLevel = getbaseinfo(actor, "level")
39
     if tonumber(needLevel) > tonumber(currentLevel) then
41
     if tonumber(needLevel) > tonumber(currentLevel) then
40
         noticeTip.noticeinfo(actor, StringIdConst.TEXT353)
42
         noticeTip.noticeinfo(actor, StringIdConst.TEXT353)
41
         return
43
         return
42
     end
44
     end
43
-    local consumeItem = ConfigDataManager.getTableValue("cfg_synthesis","consumeItem","id",synthesisCfgId)
45
+    local consumeItem = ConfigDataManager.getTableValue("cfg_synthesis", "consumeItem", "id", synthesisCfgId)
44
     local splitConsume = string.split(consumeItem, "|")
46
     local splitConsume = string.split(consumeItem, "|")
45
     -- 查询需要消耗的道具信息
47
     -- 查询需要消耗的道具信息
46
     local consumeLocal = {}
48
     local consumeLocal = {}
@@ -48,7 +50,7 @@ function ItemSynthesis.synthesis(actor,msgData)
48
         local consumeInfo = string.split(value, "#")
50
         local consumeInfo = string.split(value, "#")
49
         local consumeItemCfgId = tonumber(consumeInfo[1])
51
         local consumeItemCfgId = tonumber(consumeInfo[1])
50
         local consumeItemCount = tonumber(consumeInfo[2])
52
         local consumeItemCount = tonumber(consumeInfo[2])
51
-        local haveCount = getbagitemcountbyid(actor,consumeItemCfgId)
53
+        local haveCount = getbagitemcountbyid(actor, consumeItemCfgId)
52
         if consumeItemCount * count > haveCount then
54
         if consumeItemCount * count > haveCount then
53
             noticeTip.noticeinfo(actor, StringIdConst.TEXT357)
55
             noticeTip.noticeinfo(actor, StringIdConst.TEXT357)
54
             return
56
             return
@@ -57,13 +59,21 @@ function ItemSynthesis.synthesis(actor,msgData)
57
     end
59
     end
58
     -- 清理需要消耗道具
60
     -- 清理需要消耗道具
59
     for index, value in pairs(consumeLocal) do
61
     for index, value in pairs(consumeLocal) do
60
-        removeitemfrombag(actor,index,value,0,9999,'物品合成')
62
+        removeitemfrombag(actor, index, value, 0, 9999, "物品合成")
61
     end
63
     end
62
     local removeItemIndex = {}
64
     local removeItemIndex = {}
63
-    local successRateReal = ConfigDataManager.getTableValue("cfg_synthesis","successRateReal","id",synthesisCfgId)
65
+    local successRateReal = ConfigDataManager.getTableValue("cfg_synthesis", "successRateReal", "id", synthesisCfgId)
66
+    -- 装备等级概率
67
+    local addSuccessRateReal =
68
+        ItemSynthesis.consum_add_rate(actor, synthesisCfgId, splitConsume, special, assistantItem)
69
+    successRateReal = successRateReal + addSuccessRateReal
70
+    -- 最高概率
71
+    local maxRate = tonumber(ConfigDataManager.getTableValue("cfg_synthesis", "maxRate", "id", synthesisCfgId) or 10000)
72
+    successRateReal = math.min(maxRate, successRateReal)
73
+
64
     -- 计算合成成功次数
74
     -- 计算合成成功次数
65
     local successCount = 0
75
     local successCount = 0
66
-    for i = 1,count,1 do
76
+    for i = 1, count, 1 do
67
         local successRate = math.random(0, 10000)
77
         local successRate = math.random(0, 10000)
68
         if successRate <= tonumber(successRateReal) then
78
         if successRate <= tonumber(successRateReal) then
69
             successCount = successCount + 1
79
             successCount = successCount + 1
@@ -75,12 +85,12 @@ function ItemSynthesis.synthesis(actor,msgData)
75
             for index, value in pairs(special) do
85
             for index, value in pairs(special) do
76
                 removeItemIndex[index] = value["itemIndex"]
86
                 removeItemIndex[index] = value["itemIndex"]
77
             end
87
             end
78
-            removeitembyidxlist(actor,removeItemIndex,9999,'物品合成')
88
+            removeitembyidxlist(actor, removeItemIndex, 9999, "物品合成")
79
         end
89
         end
80
         return
90
         return
81
     end
91
     end
82
 
92
 
83
-    local productId = ConfigDataManager.getTableValue("cfg_synthesis","productId","id",synthesisCfgId)
93
+    local productId = ConfigDataManager.getTableValue("cfg_synthesis", "productId", "id", synthesisCfgId)
84
     local splitProduct = string.split(productId, "|")
94
     local splitProduct = string.split(productId, "|")
85
     local productCfgId = {}
95
     local productCfgId = {}
86
     local productRateLocal = {}
96
     local productRateLocal = {}
@@ -89,14 +99,14 @@ function ItemSynthesis.synthesis(actor,msgData)
89
         local productInfo = string.split(value, "#")
99
         local productInfo = string.split(value, "#")
90
         local productItemCfgId = tonumber(productInfo[1])
100
         local productItemCfgId = tonumber(productInfo[1])
91
         local productRate = tonumber(productInfo[2])
101
         local productRate = tonumber(productInfo[2])
92
-        table.insert(productCfgId,productItemCfgId)
102
+        table.insert(productCfgId, productItemCfgId)
93
         total = total + productRate
103
         total = total + productRate
94
-        table.insert(productRateLocal,total)
104
+        table.insert(productRateLocal, total)
95
     end
105
     end
96
 
106
 
97
-    local result= {}
107
+    local result = {}
98
     local productItemInfo = {}
108
     local productItemInfo = {}
99
-    for i = 1,successCount,1 do
109
+    for i = 1, successCount, 1 do
100
         local totalRate = math.random(0, total)
110
         local totalRate = math.random(0, total)
101
         local indexRate = 1
111
         local indexRate = 1
102
         local lastValue = 0
112
         local lastValue = 0
@@ -115,23 +125,23 @@ function ItemSynthesis.synthesis(actor,msgData)
115
                 changeItemId = value["itemId"]
125
                 changeItemId = value["itemId"]
116
                 removeIndex = value["itemIndex"]
126
                 removeIndex = value["itemIndex"]
117
             end
127
             end
118
-            local itemId = itemcompound(actor,productItem,1,removeIndex)
119
-            ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
128
+            local itemId = itemcompound(actor, productItem, 1, removeIndex)
129
+            ItemSynthesis.changeItemAtt(actor, itemId, changeItemId)
120
 
130
 
121
             local product = {
131
             local product = {
122
                 itemId = itemId,
132
                 itemId = itemId,
123
                 itemCfgId = productItem,
133
                 itemCfgId = productItem,
124
                 count = 1
134
                 count = 1
125
             }
135
             }
126
-            table.insert(result,product)
136
+            table.insert(result, product)
127
         elseif synthesisType == SYNTHESIS_CFG_TYPE.special then
137
         elseif synthesisType == SYNTHESIS_CFG_TYPE.special then
128
-            local itemId = additemtobag(actor,productItem,1, 0, 9999, '物品合成')
138
+            local itemId = additemtobag(actor, productItem, 1, 0, 9999, "物品合成")
129
             local product = {
139
             local product = {
130
                 itemId = itemId,
140
                 itemId = itemId,
131
                 itemCfgId = productItem,
141
                 itemCfgId = productItem,
132
                 count = 1
142
                 count = 1
133
             }
143
             }
134
-            table.insert(result,product)
144
+            table.insert(result, product)
135
         else
145
         else
136
             local productItemCount = productItemInfo[productItem]
146
             local productItemCount = productItemInfo[productItem]
137
             if not productItemCount then
147
             if not productItemCount then
@@ -144,17 +154,17 @@ function ItemSynthesis.synthesis(actor,msgData)
144
 
154
 
145
     if not table.isNullOrEmpty(productItemInfo) then
155
     if not table.isNullOrEmpty(productItemInfo) then
146
         for itemCfgId, count in pairs(productItemInfo) do
156
         for itemCfgId, count in pairs(productItemInfo) do
147
-            local itemId = additemtobag(actor,itemCfgId,count, 0, 9999, '物品合成')
157
+            local itemId = additemtobag(actor, itemCfgId, count, 0, 9999, "物品合成")
148
             local product = {
158
             local product = {
149
                 itemId = itemId,
159
                 itemId = itemId,
150
                 itemCfgId = itemCfgId,
160
                 itemCfgId = itemCfgId,
151
                 count = count
161
                 count = count
152
             }
162
             }
153
-            table.insert(result,product)
163
+            table.insert(result, product)
154
         end
164
         end
155
     end
165
     end
156
 
166
 
157
-    sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_SYNTHESIS,result)
167
+    sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, result)
158
     ---触发合成任务
168
     ---触发合成任务
159
     local taskParam = {
169
     local taskParam = {
160
         synthesisid = synthesisCfgId,
170
         synthesisid = synthesisCfgId,
@@ -164,8 +174,8 @@ function ItemSynthesis.synthesis(actor,msgData)
164
 end
174
 end
165
 
175
 
166
 -- 合成装备增加追加属性
176
 -- 合成装备增加追加属性
167
-function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
168
-    local allequip = getplaydef(actor,"T$luaitemextdata")
177
+function ItemSynthesis.changeItemAtt(actor, itemId, changeItemId)
178
+    local allequip = getplaydef(actor, "T$luaitemextdata")
169
     if not allequip then
179
     if not allequip then
170
         return
180
         return
171
     end
181
     end
@@ -174,11 +184,85 @@ function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
174
         return
184
         return
175
     end
185
     end
176
     allequip[itemId] = equipext
186
     allequip[itemId] = equipext
177
-    EquipAndAppear.SetItemExtData(actor,itemId,equipext)
187
+    EquipAndAppear.SetItemExtData(actor, itemId, equipext)
178
     allequip[changeItemId] = {}
188
     allequip[changeItemId] = {}
179
-    setplaydef(actor,"T$luaitemextdata",allequip)
189
+    setplaydef(actor, "T$luaitemextdata", allequip)
180
 end
190
 end
181
 
191
 
192
+-- 消耗增加概率
193
+function ItemSynthesis.consum_add_rate(actor, synthesisCfgId, consumeItems, special, assistantItem)
194
+    local configList = ConfigDataManager.getList("cfg_synthesis_material")
195
+    local allEquip = EquipAndAppear.getLuaItemExtData(actor)
196
+    -- 获取合成增加概率
197
+    local function _get_item_rate(actor, sId, itemId)
198
+        local equip = getequipinfo(actor, itemId, 1)
199
+        if equip == nil or allEquip[itemId] == nil then
200
+            return 0
201
+        end
202
+
203
+        for _, v in ipairs(configList) do
204
+            if v.synthesisCfgId == sId and v.materialId == itemId then
205
+                -- 装备强化等级
206
+                local strengthlv = allEquip[itemId].strengthlv
207
+                -- 装备追加等级
208
+                local appendlv = allEquip[itemId].appendlv
209
+                -- 是否符合等级要求
210
+                local isMatch = false
211
+                if v.related == 1 then
212
+                    -- 同时满足强化等级以及追加等级
213
+                    if strengthlv >= v.minLevel and appendlv >= v.minAppend then
214
+                        isMatch = true
215
+                    end
216
+                end
217
+                if v.related == 2 then
218
+                    -- 强化等级或追加等级满足其中一个
219
+                    if strengthlv >= v.minLevel or appendlv >= v.minAppend then
220
+                        isMatch = true
221
+                    end
222
+                end
223
+                if isMatch then
224
+                    local addRate = v.addRateBase or 0
225
+                    local addStrengthRate = (strengthlv - v.minLevel) * (v.perAddRateLevel or 0)
226
+                    local addAppendRate = (appendlv - v.minAppend) * (v.perAddRateAppend or 0)
227
+                    if v.related == 1 then
228
+                        addRate = addRate + addStrengthRate + addAppendRate
229
+                    end
230
+
231
+                    if v.related == 2 then
232
+                        addRate = addRate + math.max(addStrengthRate, addAppendRate)
233
+                    end
234
+                    return addRate
235
+                end
236
+            end
237
+        end
238
+        return 0
239
+    end
182
 
240
 
241
+    local addRate = 0
242
+    -- 公式刚需消耗
243
+    for _, v in ipairs(consumeItems) do
244
+        local consumeInfo = string.split(v, "#")
245
+        local consumeItemCfgId = tonumber(consumeInfo[1])
246
+        local consumeItemCount = tonumber(consumeInfo[2])
183
 
247
 
248
+        addRate = addRate + _get_item_rate(actor, synthesisCfgId, consumeItemCfgId)
249
+    end
250
+    -- 公式特殊消耗道具
251
+    if special then
252
+        for index, value in pairs(special) do
253
+            local itemId = value["itemId"]
254
+            local itemIndex = value["itemIndex"]
255
+            addRate = addRate + _get_item_rate(actor, synthesisCfgId, itemId)
256
+        end
257
+    end
258
+    -- 辅助消耗道具
259
+    if assistantItem then
260
+        for index, value in pairs(assistantItem) do
261
+            local itemId = value["itemId"]
262
+            local itemIndex = value["itemIndex"]
263
+            addRate = addRate + _get_item_rate(actor, synthesisCfgId, itemId)
264
+        end
265
+    end
184
 
266
 
267
+    return addRate
268
+end