参考 › 函数参考 › Functions

Functions.trends.calculateOld

公共

调用方式

Functions.trends.calculateOld(health)

将其记录为名为 Functions.trends.calculateOld 的依赖项(接受自动补全即可完成),然后按该名称调用。

作用

使用实时配置文件的历史窗口、时钟和旧版舍入服务,运行历史生命值快照的趋势公式。保留其最大生命值的过渡、在满血或零血时提前停止、加权、错误和返回值数量。空数组或未记录任何加权变化的快照只返回零,而不是 0/0 的结果;这是旧版算法,而不是经过验证的预测。

参数

名称类型作用
healthtable | false | nil以最新者在前的生命值快照,包含 time、value 和 max。为假值的输入只返回零,不会读取时钟。

返回值

1number按原始的总和/计数公式计算的生命值快照加权变化;输入为假值或未记录任何加权变化时为零。
2number | nil原始的取整时长分段数;结果为单独的零时省略。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
GetTime经典旧世TBC 周年版经典进阶服永久服正式服

示例

local now = GetTime()
local snapshots = { { time = now, value = 6000, max = 10000 },
    { time = now - 1, value = 7000, max = 10000 }, { time = now - 2, value = 8000, max = 10000 } }
local change = Functions.trends.calculateOld(snapshots)
return change < 0

源码

Functions/trends.lua,第 21 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Functions.trends.calculateOld(health)
    if not health then
        return 0
    end

    local damage_history = addon.db.profile.damage_history
    local now = GetTime()
    local total, count, seconds = 0, 0, 0

    local last_health, last_offs, last_max
    local offs_total = 0
    for _,v in ipairs(health) do
        if v.value >= v.max or v.value == 0 then
            break
        end

        if last_max ~= v.max then
            last_health = nil
            last_max = v.max
        end

        local offs = addon.round(now - v.time)
        if last_health ~= nil then
            offs_total = offs_total + (last_health - v.value)

            if last_offs ~= offs then
                local scale = damage_history - offs
                count = count + scale
                total = total + (offs_total * scale)
                seconds = seconds + 1
                offs_total = 0
            end
        end
        last_health = v.value
        last_offs = offs
    end

    -- seconds is a number, so test it: with no change recorded (or no weight)
    -- total/count is 0/0, and the trend is zero, not NaN.
    if seconds > 0 and count ~= 0 then
        return total / count, seconds
    end
    return 0

返回函数参考