initial commit
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
||||
local ____exports = {}
|
||||
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
||||
local registerEntityFunction = ____dota_ts_adapter.registerEntityFunction
|
||||
local ACTIVITY_BUTTON_NAME = "activity_button"
|
||||
local LOG_PREFIX = "[activity_button_prop]"
|
||||
local ATTACK1_TO_CAPTURE_DELAY = 0.45
|
||||
local ATTACK2_TO_IDLE_DELAY = 0.65
|
||||
local stateByPropEntIndex = {}
|
||||
local function tryAsPropEntity(self, v)
|
||||
if v == nil or v == nil then
|
||||
return nil
|
||||
end
|
||||
if not IsValidEntity(v) then
|
||||
return nil
|
||||
end
|
||||
return v
|
||||
end
|
||||
--- CallPrivateScriptFunction часто не даёт thisEntity — берём из data или FindByName.
|
||||
local function resolveProp(self, data, reason)
|
||||
do
|
||||
local ____try, ____hasReturned, ____returnValue = pcall(function()
|
||||
if thisEntity ~= nil and thisEntity ~= nil and not thisEntity:IsNull() and IsValidEntity(thisEntity) then
|
||||
print((((LOG_PREFIX .. " resolveProp(") .. (reason or "?")) .. "): thisEntity=") .. tostring(thisEntity:entindex()))
|
||||
return true, thisEntity
|
||||
end
|
||||
end)
|
||||
if ____try and ____hasReturned then
|
||||
return ____returnValue
|
||||
end
|
||||
end
|
||||
if data ~= nil and data ~= nil and type(data) == "table" then
|
||||
local t = data
|
||||
--- Порядок: сначала сам объект кнопки; caller/activator — триггер/герой, в конце.
|
||||
local keys = {
|
||||
"self",
|
||||
"entity",
|
||||
"thisEntity",
|
||||
"parent",
|
||||
"owner",
|
||||
"callee",
|
||||
"activator",
|
||||
"caller"
|
||||
}
|
||||
for ____, key in ipairs(keys) do
|
||||
local e = tryAsPropEntity(nil, t[key])
|
||||
if e ~= nil then
|
||||
print((((((LOG_PREFIX .. " resolveProp(") .. (reason or "?")) .. "): data.") .. key) .. "=") .. tostring(e:entindex()))
|
||||
return e
|
||||
end
|
||||
end
|
||||
local dbg = {}
|
||||
for ____, key in ipairs(keys) do
|
||||
dbg[#dbg + 1] = (key .. "=") .. type(t[key])
|
||||
end
|
||||
print((((LOG_PREFIX .. " resolveProp(") .. (reason or "?")) .. "): data поля: ") .. table.concat(dbg, ", "))
|
||||
end
|
||||
local byName = Entities:FindByName(nil, ACTIVITY_BUTTON_NAME)
|
||||
local named = tryAsPropEntity(nil, byName)
|
||||
if named ~= nil then
|
||||
print((((((LOG_PREFIX .. " resolveProp(") .. (reason or "?")) .. "): FindByName(\"") .. ACTIVITY_BUTTON_NAME) .. "\")=") .. tostring(named:entindex()))
|
||||
return named
|
||||
end
|
||||
print(((LOG_PREFIX .. " resolveProp(") .. (reason or "?")) .. "): FAIL — нет prop")
|
||||
return nil
|
||||
end
|
||||
local function fadeGestures(self, prop)
|
||||
do
|
||||
pcall(function()
|
||||
prop:FadeGesture(ACT_DOTA_ATTACK)
|
||||
prop:FadeGesture(ACT_DOTA_CAPTURE)
|
||||
prop:FadeGesture(ACT_DOTA_ATTACK2)
|
||||
prop:FadeGesture(ACT_DOTA_IDLE)
|
||||
end)
|
||||
end
|
||||
end
|
||||
local function clearPending(self, state)
|
||||
if state.pendingTimerId ~= nil then
|
||||
Timers:RemoveTimer(state.pendingTimerId)
|
||||
state.pendingTimerId = nil
|
||||
end
|
||||
end
|
||||
local function clearAttack2(self, state)
|
||||
if state.attack2ToIdleTimerId ~= nil then
|
||||
Timers:RemoveTimer(state.attack2ToIdleTimerId)
|
||||
state.attack2ToIdleTimerId = nil
|
||||
end
|
||||
end
|
||||
local function playIdle(self, prop)
|
||||
do
|
||||
local function ____catch(e)
|
||||
print((LOG_PREFIX .. " playIdle ошибка: ") .. tostring(e))
|
||||
end
|
||||
local ____try, ____hasReturned = pcall(function()
|
||||
fadeGestures(nil, prop)
|
||||
prop:StartGesture(ACT_DOTA_IDLE)
|
||||
print((LOG_PREFIX .. " DOTA_IDLE prop=") .. tostring(prop:entindex()))
|
||||
end)
|
||||
if not ____try then
|
||||
____catch(____hasReturned)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function playRiseThenIdle(self, prop, state)
|
||||
print((LOG_PREFIX .. " playRiseThenIdle prop=") .. tostring(prop:entindex()))
|
||||
clearAttack2(nil, state)
|
||||
do
|
||||
pcall(function()
|
||||
fadeGestures(nil, prop)
|
||||
prop:StartGesture(ACT_DOTA_ATTACK2)
|
||||
end)
|
||||
end
|
||||
state.attack2ToIdleTimerId = Timers:CreateTimer(
|
||||
ATTACK2_TO_IDLE_DELAY,
|
||||
function()
|
||||
state.attack2ToIdleTimerId = nil
|
||||
print((LOG_PREFIX .. " таймер attack2→idle prop=") .. tostring(prop:entindex()))
|
||||
playIdle(nil, prop)
|
||||
return nil
|
||||
end
|
||||
)
|
||||
end
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"OnStartTouch",
|
||||
function(____, data)
|
||||
if not IsServer() then
|
||||
return
|
||||
end
|
||||
print((LOG_PREFIX .. " OnStartTouch вызван data=") .. tostring(data))
|
||||
local prop = resolveProp(nil, data, "OnStartTouch")
|
||||
if prop == nil then
|
||||
return
|
||||
end
|
||||
local idx = prop:entindex()
|
||||
local state = stateByPropEntIndex[idx]
|
||||
if state == nil then
|
||||
state = {stillInside = true, inCapture = false}
|
||||
stateByPropEntIndex[idx] = state
|
||||
else
|
||||
clearPending(nil, state)
|
||||
clearAttack2(nil, state)
|
||||
state.stillInside = true
|
||||
state.inCapture = false
|
||||
end
|
||||
do
|
||||
local function ____catch(e)
|
||||
print((LOG_PREFIX .. " OnStartTouch жест DOTA_ATTACK: ") .. tostring(e))
|
||||
return true
|
||||
end
|
||||
local ____try, ____hasReturned, ____returnValue = pcall(function()
|
||||
fadeGestures(nil, prop)
|
||||
prop:StartGesture(ACT_DOTA_ATTACK)
|
||||
print(((((LOG_PREFIX .. " OnStartTouch → DOTA_ATTACK prop=") .. tostring(idx)) .. ", capture через ") .. tostring(ATTACK1_TO_CAPTURE_DELAY)) .. "s")
|
||||
end)
|
||||
if not ____try then
|
||||
____hasReturned, ____returnValue = ____catch(____hasReturned)
|
||||
end
|
||||
if ____hasReturned then
|
||||
return ____returnValue
|
||||
end
|
||||
end
|
||||
state.pendingTimerId = Timers:CreateTimer(
|
||||
ATTACK1_TO_CAPTURE_DELAY,
|
||||
function()
|
||||
state.pendingTimerId = nil
|
||||
if not state.stillInside then
|
||||
print((LOG_PREFIX .. " таймер capture: уже вышли — отмена prop=") .. tostring(idx))
|
||||
return nil
|
||||
end
|
||||
local p = EntIndexToHScript(idx)
|
||||
if p == nil or not IsValidEntity(p) then
|
||||
print((LOG_PREFIX .. " таймер capture: prop пропал idx=") .. tostring(idx))
|
||||
return nil
|
||||
end
|
||||
do
|
||||
local function ____catch(e)
|
||||
print((LOG_PREFIX .. " таймер capture ошибка: ") .. tostring(e))
|
||||
end
|
||||
local ____try, ____hasReturned = pcall(function()
|
||||
p:FadeGesture(ACT_DOTA_ATTACK)
|
||||
p:StartGesture(ACT_DOTA_CAPTURE)
|
||||
state.inCapture = true
|
||||
print((LOG_PREFIX .. " таймер capture → DOTA_CAPTURE prop=") .. tostring(idx))
|
||||
end)
|
||||
if not ____try then
|
||||
____catch(____hasReturned)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
registerEntityFunction(
|
||||
nil,
|
||||
"OnEndTouch",
|
||||
function(____, data)
|
||||
if not IsServer() then
|
||||
return
|
||||
end
|
||||
print((LOG_PREFIX .. " OnEndTouch вызван data=") .. tostring(data))
|
||||
local prop = resolveProp(nil, data, "OnEndTouch")
|
||||
if prop == nil then
|
||||
return
|
||||
end
|
||||
local idx = prop:entindex()
|
||||
local state = stateByPropEntIndex[idx]
|
||||
if state == nil then
|
||||
print((LOG_PREFIX .. " OnEndTouch: нет state prop=") .. tostring(idx))
|
||||
return
|
||||
end
|
||||
print((((((LOG_PREFIX .. " OnEndTouch prop=") .. tostring(idx)) .. " inCapture=") .. tostring(state.inCapture)) .. " pending=") .. tostring(state.pendingTimerId ~= nil))
|
||||
state.stillInside = false
|
||||
if state.pendingTimerId ~= nil then
|
||||
clearPending(nil, state)
|
||||
print(LOG_PREFIX .. " OnEndTouch: до захвата → ATTACK_2 + idle")
|
||||
playRiseThenIdle(nil, prop, state)
|
||||
state.inCapture = false
|
||||
return
|
||||
end
|
||||
if state.inCapture then
|
||||
do
|
||||
pcall(function()
|
||||
prop:FadeGesture(ACT_DOTA_CAPTURE)
|
||||
end)
|
||||
end
|
||||
state.inCapture = false
|
||||
print(LOG_PREFIX .. " OnEndTouch: из захвата → ATTACK_2 + idle")
|
||||
playRiseThenIdle(nil, prop, state)
|
||||
else
|
||||
print(LOG_PREFIX .. " OnEndTouch: без pending/inCapture")
|
||||
end
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
Reference in New Issue
Block a user