레퍼런스 › 함수 레퍼런스 › Functions

Functions.trends.calculateOld

공개

호출 방법

Functions.trends.calculateOld(health)

Functions.trends.calculateOld(이)라는 이름의 의존성으로 기록한 뒤(자동 완성을 수락하면 이렇게 됩니다) 그 이름으로 호출하세요.

하는 일

실시간 프로필 기록 구간, 시각, 이전 반올림 방식으로 과거의 생명력 스냅샷 추세 공식을 실행합니다. 최대 생명력 변화, 생명력이 가득하거나 0일 때의 조기 중단, 가중치, 오류, 반환 개수를 보존합니다. 빈 배열이나 가중 변화가 기록되지 않은 스냅샷은 0/0 결과 대신 0만 반환합니다. 검증된 예측이 아니라 이전 알고리즘입니다.

인수

이름유형하는 일
healthtable | false | niltime, value, max를 담은 최신순 생명력 스냅샷. 입력이 거짓 값이면 시각을 읽지 않고 0만 반환합니다.

반환값

1number원래 합계/개수 공식에 따른 생명력 스냅샷의 가중 변화량이며, 거짓 입력이거나 가중 변화가 기록되지 않았으면 0입니다.
2number | nil반올림된 경과 시간 구간의 원래 개수이며, 결과가 단독 0이면 생략됩니다.

버전

기본 제공 도우미는 모든 버전에 등록됩니다. 다른 점은 읽는 게임 API이며, API가 없으면 도우미는 대체 동작을 하거나 이유와 함께 nil을 반환합니다.

  • 해당 버전에서 사용할 수 없음 (이유는 툴팁에 표시)
  • Blizzard의 지원 중단 대체 함수가 켜져 있을 때만
게임 APIClassic EraTBC AnniversaryClassic progressionForeverRetail
GetTimeClassic EraTBC AnniversaryClassic progressionForeverRetail

예시

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

함수 레퍼런스(으)로 돌아가기