瀏覽代碼

修改合成概率

huangyuhao80 1 月之前
父節點
當前提交
fc16d361b2
共有 1 個文件被更改,包括 166 次插入32 次删除
  1. 166 32
      meta/userapi/lua/ItemSynthesis.lua

+ 166 - 32
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,20 @@ 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 = ItemSynthesis.consum_add_rate(actor, splitConsume, special, assistantItem)
68
+    successRateReal = successRateReal + addSuccessRateReal
69
+    -- 最高概率
70
+    local maxRate = tonumber(ConfigDataManager.getTableValue("cfg_synthesis", "maxRate", "id", synthesisCfgId) or 10000)
71
+    successRateReal = math.min(maxRate, successRateReal)
72
+
64
     -- 计算合成成功次数
73
     -- 计算合成成功次数
65
     local successCount = 0
74
     local successCount = 0
66
-    for i = 1,count,1 do
75
+    for i = 1, count, 1 do
67
         local successRate = math.random(0, 10000)
76
         local successRate = math.random(0, 10000)
68
         if successRate <= tonumber(successRateReal) then
77
         if successRate <= tonumber(successRateReal) then
69
             successCount = successCount + 1
78
             successCount = successCount + 1
@@ -73,14 +82,19 @@ function ItemSynthesis.synthesis(actor,msgData)
73
         noticeTip.noticeinfo(actor, StringIdConst.TEXT358)
82
         noticeTip.noticeinfo(actor, StringIdConst.TEXT358)
74
         if special then
83
         if special then
75
             for index, value in pairs(special) do
84
             for index, value in pairs(special) do
76
-                removeItemIndex[index] = value["itemIndex"]
85
+                removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
86
+            end
87
+        end
88
+        -- 辅助道具消耗
89
+        if assistantItem then
90
+            for index, value in pairs(assistantItem) do
91
+                removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
77
             end
92
             end
78
-            removeitembyidxlist(actor,removeItemIndex,9999,'物品合成')
79
         end
93
         end
80
         return
94
         return
81
     end
95
     end
82
 
96
 
83
-    local productId = ConfigDataManager.getTableValue("cfg_synthesis","productId","id",synthesisCfgId)
97
+    local productId = ConfigDataManager.getTableValue("cfg_synthesis", "productId", "id", synthesisCfgId)
84
     local splitProduct = string.split(productId, "|")
98
     local splitProduct = string.split(productId, "|")
85
     local productCfgId = {}
99
     local productCfgId = {}
86
     local productRateLocal = {}
100
     local productRateLocal = {}
@@ -89,14 +103,14 @@ function ItemSynthesis.synthesis(actor,msgData)
89
         local productInfo = string.split(value, "#")
103
         local productInfo = string.split(value, "#")
90
         local productItemCfgId = tonumber(productInfo[1])
104
         local productItemCfgId = tonumber(productInfo[1])
91
         local productRate = tonumber(productInfo[2])
105
         local productRate = tonumber(productInfo[2])
92
-        table.insert(productCfgId,productItemCfgId)
106
+        table.insert(productCfgId, productItemCfgId)
93
         total = total + productRate
107
         total = total + productRate
94
-        table.insert(productRateLocal,total)
108
+        table.insert(productRateLocal, total)
95
     end
109
     end
96
 
110
 
97
-    local result= {}
111
+    local result = {}
98
     local productItemInfo = {}
112
     local productItemInfo = {}
99
-    for i = 1,successCount,1 do
113
+    for i = 1, successCount, 1 do
100
         local totalRate = math.random(0, total)
114
         local totalRate = math.random(0, total)
101
         local indexRate = 1
115
         local indexRate = 1
102
         local lastValue = 0
116
         local lastValue = 0
@@ -115,23 +129,23 @@ function ItemSynthesis.synthesis(actor,msgData)
115
                 changeItemId = value["itemId"]
129
                 changeItemId = value["itemId"]
116
                 removeIndex = value["itemIndex"]
130
                 removeIndex = value["itemIndex"]
117
             end
131
             end
118
-            local itemId = itemcompound(actor,productItem,1,removeIndex)
119
-            ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
132
+            local itemId = itemcompound(actor, productItem, 1, removeIndex)
133
+            ItemSynthesis.changeItemAtt(actor, itemId, changeItemId)
120
 
134
 
