lua
local MATERIALS = {
GOLD = "Gold", -
ESSENCE = "Essence", -
SOUL = "Soul", -
CRYSTAL = "Crystal" -
local QUALITY = {
COMMON = 1, -
GOOD = 2, -
RARE = 3, -
EPIC = 4, -
LEGEND = 5 -
local DECOMPOSE_RULES = {
[QUALITY.COMMON] = { -
{material = MATERIALS.GOLD, chance = 1.0, min = 5, max = 10},
{material = MATERIALS.ESSENCE, chance = 0.15, min = 1, max = 1}
},
[QUALITY.GOOD] = { -
{material = MATERIALS.GOLD, chance = 1.0, min = 15, max = 30},
{material = MATERIALS.ESSENCE, chance = 0.5, min = 1, max = 2},
{material = MATERIALS.CRYSTAL, chance = 0.08, min = 1, max = 1}
},
[QUALITY.RARE] = { -
{material = MATERIALS.GOLD, chance = 1.0, min = 50, max = 100},
{material = MATERIALS.ESSENCE, chance = 0.8, min = 2, max = 3},
{material = MATERIALS.CRYSTAL, chance = 0.25, min = 1, max = 2},
{material = MATERIALS.SOUL, chance = 0.1, min = 1, max = 1}
},
[QUALITY.EPIC] = { -
{material = MATERIALS.GOLD, chance = 1.0, min = 200, max = 500},
{material = MATERIALS.ESSENCE, chance = 1.0, min = 5, max = 8},
{material = MATERIALS.CRYSTAL, chance = 0.65, min = 2, max = 3},
{material = MATERIALS.SOUL, chance = 0.35, min = 1, max = 2}
},
[QUALITY.LEGEND] = { -
{material = MATERIALS.GOLD, chance = 1.0, min = 1000, max = 2000},
{material = MATERIALS.ESSENCE, chance = 1.0, min = 10, max = 15},
{material = MATERIALS.CRYSTAL, chance = 1.0, min = 3, max = 5},
{material = MATERIALS.SOUL, chance = 0.75, min = 2, max = 4}
local VIP_BONUS = {
[0] = 1.0, -
[1] = 1.05, -
[2] = 1.1, -
[3] = 1.2 -
--[[
分解装备主函数
参数:
itemQuality
vipLevel
返回:
results
]]
function DecomposeEquipment(itemQuality, vipLevel)
local results = {}
local bonusFactor = VIP_BONUS[vipLevel] or 1.0
local rules = DECOMPOSE_RULES[itemQuality]
if not rules then
return results -
end
for _, rule in ipairs(rules) do
local rand = math.random -
local actualChance = rule.chance * bonusFactor
if rand <= actualChance then
local baseAmount = math.random(rule.min, rule.max)
local finalAmount = math.floor(baseAmount * bonusFactor)
table.insert(results, {
type = rule.material,
amount = finalAmount
})
end
end
if itemQuality >= QUALITY.EPIC and #results == 0 then
table.insert(results, {
type = MATERIALS.ESSENCE,
amount = math.random(3, 5)
})
end
return results
end
math.randomseed(tostring(os.time):reverse:sub(1,7))
local decomposeResult = DecomposeEquipment(QUALITY.LEGEND, 2)
print("===== 分解结果 =====")
for i, item in ipairs(decomposeResult) do
print(string.format("获得:%s x %d", item.type, item.amount))
end
脚本核心设计说明:
1. 分层概率系统:
2. 动态概率机制:
lua
local actualChance = rule.chance * VIP_BONUS[vipLevel]
local finalAmount = math.floor(baseAmount * bonusFactor)
3. 保底机制:
lua
if itemQuality >= QUALITY.EPIC and #results == 0 then
end
4. 产出波动设计:
扩展功能建议:
1. 幸运值系统:
lua
local luckBonus = 1 + (luckValue / 100)
actualChance = rule.chance * bonusFactor * luckBonus
2. 套装分解加成:
lua
if isSetEquipment then
finalAmount = finalAmount * 1.5 -
end
3. 全服公告功能:
lua
if itemQuality == QUALITY.LEGEND and material == MATERIALS.SOUL and amount >= 3 then
BroadcastSystemMsg("玩家【"..playerName.."】分解传说装备获得稀有灵魂宝石!")
end
该脚本实现了:
实际使用时,需配合游戏引擎的装备系统调用`DecomposeEquipment`函数,并将返回的分解结果添加到玩家背包中。