evolve
Магазин/Общие библиотеки

lotus

The lotus pools: how many lotuses each holds and when the next one grows.

hunnyc0 скриптов используют
ПоддержкаИсходник открыт
Подключить в скрипт
pack.json
"requires": { "lotus": "^1.0" }
твой lua
local lotus = require("lib/lotus")

Игрокам ставить ничего не нужно: скрипт приносит библиотеку сам, любую версию в пределах диапазона. Правку можно проверить до публикации в dev-сессии, в scripts/lib/lotus/.

API
lotus.interval(mode?: integer|nil): number#

seconds between two lotuses in this game mode

Параметры
mode integer|nil gamerules.game_mode(); nil reads the live one
Возвращает
number
lotus.next_at(t: number, mode?: integer|nil): number#

game time of the next lotus at or after t, by the clock alone (no contest, pool not full)

Параметры
t number game clock, 0 at the horn
mode integer|nil
Возвращает
number
lotus.next_in(t: number, mode?: integer|nil): number#

seconds to the next lotus by the clock alone

Параметры
t number
mode integer|nil
Возвращает
number
lotus.pools(io?: table|nil): table[]#

every lotus pool now, one row each

Параметры
io table|nil injected reads (selftest); nil = the live api
Возвращает
table[] { entity, pos, count, max, next_in, total, frac, full, contested, source }
lotus.reset()#

forget the per pool memory (a new game)

Описание

lib/lotus

The lotus pools: how many lotuses each holds and when the next one grows. One source for the uTEA lotus timer, the advisor (next_lotus_in) and the map clock (clock.next_spawn("lotus")).

local L = require("lib/lotus")

L.interval()          -- 180, or 90 in turbo (gamerules.game_mode() == 23)
L.next_in(t, mode)    -- seconds to the next lotus by the clock alone, t = gamerules.game_time()
for _, r in ipairs(L.pools()) do
    -- r.count (0..6 or nil), r.next_in (nil when full), r.frac 0..1, r.full, r.contested,
    -- r.source = "pool" (full) | "anchor" | "clock", r.pos, r.entity
end

Schedule (7.42, dota_data and liquipedia Lotus Pool): one lotus every 180 s, 90 s in turbo, up to 6, the first one interval after the horn. Before #1340 every consumer had its own 180 and the timer was off by half in turbo.

The clock is only right while nobody stands in a pool: since 7.41 an enemy hero in the radius runs the countdown backwards, and a full pool does not count. The client sees only the count: the npc_dota_thinker at each pool carries modifier_passive_lotus_pool and its stacks are the lotuses there. The pool entity holds only modifier_passive_lotus_pool_building, and the countdown fields (m_nRespawnSeconds, m_nLotusesAvailable) stay on the server and read 0 (lab, 2026-12-05). So L.pools() anchors the clock on the last spawn it saw ("anchor"), or on a pickup off a full pool, and uses the plain clock before that. Past due by more than 1 s with no new lotus means someone is in the pool: contested, next_in 0.

Test: tools\lua\lua.exe scripts\lib\lotus\selftest.lua from the repo root. It also fails on a lotus constant or a lotus row of numbers left in the three consumers.

Исходник

Код версии 1.0.0, как его получает клиент. Байткод в сборке собран из этих файлов.

