查看: 48|回复: 1

[Lua] 刀刀货币系统:打怪概率掉货币 + 每日上限 + 连击加成

[复制链接]

46

主题

42

回帖

1212

积分

金牌会员

积分
1212
发表于 2026-6-6 10:19:27 | 显示全部楼层 |阅读模式
分享一个“刀刀货币”玩法脚本,适合做散人服、打金服、活跃回收服。

功能点:
1. 每次攻击怪物都有概率获得货币。
2. 支持每日获取上限,避免脚本挂机刷爆。
3. 连续命中会提高奖励,断档后重新计数。
4. 可按怪物等级提高收益。

建议挂在攻击命中事件或怪物受伤事件里。

-- HitCurrency.lua
-- 刀刀货币:攻击怪物概率获得货币,每日上限,连击加成

local VvApi = {}

function VvApi.getPlayerName(player)
    return player.name
end

function VvApi.getMonsterLevel(monster)
    return monster.level or 1
end

function VvApi.now()
    return os.time()
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.addBindGold(player, amount)
    -- TODO: 替换为加绑定元宝/赞助币/打金点接口
    print("add currency", VvApi.getPlayerName(player), amount)
end

function VvApi.sendMsg(player, msg)
    print(msg)
end

local HitCurrency = {}

HitCurrency.config = {
    rate = 18,             -- 每刀 18% 概率获得
    baseAmount = 1,        -- 基础货币
    dailyLimit = 3000,     -- 每日上限
    comboExpire = 5,       -- 5 秒内连续命中算连击
    comboStep = 20,        -- 每 20 连击加 1
    maxComboBonus = 10,    -- 单次最多额外加 10
}

local function today()
    return os.date("%Y%m%d")
end

local function roll(rate)
    return math.random() * 100 <= rate
end

function HitCurrency.onHit(player, monster)
    if not roll(HitCurrency.config.rate) then
        return false
    end

    local name = VvApi.getPlayerName(player)
    local day = today()
    local dayKey = "hitcoin:day:" .. name
    local totalKey = "hitcoin:total:" .. name
    local lastHitKey = "hitcoin:lasthit:" .. name
    local comboKey = "hitcoin:combo:" .. name

    if VvApi.getVar(dayKey, "") ~= day then
        VvApi.setVar(dayKey, day)
        VvApi.setVar(totalKey, 0)
        VvApi.setVar(comboKey, 0)
    end

    local total = VvApi.getVar(totalKey, 0)
    if total >= HitCurrency.config.dailyLimit then
        return false
    end

    local now = VvApi.now()
    local lastHit = VvApi.getVar(lastHitKey, 0)
    local combo = VvApi.getVar(comboKey, 0)

    if now - lastHit <= HitCurrency.config.comboExpire then
        combo = combo + 1
    else
        combo = 1
    end

    local monsterLevel = VvApi.getMonsterLevel(monster)
    local levelBonus = math.floor(monsterLevel / 50)
    local comboBonus = math.min(math.floor(combo / HitCurrency.config.comboStep), HitCurrency.config.maxComboBonus)
    local amount = HitCurrency.config.baseAmount + levelBonus + comboBonus
    amount = math.min(amount, HitCurrency.config.dailyLimit - total)

    VvApi.addBindGold(player, amount)
    VvApi.setVar(totalKey, total + amount)
    VvApi.setVar(lastHitKey, now)
    VvApi.setVar(comboKey, combo)

    if combo % 50 == 0 then
        VvApi.sendMsg(player, "刀刀货币连击 " .. combo .. ",本次获得 " .. amount .. " 点。")
    end

    return true
end

return HitCurrency

1

主题

228

回帖

1585

积分

金牌会员

积分
1585
发表于 2026-6-6 22:02:02 | 显示全部楼层
独家版本后期最怕的不是功能少,而是脚本结构乱。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表