| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- ItemRecycling = {}
- local this = {}
- local ItemRecyclingType = {
- PIN_JIE = 1,
- ZHUO_YUE = 2,
- ZHI_YE = 3
- }
- ITEM_RECYCLING_TYPE = "R$itemRecyclingTYPE"
- -- 合服时取消所有选择的回收类型
- function ItemRecycling.combineglobalvar(varName)
- local allWorldGoods = getsysvar(ITEM_RECYCLING_TYPE)
- if table.isEmpty(allWorldGoods) then
- return
- end
- setsysvar(ITEM_RECYCLING_TYPE, {})
- end
- -- 分解
- function ItemRecycling.decompositionlua(actor, msgID, msgData)
- -- local decompositionItemList = msgData[1]
- -- local allItemInfo = getallbagiteminfo(actor)
- -- if table.isEmpty(allItemInfo) then
- -- return
- -- end
- -- if table.isEmpty(decompositionItemList) then
- -- return
- -- end
- -- local allequip = getplaydef(actor, "T$luaitemextdata")
- -- local allNeedMaterial = {}
- -- local allObtainList = {}
- -- for bagIndex, count in pairs(decompositionItemList) do
- -- for _, itemInfo in pairs(allItemInfo) do
- -- if itemInfo.bagindex == tonumber(bagIndex) then
- -- local itemCfgId = itemInfo.cfgid
- -- local decomposeGroup = ConfigDataManager.getTableValue("cfg_item", "decomposeGroup", "id", itemCfgId)
- -- if string.isNullOrEmpty(decomposeGroup) then
- -- tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
- -- return
- -- end
- -- local decomposeTable = ConfigDataManager.getTable("cfg_recovery_out", "id", decomposeGroup)
- -- if table.isEmpty(decomposeTable) then
- -- -- error(actor,"分解类型配置错误")
- -- return
- -- end
- -- if not table.isNullOrEmpty(allequip) then
- -- local equipext = allequip[tonumber(itemInfo.id)]
- -- if not table.isNullOrEmpty(equipext) then
- -- allequip[tonumber(itemInfo.id)] = nil
- -- end
- -- end
- -- local decomposeInfo = decomposeTable[1]
- -- -- 计算分解需要的东西
- -- local needMaterial = decomposeInfo.needmaterial
- -- if not string.isNullOrEmpty(needMaterial) then
- -- local needMaterialInfo = string.split(needMaterial, "#")
- -- local needMaterialCount = allNeedMaterial[needMaterialInfo[1]]
- -- if not needMaterialCount then
- -- needMaterialCount = 0
- -- end
- -- allNeedMaterial[needMaterialInfo[1]] = needMaterialCount + (tonumber(needMaterialInfo[2]) * count)
- -- end
- -- -- 计算分解获得的东西
- -- local material = decomposeInfo.material
- -- local group = decomposeInfo.group
- -- if tonumber(group) == 2 then
- -- if not string.isNullOrEmpty(material) then
- -- local allObtainTable = string.split(material, "|")
- -- if not table.isEmpty(allObtainTable) then
- -- if table.count(allObtainTable) == 1 then
- -- -- 分解只会获得一种物品
- -- local obtainInfo = string.split(allObtainTable[1], "#")
- -- local obtainCount = allObtainList[obtainInfo[1]]
- -- if obtainCount == nil then
- -- obtainCount = 0
- -- end
- -- local total = obtainCount + (tonumber(obtainInfo[2]) * count)
- -- allObtainList[obtainInfo[1]] = total
- -- else
- -- -- 分解获得物品配置权重
- -- local allWeight = 0
- -- local newAllObtainTable = {}
- -- for _, obtainInfo in pairs(allObtainTable) do
- -- local obtainWeight = string.split(obtainInfo, "#")
- -- allWeight = allWeight + tonumber(obtainWeight[3])
- -- obtainWeight[3] = allWeight
- -- table.insert(newAllObtainTable, obtainWeight)
- -- end
- -- for i = 1, count do
- -- local successIndex = math.random(1, allWeight)
- -- local lastWeight = 0
- -- for _, newObtainInfo in pairs(newAllObtainTable) do
- -- if lastWeight < successIndex and newObtainInfo[3] >= successIndex then
- -- local obtainCount = allObtainList[newObtainInfo[1]]
- -- if obtainCount == nil then
- -- obtainCount = 0
- -- end
- -- allObtainList[newObtainInfo[1]] = obtainCount + (tonumber(newObtainInfo[2]))
- -- end
- -- lastWeight = newObtainInfo[3]
- -- end
- -- end
- -- end
- -- end
- -- end
- -- else
- -- if not string.isNullOrEmpty(material) then
- -- local allObtainTable = string.split(material, "|")
- -- for _, obtainInfo in pairs(allObtainTable) do
- -- local obtainItemInfo = string.split(obtainInfo, "#")
- -- local obtainCount = allObtainList[obtainItemInfo[1]]
- -- if obtainCount == nil then
- -- obtainCount = 0
- -- end
- -- local total = obtainCount + (tonumber(obtainItemInfo[2]) * count)
- -- allObtainList[obtainItemInfo[1]] = total
- -- end
- -- end
- -- end
- -- end
- -- end
- -- end
- -- itemdecomposition(actor, decompositionItemList, allObtainList, allNeedMaterial)
- -- sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_DECOMPOSITION, allObtainList)
- -- setplaydef(actor, "T$luaitemextdata", allequip)
- local decompositionItemList = msgData[1]
- local allItemInfo = getallbagiteminfo(actor)
- if table.isEmpty(allItemInfo) then
- return
- end
- if table.isEmpty(decompositionItemList) then
- return
- end
- local cfgs = ConfigDataManager.getTable("cfg_recovery_out")
- local allequip = getplaydef(actor, "T$luaitemextdata")
- local allNeedMaterial = {}
- local allObtainList = {}
- for bagIndex, count in pairs(decompositionItemList) do
- for _, itemInfo in pairs(allItemInfo) do
- if itemInfo.bagindex == tonumber(bagIndex) then
- -- local itemCfgId = itemInfo.cfgid
- local cfgItem = ConfigDataManager.getById("cfg_item", itemInfo.cfgid)
- local isMatchCfg, cfgRecovery = table.findByCondi(cfgs, function(a)
- if string.isNullOrEmpty(a.needmaterial) then
- return false
- end
- local ss = string.split(a.needmaterial, "#")
- if table.count(ss) <= 0 then
- return false
- end
- return tonumber(ss[1]) == itemInfo.cfgid;
- end)
- -- local decomposeGroup = ConfigDataManager.getTableValue("cfg_item", "decomposeGroup", "id", itemCfgId)
- if isMatchCfg == nil or cfgItem == nil then
- tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
- return
- end
- local decomposeTable = cfgRecovery
- if table.isEmpty(decomposeTable) then
- -- error(actor,"分解类型配置错误")
- return
- end
- if not table.isNullOrEmpty(allequip) then
- local equipext = allequip[tonumber(itemInfo.id)]
- if not table.isNullOrEmpty(equipext) then
- allequip[tonumber(itemInfo.id)] = nil
- end
- end
- local decomposeInfo = decomposeTable
- -- 计算分解需要的东西
- local needMaterial = decomposeInfo.needmaterial
- if not string.isNullOrEmpty(needMaterial) then
- local needMaterialInfo = string.split(needMaterial, "#")
- local needMaterialCount = allNeedMaterial[needMaterialInfo[1]]
- if not needMaterialCount then
- needMaterialCount = 0
- end
- allNeedMaterial[needMaterialInfo[1]] = needMaterialCount + (tonumber(needMaterialInfo[2]) * count)
- end
- -- 计算分解获得的东西
- local material = decomposeInfo.material
- if not string.isNullOrEmpty(material) then
- local allObtainTable = string.split(material, "|")
- for _, obtainInfo in pairs(allObtainTable) do
- local obtainItemInfo = string.split(obtainInfo, "#")
- local obtainCount = allObtainList[obtainItemInfo[1]]
- if obtainCount == nil then
- obtainCount = 0
- end
- local total = obtainCount + (tonumber(obtainItemInfo[2]) * count)
- allObtainList[obtainItemInfo[1]] = total
- end
- end
- local entrymaterial = decomposeInfo.entrymaterial
- if not string.isNullOrEmpty(entrymaterial) and cfgItem.type == "2" then
- local enyrys = itemInfo.entries
- local rr = string.split(entrymaterial, "|")
- for i, v in ipairs(rr) do
- local materiald = string.split(v, "#")
- local entryId = tonumber(materiald[1])
- local entryCoe = tonumber(materiald[2])
- local rewardId = tonumber(materiald[3])
- local rewardNum = tonumber(materiald[4])
- local tk, tv = table.findByCondi(enyrys, function(a)
- return a.attrid == entryId
- end)
- if tk ~= nil then
- local getNum = math.floor(tv.value / entryCoe)
- if allObtainList[rewardId] ~= nil then
- allObtainList[rewardId] = allObtainList[rewardId] + rewardNum * getNum
- else
- allObtainList[rewardId] = rewardNum * getNum
- end
- end
- end
- end
- end
- end
- end
- removeitembyidxlist(actor, decompositionItemList, 9999, "分解消耗")
- additemmaptobag(actor, allObtainList, 0, 9999, "分解获得")
- -- itemdecomposition(actor, decompositionItemList, allObtainList, allNeedMaterial)
- sendluamsg(actor, LuaMessageIdToClient.RES_ITEM_DECOMPOSITION, allObtainList)
- setplaydef(actor, "T$luaitemextdata", allequip)
- end
- function ItemRecycling.recyclingRateReward(actor, reward)
- this.recyclingRateReward(actor, reward)
- end
- function this.recyclingRateReward(actor, reward)
- local rate = 0
- -- 月卡特权
- local is_open, count = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.RECYCLING_INCOME_UP)
- if is_open then
- rate = rate + count;
- end
- -- VIP特权
- local vip_open, vip_rate = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.recycle)
- if vip_open and string.tonumber(vip_rate) > 0 then
- rate = rate + tonumber(vip_rate)
- end
- if rate < 1 then
- return
- end
- for key, value in pairs(reward) do
- local final_value = value * rate / 100
- if final_value >= 1 then
- reward[key] = final_value
- end
- end
- additemmaptobag(actor, reward, 0, 9999, '回收')
- GameTips.sendGetRewardMsg(actor, reward)
- this.debug("加成过的回收奖励", reward)
- end
- -- 回收
- function ItemRecycling.recovery(actor, msgData)
- local allItemInfo = getallbagiteminfo(actor)
- if table.isEmpty(allItemInfo) then
- return
- end
- if table.isEmpty(msgData) then
- return
- end
- local allObtainList = {}
- local itemIdGold = tostring(10010001)
- local allequip = getplaydef(actor, "T$luaitemextdata")
- for bagIndex, count in pairs(msgData) do
- for _, itemInfo in pairs(allItemInfo) do
- if itemInfo.bagindex == tonumber(bagIndex) then
- local itemCfgId = itemInfo.cfgid
- local recoveryGroup = ConfigDataManager.getTableValue("cfg_item", "recoveryGroup", "id", itemCfgId)
- local recoveryUp = ConfigDataManager.getTableValue("cfg_item", "recoveryUp", "id", itemCfgId)
- if string.isNullOrEmpty(recoveryGroup) then
- tipinfo(actor, "选择的道具中拥有不能分解的道具,请重新选择")
- return
- end
- local recoveryTable = ConfigDataManager.getTable("cfg_recovery", "id", recoveryGroup)
- if table.isEmpty(recoveryTable) then
- -- error(actor,"回收类型配置错误")
- return
- end
- if not table.isNullOrEmpty(allequip) then
- local equipext = allequip[tonumber(itemInfo.id)]
- if not table.isNullOrEmpty(equipext) then
- allequip[tonumber(itemInfo.id)] = nil
- end
- end
- local num = EquipFunc.getEquipRecoverCost(actor, itemInfo.id)
- if allObtainList[itemIdGold] ~= nil then
- allObtainList[itemIdGold] = allObtainList[itemIdGold] + num
- else
- allObtainList[itemIdGold] = num
- end
- -- local recoveryInfo = recoveryTable[1]
- -- local materialString = recoveryInfo.material
- -- local material = string.split(materialString,"#")
- -- local addCount = math.random(tonumber(material[2]), tonumber(material[3]))
- -- addCount = addCount * count
- -- if not string.isNullOrEmpty(recoveryUp) then
- -- addCount = addCount * ( 1 + math.floor(tonumber(recoveryUp) / 100))
- -- end
- -- local obtainCount = allObtainList[material[1]]
- -- if obtainCount == nil then
- -- obtainCount = 0
- -- end
- -- allObtainList[material[1]] = obtainCount + addCount
- end
- end
- end
- -- 做每天获取金币总量限制
- -- if allObtainList[itemIdGold] ~= nil then
- -- local enough, left_num = Player.GoldCountEnough(allObtainList[itemIdGold])
- -- if enough then
- -- allObtainList[itemIdGold] = left_num
- -- else
- -- allObtainList[itemIdGold] = 0
- -- end
- -- end
- itemrecovery(actor, msgData, allObtainList)
- sendluamsg(actor, LuaMessageIdToClient.RES_RECOVERY_REWARD, allObtainList)
- sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, allObtainList)
- setplaydef(actor, "T$luaitemextdata", allequip)
- -- sendluamsg(actor,LuaMessageIdToClient.RES_ITEM_RECOVERY,allObtainList)
- end
- -- 设置玩家回收类型
- function ItemRecycling.setItemRecyclingType(ownActor, msgData)
- this.setItemRecycling(ownActor, msgData)
- sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, msgData)
- end
- function this.setItemRecycling(ownActor, msgData)
- callonserial(ownActor, "set_item_recycling", msgData)
- end
- function set_item_recycling(ownActor, msgData)
- local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
- if table.isNullOrEmpty(itemRecoveryType) then
- itemRecoveryType = {}
- end
- itemRecoveryType[ownActor:toString()] = msgData
- setsysvar(ownActor, ITEM_RECYCLING_TYPE, itemRecoveryType)
- end
- -- 获取当前玩家回收设置信息
- function ItemRecycling.getItemRecyclingType(ownActor)
- local itemRecoveryType = getsysvar(ownActor, ITEM_RECYCLING_TYPE)
- if table.isNullOrEmpty(itemRecoveryType) then
- sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
- return
- end
- for actor, recyclingType in pairs(itemRecoveryType) do
- if actor == ownActor:toString() then
- sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, recyclingType)
- return
- end
- end
- sendluamsg(ownActor, LuaMessageIdToClient.RES_GET_RECYCLING_TYPE, nil)
- end
- -- 自动回收道具
- function ItemRecycling.autoRecycling(actor)
- -- jprint("开启自动回收")
- local allItemRecoveryType = getsysvar(actor, ITEM_RECYCLING_TYPE)
- local bagIndex = {}
- if table.isNullOrEmpty(allItemRecoveryType) then
- table.insert(bagIndex, 0)
- return bagIndex
- end
- local itemRecoveryType = allItemRecoveryType[actor:toString()]
- if table.isNullOrEmpty(itemRecoveryType) then
- table.insert(bagIndex, 0)
- return bagIndex
- end
- local allItemInfo = getallbagiteminfo(actor)
- if table.isEmpty(allItemInfo) then
- table.insert(bagIndex, 0)
- return bagIndex
- end
- local alldata = EquipAndAppear.getLuaItemExtData(actor)
- for _, itemInfo in pairs(allItemInfo) do
- if this.getItemInfo(alldata, itemInfo.id) then
- local itemCfgId = itemInfo.cfgid
- if this.medicineCanRecycling(actor, itemCfgId) then
- local recoveryGroup = ConfigDataManager.getTableValue("cfg_item", "recoveryGroup", "id", itemCfgId)
- if not string.isNullOrEmpty(recoveryGroup) then
- local secondType = itemRecoveryType[recoveryGroup]
- if secondType ~= nil then
- if not secondType["1"] then
- table.insert(bagIndex, itemInfo.bagindex)
- else
- for _, type in pairs(secondType) do
- local recoveryScreen = ConfigDataManager.getTable("cfg_recovery_screen", "id", type)
- if not table.isNullOrEmpty(recoveryScreen) then
- local recoveryScreenInfo = recoveryScreen[1]
- local recoveryScreenType = tonumber(recoveryScreenInfo.type)
- if recoveryScreenType == ItemRecyclingType.PIN_JIE then
- local rank = recoveryScreenInfo.rank
- local cfgRank = ConfigDataManager.getTableValue("cfg_item", "rank", "id",
- itemCfgId)
- if not string.isNullOrEmpty(rank) and not string.isNullOrEmpty(cfgRank) and
- tonumber(rank) == tonumber(cfgRank) then
- table.insert(bagIndex, itemInfo.bagindex)
- break
- end
- elseif recoveryScreenType == ItemRecyclingType.ZHUO_YUE then
- local cfgCount = recoveryScreenInfo.count
- local entries = itemInfo.entries
- if not string.isNullOrEmpty(cfgCount) and not table.isNullOrEmpty(entries) and
- tonumber(cfgCount) == table.count(entries) then
- table.insert(bagIndex, itemInfo.bagindex)
- break
- end
- elseif recoveryScreenType == ItemRecyclingType.ZHI_YE then
- local cfgCareer = recoveryScreenInfo.career
- local job = ConfigDataManager.getTableValue("cfg_item", "job", "id", itemCfgId)
- if not string.isNullOrEmpty(cfgCareer) and not string.isNullOrEmpty(job) then
- local recoveryCareer = string.split(cfgCareer, "|")
- local itemCareer = string.split(job, "|")
- for _, career in pairs(itemCareer) do
- if table.contains(recoveryCareer, career) then
- table.insert(bagIndex, itemInfo.bagindex)
- break
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- table.insert(bagIndex, 0)
- return bagIndex
- end
- --- 判断道具是否合乎药水回收要求
- function this.medicineCanRecycling(actor, itemCfgId)
- local type = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId)
- local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", itemCfgId)
- if tonumber(type) == 3 and tonumber(subType) == 1 then
- local conditions = ConfigDataManager.getTableValue("cfg_npcShop", "conditions", "itemId", itemCfgId)
- local result = checkcondition(actor, conditions)
- return result == "0"
- end
- return true
- end
- -- 判断当前道具有没有锻造
- function this.getItemInfo(alldata, itemId)
- local equipdata = alldata[tonumber(itemId)]
- if equipdata == nil then
- return true
- end
- if equipdata.strengthlv == nil and equipdata.appendlv == nil then
- return true
- end
- if equipdata.strengthlv ~= 0 or equipdata.appendlv ~= 0 then
- return false
- end
- return true
- end
- ---------------------------- 日志打印 -----------------------------
- this.log_open = false
- function this.debug(...)
- if not this.log_open then
- return
- end
- gameDebug.print(...)
- end
- function this.jprint(param)
- if not this.log_open then
- return
- end
- if param == nil then
- param = "error! 输出内容为空. nil"
- end
- jprint(param)
- end
- function this.loginfo(actor, param)
- if not this.log_open then
- return
- end
- if param == nil then
- param = "error! 日志输出内容为空. nil"
- end
- jprint(param)
- info(actor, param)
- end
|