ItemSynthesis = {} local this = {} local SYNTHESIS_CFG_TYPE = { normal = 1, special = 2 } function testsynthesis(actor) local msgData = {30001} ItemSynthesis.synthesis(actor,msgData) end -- 道具合成 function ItemSynthesis.synthesis(actor,msgData) local synthesisCfgId = msgData[1] local arbitrarily = ConfigDataManager.getTableValue("cfg_synthesis","arbitrarily","id",synthesisCfgId) local special = nil local count = 1 if arbitrarily == "" then count = msgData[2] else special = msgData[2] if not special then noticeTip.noticeinfo(actor, StringIdConst.TEXT356) return end end local synthesisType = tonumber(ConfigDataManager.getTableValue("cfg_synthesis","synthesisType","id",synthesisCfgId)) jprint("synthesisType",synthesisType) if synthesisType == SYNTHESIS_CFG_TYPE.special and count > 10 then return end local needLevel = ConfigDataManager.getTableValue("cfg_synthesis","level","id",synthesisCfgId) local currentLevel = getbaseinfo(actor,"level") if tonumber(needLevel) > tonumber(currentLevel) then noticeTip.noticeinfo(actor, StringIdConst.TEXT353) return end local consumeItem = ConfigDataManager.getTableValue("cfg_synthesis","consumeItem","id",synthesisCfgId) local splitConsume = string.split(consumeItem, "|") -- 查询需要消耗的道具信息 local consumeLocal = {} for index, value in pairs(splitConsume) do local consumeInfo = string.split(value, "#") local consumeItemCfgId = tonumber(consumeInfo[1]) local consumeItemCount = tonumber(consumeInfo[2]) local haveCount = getbagitemcountbyid(actor,consumeItemCfgId) if consumeItemCount * count > haveCount then noticeTip.noticeinfo(actor, StringIdConst.TEXT357) return end consumeLocal[consumeItemCfgId] = consumeItemCount * count end -- 清理需要消耗道具 for index, value in pairs(consumeLocal) do removeitemfrombag(actor,index,value,0,9999,'物品合成') end local removeItemIndex = {} local successRateReal = ConfigDataManager.getTableValue("cfg_synthesis","successRateReal","id",synthesisCfgId) -- 计算合成成功次数 local successCount = 0 for i = 1,count,1 do local successRate = math.random(0, 10000) if successRate <= tonumber(successRateReal) then successCount = successCount + 1 end end if successCount == 0 then noticeTip.noticeinfo(actor, StringIdConst.TEXT358) if special then for index, value in pairs(special) do removeItemIndex[index] = value["itemIndex"] end removeitembyidxlist(actor,removeItemIndex,9999,'物品合成') end return end local productId = ConfigDataManager.getTableValue("cfg_synthesis","productId","id",synthesisCfgId) local splitProduct = string.split(productId, "|") local productCfgId = {} local productRateLocal = {} local total = 0 for index, value in pairs(splitProduct) do local productInfo = string.split(value, "#") local productItemCfgId = tonumber(productInfo[1]) local productRate = tonumber(productInfo[2]) table.insert(productCfgId,productItemCfgId) total = total + productRate table.insert(productRateLocal,total) end local result= {} local productItemInfo = {} for i = 1,successCount,1 do local totalRate = math.random(0, total) local indexRate = 1 local lastValue = 0 for index, value in pairs(productRateLocal) do if lastValue < totalRate and totalRate < value then indexRate = index end lastValue = value end local productItem = productCfgId[indexRate] -- 特殊合成需要继承之前道具的卓越属性,追加属性,强化属性 if special then local changeItemId = 0 local removeIndex = 0 for index, value in pairs(special) do changeItemId = value["itemId"] removeIndex = value["itemIndex"] end local itemId = itemcompound(actor,productItem,1,removeIndex) ItemSynthesis.changeItemAtt(actor,itemId,changeItemId) local product = { itemId = itemId, itemCfgId = productItem, count = 1 } table.insert(result,product) elseif synthesisType == SYNTHESIS_CFG_TYPE.special then local itemId = additemtobag(actor,productItem,1, 0, 9999, '物品合成') local product = { itemId = itemId, itemCfgId = productItem, count = 1 } table.insert(result,product) else local productItemCount = productItemInfo[productItem] if not productItemCount then productItemInfo[productItem] = 1 else productItemInfo[productItem] = productItemInfo[productItem] + 1 end end end if not table.isNullOrEmpty(productItemInfo) then for itemCfgId, count in pairs(productItemInfo) do local itemId = additemtobag(actor,itemCfgId,count, 0, 9999, '物品合成') local product = { itemId = itemId, itemCfgId = itemCfgId, count = count } table.insert(result,product) end end sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_SYNTHESIS,result) ---触发合成任务 local taskParam = { synthesisid = synthesisCfgId, num = count } TaskHandler.TriggerTaskGoal(actor, TaskTargetType.SYNTHESIS, taskParam) 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