--- 宝箱读表随机生成道具 FashionBox = {} local this = {} local fashionReward = "T$fashionReward" --- 使用宝箱生成道具 ---@param actor any 玩家对象 ---@param itemConfigId number 道具配置ID ---@param count number 数量 function FashionBox.generateChestItem(actor, itemConfigId, count) local itemRow = ConfigDataManager.getTable("cfg_item", "id", itemConfigId) if table.isNullOrEmpty(itemRow) then gameDebug.print("RandomChest.generateChestItem itemConfigId error") return end if itemRow[1].fashionbox ~= "1" then return end local allItem = {} if tonumber(itemRow[1].type) == ItemType.BOX and tonumber(itemRow[1].subtype) == ItemSubType.EQUIP_BOX then local rewardRecord = getplaydef(actor, fashionReward) for i = 1, count do local res = this.getItemAndCount(actor, itemRow[1].useparam) allItem = res if table.isNullOrEmpty(res) then gameDebug.print("RandomChest.generateChestItem getItemAndCount res is nil") else for k, v in pairs(res) do local itemId = res[k].cfgid if table.isNullOrEmpty(rewardRecord) then local temp = {} temp[itemId] = 1 setplaydef(actor, fashionReward, temp) else if rewardRecord[itemId] then rewardRecord[itemId] = rewardRecord[itemId] + 1 else rewardRecord[itemId] = 1 end setplaydef(actor, fashionReward, rewardRecord) end end end end end if table.count(allItem) > 0 then -- additemmaptobag(actor, allItem) this.sendRewards(actor, allItem, itemConfigId) this.excHorseLamp(actor, allItem) end end ---发送奖励导背包,并且通知面板消息 ---@param actor any 玩家 ---@param rewardsMap table {道具id=数量,道具id=数量} function this.sendRewards(actor, rewardsMap, itemConfigId, actionDesc) local tipItems = {} -- 变身卡牌需要走批量 local cardRewardMap = {} local otherRewardMap = {} for k, v in pairs(rewardsMap) do local data = rewardsMap[k] local cfgId = data.cfgid local count = data.num local itemCfg = ConfigDataManager.getById("cfg_item", cfgId) if table.notNullOrEmpty(itemCfg) then local itemType = string.tonumber(itemCfg.type) if itemType == ItemType.TRANSFER_CARD then cardRewardMap[cfgId] = count else table.insert(otherRewardMap, v) end end end if table.notNullOrEmpty(cardRewardMap) then if string.isNullOrEmpty(actionDesc) then additemmaptobag(actor, cardRewardMap) else additemmaptobag(actor, cardRewardMap, 0, 9999, actionDesc) end end -- 添加奖励到背包 for k, v in pairs(otherRewardMap) do local data = otherRewardMap[k] local cfgId = data.cfgid local count = data.num local id = data.id local tableValue = ConfigDataManager.getTable("cfg_item", "id", cfgId) if table.isNullOrEmpty(tableValue) then error("Bag.sendRewards cfgId error", cfgId) goto continue end local notEnterPack = tableValue[1]["notenterpack"] local overlying = tableValue[1]["overlying"] if (string.isNullOrEmpty(notEnterPack) or tonumber(notEnterPack) == 0) and (string.isNullOrEmpty(overlying) or tonumber(overlying) <= 1) then for i = 1, count do local itemId if string.isNullOrEmpty(actionDesc) then itemId = additemtobag(actor, cfgId, 1) else itemId = additemtobag(actor, cfgId, 1, 0, 9999, actionDesc) end if (itemId == false or itemId == "false") then error("添加道具失败:", actor, cfgId, count, actionDesc) else local itemRow = ConfigDataManager.getTable("cfg_item", "id", itemConfigId) if itemRow ~= nil and table.count(itemRow) > 0 and itemRow[1].useparam then local cfgFastionBox = ConfigDataManager.getById(itemRow[1].useparam, id) if cfgFastionBox ~= nil then this.resetEquipEntry(actor, cfgFastionBox, itemId) end end end table.insert(tipItems, { ["id"] = itemId, ["cfgId"] = cfgId, ["count"] = 1 }) end else local itemId if string.isNullOrEmpty(actionDesc) then itemId = additemtobag(actor, cfgId, count) else itemId = additemtobag(actor, cfgId, count, 0, 9999, actionDesc) end if (itemId == false or itemId == "false") then error("添加道具失败:", actor, cfgId, count, actionDesc) else local itemRow = ConfigDataManager.getTable("cfg_item", "id", itemConfigId) if itemRow ~= nil and table.count(itemRow) > 0 and itemRow[1].useparam then local cfgFastionBox = ConfigDataManager.getById(itemRow[1].useparam, id) if cfgFastionBox ~= nil then this.resetEquipEntry(actor, cfgFastionBox, itemId) end end end table.insert(tipItems, { ["id"] = itemId, ["cfgId"] = cfgId, ["count"] = count }) end ::continue:: end if table.count(tipItems) > 0 then -- 奖励面板通知 sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, tipItems) end end function this.resetEquipEntry(actor, cfgFastionBox, itemId) if cfgFastionBox == nil then return end -- 获取装备信息 local item = getequipinfo(actor, itemId, 1) if not item or item == nil then return end local entrys = {} if not string.isNullOrEmpty(cfgFastionBox.entryrandom) then local strentrys = string.split(cfgFastionBox.entryrandom, "|") local randnum = math.random(1, table.count(strentrys)) if table.count(strentrys) > 0 and randnum >= 1 and randnum <= table.count(strentrys) then local strAttr = string.split(strentrys[randnum], "#") if table.count(strAttr) > 0 then table.insert(entrys, { entryid = table.count(entrys) + 1, attrid = strAttr[1], value = tonumber(strAttr[2]) }) end end end if not string.isNullOrEmpty(cfgFastionBox.entry) then local strentrys = string.split(cfgFastionBox.entry, "|") for i, v in ipairs(strentrys) do local strAttr = string.split(v, "#") if table.count(strAttr) > 0 then table.insert(entrys, { entryid = table.count(entrys) + 1, attrid = strAttr[1], value = tonumber(strAttr[2]) }) end end end if not string.isNullOrEmpty(cfgFastionBox.fastionlevel) then local lv = tonumber(cfgFastionBox.fastionlevel) -- 刷新装备 API.SetItemData(actor, itemId, "strengthlv", lv) -- 刷新流光 API.refreshLiuGuang(actor, itemId) Equip_QiangHua.RefreshLevel(actor, itemId, tonumber(cfgFastionBox.item)) if lv == 13 then local cfg_item = ConfigDataManager.getById("cfg_item", tonumber(cfgFastionBox.item)) local itemName = cfg_item ~= nil and cfg_item.name or "" -- cfgFastionBox.item local playerName = getbaseinfo(actor, "rolename") noticeTip.noticeinfo(actor, StringIdConst.text35008, playerName, itemName) end end -- 应用新的词条到装备 local result = resetequipentry(actor, itemId, entrys) if not result then return end end function this.excHorseLamp(actor, itemMap) if table.isNullOrEmpty(itemMap) then return end local name = getbaseinfo(actor, "rolename") for k, v in pairs(itemMap) do local data = itemMap[k] local cfgid = data.cfgid local item = ConfigDataManager.getById("cfg_item", cfgid) if not table.isNullOrEmpty(item) then local itemName = item.name local noticeId = item.runninghorselamp if #noticeId > 0 then noticeTip.noticeinfo(actor, noticeId, name, itemName) end end end end --- 获取随机生成的道具数量 ---@param actor any 玩家对象 ---@param tableName string 配置表名 function this.getItemAndCount(actor, tableName) local res = {} local boxConfig = ConfigDataManager.getList(tableName) if table.isNullOrEmpty(boxConfig) then gameDebug.print("RandomChest.generateChestItem useParam error") return res end local idMap = {} -- 职业限制判断 local playerCareer = tonumber(getbaseinfo(actor, "getbasecareer")) -- 等级限制判断 local playerLevel = getbaseinfo(actor, "level") local rewardRecord = getplaydef(actor, fashionReward) for _, config in pairs(boxConfig) do if config.career ~= "" and tonumber(playerCareer) ~= tonumber(string.split(config.career, "#")[1]) then goto tag end local lv_split = string.split(config.level, "#") if config.level ~= "" and (tonumber(playerLevel) < tonumber(lv_split[1]) or tonumber(playerLevel) > tonumber(lv_split[2])) then goto tag end local id = config.id local item = config.item local probability = string.split(config.probability, "|") local pro1 = string.split(probability[1], "#") if tonumber(config.type) == 1 then if not rewardRecord or not rewardRecord[item] then idMap[id] = pro1[2] else for _, v in pairs(probability) do local strs = string.split(v, "#") idMap[id] = tonumber(strs[1]) <= tonumber(rewardRecord[item]) and strs[2] or pro1[2] end end else local weight = pro1[2] if rewardRecord and rewardRecord[item] then for _, v in pairs(probability) do local v_split = string.split(v, "#") if tonumber(v_split[1]) ~= 0 then weight = tonumber(v_split[1]) >= rewardRecord[item] and tonumber(v_split[2]) or tonumber(pro1[2]) end end end if tonumber(randomex(actor, weight, 10000)) == 1 then local num_split = string.split(config.num, "#") table.insert(res, { id = id, cfgid = item, num = math.random(num_split[1], num_split[2]) }) end end ::tag:: end if table.isNullOrEmpty(idMap) then gameDebug.print("RandomChest.generateChestItem itemMap is nil") return res end if tonumber(boxConfig[1].type) == 1 then local id = randombyweight(actor, idMap, 1)[1] local num = ConfigDataManager.getTableValue(tableName, "num", "id", id) local itemId = ConfigDataManager.getTableValue(tableName, "item", "id", id) local num_split = string.split(num, "#") table.insert(res, { id = id, cfgid = itemId, num = math.random(num_split[1], num_split[2]) }) return res else return res end end