init.lua151 строк
-- the lotus pools: how many lotuses each holds and when the next one grows.
-- the schedule (dota_data + liquipedia Lotus Pool, 7.42): one lotus every 180 s, 90 s in turbo
-- (game mode 23), up to 6, the first one interval after the horn. the cvars agree
-- (dota_lotus_respawn_time 180, dota_lotuses_max 6).
-- the clock alone is only right until someone stands in a pool: since 7.41 an enemy hero in the
-- radius runs the countdown backwards, and a full pool does not count at all. so the live read
-- (the lotus count on the pool's thinker) anchors the clock on the last spawn it saw.
local L = {
    PATCH = "7.42",
    INTERVAL = 180,
    TURBO_INTERVAL = 90,
    MAX = 6,
    TURBO_MODE = 23,
    UNIT = "npc_dota_lotus_pool",
}

---seconds between two lotuses in this game mode
---@param mode integer|nil gamerules.game_mode(); nil reads the live one
---@return number
function L.interval(mode)
    if mode == nil and type(gamerules) == "table" and type(gamerules.game_mode) == "function" then
        local ok, m = pcall(gamerules.game_mode)
        mode = ok and m or nil
    end
    return mode == L.TURBO_MODE and L.TURBO_INTERVAL or L.INTERVAL
end

---game time of the next lotus at or after t, by the clock alone (no contest, pool not full)
---@param t number game clock, 0 at the horn
---@param mode integer|nil
---@return number
function L.next_at(t, mode)
    local every = L.interval(mode)
    t = t or 0
    if t <= every then return every end
    return every * math.ceil(t / every)
end

---seconds to the next lotus by the clock alone
---@param t number
---@param mode integer|nil
---@return number
function L.next_in(t, mode) return L.next_at(t, mode) - (t or 0) end

-- ------------------------------------------------------------------ live read

-- the count lives on a thinker at the pool, not on the pool: npc_dota_thinker carries
-- modifier_passive_lotus_pool and its stacks are the lotuses there (lab 2026-12-05: stacks 1, 2, 3
-- at 3:00, 6:00, 9:00 by the client clock). its fields (m_nRespawnSeconds, m_nLotusesAvailable)
-- stay on the server and read 0 here, so the countdown is the clock from the last spawn we saw.
-- the modifier can be missing from the thinker's list while the pool is empty: count nil then.
L.MOD = "modifier_passive_lotus_pool"
L.THINKER = "npc_dota_thinker"
local NEAR2 = 400 * 400

-- reads are injectable so the selftest runs without a client:
--   io = { pools = fn() -> {Entity}, thinkers = fn() -> {Entity}, mods = fn(e) -> {modifier table},
--          pos = fn(e) -> Vector, clock = fn() -> game time, mode = fn() -> int }
local function names(sub)
    local ok, list = pcall(entities.names_like, sub)
    return ok and list or {}
end
local function live_io()
    return {
        pools = function() return names(L.UNIT) end,
        thinkers = function() return names(L.THINKER) end,
        mods = function(e) local ok, m = pcall(e.modifiers, e); return ok and m or nil end,
        pos = function(e) local ok, p = pcall(e.position, e); return ok and p or nil end,
        clock = function() local ok, t = pcall(gamerules.game_time); return ok and t or 0 end,
        mode = function() local ok, m = pcall(gamerules.game_mode); return ok and m or nil end,
    }
end

local function stacks_of(io, e)
    local mods = io.mods(e)
    if type(mods) ~= "table" then return nil end
    for i = 1, #mods do
        local m = mods[i]
        if m.name == L.MOD then return type(m.stacks) == "number" and m.stacks or 0 end
    end
    return nil
end

-- the thinker nearest the pool, within 400
local function thinker_of(io, pos, thinkers)
    if not pos then return nil end
    local best, bd
    for i = 1, #thinkers do
        local q = io.pos(thinkers[i])
        if q then
            local dx, dy = q.x - pos.x, q.y - pos.y
            local d = dx * dx + dy * dy
            if d <= NEAR2 and (not bd or d < bd) then best, bd = thinkers[i], d end
        end
    end
    return best
end

-- per pool memory: the count we saw last and when it changed, the clock fallback anchors on it
local seen = {}

---every lotus pool now, one row each
---@param io table|nil injected reads (selftest); nil = the live api
---@return table[] rows { entity, pos, count, max, next_in, total, frac, full, contested, source }
function L.pools(io)
    io = io or live_io()
    local t, mode = io.clock() or 0, io.mode()
    local every = L.interval(mode)
    local rows = {}
    local list = io.pools() or {}
    local thinkers = #list > 0 and (io.thinkers() or {}) or {}
    for i = 1, #list do
        local e = list[i]
        local pos = io.pos(e)
        local mem = seen[e] or {}   -- entity userdata is interned, a key works
        seen[e] = mem
        local th = thinker_of(io, pos, thinkers)
        local count = th and stacks_of(io, th) or nil
        if count == nil and t < every then count = 0 end   -- the modifier shows up with the first lotus
        -- a new lotus, or a pickup off a full pool, restarts the countdown: anchor the clock there
        if count ~= nil and mem.count ~= nil and count ~= mem.count then
            if count > mem.count or mem.count >= L.MAX then mem.anchor = t end
        end
        if count ~= nil then mem.count = count end
        local full = count ~= nil and count >= L.MAX
        local left, src, contested = nil, nil, false
        if not full then
            if mem.anchor then
                left, src = mem.anchor + every - t, "anchor"
                -- past due with no new lotus: an enemy in the pool is running it back
                if left < -1 then left, contested = 0, true end
                left = math.max(0, left)
            else
                left, src = L.next_in(t, mode), "clock"
            end
        end
        rows[#rows + 1] = {
            entity = e, pos = pos, count = count, max = L.MAX,
            next_in = left, total = every,
            frac = full and 1 or math.max(0, math.min(1, 1 - left / every)),
            full = full, contested = contested, source = full and "pool" or src,
        }
    end
    return rows
end

---forget the per pool memory (a new game)
function L.reset() seen = {} end

return L
pack.json2 строк
{ "kind": "lib", "version": "1.0.0" }
Изменения

Заметок к версиям нет.

Используют

Пока ни один опубликованный скрипт её не требует.

Ещё у этого автора

Ещё у этого автора

order_watch

от hunnyc

Watches the orders our scripts send and reports three invariants as a red line with the module names (#1184):

pack.json
"requires": { "order_watch": "^1.0" }
твой lua
local order_watch = require("lib/order_watch")
0 скриптов используютv1.0.0

order_class

от hunnyc

The class an order carries into `hk_order` (#1103): reaction, chain, window, background, owner.

pack.json
"requires": { "order_class": "^1.0" }
твой lua
local order_class = require("lib/order_class")
0 скриптов используютv1.0.0

fog_creeps

от hunnyc

Every enemy lane creep, in sight and in the fog, and the waves they make.

pack.json
"requires": { "fog_creeps": "^1.0" }
твой lua
local fog_creeps = require("lib/fog_creeps")
0 скриптов используютv1.0.0