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 1
 ItemSynthesis = {}
3 2
 local this = {}
4 3
 
@@ -8,13 +7,13 @@ local SYNTHESIS_CFG_TYPE = {
8 7
 }
9 8
 function testsynthesis(actor)
10 9
     local msgData = {30001}
11
-    ItemSynthesis.synthesis(actor,msgData)
10
+    ItemSynthesis.synthesis(actor, msgData)
12 11
 end
13 12
 
14 13
 -- 道具合成
15
-function ItemSynthesis.synthesis(actor,msgData)
14
+function ItemSynthesis.synthesis(actor, msgData)
16 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 18
     local special = nil
20 19
     local count = 1
@@ -27,20 +26,23 @@ function ItemSynthesis.synthesis(actor,msgData)
27 26
             return
28 27
         end
29 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 35
     if synthesisType == SYNTHESIS_CFG_TYPE.special and count > 10 then
34 36
         return
35 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 41
     if tonumber(needLevel) > tonumber(currentLevel) then
40 42
         noticeTip.noticeinfo(actor, StringIdConst.TEXT353)
41 43
         return
42 44
     end
43
-    local consumeItem = ConfigDataManager.getTableValue("cfg_synthesis","consumeItem","id",synthesisCfgId)
45
+    local consumeItem = ConfigDataManager.getTableValue("cfg_synthesis", "consumeItem", "id", synthesisCfgId)
44 46
     local splitConsume = string.split(consumeItem, "|")
45 47
     -- 查询需要消耗的道具信息
46 48
     local consumeLocal = {}
@@ -48,7 +50,7 @@ function ItemSynthesis.synthesis(actor,msgData)
48 50
         local consumeInfo = string.split(value, "#")
49 51
         local consumeItemCfgId = tonumber(consumeInfo[1])
50 52
         local consumeItemCount = tonumber(consumeInfo[2])
51
-        local haveCount = getbagitemcountbyid(actor,consumeItemCfgId)
53
+        local haveCount = getbagitemcountbyid(actor, consumeItemCfgId)
52 54
         if consumeItemCount * count > haveCount then
53 55
             noticeTip.noticeinfo(actor, StringIdConst.TEXT357)
54 56
             return
@@ -57,13 +59,21 @@ function ItemSynthesis.synthesis(actor,msgData)
57 59
     end
58 60
     -- 清理需要消耗道具
59 61
     for index, value in pairs(consumeLocal) do
60
-        removeitemfrombag(actor,index,value,0,9999,'物品合成')
62
+        removeitemfrombag(actor, index, value, 0, 9999, "物品合成")
61 63
     end
62 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 75
     local successCount = 0
66
-    for i = 1,count,1 do
76
+    for i = 1, count, 1 do
67 77
         local successRate = math.random(0, 10000)
68 78
         if successRate <= tonumber(successRateReal) then
69 79
             successCount = successCount + 1
@@ -75,12 +85,12 @@ function ItemSynthesis.synthesis(actor,msgData)
75 85
             for index, value in pairs(special) do
76 86
                 removeItemIndex[index] = value["itemIndex"]
77 87
             end
78
-            removeitembyidxlist(actor,removeItemIndex,9999,'物品合成')
88
+            removeitembyidxlist(actor, removeItemIndex, 9999, "物品合成")
79 89
         end
80 90
         return
81 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 94
     local splitProduct = string.split(productId, "|")
85 95
     local productCfgId = {}
86 96
     local productRateLocal = {}
@@ -89,14 +99,14 @@ function ItemSynthesis.synthesis(actor,msgData)
89 99
         local productInfo = string.split(value, "#")
90 100
         local productItemCfgId = tonumber(productInfo[1])
91 101
         local productRate = tonumber(productInfo[2])
92
-        table.insert(productCfgId,productItemCfgId)
102
+        table.insert(productCfgId, productItemCfgId)
93 103
         total = total + productRate
94
-        table.insert(productRateLocal,total)
104
+        table.insert(productRateLocal, total)
95 105
     end
96 106
 
97
-    local result= {}
107
+    local result = {}
98 108
     local productItemInfo = {}
99
-    for i = 1,successCount,1 do
109
+    for i = 1, successCount, 1 do
100 110
         local totalRate = math.random(0, total)
101 111
         local indexRate = 1
102 112
         local lastValue = 0
@@ -115,23 +125,23 @@ function ItemSynthesis.synthesis(actor,msgData)
115 125
                 changeItemId = value["itemId"]
116 126
                 removeIndex = value["itemIndex"]
117 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 131
             local product = {
122 132
                 itemId = itemId,
123 133
                 itemCfgId = productItem,
124 134
                 count = 1
125 135
             }
126
-            table.insert(result,product)
136
+            table.insert(result, product)
127 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 139
             local product = {
130 140
                 itemId = itemId,
131 141
                 itemCfgId = productItem,
132 142
                 count = 1
133 143
             }
134
-            table.insert(result,product)
144
+            table.insert(result, product)
135 145
         else
136 146
             local productItemCount = productItemInfo[productItem]
137 147
             if not productItemCount then
@@ -144,17 +154,17 @@ function ItemSynthesis.synthesis(actor,msgData)
144 154
 
145 155
     if not table.isNullOrEmpty(productItemInfo) then
146 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 158
             local product = {
149 159
                 itemId = itemId,
150 160
                 itemCfgId = itemCfgId,
151 161
                 count = count
152 162
             }
153
-            table.insert(result,product)
163
+            table.insert(result, product)
154 164
         end
155 165
     end
156 166
 
157
-    sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_SYNTHESIS,result)
167
+    sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, result)
158 168
     ---触发合成任务
159 169
     local taskParam = {
160 170
         synthesisid = synthesisCfgId,
@@ -164,8 +174,8 @@ function ItemSynthesis.synthesis(actor,msgData)
164 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 179
     if not allequip then
170 180
         return
171 181
     end
@@ -174,11 +184,85 @@ function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
174 184
         return
175 185
     end
176 186
     allequip[itemId] = equipext
177
-    EquipAndAppear.SetItemExtData(actor,itemId,equipext)
187
+    EquipAndAppear.SetItemExtData(actor, itemId, equipext)
178 188
     allequip[changeItemId] = {}
179
-    setplaydef(actor,"T$luaitemextdata",allequip)
189
+    setplaydef(actor, "T$luaitemextdata", allequip)
180 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