| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- -- 涉及到的相关属性在属性表配置
- EquipRefined = {}
- local this = EquipRefined;
- local filename = "EquipRefined";
- local luckAttrs = {305012, -- 幸运一击伤害加成
- 900 -- 幸运(灵魂宝石成功率)
- }
- function EquipRefined.onLoginEnd(actor)
- end
- -- 根据权重随机词条数量
- function EquipRefined.random_weighted(weight_str, count)
- local result = {}
- if count <= 0 then
- return result
- end
- local num = string.split(weight_str, "&")
- local weight_total = 0
- for _, value in pairs(num) do
- local sum = string.split(value, "#")
- weight_total = weight_total + tonumber(sum[2])
- end
- local random_weight = math.random(1, weight_total)
- local cumulative_weight = 0
- for _, value in pairs(num) do
- local sum = string.split(value, "#")
- local weight = tonumber(sum[2])
- cumulative_weight = cumulative_weight + weight
- if cumulative_weight >= random_weight then
- table.insert(result, tonumber(sum[1]))
- if table.count(result) == count then
- return result
- end
- end
- end
- end
- function EquipRefined.luarefinedequip(actor, msgData)
- local itemid = msgData.itemId
- local equip = getequipinfo(actor, itemid, 1)
- if equip == nil then
- return
- end
- local cfgRefined = ConfigDataManager.getTable("cfg_equip_refined", "id", equip.cfgid)
- if #cfgRefined > 0 then
- cfgRefined = cfgRefined[1]
- else
- return
- end
- local isMax = EquipRefined.isMax(equip)
- local costs = isMax and cfgRefined.refinedattrcost or cfgRefined.refinednumcost
- local cost_map = {}
- if not string.isNullOrEmpty(costs) then
- string.putIntIntMap(cost_map, costs, "#", "|")
- end
- -- 校验道具是否足够
- local enough = API.CheckItemMap(actor, cost_map)
- if enough == false then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足")
- return
- end
- local num = 0
- if isMax then
- num = tonumber(cfgRefined.count)
- else
- num = EquipRefined.random_weighted(cfgRefined.againnum, 1)[1]
- end
- if EquipRefined.resetEquipEntryWithRandomAttrs(actor, itemid, num) == false then
- return
- end
- API.TakeItemMap(actor, cost_map, "洗练消耗")
- sendluamsg(actor, LuaMessageIdToClient.REFINED_EQUIP_RESULT, {
- itemid = itemid
- })
- end
- function EquipRefined.isMax(equip)
- local cfgRefined = ConfigDataManager.getTable("cfg_equip_refined", "id", equip.cfgid)
- if #cfgRefined > 0 then
- cfgRefined = cfgRefined[1]
- else
- return
- end
- local entries = (equip ~= nil and equip.entries ~= nil) and equip.entries or {}
- local num = 0
- for key, value in pairs(entries) do
- local isLuck = false;
- for _, v in pairs(luckAttrs) do
- if v == value.attrid then
- isLuck = true
- break
- end
- end
- if isLuck == false then
- num = num + 1
- end
- end
- return num >= tonumber(cfgRefined.count);
- end
- function EquipRefined.resetEquipEntryWithRandomAttrs(actor, equipId, num)
- -- 获取装备信息
- local equipInfo = getequipinfo(actor, equipId, 1)
- if not equipInfo or equipInfo == nil then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取装备信息")
- return false
- end
- local itemCfg = ConfigDataManager.getTable("cfg_equip_entryLib", "id", equipInfo.cfgid)
- if #itemCfg > 0 then
- itemCfg = itemCfg[1]
- end
- if itemCfg == nil then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取词条配置")
- return
- end
- local attrGroups = {}
- attrGroups = string.split(itemCfg.att1, "|")
- -- info("装备信息:", equipInfo)
- -- 获取所有词条配置
- local allEntries = ConfigDataManager.getTable("cfg_equip_att")
- -- local allEntries = ConfigDataManager.getTable("cfg_att_info")
- -- info("所有词条配置数量:", allEntries and #allEntries or 0)
- if not allEntries or allEntries == nil then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取词条配置")
- return false
- end
- local tmpEntries = (equipInfo ~= nil and equipInfo.entries ~= nil) and equipInfo.entries or {}
- local tmpLuckAttrs = {}
- for key, value in pairs(tmpEntries) do
- local isLuck = false;
- for _, v in pairs(luckAttrs) do
- if v == value.attrid then
- table.insert(tmpLuckAttrs, value)
- break
- end
- end
- end
- -- 定义减伤属性ID(需要排除)
- local excludedEntryId = 26
- info("总词条数量:", #allEntries)
- -- 过滤可用的词条(排除减伤属性)并构建带权重的列表
- local availableEntries = {}
- local totalWeight = 0
- for _, entry in ipairs(allEntries) do
- local isGroup = false
- for key, v in pairs(attrGroups) do
- if v == entry.group then
- isGroup = true
- break
- end
- end
- -- 确保不包含减伤属性
- if entry.id ~= excludedEntryId and entry.id ~= 36 and entry.id ~= 37 and entry.id ~= 38 and isGroup then
- local attrParts = string.split(entry.att, "#")
- local weight = 1 -- 默认权重
- if #attrParts >= 4 then
- weight = tonumber(attrParts[4]) or 1 -- 获取权重,如果不存在则为1
- end
- table.insert(availableEntries, {
- entry = entry,
- weight = weight
- })
- totalWeight = totalWeight + weight
- end
- end
- if #availableEntries == 0 then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "没有可用的词条")
- return false
- end
- local entryCount = num;
- info("选择的词条数量:", entryCount)
- local selectedEntries = {}
- -- 生成新的词条列表(使用加权随机选择)
- local tempAvailableEntries = {}
- for i, weightedEntry in ipairs(availableEntries) do
- tempAvailableEntries[i] = {
- entry = weightedEntry.entry,
- weight = weightedEntry.weight
- }
- end
- local tempTotalWeight = totalWeight
- -- 根据权重随机选择词条
- for i = 1, entryCount do
- if #tempAvailableEntries <= 0 or tempTotalWeight <= 0 then
- break
- end
- -- 生成一个基于当前总权重的随机数
- local randomValue = math.random(1, tempTotalWeight)
- local currentWeight = 0
- local selectedIndex = 1
- -- 找到对应的词条
- for j, weightedEntry in ipairs(tempAvailableEntries) do
- currentWeight = currentWeight + weightedEntry.weight
- if randomValue <= currentWeight then
- selectedIndex = j
- break
- end
- end
- local selectedWeightedEntry = tempAvailableEntries[selectedIndex]
- local entryCfg = selectedWeightedEntry.entry
- info(string.format("选择的第%d条词条: ID=%d, 权重=%d", i, entryCfg.id, selectedWeightedEntry.weight))
- local attrParts = string.split(entryCfg.att, "#")
- local attrId = attrParts[1]
- local minValue = attrParts[2]
- local maxValue = attrParts[3]
- info(string.format("原始属性值: attrId=%s, minValue=%s, maxValue=%s", tostring(attrId), tostring(minValue),
- tostring(maxValue)))
- -- 转换为数字
- minValue = tonumber(minValue)
- maxValue = tonumber(maxValue)
- -- 创建词条对象
- local entry = {
- entryid = entryCfg.id,
- attrid = attrId,
- value = math.random(minValue, maxValue)
- }
- info("生成的词条对象:", entry)
- table.insert(selectedEntries, entry)
- -- 从可选列表中移除已选的词条,避免重复
- tempTotalWeight = tempTotalWeight - selectedWeightedEntry.weight
- table.remove(tempAvailableEntries, selectedIndex)
- end
- info("随机生成的词条:", selectedEntries)
- for key, value in pairs(tmpLuckAttrs) do
- table.insert(selectedEntries, value)
- end
- -- 应用新的词条到装备
- local result = resetequipentry(actor, equipId, selectedEntries)
- if not result then
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "词条重置失败")
- return false
- end
- -- 发送成功消息
- sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备词条重置成功!")
- return true
- end
- function EquipRefined.equipEntryRandomAttrOne(equipInfo, cfgEquip, cfgEquipAtt)
- local attrGroups = string.split(cfgEquip.att1, "|")
- -- 定义减伤属性ID(需要排除)
- local excludedEntryId = 26
- -- 过滤可用的词条(排除减伤属性)并构建带权重的列表
- local availableEntries = {}
- local totalWeight = 0
- for _, entry in ipairs(cfgEquipAtt) do
- local isGroup = false
- for key, v in pairs(attrGroups) do
- if v == entry.group then
- isGroup = true
- break
- end
- end
- -- 确保不包含减伤属性
- if entry.id ~= excludedEntryId and entry.id ~= 36 and entry.id ~= 37 and entry.id ~= 38 and isGroup then
- local attrParts = string.split(entry.att, "#")
- local weight = 1 -- 默认权重
- if #attrParts >= 4 then
- weight = tonumber(attrParts[4]) or 1 -- 获取权重,如果不存在则为1
- end
- table.insert(availableEntries, {
- entry = entry,
- weight = weight
- })
- totalWeight = totalWeight + weight
- end
- end
- if #availableEntries == 0 then
- return nil
- end
- local entryCount = 1;
- local selectedEntries = {}
- -- 生成新的词条列表(使用加权随机选择)
- local tempAvailableEntries = {}
- for i, weightedEntry in ipairs(availableEntries) do
- tempAvailableEntries[i] = {
- entry = weightedEntry.entry,
- weight = weightedEntry.weight
- }
- end
- local tempTotalWeight = totalWeight
- -- 根据权重随机选择词条
- for i = 1, entryCount do
- if #tempAvailableEntries <= 0 or tempTotalWeight <= 0 then
- break
- end
- -- 生成一个基于当前总权重的随机数
- local randomValue = math.random(1, tempTotalWeight)
- local currentWeight = 0
- local selectedIndex = 1
- -- 找到对应的词条
- for j, weightedEntry in ipairs(tempAvailableEntries) do
- currentWeight = currentWeight + weightedEntry.weight
- if randomValue <= currentWeight then
- selectedIndex = j
- break
- end
- end
- local selectedWeightedEntry = tempAvailableEntries[selectedIndex]
- local entryCfg = selectedWeightedEntry.entry
- local attrParts = string.split(entryCfg.att, "#")
- local attrId = attrParts[1]
- local minValue = attrParts[2]
- local maxValue = attrParts[3]
- -- 转换为数字
- minValue = tonumber(minValue)
- maxValue = tonumber(maxValue)
- -- 创建词条对象
- local entry = {
- entryid = entryCfg.id,
- attrid = attrId,
- value = math.random(minValue, maxValue)
- }
- table.insert(selectedEntries, entry)
- -- 从可选列表中移除已选的词条,避免重复
- tempTotalWeight = tempTotalWeight - selectedWeightedEntry.weight
- table.remove(tempAvailableEntries, selectedIndex)
- end
- if table.count(selectedEntries) <= 0 then
- return nil
- end
- return selectedEntries[1]
- end
|