ItemSynthesis = {} local this = {} local SYNTHESIS_CFG_TYPE = { normal = 1, special = 2 } function testsynthesis(actor) local msgData = {30001} ItemSynthesis.synthesis(actor, msgData) end function ItemSynthesis.string2table(str) local result = {} local pairs = string.split(str, "|") for _, pairStr in ipairs(pairs) do local values = string.split(pairStr, "#") table.insert(result, values) end return result end -- 道具合成 function ItemSynthesis.synthesis(actor, msgData) -- 合成ID 合成数量 合成消耗 local synthesisCfgId = msgData.cfgid -- 合成ID local count = msgData.count -- 合成数量 local tCost = msgData.costs[1] -- 必要合成消耗 local tCostEx = msgData.costs[2] -- 附加合成消耗 local useluck = msgData.useluck local useprotect = msgData.useprotect local cfg_synthesis = ConfigDataManager.getTable("cfg_synthesis", "id", synthesisCfgId)[1] -- 检测合成配方所需等级 local needLevel = tonumber(cfg_synthesis.level) or 0 local currentLevel = getbaseinfo(actor, "level") -- info(cfg_synthesis,"cfg_synthesis","合成数据") if tonumber(needLevel) > tonumber(currentLevel) then noticeTip.noticeinfo(actor, StringIdConst.TEXT353) return end -- 检测合成配方所需职业 -- 检测合成消耗 local tCostItem1 = {} -- 装备消耗 local tCostItem2 = {} -- 材料 local consumeItem = cfg_synthesis.consumeitem1 info(consumeItem, "consumeItem", "合成数据") local consumeitem2 = cfg_synthesis.consumeitem2 local tConsumeItem = ItemSynthesis.string2table(consumeItem) local tConsumeItem2 = ItemSynthesis.string2table(consumeitem2) info(tConsumeItem, "tConsumeItem", "合成数据") -- 检测必选消耗 -- if not tConsumeItem or next(tConsumeItem) then -- messagebox(actor,"尚未放入必选材料001!") -- return -- end local addRate = 0 local luckRate = 0 local isCostLuck = false if useluck and not string.isNullOrEmpty(cfg_synthesis.useluck) then local cfgId = tonumber(cfg_synthesis.useluck) local allitems = getallbagiteminfo(actor) local kk, vv = table.findByCondi(allitems, function(a) return a.cfgid == cfgId; end) if kk ~= nil then isCostLuck = true luckRate = luckRate + EquipFunc.getEquipSynValue(actor, vv.id) / 20000 end end local isCostProtect = false if useprotect and not string.isNullOrEmpty(cfg_synthesis.useprotect) then local cfgId = tonumber(cfg_synthesis.useprotect) local allitems = getallbagiteminfo(actor) local kk, vv = table.findByCondi(allitems, function(a) return a.cfgid == cfgId; end) if kk ~= nil then isCostProtect = true end end local costIndex = 1 for index, v in pairs(tConsumeItem) do local costType = tonumber(v[1]) if costType == 1 then local cfgId = tonumber(v[2]) local count = tonumber(v[3]) local num = getbagitemcountbyid(actor, cfgId) or 0 local itemName = ConfigDataManager.getTable("cfg_item", "id", cfgId)[1].name if num < count then messagebox(actor, itemName .. "数量不足" .. count .. "个!") return end -- table.insert(tCostItem2,{costType = costType, [cfgId]=count,}) tCostItem2[cfgId] = count elseif costType == 2 then -- 检查是否有对应的装备材料放入 local foundItem = nil if tCost then for i, v in ipairs(tCost) do if v and v.id and i == costIndex then foundItem = v break end end costIndex = costIndex + 1 end if not foundItem then messagebox(actor, "尚未放入必选材料!") return end local itemId = foundItem.id local cfgId = foundItem.cfgId -- local item = getequipinfo(actor, itemId, 1) local itemInfo = getbagiteminfo(actor, itemId, 1) local bagIndex = itemInfo.bagindex local strenthLv = tonumber(v[2]) local appendLevel = tonumber(v[3]) local pz = tonumber(v[4]) local itemType = tonumber(v[5]) local itemCfgId = v[6] or 0 -- info("itemCfgId",itemCfgId,type(itemCfgId)) if itemCfgId and itemCfgId ~= 0 and itemCfgId ~= "0" then local tab = string.split(itemCfgId, "_") local idx = false -- info("tab",tab) for i = 1, #tab do if tonumber(tab[i]) ~= 0 then if cfgId == tonumber(tab[i]) then idx = true end end end if not idx then messagebox(actor, "尚未放入必选材料") return "" end end if strenthLv > 0 then if EquipFunc.getEquipStrengthLevel(actor, itemId) < strenthLv then messagebox(actor, "强化等级不符") return "" end end if appendLevel > 0 then if EquipFunc.getEquipAppendLevel(actor, itemId) < appendLevel then messagebox(actor, "追加等级不符") return "" end end if pz > 0 then if pz ~= 99 then local Outstanding = ConfigDataManager.getTableValue("cfg_item", "Outstanding", "id", cfgId) Outstanding = tonumber(Outstanding) or 0 if pz ~= Outstanding then messagebox(actor, "品质不符") return "" end end end if itemType == 1 then if not EquipFunc.getEquipIsSpecial(cfgId) then messagebox(actor, "装备类型不符") return "" end -- local useLevelLimit = ConfigDataManager.getTableValue("cfg_item", "useLevelLimit", "id", cfgId) -- useLevelLimit = tonumber(useLevelLimit) -- if useLevelLimit < 380 then -- messagebox(actor,"装备类型不符") -- return "" -- end end -- info(bagIndex,"bagIndex","合成数据") table.insert(tCostItem1, { costType = costType, bagIndex = bagIndex, cfgid = cfgId, cantDestroy = isCostProtect == true and costIndex == 2, -- 因为上面自增了.所以这里是2 }) elseif costType == 3 then local cfgId = index if tCost[cfgId] then if tCostItem2[cfgId] == nil then tCostItem2[cfgId] = 1 else tCostItem2[cfgId] = tCostItem2[cfgId] + 1 end end -- local cfgId = index -- if not tCost[cfgId] then -- messagebox(actor,"道具ID不符") -- return "" -- end -- tCostItem2[cfgId] = 1 -- table.insert(tCostItem2,{costType = costType, [cfgId]=1,}) elseif costType == 4 then -- 检查是否有对应的装备材料放入 local foundItem = nil if tCost then for _, costData in pairs(tCost) do if costData and costData.id then foundItem = costData break end end end if not foundItem then messagebox(actor, "尚未放入必选材料!") return end local itemId = foundItem.id local cfgId = foundItem.cfgId local itemCfg = ConfigDataManager.getById("cfg_item", cfgId) local itemInfo = getbagiteminfo(actor, itemId, 1) local bagIndex = itemInfo.bagindex local entrys = itemInfo.entries local count = table.count(v) local needEnyrys = {} for i = 3, count, 2 do table.insert(needEnyrys, { type = tonumber(v[i]), value = tonumber(v[i + 1]) }) end local matchNum = 0 local needNum = table.count(needEnyrys) for k, v in pairs(needEnyrys) do local tk, tv = table.findByCondi(entrys, function(a) return a.attrid == v.type and a.value == v.value end) if tk ~= nil then matchNum = matchNum + 1 end end if matchNum < needNum then messagebox(actor, "材料不符!") return end table.insert(tCostItem1, { costType = costType, bagIndex = bagIndex, cantDestroy = itemCfg ~= nil and itemCfg.outstanding == "4" }) end end -- 额外材料附加概率 -- 真实合成概率 local successRateReal = ConfigDataManager.getTableValue("cfg_synthesis", "successRateReal", "id", synthesisCfgId) successRateReal = tonumber(successRateReal) / 100 -- 最大合成概率 local successRateMax = ConfigDataManager.getTableValue("cfg_synthesis", "successRateMax", "id", synthesisCfgId) successRateMax = tonumber(successRateMax) / 100 info(tConsumeItem2, "tConsumeItem2", "合成数据") local costItemIds = {} for index, v in pairs(tConsumeItem2) do costItemIds[tonumber(v[2])] = v end if tCost and next(tCost) then for key, value in pairs(tCost) do local itemId = value.id local cfgId = value.cfgId -- local itemInfo = getbagiteminfo(actor, itemId, 1) local jiazhi = EquipFunc.getEquipSynValue(actor, itemId) addRate = addRate + math.floor(jiazhi / 20000) local name = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId) if name == "合成幸运符" then luckRate = luckRate + EquipFunc.getEquipSynValue(actor, itemId) / 20000 end end end if tConsumeItem2 and next(tConsumeItem2) then if tCostEx and next(tCostEx) then for key, value in pairs(tCostEx) do local costItemIdData = costItemIds[value.cfgId] if costItemIdData ~= nil then local costType = tonumber(costItemIdData[1]) local itemId = value.id local cfgId = value.cfgId local itemInfo = getbagiteminfo(actor, itemId, 1) local jiazhi = EquipFunc.getEquipSynValue(actor, itemId) addRate = addRate + math.floor(jiazhi / 20000) -- local name = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId) -- if name == "合成幸运符" then -- luckRate = luckRate + EquipFunc.getEquipSynValue(actor, itemId) / 20000 -- end if costType == 2 then local bagIndex = itemInfo.bagindex table.insert(tCostItem1, { costType = costType, bagIndex = bagIndex }) elseif costType == 3 then if tCostItem2[cfgId] == nil then tCostItem2[cfgId] = 1 else tCostItem2[cfgId] = tCostItem2[cfgId] + 1 end -- table.insert(tCostItem2,{costType = costType, [cfgId]=1,}) end end end end -- for index, v in pairs(tConsumeItem2) do -- if tCostEx and tCostEx[index] and tCostEx[index].id then -- local costType = tonumber(v[1]) -- local itemId = tCostEx[index].id -- local cfgId = tCostEx[index].cfgId -- -- local item = getequipinfo(actor,itemId,1) -- local itemInfo = getbagiteminfo(actor,itemId,1) -- local jiazhi = EquipFunc.getEquipJiaZhi(actor,itemId) -- addRate = addRate + math.floor( jiazhi / 20000) -- local name = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId) -- if name == "合成幸运符" then -- luckRate = luckRate + EquipFunc.getEquipJiaZhi(actor, itemId) -- end -- if costType == 2 then -- local bagIndex = itemInfo.bagindex -- table.insert(tCostItem1,{costType = costType, bagIndex=bagIndex}) -- elseif costType == 3 then -- tCostItem2[cfgId] = 1 -- -- table.insert(tCostItem2,{costType = costType, [cfgId]=1,}) -- end -- end -- end end -- 发放奖励 local productId = cfg_synthesis.productid --合成后的道具id字段 21310011#33|21310021#33|21310031#33 local tProductId = ItemSynthesis.string2table(cfg_synthesis.productid) for i = 1, #tProductId do tProductId[i].qz = tProductId[i][2] end local qz = API.GetQZ(tProductId) local productId = tProductId[qz][1] local extraRate = 0 successRateReal = successRateReal + addRate + extraRate + luckRate successRateMax = successRateMax + luckRate if successRateReal > successRateMax then successRateReal = successRateMax end info(tCostItem1, "tCostItem1", "合成数据") local isMarkEquip = false local equipStrengthlv = nil local equipAppendLv = nil local equipEntrys = {} local luckEntrys = {} for i = 1, #tCostItem1 do local bagIndex = tCostItem1[i].bagIndex if isMarkEquip == false then isMarkEquip = true local itemInfo = getbagiteminfo(actor, bagIndex, 0) local cfgItem = nil if itemInfo ~= nil then cfgItem = ConfigDataManager.getById("cfg_item", itemInfo.cfgid) end if cfgItem ~= nil and cfgItem.type == "2" then equipStrengthlv = EquipFunc.getEquipStrengthLevel(actor, itemInfo.id) equipAppendLv = EquipFunc.getEquipAppendLevel(actor, itemInfo.id) local tmpentrys = API.TableDeepcopy(itemInfo.entries) for i, v in ipairs(tmpentrys) do if EquipRandom.Config.ATTR_VALUES[v.entryid] then table.insert(luckEntrys, { value = v.value, entryid = tostring(v.entryid), attrid = tostring(v.attrid) }) else table.insert(equipEntrys, { value = v.value, entryid = tostring(v.entryid), attrid = tostring(v.attrid) }) end end end end if tCostItem1[i].cantDestroy == nil or tCostItem1[i].cantDestroy ~= true then destroyitemafter(actor, bagIndex, "道具合成") end end info(tCostItem2, "tCostItem2", "合成数据") if isCostLuck then Bag.costMap(actor, { [tonumber(cfg_synthesis.useluck)] = 1 }, "合成扣除材料消耗") end if isCostProtect then Bag.costMap(actor, { [tonumber(cfg_synthesis.useprotect)] = 1 }, "合成扣除材料消耗") end Bag.costMap(actor, tCostItem2, "合成扣除材料消耗") -- 检测概率 successRateReal local successRate = math.random(1, 100) if successRate > successRateReal then sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, {}) messagebox(actor, "合成失败") return end for i = 1, #tCostItem1 do local bagIndex = tCostItem1[i].bagIndex if tCostItem1[i].cantDestroy ~= nil and tCostItem1[i].cantDestroy == true then destroyitemafter(actor, bagIndex, "道具合成") end end local itemId = ItemSynthesis.addItemToBag(actor, productId, 1, 1, 9999, "合成") -- local itemId = additemtobag(actor, productId, 1, 1, 9999, "合成") if extraRate > 0 then local itemList = MaYaJiYuan_Data.PetRevelryCfg.extraRewardList for k, v in pairs(itemList) do local itemId = CommonUtil.GetItemIdByItemName(v[1]) local itemCount = v[2] ItemSynthesis.addItemToBag(actor, itemId, itemCount, 1, 9999, "玛雅纪元宠物狂欢合成额外获得") end end if not string.isNullOrEmpty(cfg_synthesis.entry) then local strEntrys = string.split(cfg_synthesis.entry, "|") local entrys = {} for i, v in ipairs(strEntrys) do local ev = string.split(v, "#") table.insert(entrys, { entryid = table.count(entrys) + 1, attrid = ev[1], value = tonumber(ev[2]) }) end resetequipentry(actor, itemId, entrys) if cfg_synthesis.type == "11" then local cfg_item = ConfigDataManager.getById("cfg_item", tonumber(productId)) local itemName = cfg_item ~= nil and cfg_item.name or "" local playerName = getbaseinfo(actor, "rolename") noticeTip.noticeinfo(actor, StringIdConst.text35009, playerName, itemName) end end if not string.isNullOrEmpty(cfg_synthesis.fastionlevel) then local lv = tonumber(cfg_synthesis.fastionlevel) -- 刷新装备 API.SetItemData(actor, itemId, "strengthlv", lv) -- 刷新流光 API.refreshLiuGuang(actor, itemId) Equip_QiangHua.RefreshLevel(actor, itemId, tonumber(productId)) end local transfers = cfg_synthesis.transfer if not string.isNullOrEmpty(transfers) and ConfigDataManager.getTableValue("cfg_item", "type", "id", productId) == "2" then local ss = string.split(transfers, "#") local resultEntrys = {} for i, v in ipairs(ss) do local type = tonumber(v) if type == 1 and equipStrengthlv ~= nil and equipStrengthlv > 0 and Equip_QiangHua.canQiangHua(actor, nil, itemId) then local lv = equipStrengthlv -- 刷新装备 API.SetItemData(actor, itemId, "strengthlv", lv) -- 刷新流光 API.refreshLiuGuang(actor, itemId) Equip_QiangHua.RefreshLevel(actor, itemId, tonumber(productId)) elseif type == 2 and equipAppendLv ~= nil and equipAppendLv > 0 and ConfigDataManager.getById("cfg_equip_appends", productId) ~= nil then EquipAndAppear.setAppendLv(actor, itemId, equipAppendLv) elseif type == 3 and table.count(luckEntrys) > 0 then for i, v in ipairs(luckEntrys) do table.insert(resultEntrys, v) end elseif type == 4 and table.count(equipEntrys) > 0 then for i, v in ipairs(equipEntrys) do table.insert(resultEntrys, v) end end end if table.count(resultEntrys) > 0 then resetequipentry(actor, itemId, resultEntrys) end end -- info(tConsumeItem,"tConsumeItem","合成数据") -- local name = getrolefield(actor, "role.basic.name") -- local itemName = ConfigDataManager.getTableValue("cfg_item", "name", "id", itemId) -- noticeTip.noticeinfo(actor, StringIdConst.TEXT503, name, itemName) sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_SYNTHESIS, {}) sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, {{ id = itemId, cfgId = productId, count = 1 }}) -- ---触发合成任务 local taskParam = { synthesisid = synthesisCfgId, num = count } TaskHandler.TriggerTaskGoal(actor, TaskTargetType.SYNTHESIS, taskParam) -- HeChengQiangHuaTiaoZhan.CheckTaskIsFinish(actor, { { itemId = itemId, itemCfgId = productId, count = 1 } }) -- DaKaHuoDong.CheckTaskIsFinish(actor, DaKaHuoDong.taskType.forging, 1) end function ItemSynthesis.addItemToBag(actor, itemCfgId, num, bind, type, desc) local itemId = additemtobag(actor, itemCfgId, num, bind, type, desc) local item = getbagiteminfo(actor, itemId, 1) local cfgEquip = ConfigDataManager.getById("cfg_equip_entryLib", itemCfgId) if item ~= nil and cfgEquip ~= nil and cfgEquip.skillgemprobability ~= nil and cfgEquip.skillgemprobability ~= "" then local skillGems = string.split(cfgEquip.skillgemprobability, "#") if table.count(skillGems) == 3 then local skillId = tonumber(skillGems[1]) local level = tonumber(skillGems[2]) local probability = tonumber(skillGems[3]) local skills = {} if math.random(1, 10000) <= probability then -- -- 添加装备技能 -- local info = getbagiteminfo(actor, itemId, 1) -- if table.count(info.skill) == 0 then -- setequipskillbyid(actor, itemId, skillId, level) -- end3 table.insert(skills, { skillid = skillId, skilllevel = level }) end if table.count(skills) > 0 then API.SetItemData(actor, itemId, "skillinfo", skills) end end end -- 装备添加物品来源 if cfgEquip ~= nil then local playerName = getbaseinfo(actor, "rolename") API.SetItemData(actor, itemId, "formt", 2) API.SetItemData(actor, itemId, "form1", "") API.SetItemData(actor, itemId, "form2", playerName) API.SetItemData(actor, itemId, "form3", getbaseinfo("now")) end return itemId end -- 合成装备增加追加属性 function ItemSynthesis.changeItemAtt(actor, itemId, changeItemId) local allequip = getplaydef(actor, "T$luaitemextdata") if not allequip then return end local equipext = allequip[changeItemId] if equipext == nil then return end allequip[itemId] = equipext EquipAndAppear.SetItemExtData(actor, itemId, equipext) allequip[changeItemId] = {} setplaydef(actor, "T$luaitemextdata", allequip) end -- 前后交互 GameEvent.add(EventCfg.onHandlereQuest, function(actor, msgid, sMsg) if msgid == LuaMessageIdToSever.REQ_ITEM_SYNTHESIS then ItemSynthesis.synthesis(actor, sMsg) return true end end, this.filename) -- end