evolve
商店/共享库

fountain

Where each team's fountain stands and where its heroes respawn.

hunnyc2 个脚本在用
支持源码公开
在脚本中使用
pack.json
"requires": { "fountain": "^1.0" }
你的 lua
local fountain = require("lib/fountain")

玩家无需安装:脚本会自动带上库,取范围内的任一版本。发布前可在开发会话中修改 scripts/lib/fountain/ 来试验。

API
fountain.scan(by_class, team_of, pos_of)#
fountain.of_team(team, opts)#
fountain.xy(team, opts)#
fountain.vec(team, opts)#
fountain.spawn_of(team)#
fountain.reset()#
介绍

lib/fountain

Where each team's fountain stands and where its heroes respawn. The fountain comes from the game first (the C_DOTA_Unit_Fountain entity of that team), then from the map file of the build in PATCH. Spawns come from the map only: info_player_start_<team> has no entity to read.

local FN = require("lib/fountain")

local p, src = FN.of_team(3)   -- { x, y, z }, "game" | "map"
local v      = FN.vec(2)       -- the same as a Vector ({x=, y=, z=} without the native one)
local t      = FN.xy(2)        -- { x =, y =, z = }
local s      = FN.spawn_of(3)  -- { x =, y =, z = }, mean of the five spawn points

7.42 moved dire's fountain from (7408, 6848) to (7152, 6592) and its spawns by ~520 toward the river; radiant's fountain stayed at (-7456, -6938). Before #827 fifteen packs quoted ±(6733, 6163), a spot ~1000 in front of the fountain, as "the fountain". A new build that moves them again: read maps/dota/default_ents.vents in E:\code\dota_data (ent_dota_fountain, info_player_start_*) and change MAP, SPAWN and PATCH.

A failed entity scan is not repeated for 5 s. Test: tools\lua\lua.exe scripts\lib\fountain\selftest.lua from the repo root; tools/test_fountain_literals_827.py fails on a fountain coordinate quoted anywhere else under scripts/.

源码

1.0.0 版本的代码,即客户端拿到的内容。包内字节码由这些文件编译而来。

init.lua81 行
-- where each team's fountain stands. the game first: the C_DOTA_Unit_Fountain entity of that team.
-- then the map file of PATCH (maps/dota.vpk default_ents.vents, ent_dota_fountain origin).
--   7.42 (#827): dire moved (7408, 6848) -> (7152, 6592), radiant unchanged (-7456, -6938)
-- the old helper returned +-(6733, 6163), a spot ~1000 in front of the fountain, not the fountain.
-- SPAWN: mean of the five info_player_start_<team> origins, where a hero comes back to life.
--   7.41 (-6880, -6420) / (7051, 6316); 7.42 dire moved ~520 toward the river
local F = {
    PATCH = "7.42",
    MAP = { [2] = { -7456, -6938, 393 }, [3] = { 7152, 6592, 377 } },
    SPAWN = { [2] = { -6802, -6293, 384 }, [3] = { 6519, 5858, 384 } },
}

local found = {}      -- team -> {x, y, z}; fountains do not move within a build
local miss_at = -1e9  -- last failed scan, so a client without the entity does not rescan per call
local RESCAN = 5

local function clock()
    local ok, t = pcall(function() return os.clock() end)
    return ok and t or 0
end

-- by_class(cls) -> list, team_of(e) -> 2|3, pos_of(e) -> {x, y, z}. defaults read the live api.
function F.scan(by_class, team_of, pos_of)
    by_class = by_class or (type(entities) == "table" and entities.by_class)
    if type(by_class) ~= "function" then return 0 end
    team_of = team_of or function(e) return e:team() end
    pos_of = pos_of or function(e) local p = e:position(); return { p.x, p.y, p.z } end
    local ok, list = pcall(by_class, "C_DOTA_Unit_Fountain")
    if not ok or type(list) ~= "table" then return 0 end
    local n = 0
    for _, e in ipairs(list) do
        local okt, team = pcall(team_of, e)
        local okp, p = pcall(pos_of, e)
        if okt and okp and (team == 2 or team == 3) and type(p) == "table"
            and type(p[1]) == "number" and (p[1] ~= 0 or p[2] ~= 0) then
            found[team], n = p, n + 1
        end
    end
    return n
end

-- {x, y, z} of `team`'s fountain and where it came from ("game" | "map")
function F.of_team(team, opts)
    team = (team == 2) and 2 or 3
    if not found[team] then
        local now = (opts and opts.now) or clock()
        if (opts and opts.force) or now - miss_at >= RESCAN then
            if F.scan(opts and opts.by_class, opts and opts.team_of, opts and opts.pos_of) < 2 then
                miss_at = now
            end
        end
    end
    if found[team] then return found[team], "game" end
    return F.MAP[team], "map"
end

-- {x=, y=, z=} of a fountain or a spawn, the shape most callers keep
function F.xy(team, opts)
    local p = F.of_team(team, opts)
    return { x = p[1], y = p[2], z = p[3] }
end

-- the fountain as a Vector (the native one when there is one, else {x=, y=, z=})
function F.vec(team, opts)
    local p = F.of_team(team, opts)
    if type(Vector) == "function" or (type(Vector) == "table" and getmetatable(Vector)) then
        return Vector(p[1], p[2], p[3])
    end
    return { x = p[1], y = p[2], z = p[3] }
end

-- {x=, y=, z=} where `team`'s heroes respawn (map file only, the spawn has no entity to read)
function F.spawn_of(team)
    local p = F.SPAWN[(team == 2) and 2 or 3]
    return { x = p[1], y = p[2], z = p[3] }
end

function F.reset() found, miss_at = {}, -1e9 end

return F
pack.json2 行
{ "kind": "lib", "version": "1.0.0" }
更新日志

这个作品没有版本说明。

使用它的脚本

该作者的其他作品

该作者的其他作品

lotus

作者 hunnyc

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

pack.json
"requires": { "lotus": "^1.0" }
你的 lua
local lotus = require("lib/lotus")
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