呼叫方式
Functions.trends.calculate(history, window, noheals, nodmg)
將它記錄為名為 Functions.trends.calculate 的相依項目(接受自動完成即可完成此步驟),然後以該名稱呼叫。
作用
根據加權的傷害與治療歷史估算帶正負號的生命力變化。傷害貢獻負速率,治療貢獻正速率。未提供時間區間時讀取即時設定檔中的時間區間,使用即時時鐘與舊版捨入服務,並保留現有的加權與捨入後時長計算。此輔助函式不會驗證或清理歷史,不會截斷時間戳記,也不保證結果有限。
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
history | table | false | nil | 歷史記錄,包含以最新者在前的傷害與治療陣列,元素為時間/數值項目。為假值的歷史只傳回零,不會讀取時鐘。 |
window | number | false | nil | 加權時間區間,單位為秒;為 nil 或 false 時使用目前設定檔的 damage_history 設定。 |
noheals | boolean | nil | 為真值時略過治療資料流,不讀取其陣列。 |
nodmg | boolean | nil | 為真值時略過傷害資料流,不讀取其陣列。 |
傳回值
| 1 | number | 來自原始公式的帶正負號加權合併速率;格式錯誤或非有限的輸入保留舊版的錯誤/數值行為。 |
|---|---|---|
| 2 | number | nil | 較大的捨入後資料流時長(秒),並非樣本數量,也不能證明是連續觀測。歷史為假值時省略。 |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
- 該版本無法使用(原因請見提示)
- 僅在暴雪的棄用相容層開啟時
| 遊戲 API | |||||
|---|---|---|---|---|---|
GetTime |
範例
local guid = UnitGUID("target")
local history = guid and addon.damageHistory[guid]
if not history then return false end
local rate = Functions.trends.calculate(history, 5, true)
return rate < -1000原始碼
Functions/trends.lua,第 75 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
Functions.trends.calculate(history, window, noheals, nodmg)
if not history then
return 0
end
if not window then
window = addon.db.profile.damage_history
end
local now = GetTime()
local damage_total, damage_count, damage_seconds = 0, 0, 0
local heal_total, heal_count, heal_seconds = 0, 0, 0
local maxoffs, data = 0, {}
if not nodmg then
for _,v in ipairs(history.damage) do
local diff = now - v.time
local scale = window - diff
maxoffs = addon.round(diff)
if maxoffs > window then
break
end
if v.value then
data[maxoffs] = (data[maxoffs] or 0) + (v.value * scale)
end
end
damage_seconds = maxoffs
for i=0,maxoffs do
damage_total = damage_total + (data[i] or 0)
damage_count = damage_count + (window - i)
end
end
if not noheals then
maxoffs, data = 0, {}
for _,v in ipairs(history.heals) do
local diff = now - v.time
local scale = window - diff
maxoffs = addon.round(diff)
if maxoffs > window then
break
end
if v.value then
data[maxoffs] = (data[maxoffs] or 0) + (v.value * scale)
end
end
heal_seconds = maxoffs
for i=0,maxoffs do
heal_total = heal_total + (data[i] or 0)
heal_count = heal_count + (window - i)
end
end
return (((damage_count > 0) and (-damage_total / damage_count) or 0) +
((heal_count > 0) and (heal_total / heal_count) or 0)),
(damage_seconds > heal_seconds and damage_seconds or heal_seconds)




