EquipAndAppear = {} local this = {} ---玩家装备信息记录 local ROLE_EQUIP_INFO_RECORDE = "T$role_equip_info_recorde" local ROLE_EQUIP_STRENGTH_TIMES = "T$role_equip_strength_times" EquipAndAppear.RecordeType = { ---全身最大强化等级 MAX_STRENGTH_LEVEL = 1, ---全身最大追加等级 MAX_APPEND_LEVEL = 2, ---全身最大卓越词条数量 MAX_ENTRY_COUNT = 3, ---全身最大首饰等级 MAX_JEWELRY_LEVEL = 4 } ---装备信息记录数据结构 function this.GetNewEquipInfoRecorde() local recorde = { ---全身最大强化等级 max_strength_level = 0, ---全身最大追加等级 max_append_level = 0, ---全身最大卓越词条数量 max_entry_count = 0, ---全身最大首饰等级 max_jewelry_level = 0 } return recorde end ---装备bind数据修复 local EQUIP_BIND_DATA_REPAIR = "T$equipbinddatarepair" local EQUIP_UP_DATA_REPAIR = "T$equipssupdatarepair" function EquipAndAppear.login(actor) RepairRoleData.action(actor, EQUIP_BIND_DATA_REPAIR, 202503192016, EquipAndAppear.repairEquipBindData2025_03_19, actor) RepairRoleData.action(actor, EQUIP_UP_DATA_REPAIR, 202503241400, EquipAndAppear.repairEquipSsupData2025_03_24, actor) EquipAndAppear.UpdateWear(actor) end function EquipAndAppear.onLogout(actor) local rid = getbaseinfo(actor, "rid") local list = getnarplayer(actor) for k, v in pairs(list) do local targetActor = getactor(actor, v.rid) sendluamsg(targetActor, 10000500, { playerid = rid }) end end function EquipAndAppear.repairEquipBindData2025_03_19(actor) local allData = EquipAndAppear.getLuaItemExtData(actor) local infos = getallequipinfo(actor) for _, equip in pairs(infos) do if this.checkEquipData(actor, allData, equip.id) then changeitembindstate(actor, equip.id, 1) end end info(actor, "修复bind数据成功") end ---装备首饰升级数据修复 function EquipAndAppear.repairEquipSsupData2025_03_24(actor) local allData = EquipAndAppear.getLuaItemExtData(actor) local infos = getallequipinfo(actor) for _, equip in pairs(infos) do local cfgId = equip.cfgid local itemId = tonumber(equip.id) local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId) if group ~= nil and group ~= "" then local equipext = allData[itemId] if equipext then local ssUpLv = equipext.ssuplv or 0 local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", ssUpLv) if (ornaments == nil) and ssUpLv > 0 then -- 修复数据 for i = ssUpLv - 1, 1, -1 do local newNaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", i) if newNaments and table.count(newNaments) > 0 then equipext.ssuplv = i local att = newNaments[1].basicatt local attr = splitbyshuxianandjinghao2(att) equipext.ssupattr = attr EquipAndAppear.SetItemExtData(actor, itemId, equipext) allData[itemId] = equipext setplaydef(actor, "T$luaitemextdata", allData) break end end end end end end info(actor, "修复首饰升级数据成功") end function this.checkEquipData(actor, allData, itemId) local equipData = allData[tonumber(itemId)] if not equipData then return false end if equipData.strengthlv ~= 0 then return true end if equipData.appendlv ~= 0 then return true end local equip = getequipinfo(actor, itemId, 1) if table.count(equip.entries) > 2 then return true end return false end function EquipAndAppear.GetEquipInfoRecorde(actor) local equipInfoRecorde = getplaydef(actor, ROLE_EQUIP_INFO_RECORDE) if equipInfoRecorde == nil then equipInfoRecorde = this.GetNewEquipInfoRecorde() end return equipInfoRecorde end function this.SaveEquipInfoRecorde(actor, equipInfoRecorde) setplaydef(actor, ROLE_EQUIP_INFO_RECORDE, equipInfoRecorde) end -- 保存角色外观(幻化也走这个方法) function EquipAndAppear.settingequipappear(actor, msgData) local equipappear = msgData["equipindex"] local data = {} for _, value in pairs(equipappear) do local pos = tonumber(value["slot"]) local cfgId = tonumber(value["cfgId"]) if pos ~= nil then data[pos] = cfgId end end setitemappeardata(actor, data) sendluamsg(actor, LuaMessageIdToClient.RES_SETTING_EQUIP_APPEAR, data) NewEquipWear.UpdateWear(actor, data); EquipAndAppear.UpdateWear(actor) end -- 初始化角色外观 function initequipppear(actor) local equipappear = {} setplaydef(actor, "T$equipappear", equipappear) end -- 获取角色外观 function EquipAndAppear.getequipappear(actor, msgId) local data = getrolefield(actor, "role.roleappear.appear") if data == nil then return end -- local lv = API.GetItemData(actor,itemId,"strengthlv") or 0 -- local infos = getallequipinfo(actor) local infos = getputonequipinfo(actor) local result = {} local tmpEquipSlots = {} for k, v in pairs(infos) do local equip = infos[k] local pos = gameequip.pos(equip.equipindex) tmpEquipSlots[pos] = API.GetItemData(actor, equip.id, "strengthlv") or 0 end for key, value in pairs(data) do local appear = {} appear["slot"] = key appear["cfgId"] = value appear["lv"] = tmpEquipSlots[key] or 0 table.insert(result, appear) end -- 发送lua消息到客户端 if LuaMessageIdToSever.GET_EQUIP_APPEAR == msgId then sendluamsg(actor, LuaMessageIdToClient.GET_EQUIP_APPEAR, result) end return result end function EquipAndAppear.UpdateWear(actor) -- local data = getrolefield(actor, "role.roleappear.appear") -- if data == nil then -- return -- end -- local infos = getallequipinfo(actor) -- local result = {} -- local tmpEquipSlots = {} -- for k, v in pairs(infos) do -- local equip = infos[k] -- local pos = gameequip.pos(equip.equipindex) -- tmpEquipSlots[pos] = API.GetItemData(actor, equip.id, "strengthlv") or 0 -- end -- for key, value in pairs(data) do -- local appear = {} -- appear["slot"] = key -- appear["cfgId"] = value -- appear["lv"] = tmpEquipSlots[key] or 0 -- table.insert(result, appear) -- end -- local rid = getbaseinfo(actor, "rid") -- local list = getnarplayer(actor) -- for k, v in pairs(list) do -- sendluamsg(v.rid, LuaMessageIdToSever.UpdateWear, {rid = rid, data = result, oriData = data}) -- end -- 发送幻化染色数据 local appear = EquipAndAppear.getequipappear(actor, 0) local title = EquipAndAppear.gettitleinfo(actor, 0) local alldata = {} alldata["appear"] = appear alldata["ring"] = EquipAndAppear.getnowwearshapering(actor) local curTitle = 0 if not title.hidden then curTitle = title.curEquipTitle end alldata["title"] = curTitle local rid = getbaseinfo(actor, "rid") alldata["rid"] = rid local isTransfet = APIGetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET") if isTransfet ~= nil and isTransfet > 0 then -- local isTransfet = APIGetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET") APISetInt(actor, "IS_TAKEOFF_EQUIP_TRANSFET", 0) return end local list = getnarplayer(actor) for k, v in pairs(list) do local targetActor = getactor(actor, v.rid) sendluamsg(targetActor, LuaMessageIdToClient.OTHER_ROLE_APPEAR, alldata) end end -- 外观幻化激活 function EquipAndAppear.equipfashion(actor, msgData) local cfgIds = msgData["cfgIds"] local equipFashion = getplaydef(actor, "T$equipfashion") if equipFashion == nil then equipFashion = {} end for _, cfgId in pairs(cfgIds) do local isExist = table.contains(equipFashion, cfgId) if isExist then -- 存在已激活的 return end end -- 计算所有消耗 local allData = getAllEquipAppearCost(cfgIds, 4) if allData == nil then return end -- 检查背包是否道具充足 local enough = Bag.checkItemEnough(actor, allData) if enough == false then return end -- 扣材料 for _, v in ipairs(allData) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 保存幻化 for _, v in pairs(cfgIds) do table.insert(equipFashion, v) end setplaydef(actor, "T$equipfashion", equipFashion) sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_FASHION, equipFashion) end -- 获取已激活外观 function EquipAndAppear.getallequipfashion(actor) local equipFashion = getplaydef(actor, "T$equipfashion") sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_FASHION, equipFashion) end -- 激活染色 function EquipAndAppear.actquipcolor(actor, msgData) local cfgIds = msgData["cfgIds"] local color = msgData["color"] -- 计算消耗材料 local allCost = getAllEquipAppearCost(cfgIds, 5) if allCost == nil then return end -- 检查背包是否道具充足 local enough = Bag.checkItemEnough(actor, allCost) if enough == false then return end -- 扣材料 for _, v in ipairs(allCost) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 染色 local equipcolor = EquipAndAppear.getequipcolor(actor, 0) for i, v in ipairs(cfgIds) do local num = 0 for _, val in pairs(equipcolor) do if val["cfgid"] == v then table.insert(val["color"], color) num = num + 1 break end end if num == 0 then local dt = {} dt["cfgid"] = v dt["color"] = {} table.insert(dt["color"], color) table.insert(equipcolor, dt) end end setplaydef(actor, "actequipcolor", equipcolor) end -- 保存染色 function EquipAndAppear.settingequipcolor(actor, msgData) local cfgId = msgData["cfgid"] local color = msgData["color"] -- 先校验是否激活该颜色 local actequipcolor = getplaydef(actor, "T$actequipcolor") local bool = false for _, v in pairs(actequipcolor) do local cId = v["cfgid"] if cId == cfgId then bool = table.contains(v["color"], color) break end end if bool ~= true then return end local equipcolor = EquipAndAppear.getequipcolor(actor, 0) for _, v in ipairs(equipcolor) do if v["cfgid"] == cfgId then v["color"] = color break end end setplaydef(actor, "T$equipcolor", equipcolor) end -- 获取角色染色数据 function EquipAndAppear.getequipcolor(actor, msgId) local equipcolor = getplaydef(actor, "T$equipcolor") if equipcolor == nil then equipcolor = {} setplaydef(actor, "T$equipcolor", equipcolor) end local data = getplaydef(actor, "T$equipcolor") -- 发送lua消息到客户端 if msgId == LuaMessageIdToClient.GET_EQUIP_COLOR then sendluamsg(actor, msgId, data) end return data end -- 计算所有消耗 function getAllEquipAppearCost(cfgIds, type) local allData = {} for _, cfgId in pairs(cfgIds) do local cost = ConfigDataManager.getTableValue("cfg_fashion", "deplete", "id", cfgId, "type", type) if cost == nil then return nil end local data = splitbyshuxianandjinghao(cost) for _1, v in pairs(data) do local id = v["cfgid"] local count = v["count"] local num = 0 for _2, val in pairs(allData) do if val["cfgid"] == id then val["count"] = val["count"] + count num = num + 1 break end end if num == 0 then local element = {} element["cfgid"] = id element["count"] = count table.insert(allData, element) end end end return allData end function EquipAndAppear.playerequipview(actor, otherActor) if otherActor == nil then return end -- 发送幻化染色数据 local appear = EquipAndAppear.getequipappear(otherActor, 0) local title = EquipAndAppear.gettitleinfo(otherActor, 0) local alldata = {} alldata["appear"] = appear alldata["ring"] = EquipAndAppear.getnowwearshapering(otherActor) local curTitle = 0 if not title.hidden then curTitle = title.curEquipTitle end alldata["title"] = curTitle local rid = getbaseinfo(otherActor, "rid") alldata["rid"] = rid sendluamsg(actor, LuaMessageIdToClient.OTHER_ROLE_APPEAR, alldata) end -- 玩家进入视野时发送玩家装备的强化信息 function EquipAndAppear.playerequipstrength(actor, otherActor) if otherActor == 0 then otherActor = actor end local alldata = getplaydef(otherActor, "T$luaitemextdata") local equiplist = getputonequipinfo(otherActor) local result = {} local info = {} for _, equipinfo in pairs(equiplist) do local itemId = equipinfo.id local data = alldata[itemId] local equip = {} equip.itemid = itemId if data ~= nil then if data.strengthlv ~= nil then equip.strengthlv = data.strengthlv else equip.strengthlv = 0 end else equip.strengthlv = 0 end table.insert(info, equip) end result.rid = getbaseinfo(otherActor, "rid") result.equip = info result = table.valueConvertToString(result) sendrefluamsg(actor, LuaMessageIdToClient.RES_PLAYER_EQUIP_STRENGTHLV, result) end -- 检查表是否包含某个元素 -- function table.contains(table, element) -- for _, value in pairs(table) do -- if value == element then -- return true -- end -- end -- return false -- end -- 分割字符串 function splitbyshuxianandjinghao(str) local dt = {} local data = string.split(str, "|") for _, v in ipairs(data) do local data2 = string.split(v, "#") local v2 = {} v2["cfgid"] = data2[1] v2["count"] = data2[2] table.insert(dt, v2) end return dt end -- 称号入包 function EquipAndAppear.titleenterbag(actor, configId) local itemList = ConfigDataManager.getTable("cfg_item", "id", configId) if itemList == nil then return end local item = itemList[1] if tonumber(item.type) ~= 2 or tonumber(item.subtype) ~= 15 then return end -- 计算时间 local fashionList = ConfigDataManager.getTable("cfg_fashion", "id", configId) if fashionList == nil then return end if table.count(fashionList) == 0 then return end local fashion = fashionList[1] local titledata = EquipAndAppear.gettitleinfo(actor, 0) local titles = titledata.title -- 不限时 local flag = true local time = 0 local type = 0 local timeType = tonumber(fashion.timetype) local nowTime = math.ceil(getbaseinfo("now") / 1000) if timeType == 1 then type = 1 for _, value in pairs(titles) do if value.confId == configId then value.obtainTime = nowTime -- 获得时间 value.expiresTime = -1 -- 到期时间 flag = false end end time = -1 end -- 限时 if timeType == 2 then type = 2 -- 获取称号的有效期 local times = fashion.time local timestr = string.split(times, "#") -- 总时间 time = tonumber(timestr[1]) * 60 * 60 + tonumber(timestr[2]) * 60 + tonumber(timestr[3]) for _, value in pairs(titles) do if value.confId == configId then value.obtainTime = nowTime -- 获得时间 value.expiresTime = value.obtainTime + time -- 到期时间 flag = false end end end -- 活动限时 if timeType == 3 then type = 3 -- todo 获取称号的有效期 local actId = fashion.time local actdata = getactivityinfo(actor, actId) time = math.ceil(actdata.nextopentime / 1000) for _, value in pairs(titles) do if value.confId == configId then value.obtainTime = nowTime -- 获得时间 value.expiresTime = time -- 到期时间 flag = false end end end if flag then local tt = {} tt.obtainTime = math.ceil(getbaseinfo("now") / 1000) if type == 1 or type == 3 then tt.expiresTime = time else tt.expiresTime = tt.obtainTime + time end tt.confId = configId table.insert(titles, tt) end setplaydef(actor, "T$titledata", titledata) -- 更新称号属性 EquipAndAppear.updatetitleattr(actor) end -- 更新称号属性信息 function EquipAndAppear.updatetitleattr(actor) local data = getplaydef(actor, "T$titledata") local titles = data.title local titleattr = {} local nowTime = math.ceil(getbaseinfo("now") / 1000) for _, value in pairs(titles) do -- 先校验是否过期 if value.expiresTime == -1 or value.expiresTime > nowTime then -- 计算属性 local fashion = ConfigDataManager.getTable("cfg_fashion", "id", value.confId) local attr = fashion[1].att local str = string.split(attr, "|") for _, value in pairs(str) do local str2 = string.split(value, "#") local num = titleattr[str2[1]] local nowNum = str2[2] if num == nil then titleattr[str2[1]] = tonumber(nowNum) else titleattr[str2[1]] = tonumber(nowNum) + tonumber(num) end end end end -- 更新称号属性 addrolekmlattributes(actor, "titleattr", titleattr) end -- 获取称号详细信息 function EquipAndAppear.gettitleinfo(actor, msgId) local data = getplaydef(actor, "T$titledata") if data == nil then data = EquipAndAppear.inittitledata(actor) end if msgId == LuaMessageIdToSever.GET_TITLE then sendluamsg(actor, LuaMessageIdToClient.GET_TITLE, data) end return data end -- 保存称号外观 function EquipAndAppear.settingtitleappear(actor, msgId, msgData) local data = getplaydef(actor, "T$titledata") local titleappear = msgData["title"] data.curEquipTitle = titleappear setplaydef(actor, "T$titledata", data) if msgId == LuaMessageIdToSever.SET_TITLE then sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, titleappear) local result = {} result.rid = getbaseinfo(actor, "rid") result.curEquipTitle = titleappear sendrefluamsg(actor, LuaMessageIdToClient.RES_TITLE_CHANGE_UPDATE, result) end end -- 初始化数据 function EquipAndAppear.inittitledata(actor) local data = {} data.title = {} data.hidden = false data.curEquipTitle = 0 setplaydef(actor, "T$titledata", data) return data end -- 校验称号的过期时间 function EquipAndAppear.checktitleovertime(actor) local data = getplaydef(actor, "T$titledata") if table.count(data) == 0 then data = EquipAndAppear.inittitledata(actor) end local titles = data.title if table.count(titles) == 0 then return end local curTitle = data.curEquipTitle local flag = false local nowTime = math.ceil(getbaseinfo("now") / 1000) for key, value in pairs(titles) do -- 先校验是否过期 -- jprint("检查称号过期0",value.expiresTime > nowTime, value.expiresTime, nowTime) if value.expiresTime ~= -1 and value.expiresTime < nowTime then table.remove(titles, key) flag = true if curTitle == value.confId then data.curEquipTitle = 0 end end end if flag then data.title = titles setplaydef(actor, "T$titledata", data) EquipAndAppear.updatetitleattr(actor) -- 发送消息 sendluamsg(actor, LuaMessageIdToClient.SETTING_TITLE_APPEAR, 0) end end -- 获取守护外观 function EquipAndAppear.getguardappear(actor, msgId) local data = getrolefield(actor, "role.roleEquip.guardAppear") if data == nil then sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, {}) return {} end local result = {} for key, value in pairs(data) do local mm = {} mm.att = value.attr mm.getTime = math.floor(value.getTime / 1000) mm.itemId = key if value.time ~= -1 then mm.time = mm.getTime + math.floor(value.time / 1000) else mm.time = -1 end table.insert(result, mm) end if msgId == LuaMessageIdToSever.GET_GUARD_APPEAR then sendluamsg(actor, LuaMessageIdToClient.RES_GUARD_APPEAR, result) end return data end -- 获取变身戒指数据 function EquipAndAppear.getshapering(actor, msgId) local data = getrolefield(actor, "role.roleEquip.shapeRing") if data == nil then return {} end local nowwear = EquipAndAppear.getnowwearshapering(actor) local rd = {} local result = {} rd.curWearRing = nowwear for key, value in pairs(data) do local mm = {} mm.monsterId = tonumber(key) mm.ringAttr = value.ringAttr mm.getTime = math.floor(value.getTime / 1000) mm.itemId = value.itemId if value.time ~= -1 then mm.time = math.floor(value.time / 1000) else mm.time = -1 end table.insert(result, mm) end rd.title = result if msgId == LuaMessageIdToSever.GET_SHAPE_RING then sendluamsg(actor, LuaMessageIdToClient.GET_SHAPE_RING, rd) end return data end -- 穿戴变身戒指 function EquipAndAppear.wearshapering(actor, msgData) local monsterId = msgData["monsterId"] setplaydef(actor, "T$wearshapering", monsterId) setshaperingdata(actor, monsterId) sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, monsterId) local result = {} result.rid = getbaseinfo(actor, "rid") result.curEquipRing = monsterId sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result) end -- 获取当前穿戴的变身戒指 function EquipAndAppear.getnowwearshapering(actor) local data = getplaydef(actor, "T$wearshapering") if data == nil then return 0 end return data end -- 校验变身戒指过期时间 function EquipAndAppear.checkringovertime(actor) local data = EquipAndAppear.getshapering(actor) local ringId = EquipAndAppear.getnowwearshapering(actor) if ringId == 0 then return end local monsterId = ConfigDataManager.getTableValue("cfg_item", "useParam", "id", ringId) if not monsterId then return end if not data[tostring(monsterId)] then setplaydef(actor, "T$wearshapering", 0) sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0) local result = {} result.rid = getbaseinfo(actor, "rid") result.curEquipRing = 0 sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result) end -- local nowTime = math.ceil(getbaseinfo("now") / 1000) -- for index, ring in pairs(data) do -- if ring ~= -1 then -- --检查 -- if nowTime > math.floor(ring.time / 1000) then -- --删除穿戴外观 -- local ringId = EquipAndAppear.getnowwearshapering(actor) -- if ringId == ring then -- setplaydef(actor, "T$wearshapering", 0) -- sendluamsg(actor, LuaMessageIdToClient.RES_PUTOON_RING, 0) -- local result = {} -- result.rid = getbaseinfo(actor, "rid") -- result.curEquipRing = 0 -- sendrefluamsg(actor, LuaMessageIdToClient.RES_RING_CHANGE_UPDATE, result) -- end -- table.remove(data, index) -- end -- end -- end end function EquipAndAppear.initequipluaextdata(alldata, itemid) local equipdata = {} equipdata.strengthlv = 0 equipdata.appendlv = 0 equipdata.strengthattr = {} equipdata.appendattr = {} alldata[itemid] = equipdata end -- 装备强化 function EquipAndAppear.luastrengthequip(actor, msgData) local itemid = msgData.itemId local equip = getequipinfo(actor, itemid, 1) if equip == nil then return end local alldata = EquipAndAppear.getLuaItemExtData(actor) local equipdata = alldata[itemid] if equipdata == nil then EquipAndAppear.initequipluaextdata(alldata, itemid) equipdata = alldata[itemid] end if equipdata.strengthlv == nil then equipdata.strengthlv = 0 equipdata.strengthattr = {} end local lv = equipdata.strengthlv + 1 local cfgId = equip.cfgid -- 首饰的强化等级特殊处理 local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId) if group ~= nil and group ~= "" then local strengthenmaxLevel = ConfigDataManager.getTableValue("cfg_equip_ornaments", "strengthenmaxLevel", "ornamentsGroup", group, "lv", equipdata.ssuplv or 0) if tonumber(strengthenmaxLevel) < lv then sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级") return end else local maxLevel = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", cfgId) if tonumber(maxLevel) < lv then sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已强化到最大等级") return end end local costId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "costId", "id", cfgId) local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", cfgId) -- 获取消耗 local coststr = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "cost", "costGroupId", costId, "level", lv) if coststr == nil then return end local cost = splitbyshuxianandjinghao(coststr) -- 校验道具是否足够 local enough = Bag.checkItemEnough(actor, cost) if enough == false then TimeLimitGift.checkSpecial2Condition(actor) sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣材料 for _, v in ipairs(cost) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end TimeLimitGift.checkSpecial2Count(actor) -- 获取成功率 local rate = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "rate", "costGroupId", costId, "level", lv) local randomNumber = math.random(1, 10000) rate = tonumber(rate) if rate < randomNumber then -- 失败,校验是否等级回退 local failLevel = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "failLevel", "costGroupId", costId, "level", lv) failLevel = tonumber(failLevel) -- if not equip.isbind then -- changeitembindstate(actor,itemid,1) -- local res = {itemId = itemid,bindId = true} -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res) -- end if failLevel == equipdata.strengthlv then -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.strengthlv = tonumber(failLevel) dddd.issuccess = false sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd) return end local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", failLevel) local attr = splitbyshuxianandjinghao2(att) equipdata.strengthlv = failLevel equipdata.strengthattr = attr EquipAndAppear.SetItemExtData(actor, itemid, equipdata) setplaydef(actor, "T$luaitemextdata", alldata) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) info(actor, "玩家", actor, "强化装备至" .. lv .. "级失败,失败后等级" .. failLevel, "道具id" .. itemid, "cfgId:" .. cfgId) -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.strengthlv = tonumber(failLevel) dddd.issuccess = false sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd) EquipMaster.strengthMaster(actor) -- 装备强化之后发送装备强化信息 EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv) return end -- 获取属性加成 local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", lv) local attr = splitbyshuxianandjinghao2(att) equipdata.strengthlv = lv equipdata.strengthattr = attr EquipAndAppear.SetItemExtData(actor, itemid, equipdata) setplaydef(actor, "T$luaitemextdata", alldata) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) local firstRate = ConfigDataManager.getTableValue("cfg_equip_strengthenCost", "firstRate", "costGroupId", costId, "level", lv) firstRate = tonumber(firstRate) if firstRate == 1 then -- 发送跑马灯 local name = getrolefield(actor, "role.basic.name") local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId) local content = "恭喜" .. name .. "将" .. equipName .. "强化至" .. lv .. "级" local horseled = {} horseled.content = content horseled.cfgId = 109 -- 109是直接写死的 sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled) end info(actor, "玩家", actor, "强化装备至" .. lv .. "级成功", "道具id" .. itemid, "cfgId:" .. cfgId) -- if not equip.isbind then -- changeitembindstate(actor,itemid,1) -- local res = {itemId = itemid,bindId = true} -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res) -- end -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.strengthlv = tonumber(lv) dddd.issuccess = true sendluamsg(actor, LuaMessageIdToClient.STRENGTH_EQUIP_RESULT, dddd) EquipMaster.strengthMaster(actor) -- 记录强化次数 local oldCount = EquipAndAppear.GetEquipStrengthCount(actor) setplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES, oldCount + 1) ---触发装备强化任务 local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId) local taskParam = { part = strPart, level = lv } TaskHandler.TriggerTaskGoal(actor, TaskTargetType.PARTS_STRENGTHEN_LV, taskParam) TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_STRENGTHEN_TIMES, lv) this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL) -- 装备强化之后发送装备强化信息 EquipAndAppear.updateequipgmext(actor, itemid, dddd.strengthlv) LogManager.RoleStrenthenEquip(actor) end ---获取玩家装备累计强化次数 function EquipAndAppear.GetEquipStrengthCount(actor) local totalCount = getplaydef(actor, ROLE_EQUIP_STRENGTH_TIMES) if totalCount == nil then totalCount = 0 end return totalCount end function EquipAndAppear.updateequipgmext(actor, itemid, strengthlv) -- local gmext = getequipgmext(actor,itemid) -- if gmext == nil or gmext == "null" then -- gmext = {} -- end local gmext = {} gmext.strengthlv = strengthlv setequipgmext(actor, itemid, gmext) end function splitbyshuxianandjinghao2(str) local dt = {} local data = string.split(str, "|") for _, v in ipairs(data) do local data2 = string.split(v, "#") dt[data2[1]] = data2[2] end return dt end -- 装备追加 function EquipAndAppear.luaappendequip(actor, msgData) local itemid = msgData.itemId local equip = getequipinfo(actor, itemid, 1) if equip == nil then return end local alldata = EquipAndAppear.getLuaItemExtData(actor) local equipdata = API.GetItemDataSrc(actor, itemid) if equipdata == nil then EquipAndAppear.initequipluaextdata(alldata, itemid) equipdata = alldata[itemid] end if equipdata.appendlv == nil then equipdata.appendlv = 0 equipdata.appendattr = {} end local lv = equipdata.appendlv + 1 local cfgId = equip.cfgid -- 首饰的强化等级特殊处理 local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId) if group ~= nil and group ~= "" then local appendsmaxLevel = ConfigDataManager.getTableValue("cfg_equip_ornaments", "appendsmaxLevel", "ornamentsGroup", group, "lv", equipdata.ssuplv or 0) if tonumber(appendsmaxLevel) < lv then sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级") return end else local maxLevel = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", cfgId) if tonumber(maxLevel) < lv then sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已追加到最大等级") return end end local costId = ConfigDataManager.getTableValue("cfg_equip_appends", "costId", "id", cfgId) local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", cfgId) -- 获取消耗 local coststr = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "cost", "costGroupId", costId, "level", lv) if coststr == nil then return end local cost = splitbyshuxianandjinghao(coststr) -- 校验道具是否足够 local enough = Bag.checkItemEnough(actor, cost) if enough == false then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣材料 for _, v in ipairs(cost) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 获取成功率 local rate = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "rate", "costGroupId", costId, "level", lv) local randomNumber = math.random(1, 10000) rate = tonumber(rate) if rate < randomNumber then -- 失败,校验是否等级回退 local failLevel = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "failLevel", "costGroupId", costId, "level", lv) failLevel = tonumber(failLevel) -- if not equip.isbind then -- changeitembindstate(actor,itemid,1) -- local res = {itemId = itemid,bindId = true} -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res) -- end if failLevel == equipdata.appendlv then -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.appendlv = tonumber(failLevel) dddd.issuccess = false sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd) return end local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", failLevel) local attr = splitbyshuxianandjinghao2(att) equipdata.appendlv = failLevel equipdata.appendattr = attr EquipAndAppear.SetItemExtData(actor, itemid, equipdata) setplaydef(actor, "T$luaitemextdata", alldata) info(actor, "玩家", actor, "追加装备至" .. lv .. "级失败,失败后等级" .. failLevel, "道具id" .. itemid, "cfgId:" .. cfgId) -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.appendlv = tonumber(failLevel) dddd.issuccess = false sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd) EquipMaster.appendMaster(actor) return end -- 获取属性加成 local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", lv) local attr = splitbyshuxianandjinghao2(att) equipdata.appendlv = lv equipdata.appendattr = attr EquipAndAppear.SetItemExtData(actor, itemid, equipdata) setplaydef(actor, "T$luaitemextdata", alldata) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) local firstRate = ConfigDataManager.getTableValue("cfg_equip_appendsCost", "firstRate", "costGroupId", costId, "level", lv) firstRate = tonumber(firstRate) if firstRate == 1 then -- 发送跑马灯 local name = getrolefield(actor, "role.basic.name") local equipName = ConfigDataManager.getTableValue("cfg_item", "name", "id", cfgId) -- local content = "恭喜" .. name .. "将" .. equipName .. "追加至" .. lv .. "级" -- local horseled = {} -- horseled.cfgId = 115 -- horseled.content = content -- sendluamsg(actor, LuaMessageIdToClient.HORSE_LAMP, horseled) noticeTip.noticeinfo(actor, 115, name, equipName, lv) end -- 给客户端发强化结果 local dddd = {} dddd.itemId = itemid dddd.appendlv = tonumber(lv) dddd.issuccess = true sendluamsg(actor, LuaMessageIdToClient.APPEND_EQUIP_RESULT, dddd) info(actor, "玩家", actor, "追加装备至" .. lv .. "级成功", "道具id" .. itemid, "cfgId:" .. cfgId) -- if not equip.isbind then -- changeitembindstate(actor,itemid,1) -- local res = {itemId = itemid,bindId = true} -- sendluamsg(actor,LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE,res) -- end EquipMaster.appendMaster(actor) this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_APPEND_LEVEL) -- 刷新任务进度 local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId) local taskParam = { part = strPart, level = lv } TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND, taskParam) TaskHandler.TriggerTaskGoal(actor, TaskTargetType.EQUIP_APPEND_TOTAL_LV) LogManager.RoleAppendEquip(actor) end function EquipAndAppear.setAppendLv(actor, itemid, lv) local equip = getequipinfo(actor, itemid, 1) if equip == nil then return end local cfgId = equip.cfgid local alldata = EquipAndAppear.getLuaItemExtData(actor) local equipdata = API.GetItemDataSrc(actor, itemid) if equipdata == nil then EquipAndAppear.initequipluaextdata(alldata, itemid) equipdata = alldata[itemid] end if equipdata.appendlv == nil then equipdata.appendlv = 0 equipdata.appendattr = {} end local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", cfgId) -- 获取属性加成 local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", lv) local attr = splitbyshuxianandjinghao2(att) equipdata.appendlv = lv equipdata.appendattr = attr EquipAndAppear.SetItemExtData(actor, itemid, equipdata) setplaydef(actor, "T$luaitemextdata", alldata) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) end --- 获取所有装备数据 function EquipAndAppear.getLuaItemExtData(actor) local alldata = getplaydef(actor, "T$luaitemextdata") if alldata == nil then -- 说明还没有进行过锻造 setplaydef(actor, "T$luaitemextdata", {}) alldata = getplaydef(actor, "T$luaitemextdata") end return alldata end -- 装备属性转移 function EquipAndAppear.luatransferequip(actor, msgData) local firstId = msgData.firstItem local secId = msgData.secondItem local equip1 = getequipinfo(actor, firstId, 1) if equip1 == nil then return end local equip2 = getequipinfo(actor, secId, 1) if equip2 == nil then return end local id1 = equip1.cfgid local id2 = equip2.cfgid local data1 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id1) local data2 = ConfigDataManager.getTable("cfg_equip_transfer", "id", id2) if (data1 == nil) or (data2 == nil) or (data1.transferGroup ~= data2.transferGroup) or (data1.transfer ~= data2.transfer) then return end local ts = msgData.transferStrength -- bool类型 local ta = msgData.transferAppend local tr = msgData.transferRegeneration if not ts and not ta and not tr then return end -- 扩展数据 local extdata = getplaydef(actor, "T$luaitemextdata") local ext1 = extdata[firstId] local ext2 = extdata[secId] if ext2 == nil then ext2 = {} ext2.appendattr = {} ext2.strengthattr = {} ext2.appendlv = 0 ext2.strengthlv = 0 end -- 转移前强化追加 info(actor, "转移前强化追加等级,rid:", actor, "强化等级:", ext1.strengthlv, ext2.strengthlv, "追加等级:", ext1.appendlv, ext2.appendlv, "主装备id:" .. firstId .. "主装备cfgId:" .. id1, "副装备id:" .. secId .. "副装备cfgId:" .. id2) local allCost = {} -- 强化消耗 if ts then local lv1 = ext1.strengthlv local lv2 = ext2.strengthlv if lv2 ~= 0 then return end local costItem = data1[1].strengthencost local cost = splittransfercoststr(costItem) local realLv = 0 local realCost = {} for key, value in pairs(cost) do if key > realLv and key <= lv1 then realLv = key realCost = value end end table.insert(allCost, realCost) end if table.count(allCost[1]) == 0 then allCost[1] = {} end -- 追加消耗 if ta then local lv1 = ext1.appendlv local lv2 = ext2.appendlv if lv2 ~= 0 then return end local costItem = data1[1].appendscost local cost = splittransfercoststr(costItem) local realLv = 0 local realCost = {} for key, value in pairs(cost) do if key > realLv and key <= lv1 then realLv = key realCost = value end end for _, value in pairs(realCost) do local cId = value["cfgid"] local num = value["count"] local n = 0 for _1, v in pairs(allCost[1]) do if v["cfgid"] == cId then v["count"] = v["count"] + num n = n + 1 end end if n == 0 then table.insert(allCost[1], value) end end end -- 再生消耗 if tr then local lv1 = ext1.regenerationlv local lv2 = ext2.regenerationlv if lv2 == nil then ext2.regenerationlv = 0 lv2 = 0 end if lv2 ~= 0 then return end local costItem = data1[1].regenerationcost local cost = splittransfercoststr(costItem) local realLv = 0 local realCost = {} for key, value in pairs(cost) do if key > realLv and key <= lv1 then realLv = key realCost = value end end for _, value in pairs(realCost) do local cId = value["cfgid"] local num = value["count"] local n = 0 for _1, v in pairs(allCost[1]) do if v["cfgid"] == cId then v["count"] = v["count"] + num n = n + 1 end end if n == 0 then table.insert(allCost[1], value) end end end -- 检查道具是否足够 local enough = Bag.checkItemEnough(actor, allCost[1]) if not enough then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣道具 for _, v in ipairs(allCost[1]) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 转移强化 if ts then local slv1 = ext1.strengthlv ext2.strengthlv = slv1 ext1.strengthlv = 0 ext1.strengthattr = {} -- 赋值属性 local maxLv = ConfigDataManager.getTableValue("cfg_equip_strengthen", "maxLevel", "id", equip2.cfgid) local groupId = ConfigDataManager.getTableValue("cfg_equip_strengthen", "groupId", "id", equip2.cfgid) if ext2.strengthlv > tonumber(maxLv) then ext2.strengthlv = tonumber(maxLv) end local att = ConfigDataManager.getTableValue("cfg_equip_strengthenGroup", "att", "group", groupId, "lv", ext2.strengthlv) local attr = splitbyshuxianandjinghao2(att) ext2.strengthattr = attr EquipAndAppear.updateequipgmext(actor, firstId, 0) EquipAndAppear.updateequipgmext(actor, secId, ext2.strengthlv) end -- 转移追加 if ta then local slv1 = ext1.appendlv ext2.appendlv = slv1 ext1.appendlv = 0 ext1.appendattr = {} -- 赋值属性 local maxLv = ConfigDataManager.getTableValue("cfg_equip_appends", "maxLevel", "id", equip2.cfgid) local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", equip2.cfgid) if ext2.appendlv > tonumber(maxLv) then ext2.appendlv = tonumber(maxLv) end local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", ext2.appendlv) local attr = splitbyshuxianandjinghao2(att) ext2.appendattr = attr end -- 转移再生 if tr then local relv = ext1.regenerationlv ext2.regenerationlv = relv ext1.regenerationlv = 0 ext2.regenerationattr = {} -- 赋值属性 local maxLv = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip2.cfgid) local groupId = ConfigDataManager.getTableValue("cfg_equip_regeneration", "Group", "id", equip2.cfgid) if ext2.regenerationlv > tonumber(maxLv) then ext2.regenerationlv = tonumber(maxLv) end local regeattr = ext1.regenerationattr for _, value in pairs(regeattr) do local id = value.id local regenerationgroup = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id) if table.count(regenerationgroup) ~= 0 then local sequence = regenerationgroup[1].sequence -- 找对应的表 local nexttable = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", groupId, "sequence", sequence, "level", ext2.regenerationlv) if table.count(nexttable) ~= 0 then local att = nexttable[1].att local str = string.split(att, "#") local dd = {} dd[str[1]] = tonumber(str[2]) dd.id = tonumber(nexttable[1].id) ext2.regenerationattr[tostring(table.count(ext2.regenerationattr) + 1)] = dd end end end ext1.regenerationattr = {} end -- 更新数据 extdata[firstId] = ext1 extdata[secId] = ext2 EquipAndAppear.SetItemExtData(actor, firstId, ext1) EquipAndAppear.SetItemExtData(actor, secId, ext2) setplaydef(actor, "T$luaitemextdata", extdata) EquipAndAppear.updateluaextattr(actor) -- 转移后强化追加 info(actor, "转移后强化追加等级,rid:", actor, "强化等级:", ext1.strengthlv, ext2.strengthlv, "追加等级:", ext1.appendlv, ext2.appendlv, "主装备id:" .. firstId .. "主装备cfgId:" .. id1, "副装备id:" .. secId .. "副装备cfgId:" .. id2) if not equip2.isbind then changeitembindstate(actor, secId, 1) local res = { itemId = secId, bindId = true } sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE, res) end -- 检查主装备是否还有强化追加属性 if this.checkEquipStrengthAndAppend(actor, firstId) then -- 变为非绑定 changeitembindstate(actor, firstId, 0) local res = { itemId = firstId, bindId = false } sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_BIND_DATA_CHANGE, res) end EquipMaster.transferTrigger(actor, equip1, equip2, ts, ta) -- 发送lua消息到客户端 local data = {} data.oldItem = firstId data.newItem = secId data.issuccess = true sendluamsg(actor, LuaMessageIdToClient.RES_TRANSFER_EQUIP, data) end function this.checkEquipStrengthAndAppend(actor, itemId) local allData = EquipAndAppear.getLuaItemExtData(actor) local equipData = allData[tonumber(itemId)] if not equipData then return true end local strengthlv = equipData.strengthlv local appendlv = equipData.appendlv if (strengthlv == 0) and (appendlv == 0) then return true end return false end function EquipAndAppear.checkCanTransfer(actor, firstId, secId) if firstId == 0 then return end local data = {} data.oldItem = firstId data.newItem = secId sendluamsg(actor, LuaMessageIdToClient.RES_CAN_TRANSFER, data) end function splittransfercoststr(str) local s = string.split(str, "|") local data = {} for _, value in pairs(s) do local x = string.split(value, "#") local len = #x local itemList = {} if len == 3 then local item = {} item["cfgid"] = x[2] item["count"] = x[3] table.insert(itemList, item) else if len > 3 then for i = 1, len do local item = {} if i == 1 then item["cfgid"] = x[i + 1] item["count"] = x[i + 2] i = i + 3 else item["cfgid"] = x[i] item["count"] = x[i + 1] i = i + 2 end table.insert(itemList, item) end end end data[tonumber(x[1])] = itemList end return data end function EquipAndAppear.updateluaextattr(actor) local alldata = getplaydef(actor, "T$luaitemextdata") local equiplist = getputonequipinfo(actor) local allattr = {} for _, equipinfo in pairs(equiplist) do local itemId = equipinfo.id local data = alldata[itemId] if data ~= nil then -- 将该装备的属性加到角色身上 if data.strengthlv ~= nil then local strengthattr = EquipFunc.getEquipStrengthWearAddAttr(actor, itemId) table.mergeAdd(allattr, strengthattr) end if data.appendlv ~= nil then local appendattr = data.appendattr if appendattr == nil then local groupId = ConfigDataManager.getTableValue("cfg_equip_appends", "groupId", "id", equipinfo.cfgid) local att = ConfigDataManager.getTableValue("cfg_equip_appendsGroup", "att", "group", groupId, "lv", data.appendlv) local attr = splitbyshuxianandjinghao2(att) appendattr = attr end table.mergeAdd(allattr, appendattr) end if data.ssuplv ~= nil then local ssupattr = data.ssupattr local ssactattr = data.ssactattr table.mergeAdd(allattr, ssupattr) table.mergeAdd(allattr, ssactattr) end if data.regenerationlv ~= nil then local reattr = data.regenerationattr local regenerationattr = {} for _, att in pairs(reattr) do for key, value in pairs(att) do if key ~= "id" then local num = regenerationattr[key] if num == nil then num = 0 end regenerationattr[key] = num + value end end end table.mergeAdd(allattr, regenerationattr) end end end -- 更新装备记录 this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_ENTRY_COUNT) -- 记录强化追加等属性 if table.count(allattr) == 0 then addrolekmlattributes(actor, "luaextdataforever", {}) return end addrolekmlattributes(actor, "luaextdataforever", allattr) end -- 首饰升级 function EquipAndAppear.ssupdate(actor, msgData) local itemId = msgData["itemId"] local allequip = getplaydef(actor, "T$luaitemextdata") local equipext = allequip[itemId] if equipext == nil then equipext = {} end if equipext.ssuplv == nil then equipext.ssupattr = {} equipext.ssuplv = 0 equipext.ssactlv = {} equipext.ssactattr = {} end local equip = getequipinfo(actor, itemId, 1) local cfgId = equip.cfgid local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId) if group == nil then return end local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", equipext.ssuplv) if ornaments == nil or table.count(ornaments) == 0 then return end local ornaments2 = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", (equipext.ssuplv or 0) + 1) if ornaments2 == nil or table.count(ornaments2) == 0 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "已经是最大等级!") return end local data = ornaments2[1] local cost = ornaments[1].lvdeplete local costItem = splitbyshuxianandjinghao(cost) -- 检查背包是否道具充足 local enough = Bag.checkItemEnough(actor, costItem) if enough == false then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣材料 for _, v in ipairs(costItem) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 升级,加属性 equipext.ssuplv = tonumber(data.lv) local att = data.basicatt local attr = splitbyshuxianandjinghao2(att) equipext.ssupattr = attr allequip[itemId] = equipext EquipAndAppear.SetItemExtData(actor, itemId, equipext) setplaydef(actor, "T$luaitemextdata", allequip) -- 升级成功 回包给客户端 local result = {} result.ssupattr = equipext.ssupattr result.ssuplv = tostring(equipext.ssuplv) result.ssactlv = equipext.ssactlv result.ssactattr = equipext.ssactattr result.itemId = itemId sendluamsg(actor, LuaMessageIdToClient.RES_UPDATE_EQUIP_ORNAMENTS, result) -- 更新属性 EquipAndAppear.updateluaextattr(actor) -- 更新等级记录 this.TryUpdateEquipInfoRecorde(actor, EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL) -- 刷新任务进度 TaskHandler.TriggerTaskGoal(actor, TaskTargetType.JEWELRY_LV_UP) end -- 首饰等级属性激活 function EquipAndAppear.actssattr(actor, msgData) local itemId = msgData["itemId"] local lv = msgData["lv"] local allequip = getplaydef(actor, "T$luaitemextdata") local equipext = allequip[itemId] if equipext.ssuplv == nil then return end local equip = getequipinfo(actor, itemId, 1) local cfgId = equip.cfgid local group = ConfigDataManager.getTableValue("cfg_equip_ornamentsMain", "ornamentsGroup", "id", cfgId) local ssuplv = equipext.ssuplv if ssuplv < lv then return end if table.contains(equipext.ssactlv, lv) then return end local ornaments = ConfigDataManager.getTable("cfg_equip_ornaments", "ornamentsGroup", group, "lv", lv) if table.count(ornaments) == 0 then return end if ornaments[1].unlockdeplete == nil then return end local unlockDeplete = ornaments[1].unlockdeplete if unlockDeplete == nil then return end local costItem = splitbyshuxianandjinghao(unlockDeplete) -- 检查背包是否道具充足 local enough = Bag.checkItemEnough(actor, costItem) if enough == false then return end -- 扣材料 for _, v in ipairs(costItem) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end equipext.ssactlv[tostring(lv)] = lv local att = ornaments[1].excellenceatt local attr = splitbyshuxianandjinghao2(att) table.mergeAdd(equipext.ssactattr, attr) allequip[itemId] = equipext EquipAndAppear.SetItemExtData(actor, itemId, equipext) setplaydef(actor, "T$luaitemextdata", allequip) -- 发送回包给客户端 local result = {} result.ssupattr = equipext.ssupattr result.ssuplv = equipext.ssuplv result.ssactlv = equipext.ssactlv result.ssactattr = equipext.ssactattr result.itemId = itemId sendluamsg(actor, LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, result) -- 更新属性 EquipAndAppear.updateluaextattr(actor) end function EquipAndAppear.allequipstrengthlv(actor) local alldata = getplaydef(actor, "T$luaitemextdata") local equiplist = getputonequipinfo(actor) local allequipstrengthlv = 0 for _, equipinfo in pairs(equiplist) do local itemId = equipinfo.id local data = alldata[itemId] if data ~= nil then if data.strengthlv ~= nil then allequipstrengthlv = allequipstrengthlv + data.strengthlv end end end return allequipstrengthlv end function EquipAndAppear.allequipappendlv(actor) local alldata = getplaydef(actor, "T$luaitemextdata") local equiplist = getputonequipinfo(actor) local allequipstrengthlv = 0 for _, equipinfo in pairs(equiplist) do local itemId = equipinfo.id local data = alldata[itemId] if data ~= nil then if data.appendlv ~= nil then allequipstrengthlv = allequipstrengthlv + data.appendlv end end end return allequipstrengthlv end function rand_cfgs_weight(cfgs) local weightTotal = 0 for i,v in ipairs(cfgs) do weightTotal = weightTotal + tonumber(v.weight) end local randWeight = math.random(1, weightTotal) for i,v in ipairs(cfgs) do local weight = tonumber(v.weight) if randWeight < weight then return v end randWeight = randWeight - weight end return cfgs[1] end -- 再生 function EquipAndAppear.regeneration(actor, msgData) local itemId = msgData["itemId"] local isUseProtect = msgData.useProtect == true local equip = getequipinfo(actor, itemId, 1) local regenerationlv = API.GetItemData(actor, itemId, "regenerationlv") or 0 local regenerationattr = API.GetItemData(actor, itemId, "regenerationattr") or {} local lv = regenerationlv local tabledata = ConfigDataManager.getTable("cfg_equip_regeneration", "id", equip.cfgid) if table.count(tabledata) == 0 then return end local group = tabledata[1].group -- 获取消耗 local lockattr = msgData["lockattrpos"] local startcost = {} local type = 0 if table.count(regenerationattr) == 0 then startcost = tabledata[1].start type = 1 else if table.count(lockattr) == 0 then startcost = tabledata[1].again type = 2 else startcost = tabledata[1].lock type = 3 end end local cost = getlockcost(startcost, lockattr) -- 校验道具是否足够 local enough = Bag.checkItemEnough(actor, cost) if enough and isUseProtect then enough = Bag.checkItemEnough(actor, {{cfgid="21000110", count="1"}}) end if enough == false then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣道具 for _, v in ipairs(cost) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备再生") end if isUseProtect then removeitemfrombag(actor, 21000110, 1, 0, 9999, "装备再生") end -- 随机词条数量 local attrNum = {} if type == 1 then attrNum = tabledata[1].startnum else if type == 2 then attrNum = tabledata[1].againnum else if type == 3 then attrNum = tabledata[1].locknum end end end local result = random_weighted(attrNum, 1) if lv == 0 then lv = 1 end -- 校验词条数是否超过最大值 local maxAttrNum = tabledata[1].count local realNum = result[1] + table.count(lockattr) if realNum >= tonumber(maxAttrNum) then realNum = tonumber(maxAttrNum) - table.count(lockattr) else realNum = result[1] end -- local attdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "level", lv) local attdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group) local entrytable = build_weight_attr(attdata, regenerationattr, lockattr) local entryattr = random_attr(entrytable, realNum) -- 把这次结果临时存一下 local xilianattr = {} for _, key in pairs(lockattr) do -- xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key) local cfg = ConfigDataManager.getById("cfg_equip_regenerationGroup", key) if cfg == nil then xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key) else local cfgs = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", cfg.group, "sequence", cfg.sequence) local cfgRand = rand_cfgs_weight(cfgs) if cfgRand == nil then xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key) else if isUseProtect then if tonumber(cfgRand.level) > tonumber(cfg.level) then xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(cfgRand.id) else xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key) end else xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(cfgRand.id) end end end end if table.count(lockattr) == 0 then for _, key in pairs(entryattr) do xilianattr[tostring(table.count(xilianattr) + 1)] = tonumber(key) end end local allequiprecord = getplaydef(actor, "T$regeneration") if allequiprecord == nil then allequiprecord = {} end local regenerationresult = {} regenerationresult.entryAttr = xilianattr regenerationresult.itemId = itemId allequiprecord[itemId] = regenerationresult setplaydef(actor, "T$regeneration", allequiprecord) local msg = {} msg.id = itemId msg.attrs = {} msg.attrs.entryAttr = xilianattr -- 告诉客户端本次洗练结果 sendluamsg(actor, LuaMessageIdToClient.RES_EQUIP_REGENERATION, msg) end function EquipAndAppear.getupregenerationattr(actor, msgData) local itemId = msgData.itemId local data = getplaydef(actor, "T$regeneration") if data == nil then sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, {}) return end local result = data[itemId] if result == nil then result = {} end local equipData = {} equipData.id = itemId equipData.attrs = result sendluamsg(actor, LuaMessageIdToClient.RES_UP_REGENERATION_ATTR, equipData) end -- 确认替换词条 function EquipAndAppear.confirmreplaceentry(actor, msgData) -- local lockattr = msgData.lockattrpos local itemId = msgData.itemId local alldata = getplaydef(actor, "T$regeneration") if alldata == nil then sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!") return end local data = alldata[itemId] if data == nil then sendluamsg(actor, LuaMessageIdToClient.TIPS, "洗练后再进行替换!") return end if data.itemId ~= itemId then sendluamsg(actor, LuaMessageIdToClient.TIPS, "两次itemId不一致!") return end local regenerationattr = {} local regenerationlv = 1 for _, id in pairs(data.entryAttr) do local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id) if table.count(td) ~= 0 then local attr = td[1].att local str = string.split(attr, "#") local dd = {} dd[str[1]] = tonumber(str[2]) dd.id = id regenerationattr[tostring(table.count(regenerationattr) + 1)] = dd regenerationlv = tonumber(td[1].level) end end -- EquipAndAppear.SetItemExtData(actor, itemId, ext) -- setplaydef(actor, "T$luaitemextdata", allequip) API.SetItemData(actor, itemId, "regenerationlv", regenerationlv) API.SetItemData(actor, itemId, "regenerationattr", regenerationattr) alldata[itemId] = nil setplaydef(actor, "T$regeneration", alldata) -- 给客户端发替换结果 sendluamsg(actor, LuaMessageIdToClient.RES_REPLACE_REGENERATION_ATTR, true) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) end -- 词条强化 function EquipAndAppear.strengthregenerationattr(actor, msgData) local itemId = msgData.itemId local allequip = getplaydef(actor, "T$luaitemextdata") local ext = allequip[itemId] local equip = getequipinfo(actor, itemId, 1) local group = ConfigDataManager.getTableValue("cfg_equip_regeneration", "group", "id", equip.cfgid) local lv = ext.regenerationlv local data = ConfigDataManager.getTable("cfg_equip_regenerationCost", "group", group, "level", lv) if table.count(data) == 0 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "当前装备词条不能强化!") return end local maxLevel = ConfigDataManager.getTableValue("cfg_equip_regeneration", "levelMax", "id", equip.cfgid) if tonumber(maxLevel) < lv + 1 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "该装备已再生到最大等级") return end local str = data[1].cost local cost = splitbyshuxianandjinghao(str) -- 检查材料 local enough = Bag.checkItemEnough(actor, cost) if enough == false then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具不足") return end -- 扣道具 for _, v in ipairs(cost) do local cId = v["cfgid"] local count = v["count"] removeitemfrombag(actor, cId, count, 0, 9999, "装备外观") end -- 计算成功率 local rate = data[1].rate local randomNum = math.random(1, 10000) if randomNum > tonumber(rate) then -- 强化失败 sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, false) return end -- 强化成功增加属性 local regenerationattr = ext.regenerationattr for i, value in pairs(regenerationattr) do local key = value.id local data = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", key) if table.count(data) ~= 0 then local sequence = data[1].sequence -- 查找下一级属性 local nextdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "sequence", sequence, "level", lv + 1) if table.count(nextdata) ~= 0 then local att = nextdata[1].att local attr = string.split(att, "#") local dd = {} dd[attr[1]] = tonumber(attr[2]) dd.id = tonumber(nextdata[1].id) ext.regenerationattr[i] = dd -- table.remove(ext.regenerationattr,key) end end end ext.regenerationlv = lv + 1 allequip[itemId] = ext EquipAndAppear.SetItemExtData(actor, itemId, ext) setplaydef(actor, "T$luaitemextdata", allequip) -- 给客户端发消息 sendluamsg(actor, LuaMessageIdToClient.RES_STRENGTH_REGENERATION_ATTR, true) -- 更新强化追加等属性 EquipAndAppear.updateluaextattr(actor) -- 更新洗练未替换的数据 updateregenoreplaceattr(actor, itemId, ext.regenerationlv, group) end function updateregenoreplaceattr(actor, itemId, lv, group) local alldata = getplaydef(actor, "T$regeneration") if alldata == nil then return end local data = alldata[itemId] if data == nil then return end local attrs = data.entryAttr if attrs == nil then return end for i, id in pairs(data.entryAttr) do local td = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "id", id) if table.count(td) ~= 0 then local sequence = td[1].sequence -- 查找对应等级属性 local nextdata = ConfigDataManager.getTable("cfg_equip_regenerationGroup", "group", group, "sequence", sequence, "level", lv) if table.count(nextdata) ~= 0 then attrs[i] = tonumber(nextdata[1].id) end end end data.entryAttr = attrs alldata[itemId] = data setplaydef(actor, "T$regeneration", alldata) end function mergeitemcost(cost, lockcost) for _, item in pairs(lockcost) do local flag = true for _, value in pairs(cost) do if item.cfgid == value.cfgid then value.count = value.count + item.count flag = false end end if flag then table.insert(cost, item) end end return cost end function getlockcost(cost, lockattr) local result = {} local locknum = table.count(lockattr) local lc = string.split(cost, "|") local str = {} if locknum ~= 0 then str = string.split(lc[locknum], "&") for _, value in pairs(str) do local item = string.split(value, "#") local i = {} i.cfgid = item[1] i.count = item[2] table.insert(result, i) end else result = splitbyshuxianandjinghao(cost) end return result end -- 根据权重随机词条数量 function 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 random_weighted_one(attrsWeighteds, weightedTotal) local random_weight = math.random(1, weightedTotal) for i,v in ipairs(attrsWeighteds) do if random_weight <= v.weighted then return v end random_weight = random_weight - v.weighted end return attrsWeighteds[1] end function random_attr(attr_str, count) local attrs = string.split(attr_str, "&") local attrsWeighteds = {} local weightedTotal = 0 for i,v in ipairs(attrs) do local attr = string.split(v, "#") local attrId = attr[1] local attrWeighted = tonumber(attr[2]) weightedTotal = weightedTotal + attrWeighted table.insert(attrsWeighteds, {attrId = attrId, weighted = attrWeighted}) end local results = {} for i = 1, count do local attr = random_weighted_one(attrsWeighteds, weightedTotal) if attr ~= nil then table.insert(results, tonumber(attr.attrId)) end end return results end -- 构造随机词条权重库 function build_weight_attr(attdata, regenenrationattr, lockattr) local entrystr = "" local sequences = {} for k, v in pairs(regenenrationattr) do -- local sequence = ConfigDataManager.getTableValue("cfg_equip_regenerationGroup","Countkey","parameter",operateActivityId,"type",_rechargeType()) local cfgRegeneration = ConfigDataManager.getById("cfg_equip_regenerationGroup", v.id) if cfgRegeneration ~= nil and not string.isNullOrEmpty(cfgRegeneration) then sequences[cfgRegeneration.sequence] = tonumber(cfgRegeneration.weightdown) end end for i, value in pairs(attdata) do local len = #entrystr local id = value.id local flag = true for _, k in pairs(lockattr) do if k == id then table.remove(attdata, i) flag = false end end if flag then local weight = 0 local sequence = ConfigDataManager.getTableValue("cfg_equip_regenerationGroup", "sequence", "id", id) if sequences[sequence] ~= nil then weight = sequences[sequence] end if weight == 0 then weight = value.weight end if len == 0 then entrystr = id .. "#" .. weight else entrystr = entrystr .. "&" .. id .. "#" .. weight end end end return entrystr end function getequipssumstrengthlvtest(actor) this.GetSumJewelryLv(actor) end ---获取角色全身装备强化等级 function EquipAndAppear.GetEquipsSumStrengthLv(actor) return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL) end ---获取角色全身装备追加等级 function EquipAndAppear.GetEquipsSumAppendLv(actor) return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_APPEND_LEVEL) end ---获取角色全身装备卓越词条数量(不包含再生词条) function EquipAndAppear.GetEquipsSumExcellentEntryCount(actor) return this.GetEquipsSumExcellentEntryCount(actor) end ---获取角色全身装备卓越词条数量(不包含再生词条) function this.GetEquipsSumExcellentEntryCount(actor) local allEquip = getputonequipinfo(actor) if table.isNullOrEmpty(allEquip) then return 0 end local sumCount = 0 for _, equip in pairs(allEquip) do local entryAttrMap = equip.entries if not table.isNullOrEmpty(entryAttrMap) then sumCount = sumCount + table.count(entryAttrMap) end end return sumCount end ---获取全身首饰等级 function this.GetSumJewelryLv(actor) return this.GetSumLvByType(actor, EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL) end function this.GetSumLvByType(actor, lvType) local equipList = getputonequipinfo(actor) if table.isNullOrEmpty(equipList) then return 0 end local allEquip = EquipAndAppear.getLuaItemExtData(actor) if table.isNullOrEmpty(allEquip) then return 0 end local sumLv = 0 for _, equipInfo in pairs(equipList) do local itemId = equipInfo.id local equip = allEquip[itemId] local lv = this.GetEquipLvByType(equip, lvType) if lv ~= 0 then sumLv = sumLv + lv end end return sumLv end function this.GetEquipLvByType(equip, lvType) if table.isNullOrEmpty(equip) then return 0 end local lv = 0 if lvType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then lv = equip.strengthlv elseif lvType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then lv = equip.appendlv elseif lvType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then lv = equip.ssuplv end if lv == nil then return 0 end return tonumber(lv) end ---更新装备信息记录 function EquipAndAppear.TryUpdateEquipInfoRecorde(actor, recordeType) this.TryUpdateEquipInfoRecorde(actor, recordeType) end ---更新装备信息记录 function this.TryUpdateEquipInfoRecorde(actor, recordeType) local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor) if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then local oldLv = equipInfoRecorde.max_strength_level local newLv = EquipAndAppear.GetEquipsSumStrengthLv(actor) if newLv > oldLv then equipInfoRecorde.max_strength_level = newLv this.SaveEquipInfoRecorde(actor, equipInfoRecorde) end OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_STRENGTHEN_LV, newLv) OpenServerCompetition.updateRankData(actor, CompetitionType.STRENGTHEN, newLv) elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then local oldLv = equipInfoRecorde.max_append_level local newLv = EquipAndAppear.GetEquipsSumAppendLv(actor) if newLv > oldLv then equipInfoRecorde.max_append_level = newLv this.SaveEquipInfoRecorde(actor, equipInfoRecorde) end OpenServerAct.UpdateRankValue(actor, OpenServerAct.StageRank.EQUIP_MAX_APPEND_LV, newLv) OpenServerCompetition.updateRankData(actor, CompetitionType.APPEND, newLv) elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then local oldCount = equipInfoRecorde.max_entry_count local newCount = this.GetEquipsSumExcellentEntryCount(actor) if newCount > oldCount then equipInfoRecorde.max_entry_count = newCount this.SaveEquipInfoRecorde(actor, equipInfoRecorde) OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.SUPERIOR_ENTRY_COUNT, newCount) end elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then local oldLv = equipInfoRecorde.max_jewelry_level local newLv = this.GetSumJewelryLv(actor) if newLv > oldLv then equipInfoRecorde.max_jewelry_level = newLv this.SaveEquipInfoRecorde(actor, equipInfoRecorde) end OpenServerAct.UpdateRankValue(actor, OpenServerAct.RealTimeRank.JEWELRY_LEVEL, newLv) end end function EquipAndAppear.GetEquipInfoRecordeValue(actor, recordeType) local equipInfoRecorde = EquipAndAppear.GetEquipInfoRecorde(actor) if recordeType == EquipAndAppear.RecordeType.MAX_STRENGTH_LEVEL then return equipInfoRecorde.max_strength_level elseif recordeType == EquipAndAppear.RecordeType.MAX_APPEND_LEVEL then return equipInfoRecorde.max_append_level elseif recordeType == EquipAndAppear.RecordeType.MAX_ENTRY_COUNT then return equipInfoRecorde.max_entry_count elseif recordeType == EquipAndAppear.RecordeType.MAX_JEWELRY_LEVEL then return equipInfoRecorde.max_jewelry_level end return 0 end function EquipAndAppear.CheckPartEquipStrengthLv(actor, part, goalLv) local equipList = getputonequipinfo(actor) if table.isNullOrEmpty(equipList) then return false end local allData = EquipAndAppear.getLuaItemExtData(actor) if table.isNullOrEmpty(allData) then return false end for _, equipInfo in pairs(equipList) do local itemId = equipInfo.id local cfgId = equipInfo.cfgid local equipData = allData[itemId] if not table.isNullOrEmpty(equipData) then local strengthLv = equipData.strengthlv if part == nil and strengthLv >= goalLv then return true end if part ~= nil then local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId) if tonumber(strPart) == part and strengthLv >= goalLv then return true end end end end return false end function checkspecificstageequipcounttest(actor) EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, equipType) end ---检查阶段装备数量 function EquipAndAppear.CheckSpecificStageEquipCount(actor, stageLimit, ratingLimit) local allEquip = getputonequipinfo(actor) if table.isNullOrEmpty(allEquip) then return 0 end local sumCount = 0 for _, equip in pairs(allEquip) do local cfgId = equip.cfgid local armor = this.IsArmor(cfgId) if armor then local stage = tonumber(ConfigDataManager.getTableValue("cfg_item", "rank", "id", cfgId)) if stage ~= nil and (stageLimit == nil or stage >= stageLimit) then local rating = EquipAndAppear.GetEquipRating(cfgId) if table.isNullOrEmpty(ratingLimit) or ratingLimit == rating or table.contains(ratingLimit, rating) then sumCount = sumCount + 1 end end end end return sumCount end ---获取装备评级 function EquipAndAppear.GetEquipRating(itemCfgId) local ratingScore = tonumber(ConfigDataManager.getTableValue("cfg_equip_entrylib", "initialrating", "id", itemCfgId)) if ratingScore == nil then return 0 end local equipQualityCfgList = ConfigDataManager.getTable("cfg_equip_quality") if table.isNullOrEmpty(equipQualityCfgList) then return 0 end for rating, equipQualityCfg in pairs(equipQualityCfgList) do local stageParam = string.split(equipQualityCfg["stage"], "#") if ratingScore >= tonumber(stageParam[1]) and ratingScore <= tonumber(stageParam[2]) then return tonumber(rating) end end return 0 end ---是否防具 function this.IsArmor(cfgId) -- 策划要求代码写死 local strPart = tonumber(ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId)) if strPart == nil then return false end if strPart == 4 or strPart == 5 or strPart == 6 or strPart == 7 or strPart == 8 then return true end return false end function EquipAndAppear.SetItemExtData(actor, itemId, equipData) local result = setitemextdata(actor, itemId, equipData) if result == nil or result == false then gameDebug.assertPrintTrace(false, actor, "setitemextdata失败!", itemId, equipData) end end -- -- -- function EquipAndAppear.CheckPartEquipStrengthLv(actor, part,goalLv) -- EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, "strengthlv") -- end -- -- function EquipAndAppear.CheckPartEquipAppendLv(actor, part, goalLv) -- -- end -- -- function EquipAndAppear.CheckPartEquipInfo(actor, part, goalLv, param) -- jprint("--------------1", part, goalLv, param) -- local allData = EquipAndAppear.getLuaItemExtData(actor) -- if table.isNullOrEmpty(allData) then -- return false -- end -- for itemId, equipData in pairs(allData) do -- gameDebug.print("---- equip ----", itemId, equipData) -- local strengthLv = equipData[param] -- if part == nil and strengthLv >= goalLv then -- return true -- end -- if part ~= nil then -- local equip = getequipinfo(actor, itemId,1) -- if not table.isNullOrEmpty(equip) then -- local cfgId = equip.cfgid -- local strPart = ConfigDataManager.getTableValue("cfg_item", "strpart", "id", cfgId) -- if tonumber(strPart) == part and strengthLv >= goalLv then -- return true -- end -- end -- end -- end -- return false -- end -- 新道具入包 function EquipAndAppear.ItemAdd(actor, itemId, itemCfgId) -- 必须是装备 local type = ConfigDataManager.getTableValue("cfg_item", "type", "id", itemCfgId) if tonumber(type) ~= ItemType.EQUIP then return end local itemExtData = getitemextdata(actor, itemId) if itemExtData == nil then return end local allequip = getplaydef(actor, "T$luaitemextdata") or {} allequip[itemId] = itemExtData setplaydef(actor, "T$luaitemextdata", allequip) end -- 喇叭使用,跑马灯 function EquipAndAppear.Horn(actor, msgData) info("MS => EquipAndAppear.Horn", msgData) -- 检查消息内容 local content = msgData.content if not content or content == "" then tipinfo(actor, "消息内容不能为空") return end -- 喇叭道具ID local hornItemId = 23000008 -- 检测背包是否有喇叭道具 local hornCount = getbagitemcountbyid(actor, hornItemId) if not hornCount or tonumber(hornCount) < 1 then tipinfo(actor, "背包中没有喇叭道具") return end -- 消耗一个喇叭道具 local removeResult = removeitemfrombag(actor, hornItemId, 1, 0, 9999, "使用喇叭") if not removeResult then tipinfo(actor, "消耗喇叭道具失败") return end -- 获取玩家名称 local playerName = getbaseinfo(actor, "rolename") info("MS => playerName", playerName) if not playerName then playerName = "未知玩家" end -- 构建跑马灯消息内容 local finalContent = "[" .. playerName .. "]: " .. content -- 发送跑马灯消息给所有玩家 local allPlayers = getallplayer() if allPlayers and #allPlayers > 0 then for _, playerId in pairs(allPlayers) do local playerActor = getactor(playerId) if playerActor then local horseled = {} horseled.cfgId = 109 horseled.content = finalContent sendluamsg(playerActor, LuaMessageIdToClient.HORSE_LAMP, horseled) end end end -- 发送成功提示给使用喇叭的玩家 tipinfo(actor, "喇叭消息发送成功") info("MS => 喇叭消息发送成功", "玩家", playerName, "内容", content) end -- 新增消耗道具逻辑 function EquipAndAppear.addbuffcostitem(actor, itemConfigId, count) local itemId = itemConfigId local uid = getbaseinfo(actor, "uid") info("EquipAndAppear.addbuffcostitem: " .. uid .. " " .. itemConfigId .. " " .. count) if itemConfigId == 60080001 then info("魔剑士id:" .. itemConfigId) unlockusercareer(actor, 4, uid) info("魔剑士已解锁") return elseif itemConfigId == 60080002 then info("圣导师id:" .. itemConfigId) unlockusercareer(actor, 5, uid) info("圣导师已解锁") return elseif itemConfigId == 60080003 then info("召唤师id:" .. itemConfigId) local result = unlockusercareer(actor, 6, uid) info("召唤师已解锁") info("召唤师解锁结果:" .. result) return end -- 检测战旗/纪念戒指词条重置符 if itemId == "60090007" or itemId == 60090007 then info("使用纪念戒指重置符") -- 战旗/纪念戒指词条重置符处理 -- 获取玩家背包中的战旗或纪念戒指 local equipItems = getallequipinfo(actor) if table.isNullOrEmpty(equipItems) then sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置词条的装备(纪念戒指或战旗)") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end local targetItems = {} for _, equip in pairs(equipItems) do local equipCfgId = equip.cfgid -- 检查是否为纪念戒指(23000003)或战旗(23000002) if equipCfgId == 23000003 or equipCfgId == 23000002 then table.insert(targetItems, equip) end end -- 如果没有找到目标装备,提示玩家 if #targetItems == 0 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置词条的装备(纪念戒指或战旗)") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end -- 如果只有一个目标装备,直接处理 if #targetItems == 1 then -- this.resetEquipEntryWithRandomAttrs(actor, 23000003, itemId, count) this.resetEquipEntryWithRandomAttrs(actor, targetItems[1].id, itemId, count) return end -- 如果有多个目标装备,需要玩家选择 -- 这里我们默认选择第一个找到的装备进行处理 -- 需要弹出选择界面 this.resetEquipEntryWithRandomAttrs(actor, targetItems[1].id, itemId, count) return -- 检测战旗/纪念戒指属性重置符 elseif itemId == "60090008" or itemId == 60090008 then info("使用战旗/纪念戒指属性重置符") -- 战旗/纪念戒指属性重置符处理 -- 获取玩家背包中的战旗或纪念戒指 local equipItems = getallequipinfo(actor) if table.isNullOrEmpty(equipItems) then sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置属性的装备(纪念戒指或战旗)") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end local targetItems = {} for _, equip in pairs(equipItems) do local equipCfgId = equip.cfgid -- 检查是否为纪念戒指(23000003)或战旗(23000002) if equipCfgId == 23000003 or equipCfgId == 23000002 then table.insert(targetItems, equip) end end -- 如果没有找到目标装备,提示玩家 if #targetItems == 0 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "背包中没有可以重置属性的装备(纪念戒指或战旗)") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 如果只有一个目标装备,直接处理 if #targetItems == 1 then this.resetEquipPropertyWithFourRandomAttrs(actor, targetItems[1].id, itemId, count) return end -- 如果有多个目标装备,选择第一个找到的装备进行处理 this.resetEquipPropertyWithFourRandomAttrs(actor, targetItems[1].id, itemId, count) return end -- 使用大天使属性重置符 if itemId == "60090009" or itemId == 60090009 then info("使用大天使属性重置符") -- sendluamsg(actor, LuaMessageIdToClient.REQ_RESET_ANGEL_TALENT_POINT, {}) local result = this.useAngelEquipResetItem(actor, itemId, count) if not result then -- 如果使用失败,恢复道具 additemtobag(actor, itemId, count, 0, 9999, '大天使属性重置符使用失败') end return end -- 检查是否为血色城堡通行证 if itemId == "50010013" then local result = this.useBloodyCastleTicket(actor, itemId, count) if not result then -- 如果使用失败,恢复道具 additemtobag(actor, itemId, count, 0, 9999, '血色城堡门票使用失败') end return -- 检查是否为赤色要塞通行证 elseif itemId == "50010014" then local result = this.useRedFortressTicket(actor, itemId, count) if not result then -- 如果使用失败,恢复道具 additemtobag(actor, itemId, count, 0, 9999, '赤色要塞门票使用失败') end return -- 检查是否为卡利玛神庙通行证 elseif itemId == "50010015" then local result = this.useKalimaTempleTicket(actor, itemId, count) if not result then -- 如果使用失败,恢复道具 additemtobag(actor, itemId, count, 0, 9999, '卡利玛神庙门票使用失败') end return end -- 检查是否为大师天赋洗点果实 if itemId == "60090006" then local result = this.useMasterTalentResetFruit(actor, itemId, count) if not result then -- 如果使用失败,恢复道具 additemtobag(actor, itemId, count, 0, 9999, '大师天赋洗点果实使用失败') end return end end -- 使用大天使属性重置符 function this.useAngelEquipResetItem(actor, itemId, count) -- 检查道具数量 local hasCount = getbagitemcountbyid(actor, itemId) if hasCount == nil or tonumber(hasCount) < count then sendluamsg(actor, LuaMessageIdToClient.TIPS, "道具数量不足,无法使用大天使属性重置符") return false end -- 获取玩家身上穿戴的大天使装备(武器、项链、戒指、旗帜) local angelEquips = {} local equipInfo = getputonequipinfo(actor) if not table.isNullOrEmpty(equipInfo) then for _, equip in pairs(equipInfo) do local equipCfgId = equip["cfgid"] -- 检查是否为大天使装备 if AngelMajorEquipment.isAngelEquip(equipCfgId) then -- 检查是否为武器(1)、项链(2)、戒指(3)、旗帜(11) local strPart = ConfigDataManager.getTableValue("cfg_item", "strPart", "id", equipCfgId) if strPart == 1 or strPart == 2 or strPart == 3 or strPart == 11 then table.insert(angelEquips, equip) end end end end -- 如果没有找到符合条件的大天使装备 if #angelEquips == 0 then noticeTip.noticeinfo(actor, "您身上没有穿戴可重置的大天使装备(武器、项链、戒指、旗帜)") return false end -- 扣除道具 removeitemfrombag(actor, itemId, count, 0, 9999, '大天使属性重置符') -- 重置每件装备的属性 for _, equip in pairs(angelEquips) do this.resetAngelEquipRandomAttrs(actor, equip["id"], equip["cfgid"]) end noticeTip.noticeinfo(actor, "成功重置大天使装备属性,生成了3-6条随机属性") return true end -- 重置大天使装备的随机属性 function this.resetAngelEquipRandomAttrs(actor, equipId, equipCfgId) -- 获取装备属性信息 local equipAttr = getplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA) if table.isNullOrEmpty(equipAttr) then equipAttr = {} end local equipInfo = equipAttr[equipId] if table.isNullOrEmpty(equipInfo) then equipInfo = {} end -- 获取装备当前等级 local level = equipInfo["level"] or 1 -- 获取装备组ID local groupId = ConfigDataManager.getTableValue("cfg_equip_angelGroup", "angelEquipGroup", "id", equipCfgId) if not groupId then return false end -- 获取该等级的属性配置 local attrConfig = ConfigDataManager.getTable("cfg_equip_angelAtt", "ornamentsGroup", groupId, "lv", level) if table.isNullOrEmpty(attrConfig) then return false end -- 随机生成3-6条属性 local minAttrs = 3 local maxAttrs = 6 local attrCount = math.random(minAttrs, maxAttrs) -- 获取所有可用的属性条目(从词条库中) local allEntries = ConfigDataManager.getTable("cfg_equip_angelEntry") if table.isNullOrEmpty(allEntries) then return false end -- 筛选出合适的属性组(根据装备类型) local validEntries = {} -- 根据装备配置ID判断装备类型并选择合适的属性组范围 local groupStart = 101 -- 1级绿色品质属性组 local groupEnd = 804 -- 8级金色品质属性组 for _, entry in pairs(allEntries) do if entry.group >= groupStart and entry.group <= groupEnd then table.insert(validEntries, entry) end end -- 随机选择属性条目并生成属性值 local selectedAttrs = {} for i = 1, math.min(attrCount, #validEntries) do if #validEntries <= 0 then break end local randomIndex = math.random(1, #validEntries) local entry = validEntries[randomIndex] table.remove(validEntries, randomIndex) -- 从该条目中随机选择一个属性 local attList = entry.att if not table.isNullOrEmpty(attList) then local randomAttIndex = math.random(1, #attList) local att = attList[randomAttIndex] -- 生成属性值(在配置的范围内随机) local attrId = att[1] local minValue = att[2] local maxValue = att[3] local value = math.random(minValue, maxValue) -- 累加相同属性的值 selectedAttrs[attrId] = (selectedAttrs[attrId] or 0) + value end end -- 构造属性字符串 local attrString = "" local attrIndex = 1 for attrId, value in pairs(selectedAttrs) do if attrIndex > 1 then attrString = attrString .. "|" end attrString = attrString .. attrId .. "#" .. value attrIndex = attrIndex + 1 end -- 更新装备属性信息 equipInfo["level"] = level equipInfo["exp"] = equipInfo["exp"] or 0 equipInfo["rank"] = equipInfo["rank"] or 0 equipInfo["grails"] = equipInfo["grails"] or {} equipAttr[equipId] = equipInfo setplaydef(actor, PlayerDefKey.angel.ANGEL_EQUIPMENT_ATTR_DATA, equipAttr) -- 移除旧属性 local attrKey = string.format(RoleAttrKey.ANGEL_MAJOR_EQUIPMENT, equipId) RoleAttr.clearRoleAttrAndDB(actor, attrKey) -- 添加新属性 if attrString ~= "" then local attrTable = string.split(attrString, "|") local temp = {} for _, attr in pairs(attrTable) do local tmps = string.split(attr, "#") local attrId = tmps[1] local attrValue = tmps[2] if tonumber(attrValue) ~= 0 then temp[tonumber(attrId)] = tonumber(attrValue) end end RoleAttr.addAndSaveRoleAttr(actor, attrKey, temp) end -- 发送更新后的属性信息给客户端 local res = {} res[equipId] = equipInfo sendluamsg(actor, LuaMessageIdToClient.RES_ALL_ANGEL_EQUIPMENT_ATTR_INFO, res) return true end -- 重置装备词条为随机属性(排除减伤属性) function this.resetEquipEntryWithRandomAttrs(actor, equipId, itemId, count) info("使用战旗/纪念戒指词条重置符,重置装备ID:", equipId) -- 获取装备信息 local equipInfo = getequipinfo(actor, equipId, 1) -- info("装备信息:", equipInfo) if not equipInfo or equipInfo == nil then sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取装备信息") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end 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, "无法获取词条配置") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end -- 定义减伤属性ID(需要排除) local excludedEntryId = 26 info("总词条数量:", #allEntries) -- 过滤可用的词条(排除减伤属性)并构建带权重的列表 local availableEntries = {} local totalWeight = 0 for _, entry in ipairs(allEntries) do -- 确保不包含减伤属性 if entry.id ~= excludedEntryId and entry.id ~= 36 and entry.id ~= 37 and entry.id ~= 38 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, "没有可用的词条") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end info("可用词条数量:", #availableEntries, "总权重:", totalWeight) -- 根据阶梯状概率选择词条数量(2条:3条:4条 = 60%:30%:10%) local entryCountWeights = {{ count = 2, weight = 60 }, { count = 3, weight = 30 }, { count = 4, weight = 10 }} local totalCountWeight = 0 for _, cw in ipairs(entryCountWeights) do totalCountWeight = totalCountWeight + cw.weight end local randomCountValue = math.random(1, totalCountWeight) local cumulativeCountWeight = 0 local entryCount = 2 -- 默认2条 for _, cw in ipairs(entryCountWeights) do cumulativeCountWeight = cumulativeCountWeight + cw.weight if randomCountValue <= cumulativeCountWeight then entryCount = cw.count break end end 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) -- 应用新的词条到装备 local result = resetequipentry(actor, equipId, selectedEntries) -- info("resetequipentry结果:", result) if not result then sendluamsg(actor, LuaMessageIdToClient.TIPS, "词条重置失败") additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指词条重置符使用失败') return end -- 删除使用的道具 local bagIdx = gainbagidxbyitemid(actor, itemId) if bagIdx and bagIdx > 0 then removeitembyidxlist(actor, {bagIdx}, 0, "词条重置") end -- 发送成功消息 sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备词条重置成功!") return true end -- 重置装备属性为四个随机属性(专门用于60090008道具,仅限四属性的战旗和纪念戒指) function this.resetEquipPropertyWithFourRandomAttrs(actor, equipId, itemId, count) info("使用战旗/纪念戒指属性重置符,重置装备ID:", equipId) -- 获取装备信息 local equipInfo = getequipinfo(actor, equipId, 1) info("装备信息:", equipInfo) if not equipInfo or equipInfo == nil then sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取装备信息") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 检查装备是否为四属性装备(纪念戒指23000003或战旗23000002) local equipCfgId = equipInfo.cfgid if equipCfgId ~= 23000003 and equipCfgId ~= 23000002 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "只能对纪念戒指或战旗使用此道具") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 检查装备当前是否具有四个属性 local entries = equipInfo.entries if not entries or table.count(entries) ~= 4 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "只能对具有四个属性的装备使用此道具") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 获取所有词条配置 local allEntries = ConfigDataManager.getTable("cfg_equip_att") info("所有词条配置数量:", allEntries and #allEntries or 0) if not allEntries or allEntries == nil then sendluamsg(actor, LuaMessageIdToClient.TIPS, "无法获取词条配置") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 定义减伤属性ID(需要排除) local excludedEntryId = 312012 -- 过滤可用的词条(排除减伤属性)并构建带权重的列表 local availableEntries = {} local totalWeight = 0 for _, entry in ipairs(allEntries) do -- 确保不包含减伤属性 if entry.id ~= excludedEntryId 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 info("可用词条数量:", #availableEntries, "总权重:", totalWeight) if #availableEntries == 0 then sendluamsg(actor, LuaMessageIdToClient.TIPS, "没有可用的词条") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 固定选择4个属性 local propertyCount = 4 local selectedProperties = {} -- 创建一个副本来避免重复选择 local tempAvailableEntries = {} for i, weightedEntry in ipairs(availableEntries) do tempAvailableEntries[i] = { entry = weightedEntry.entry, weight = weightedEntry.weight } end local tempTotalWeight = totalWeight -- 生成4个随机属性(使用加权随机选择) for i = 1, propertyCount 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) -- 确保最小值不大于最大值 if minValue > maxValue then info(string.format("词条%d最小值大于最大值,交换值: %d > %d", entryCfg.id, minValue, maxValue)) minValue, maxValue = maxValue, minValue end -- 生成随机值 local randomValue local success, errorMsg = pcall(function() randomValue = math.random(minValue, maxValue) return true end) if not success then info(string.format("生成随机值失败: %s, 范围: %d - %d", tostring(errorMsg), minValue, maxValue)) sendluamsg(actor, LuaMessageIdToClient.TIPS, "生成随机值失败") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end info(string.format("生成的随机值: %d", randomValue)) -- 创建属性对象 local propertyEntry = { entryid = entryCfg.id, -- 词条ID attrid = attrId, -- 属性ID value = randomValue -- 随机生成的值 } info("创建的属性对象:", propertyEntry) table.insert(selectedProperties, propertyEntry) info(string.format("已添加第%d个词条到列表", i)) -- 从可用列表中移除已选词条,避免重复 tempTotalWeight = tempTotalWeight - selectedWeightedEntry.weight table.remove(tempAvailableEntries, selectedIndex) end if #selectedProperties ~= 4 then info(string.format("生成的词条数量不正确: 期望4个,实际%d个", #selectedProperties)) sendluamsg(actor, LuaMessageIdToClient.TIPS, "词条生成数量错误") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end info("随机生成的4个词条:", selectedProperties) -- 应用新的属性到装备 local result = resetequipentry(actor, equipId, selectedProperties) info("resetequipentry结果:", result) if not result then sendluamsg(actor, LuaMessageIdToClient.TIPS, "属性重置失败") if itemId and count then additemtobag(actor, itemId, count, 0, 9999, '战旗/纪念戒指属性重置符使用失败') end return end -- 删除使用的道具 if itemId and count then local bagIdx = gainbagidxbyitemid(actor, itemId) if bagIdx and bagIdx > 0 then removeitembyidxlist(actor, {bagIdx}, 0, "属性重置") end end -- 发送成功消息 sendluamsg(actor, LuaMessageIdToClient.TIPS, "装备属性重置成功!") return true end -- 使用血色城堡通行证(ID 50010013) function this.useBloodyCastleTicket(actor, itemId, count) -- 检查道具数量 local hasCount = getbagitemcountbyid(actor, itemId) if hasCount == nil or tonumber(hasCount) < count then noticeTip.noticeinfo(actor, "道具数量不足") return false end -- 获取血色城堡面板信息 local configId = 11001 -- 默认使用第一个血色城堡配置 -- 检查玩家等级是否符合要求 local playerLevel = getbaseinfo(actor, "level") local castleConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId) if castleConfig == nil or #castleConfig == 0 then noticeTip.noticeinfo(actor, "无法获取血色城堡配置信息") return false end local minLevel = castleConfig[1][1] local maxLevel = castleConfig[1][2] if playerLevel < minLevel or playerLevel > maxLevel then noticeTip.noticeinfo(actor, "您的等级不符合该血色城堡的要求") return false end -- 检查今日剩余次数 local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId) local leftCount = getleftcountofactivity(actor, activityId) if leftCount <= 0 then noticeTip.noticeinfo(actor, "今日血色城堡挑战次数已用完") return false end -- 扣除道具 removeitemfrombag(actor, itemId, count, 0, 9999, '血色城堡') -- 请求进入血色城堡 BloodyCastle.ReqEnterBloodyCastle(actor, configId) noticeTip.noticeinfo(actor, "正在进入血色城堡...") return true end -- 使用赤色要塞通行证(ID 50010014) function this.useRedFortressTicket(actor, itemId, count) -- 检查道具数量 local hasCount = getbagitemcountbyid(actor, itemId) if hasCount == nil or tonumber(hasCount) < count then noticeTip.noticeinfo(actor, "道具数量不足") return false end -- 获取赤色要塞配置信息 local configId = 17001 -- 默认使用第一个赤色要塞配置 -- 检查玩家等级是否符合要求 local playerLevel = getbaseinfo(actor, "level") local fortressConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId) if fortressConfig == nil or #fortressConfig == 0 then noticeTip.noticeinfo(actor, "无法获取赤色要塞配置信息") return false end local minLevel = fortressConfig[1][1] local maxLevel = fortressConfig[1][2] if playerLevel < minLevel or playerLevel > maxLevel then noticeTip.noticeinfo(actor, "您的等级不符合该赤色要塞的要求") return false end -- 检查今日剩余次数 local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId) local leftCount = getleftcountofactivity(actor, activityId) if leftCount <= 0 then noticeTip.noticeinfo(actor, "今日赤色要塞挑战次数已用完") return false end -- 扣除道具 removeitemfrombag(actor, itemId, count, 0, 9999, '赤色要塞') -- 请求进入赤色要塞 RedFortress.ReqEnterRedFortress(actor, configId) noticeTip.noticeinfo(actor, "正在进入赤色要塞...") return true end -- 使用卡利玛神庙通行证(ID 50010015) function this.useKalimaTempleTicket(actor, itemId, count) -- 检查道具数量 local hasCount = getbagitemcountbyid(actor, itemId) if hasCount == nil or tonumber(hasCount) < count then noticeTip.noticeinfo(actor, "道具数量不足") return false end -- 获取卡利玛神庙配置信息 local configId = 19001001 -- 默认使用第一个卡利玛神庙配置 -- 检查玩家等级是否符合要求 local playerLevel = getbaseinfo(actor, "level") local templeConfig = ConfigDataManager.getTable("cfg_rep", "level", "id", configId) if templeConfig == nil or #templeConfig == 0 then noticeTip.noticeinfo(actor, "无法获取卡利玛神庙配置信息") return false end local minLevel = templeConfig[1][1] local maxLevel = templeConfig[1][2] if playerLevel < minLevel or playerLevel > maxLevel then noticeTip.noticeinfo(actor, "您的等级不符合该卡利玛神庙的要求") return false end -- 检查今日剩余次数 local activityId = ConfigDataManager.getTableValue("cfg_rep", "type", "id", configId) local leftCount = getleftcountofactivity(actor, activityId) if leftCount <= 0 then noticeTip.noticeinfo(actor, "今日卡利玛神庙挑战次数已用完") return false end -- 扣除道具 removeitemfrombag(actor, itemId, count, 0, 9999, '卡利玛神庙') -- 请求进入卡利玛神庙 KalimaTemple.ReqEnterKalimaTemple(actor, configId) noticeTip.noticeinfo(actor, "正在进入卡利玛神庙...") return true end -- 使用大师天赋洗点果实 function this.useMasterTalentResetFruit(actor, itemId, count) -- 检查道具数量 local hasCount = getbagitemcountbyid(actor, itemId) if hasCount == nil or tonumber(hasCount) < count then noticeTip.noticeinfo(actor, "道具数量不足") return false end -- 检查玩家是否有大师天赋数据 local masterTalentData = getplaydef(actor, "T$大师天赋数据") if masterTalentData == nil or next(masterTalentData) == nil then noticeTip.noticeinfo(actor, "您还没有大师天赋数据") return false end -- 扣除道具 removeitemfrombag(actor, itemId, count, 0, 9999, '大师天赋洗点果实') -- 重置所有类型的大师天赋 for _, masterType in pairs(MasterTalentType) do local msgData = { type = masterType } Master.reqResetMaster(actor, msgData) end noticeTip.noticeinfo(actor, "大师天赋点数已重置") return true end