121
             local product = {
135
             local product = {
122
                 itemId = itemId,
136
                 itemId = itemId,
123
                 itemCfgId = productItem,
137
                 itemCfgId = productItem,
124
                 count = 1
138
                 count = 1
125
             }
139
             }
126
-            table.insert(result,product)
140
+            table.insert(result, product)
127
         elseif synthesisType == SYNTHESIS_CFG_TYPE.special then
141
         elseif synthesisType == SYNTHESIS_CFG_TYPE.special then
128
-            local itemId = additemtobag(actor,productItem,1, 0, 9999, '物品合成')
142
+            local itemId = additemtobag(actor, productItem, 1, 0, 9999, "物品合成")
129
             local product = {
143
             local product = {
130
                 itemId = itemId,
144
                 itemId = itemId,
131
                 itemCfgId = productItem,
145
                 itemCfgId = productItem,
132
                 count = 1
146
                 count = 1
133
             }
147
             }
134
-            table.insert(result,product)
148
+            table.insert(result, product)
135
         else
149
         else
136
             local productItemCount = productItemInfo[productItem]
150
             local productItemCount = productItemInfo[productItem]
137
             if not productItemCount then
151
             if not productItemCount then
@@ -140,21 +154,27 @@ function ItemSynthesis.synthesis(actor,msgData)
140
                 productItemInfo[productItem] = productItemInfo[productItem] + 1
154
                 productItemInfo[productItem] = productItemInfo[productItem] + 1
141
             end
155
             end
142
         end
156
         end
157
+        -- 辅助道具消耗
158
+        if assistantItem then
159
+            for index, value in pairs(assistantItem) do
160
+                removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
161
+            end
162
+        end
143
     end
163
     end
144
 
164
 
145
     if not table.isNullOrEmpty(productItemInfo) then
165
     if not table.isNullOrEmpty(productItemInfo) then
146
         for itemCfgId, count in pairs(productItemInfo) do
166
         for itemCfgId, count in pairs(productItemInfo) do
147
-            local itemId = additemtobag(actor,itemCfgId,count, 0, 9999, '物品合成')
167
+            local itemId = additemtobag(actor, itemCfgId, count, 0, 9999, "物品合成")
148
             local product = {
168
             local product = {
149
                 itemId = itemId,
169
                 itemId = itemId,
150
                 itemCfgId = itemCfgId,
170
                 itemCfgId = itemCfgId,
151
                 count = count
171
                 count = count
152
             }
172
             }
153
-            table.insert(result,product)
173
+            table.insert(result, product)
154
         end
174
         end
155
     end
175
     end
156
 
176
 
157
-    sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_SYNTHESIS,result)
177
+    sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, result)
158
     ---触发合成任务
178
     ---触发合成任务
