123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- 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 assistantItem = msgData[3]
- 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 addSuccessRateReal = ItemSynthesis.consum_add_rate(actor, splitConsume, special, assistantItem)
- successRateReal = successRateReal + addSuccessRateReal
- -- 最高概率
- local maxRate = tonumber(ConfigDataManager.getTableValue("cfg_synthesis", "maxRate", "id", synthesisCfgId) or 10000)
- successRateReal = math.min(maxRate, successRateReal)
- -- 计算合成成功次数
- 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
- removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
- end
- end
- -- 辅助道具消耗
- if assistantItem then
- for index, value in pairs(assistantItem) do
- removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
- end
- 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
- -- 辅助道具消耗
- if assistantItem then
- for index, value in pairs(assistantItem) do
- removeitembyidxlist(actor, value["itemIndex"], 9999, "物品合成")
- 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
- -- 消耗增加概率
- function ItemSynthesis.consum_add_rate(actor, consumeItems, special, assistantItem)
- local confMaterialList = ConfigDataManager.getList("cfg_synthesis_material")
- local confAssistantList = ConfigDataManager.getList("cfg_synthesis_assistant")
- local allEquip = EquipAndAppear.getLuaItemExtData(actor)
- -- 获取合成增加概率
- local function _get_item_rate(actor, itemId, groupId)
- -- 装备强化等级
- local strengthlv = 0
- -- 装备追加等级
- local appendlv = 0
- local equip = getequipinfo(actor, itemId, 1)
- if equip and allEquip[itemId] then
- strengthlv = allEquip[itemId].strengthlv
- appendlv = allEquip[itemId].appendlv
- end
- -- 获取配置
- local conf = nil
- if groupId == nil then
- for _, v in ipairs(confMaterialList) do
- if v.materialId == itemId then
- -- 装备,增加等级判断
- if v.type == 2 then
- -- 是否符合等级要求
- if v.related == 1 then
- -- 同时满足强化等级以及追加等级
- if strengthlv >= v.minLevel and appendlv >= v.minAppend then
- conf = table.copy(v)
- break
- end
- end
- if v.related == 2 then
- -- 强化等级或追加等级满足其中一个
- if strengthlv >= v.minLevel or appendlv >= v.minAppend then
- conf = table.copy(v)
- break
- end
- end
- else
- conf = table.copy(v)
- break
- end
- end
- end
- else
- for _, v in ipairs(confMaterialList) do
- if v.groupId == groupId and v.itemId == itemId then
- -- 装备,增加等级判断
- if v.type == 2 then
- -- 是否符合等级要求
- if v.related == 1 then
- -- 同时满足强化等级以及追加等级
- if strengthlv >= v.minLevel and appendlv >= v.minAppend then
- conf = table.copy(v)
- break
- end
- end
- if v.related == 2 then
- -- 强化等级或追加等级满足其中一个
- if strengthlv >= v.minLevel or appendlv >= v.minAppend then
- conf = table.copy(v)
- break
- end
- end
- else
- conf = table.copy(v)
- break
- end
- end
- end
- end
- if conf then
- local addRate = conf.addRateBase or 0
- local addStrengthRate = (strengthlv - (conf.minLevel or 0)) * (conf.perAddRateLevel or 0)
- local addAppendRate = (appendlv - (conf.minAppend or 0)) * (conf.perAddRateAppend or 0)
- if conf.related == 1 then
- addRate = addRate + addStrengthRate + addAppendRate
- end
- if conf.related == 2 then
- addRate = addRate + math.max(addStrengthRate, addAppendRate)
- end
- return addRate
- end
- return 0
- end
- local addRate = 0
- -- 公式刚需消耗
- for _, v in ipairs(consumeItems) do
- local consumeInfo = string.split(v, "#")
- local consumeItemCfgId = tonumber(consumeInfo[1])
- local consumeItemCount = tonumber(consumeInfo[2])
- addRate = addRate + _get_item_rate(actor, consumeItemCfgId)
- end
- -- 公式特殊消耗道具
- if special then
- for index, value in pairs(special) do
- local itemId = value["itemId"]
- local itemIndex = value["itemIndex"]
- local groupId = value["groupId"]
- addRate = addRate + _get_item_rate(actor, itemId, groupId)
- end
- end
- -- 辅助消耗道具
- if assistantItem then
- for index, value in pairs(assistantItem) do
- local itemId = value["itemId"]
- local itemIndex = value["itemIndex"]
- local groupId = value["groupId"]
- addRate = addRate + _get_item_rate(actor, itemId, groupId)
- end
- end
- return addRate
- end
|