|
@@ -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,20 @@ 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 = 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
|
74
|
local successCount = 0
|
66
|
|
- for i = 1,count,1 do
|
|
75
|
+ for i = 1, count, 1 do
|
67
|
76
|
local successRate = math.random(0, 10000)
|
68
|
77
|
if successRate <= tonumber(successRateReal) then
|
69
|
78
|
successCount = successCount + 1
|
|
@@ -73,14 +82,19 @@ function ItemSynthesis.synthesis(actor,msgData)
|
73
|
82
|
noticeTip.noticeinfo(actor, StringIdConst.TEXT358)
|
74
|
83
|
if special then
|
75
|
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
|
92
|
end
|
78
|
|
- removeitembyidxlist(actor,removeItemIndex,9999,'物品合成')
|
79
|
93
|
end
|
80
|
94
|
return
|
81
|
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
|
98
|
local splitProduct = string.split(productId, "|")
|
85
|
99
|
local productCfgId = {}
|
86
|
100
|
local productRateLocal = {}
|
|
@@ -89,14 +103,14 @@ function ItemSynthesis.synthesis(actor,msgData)
|
89
|
103
|
local productInfo = string.split(value, "#")
|
90
|
104
|
local productItemCfgId = tonumber(productInfo[1])
|
91
|
105
|
local productRate = tonumber(productInfo[2])
|
92
|
|
- table.insert(productCfgId,productItemCfgId)
|
|
106
|
+ table.insert(productCfgId, productItemCfgId)
|
93
|
107
|
total = total + productRate
|
94
|
|
- table.insert(productRateLocal,total)
|
|
108
|
+ table.insert(productRateLocal, total)
|
95
|
109
|
end
|
96
|
110
|
|
97
|
|
- local result= {}
|
|
111
|
+ local result = {}
|
98
|
112
|
local productItemInfo = {}
|
99
|
|
- for i = 1,successCount,1 do
|
|
113
|
+ for i = 1, successCount, 1 do
|
100
|
114
|
local totalRate = math.random(0, total)
|
101
|
115
|
local indexRate = 1
|
102
|
116
|
local lastValue = 0
|
|
@@ -115,23 +129,23 @@ function ItemSynthesis.synthesis(actor,msgData)
|
115
|
129
|
changeItemId = value["itemId"]
|
116
|
130
|
removeIndex = value["itemIndex"]
|
117
|
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
|
135
|
local product = {
|
122
|
136
|
itemId = itemId,
|
123
|
137
|
itemCfgId = productItem,
|
124
|
138
|
count = 1
|
125
|
139
|
}
|
126
|
|
- table.insert(result,product)
|
|
140
|
+ table.insert(result, product)
|
127
|
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
|
143
|
local product = {
|
130
|
144
|
itemId = itemId,
|
131
|
145
|
itemCfgId = productItem,
|
132
|
146
|
count = 1
|
133
|
147
|
}
|
134
|
|
- table.insert(result,product)
|
|
148
|
+ table.insert(result, product)
|
135
|
149
|
else
|
136
|
150
|
local productItemCount = productItemInfo[productItem]
|
137
|
151
|
if not productItemCount then
|
|
@@ -140,21 +154,27 @@ function ItemSynthesis.synthesis(actor,msgData)
|
140
|
154
|
productItemInfo[productItem] = productItemInfo[productItem] + 1
|
141
|
155
|
end
|
142
|
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
|
163
|
end
|
144
|
164
|
|
145
|
165
|
if not table.isNullOrEmpty(productItemInfo) then
|
146
|
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
|
168
|
local product = {
|
149
|
169
|
itemId = itemId,
|
150
|
170
|
itemCfgId = itemCfgId,
|
151
|
171
|
count = count
|
152
|
172
|
}
|
153
|
|
- table.insert(result,product)
|
|
173
|
+ table.insert(result, product)
|
154
|
174
|
end
|
155
|
175
|
end
|
156
|
176
|
|
157
|
|
- sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_SYNTHESIS,result)
|
|
177
|
+ sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, result)
|
158
|
178
|
---触发合成任务
|
159
|
179
|
local taskParam = {
|
160
|
180
|
synthesisid = synthesisCfgId,
|
|
@@ -164,8 +184,8 @@ function ItemSynthesis.synthesis(actor,msgData)
|
164
|
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
|
189
|
if not allequip then
|
170
|
190
|
return
|
171
|
191
|
end
|
|
@@ -174,11 +194,125 @@ function ItemSynthesis.changeItemAtt(actor,itemId,changeItemId)
|
174
|
194
|
return
|
175
|
195
|
end
|
176
|
196
|
allequip[itemId] = equipext
|
177
|
|
- EquipAndAppear.SetItemExtData(actor,itemId,equipext)
|
|
197
|
+ EquipAndAppear.SetItemExtData(actor, itemId, equipext)
|
178
|
198
|
allequip[changeItemId] = {}
|
179
|
|
- setplaydef(actor,"T$luaitemextdata",allequip)
|
|
199
|
+ setplaydef(actor, "T$luaitemextdata", allequip)
|
180
|
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
|