|
|
这个脚本适合用在怪物死亡事件里,解决低概率装备长期不出的问题。
功能点:
1. 支持稀有、史诗、传说三档掉落。
2. 玩家幸运值会提高实际爆率。
3. 怪物等级越高,掉落概率略微提高。
4. 连续未出指定品质时触发保底。
实际使用时,把 DropPity.onMonsterDead(player, monsterLevel) 挂到怪物死亡回调里即可。
-- DropPity.lua
-- 掉落保底:基础爆率、幸运值加成、连续未出保底
local VvApi = {}
function VvApi.getPlayerName(player)
return player.name
end
function VvApi.getPlayerLuck(player)
return player.luck or 0
end
function VvApi.getVar(key, default)
_G.__vv_vars = _G.__vv_vars or {}
local v = _G.__vv_vars[key]
if v == nil then return default end
return v
end
function VvApi.setVar(key, value)
_G.__vv_vars = _G.__vv_vars or {}
_G.__vv_vars[key] = value
end
function VvApi.addItem(player, itemName, count)
print("drop item", VvApi.getPlayerName(player), itemName, count)
end
function VvApi.sendMsg(player, msg)
print(msg)
end
local DropPity = {}
DropPity.config = {
baseRate = {
rare = 8,
epic = 2,
legend = 0.5,
},
pityLimit = {
rare = 25,
epic = 80,
legend = 200,
},
itemPool = {
rare = { "祝福油", "强化石", "技能残页" },
epic = { "高级强化石", "转生证明", "稀有宝石" },
legend = { "传说装备箱", "神铸材料", "顶级技能书" },
},
}
local function rollPercent(rate)
return math.random() * 100 <= rate
end
local function pick(pool)
return pool[math.random(1, #pool)]
end
local function rateWithLuck(baseRate, luck)
local bonus = math.min(luck / 1000, 0.5)
return baseRate * (1 + bonus)
end
function DropPity.onMonsterDead(player, monsterLevel)
local name = VvApi.getPlayerName(player)
local luck = VvApi.getPlayerLuck(player)
local levelBonus = math.min((monsterLevel or 1) / 200, 0.5)
for _, quality in ipairs({ "legend", "epic", "rare" }) do
local counterKey = "drop:pity:" .. quality .. ":" .. name
local counter = VvApi.getVar(counterKey, 0)
local baseRate = DropPity.config.baseRate[quality]
local rate = rateWithLuck(baseRate, luck) * (1 + levelBonus)
local isPity = counter + 1 >= DropPity.config.pityLimit[quality]
if isPity or rollPercent(rate) then
local itemName = pick(DropPity.config.itemPool[quality])
VvApi.addItem(player, itemName, 1)
VvApi.setVar(counterKey, 0)
if isPity then
VvApi.sendMsg(player, "触发保底,获得:" .. itemName)
end
return quality, itemName
end
VvApi.setVar(counterKey, counter + 1)
end
return nil
end
return DropPity
|
|