159
     local taskParam = {
179
     local taskParam = {
160
         synthesisid = synthesisCfgId,
180
         synthesisid = synthesisCfgId,
@@ -164,8 +184,8 @@ function ItemSynthesis.synthesis(actor,msgData)
164
 end
184
 end
165
 
185
 
166
 -- 合成装备增加追加属性
186
 -- 合成装备增加追加属性
167
-function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
168
-    local allequip = getplaydef(actor,"T$luaitemextdata")
187
+function ItemSynthesis.changeItemAtt(actor, itemId, changeItemId)
188
+    local allequip = getplaydef(actor, "T$luaitemextdata")
169
     if not allequip then
189
     if not allequip then
170
         return
190
         return
171
     end
191
     end
@@ -174,11 +194,125 @@ function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
174
         return
194
         return
175
     end
195
     end
176
     allequip[itemId] = equipext
196
     allequip[itemId] = equipext
177
-    EquipAndAppear.SetItemExtData(actor,itemId,equipext)
197
+    EquipAndAppear.SetItemExtData(actor, itemId, equipext)
178
     allequip[changeItemId] = {}
198
     allequip[changeItemId] = {}
179
-    setplaydef(actor,"T$luaitemextdata",allequip)
199
+    setplaydef(actor, "T$luaitemextdata", allequip)
180
 end
200
 end
181
 
201
 
202
+-- 消耗增加概率
203
+function ItemSynthesis.consum_add_rate(actor, consumeItems, special, assistantItem)
204
+    local confMaterialList = ConfigDataManager.getList("cfg_synthesis_material")
205
+    local confAssistantList = ConfigDataManager.getList("cfg_synthesis_assistant")
206
+    local allEquip = EquipAndAppear.getLuaItemExtData(actor)
207
+    -- 获取合成增加概率
208
+    local function _get_item_rate(actor, itemId, groupId)
209
+        -- 装备强化等级
210
+        local strengthlv = 0
211
+        -- 装备追加等级
212
+        local appendlv = 0
213
+        local equip = getequipinfo(actor, itemId, 1)
214
+        if equip and allEquip[itemId] then
215
+            strengthlv = allEquip[itemId].strengthlv
216
+            appendlv = allEquip[itemId].appendlv
217
+        end
218
+        -- 获取配置
219
+        local conf = nil
220
+        if groupId == nil then
221
+            for _, v in ipairs(confMaterialList) do
222
+                if v.materialId == itemId then
223
+                    -- 装备,增加等级判断
224
+                    if v.type == 2 then
225
+                        -- 是否符合等级要求
226
+                        if v.related == 1 then
227
+                            -- 同时满足强化等级以及追加等级
228
+                            if strengthlv >= v.minLevel and appendlv >= v.minAppend then
229
+                                conf = table.copy(v)
230
+                                break
231
+                            end
232
+                        end
233
+                        if v.related == 2 then
234
+                            -- 强化等级或追加等级满足其中一个
235
+                            if strengthlv >= v.minLevel or appendlv >= v.minAppend then
236
+                                conf = table.copy(v)
237
+                                break
238
+                            end
239
+                        end
240
+                    else
241
+                        conf = table.copy(v)
242
+                        break
243
+                    end
244
+                end
245
+            end
246
+        else
247
+            for _, v in ipairs(confMaterialList) do
248
+                if v.groupId == groupId and v.itemId == itemId then
249
+                    -- 装备,增加等级判断
250
+                    if v.type == 2 then
251
+                        -- 是否符合等级要求
252
+                        if v.related == 1 then
253
+                            -- 同时满足强化等级以及追加等级
254
+                            if strengthlv >= v.minLevel and appendlv >= v.minAppend then
255
+                                conf = table.copy(v)
256
+                                break
257
+                            end
258
+                        end
259
+                        if v.related == 2 then
260
+                            -- 强化等级或追加等级满足其中一个
261
+                            if strengthlv >= v.minLevel or appendlv >= v.minAppend then
262
+                                conf = table.copy(v)
263
+                                break
264
+                            end
265
+                        end
266
+                    else
267
+                        conf = table.copy(v)
268
+                        break
269
+                    end
270
+                end
271
+            end
272
+        end
273
+        if conf then
274
+            local addRate = conf.addRateBase or 0
275
+            local addStrengthRate = (strengthlv - (conf.minLevel or 0)) * (conf.perAddRateLevel or 0)
276
+            local addAppendRate = (appendlv - (conf.minAppend or 0)) * (conf.perAddRateAppend or 0)
277
+            if conf.related == 1 then
278
+                addRate = addRate + addStrengthRate + addAppendRate
279
+            end
280
+
281
+            if conf.related == 2 then
282
+                addRate = addRate + math.max(addStrengthRate, addAppendRate)
283
+            end
284
+            return addRate
285
+        end
286
+        return 0
287
+    end
182
 
288
 
289
+    local addRate = 0
290
+    -- 公式刚需消耗
291
+    for _, v in ipairs(consumeItems) do
292
+        local consumeInfo = string.split(v, "#")
293
+        local consumeItemCfgId = tonumber(consumeInfo[1])
294
+        local consumeItemCount = tonumber(consumeInfo[2])
183
 
295
 
296
+        addRate = addRate + _get_item_rate(actor, consumeItemCfgId)
297
+    end
298
+    -- 公式特殊消耗道具
299
+    if special then
300
+        for index, value in pairs(special) do
301
+            local itemId = value["itemId"]
302
+            local itemIndex = value["itemIndex"]
303
+            local groupId = value["groupId"]
304
+            addRate = addRate + _get_item_rate(actor, itemId, groupId)
305
+        end
306
+    end
307
+    -- 辅助消耗道具
308
+    if assistantItem then
309
+        for index, value in pairs(assistantItem) do
310
+            local itemId = value["itemId"]
311
+            local itemIndex = value["itemIndex"]
312
+            local groupId = value["groupId"]
313
+            addRate = addRate + _get_item_rate(actor, itemId, groupId)
314
+        end
315
+    end
184
 
316
 
317
+    return addRate
318
+end