edit | blame | history | raw
local CONST     = require 'config.const'
local Suspicion = require 'systems.suspicion'
local Base      = require 'profession.base'

local trap_count = {}

Base.register('surgeon', function(unit, ability)
    local pid = unit:get_owner():get_id()
    trap_count[pid] = trap_count[pid] or 0
    if trap_count[pid] >= 2 then return end

    local pos = unit:get_point()
    local trap_area = clicli.area.create_circle_area(pos, 1.5)
    trap_area:add_tag('trap')
    trap_count[pid] = trap_count[pid] + 1

    Suspicion.add(unit, 5)

    clicli.timer.loop(0.5, function(timer, count)
        if count > 180 then
            trap_area:remove()
            timer:remove()
            trap_count[pid] = math.max(0, (trap_count[pid] or 1) - 1)
            return
        end

        local trapped_units = trap_area:get_all_unit_in_area()
        for _, u in ipairs(trapped_units) do
            if u:has_tag('player_controlled') and u ~= unit and u:is_alive() then
                u:add_state(CONST.STATE_IMMOBILE)
                u:add_buff({ key = CONST.BUFF_TRAP_ROOT, time = 2.0 })
                clicli.timer.wait(2.0, function()
                    u:remove_state(CONST.STATE_IMMOBILE)
                end)

                trap_area:remove()
                timer:remove()
                trap_count[pid] = math.max(0, (trap_count[pid] or 1) - 1)
                return
            end
        end
    end, '陷阱检测')
end)

return Base