呼叫方式
Functions.trends.calculateOld(health)
將它記錄為名為 Functions.trends.calculateOld 的相依項目(接受自動完成即可完成此步驟),然後以該名稱呼叫。
作用
使用即時設定檔的歷史時間區間、時鐘與舊版捨入服務,執行歷史生命力快照的趨勢公式。保留其最大生命力的過渡、在滿血或零血時提前停止、加權、錯誤與傳回值數量。空陣列或未記錄任何加權變化的快照只傳回零,而不是 0/0 的結果;這是舊版演算法,而不是經過驗證的預測。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
health | table | false | nil | 以最新者在前的生命力快照,包含 time、value 與 max。為假值的輸入只傳回零,不會讀取時鐘。 |
傳回值
| 1 | number | 依原始的總和/計數公式計算的生命力快照加權變化;輸入為假值或未記錄任何加權變化時為零。 |
|---|---|---|
| 2 | number | nil | 原始的取整時長分段數;結果為單獨的零時省略。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
| 遊戲 API | |||||
|---|---|---|---|---|---|
GetTime |
範例
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




