薛之猫大王
2026-02-22 35593fff68c76413ce82a918e56f127355bf6c55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local CONST   = require 'config.const'
local Balance = require 'config.balance'
 
local M = {}
 
local spawn_points = {}
 
local ITEM_POOL = {
    { key = CONST.ITEM_POISON,   weight = 15 },
    { key = CONST.ITEM_KNIFE,    weight = 10 },
    { key = CONST.ITEM_ARMOR,    weight = 15 },
    { key = CONST.ITEM_SMOKE,    weight = 15 },
    { key = CONST.ITEM_MASK,     weight = 8  },
    { key = CONST.ITEM_TRACKER,  weight = 15 },
    { key = CONST.ITEM_SILENCER, weight = 10 },
    { key = CONST.ITEM_JAMMER,   weight = 12 },
}
 
-- ---------------------------------------------------------
-- 初始化
-- ---------------------------------------------------------
function M.init()
    local areas = clicli.area.get_circle_areas_by_tag('item_spawn')
    for _, area in ipairs(areas) do
        local sp = {
            area          = area,
            current_item  = nil,
            respawn_timer = nil,
        }
        M.spawn_item(sp)
        table.insert(spawn_points, sp)
    end
 
    clicli.game:subscribe_event('单位-获得物品', function(trg, data)
        local unit = data.unit
        if unit and unit:has_tag('player_controlled') then
            local Suspicion = require 'systems.suspicion'
            Suspicion.add(unit, 3)
 
            M.on_item_picked_by_unit(data.item)
        end
    end)
end
 
-- ---------------------------------------------------------
-- 在刷新点生成物品
-- ---------------------------------------------------------
function M.spawn_item(sp)
    local item_key = M.roll_item()
    local pos = sp.area:get_center_point()
    local item = clicli.item.create_item(pos, item_key)
    sp.current_item = item
end
 
-- ---------------------------------------------------------
-- 物品权重随机
-- ---------------------------------------------------------
function M.roll_item()
    local total = 0
    for _, e in ipairs(ITEM_POOL) do
        total = total + e.weight
    end
    local r = math.random(total)
    local acc = 0
    for _, e in ipairs(ITEM_POOL) do
        acc = acc + e.weight
        if r <= acc then return e.key end
    end
    return ITEM_POOL[1].key
end
 
-- ---------------------------------------------------------
-- 被拾取后,找到对应刷新点并开始刷新倒计时
-- ---------------------------------------------------------
function M.on_item_picked_by_unit(item)
    for _, sp in ipairs(spawn_points) do
        if sp.current_item == item then
            M.on_item_picked(sp)
            break
        end
    end
end
 
function M.on_item_picked(sp)
    sp.current_item = nil
    local delay = Balance.ITEM_RESPAWN_TIME
 
    local GameMgr = require 'core.game_manager'
    if GameMgr.get_state() == 'overtime' then
        delay = delay * 0.5
    end
 
    sp.respawn_timer = clicli.timer.wait(delay, function()
        M.spawn_item(sp)
    end)
end
 
return M