薛之猫大王
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- =========================================================
-- Killer - 多人潜行刺杀游戏
-- 入口脚本:注册游戏初始化事件,串联所有模块
-- =========================================================
 
-- 预加载所有模块
local GameManager  = require 'core.game_manager'
local PlayerMgr    = require 'core.player_manager'
local NpcMgr       = require 'core.npc_manager'
local ModeMgr      = require 'core.mode_manager'
local TimerMgr     = require 'core.timer_manager'
local Suspicion    = require 'systems.suspicion'
local Disguise     = require 'systems.disguise'
local Corpse       = require 'systems.corpse'
local Assassination = require 'systems.assassination'
local ItemSpawner  = require 'systems.item_spawner'
local Circle       = require 'systems.circle'
local NpcBehavior  = require 'ai.npc_behavior'
local HUD          = require 'ui.hud'
local ProfBase     = require 'profession.base'
 
-- 加载所有职业(注册到 base 中)
require 'profession.shadow_blade'
require 'profession.mimic'
require 'profession.eagle_eye'
require 'profession.surgeon'
require 'profession.phantom'
require 'profession.hound'
 
-- =========================================================
-- 游戏初始化
-- =========================================================
clicli.game:event('游戏-初始化', function(trg, data)
    local seed = os.time()
    clicli.game.set_random_seed(seed)
 
    TimerMgr.start()
    GameManager.init()
    NpcBehavior.start()
    HUD.start()
end)
 
-- =========================================================
-- 全局事件注册
-- =========================================================
 
-- 单位死亡事件
clicli.game:event('游戏-初始化', function()
    clicli.game:subscribe_event('单位-死亡', function(trg, data)
        local dead   = data.dead_unit
        local killer = data.killer_unit
        if dead and dead:has_tag('player_controlled') then
            PlayerMgr.on_player_killed(killer, dead)
        end
    end)
end)
 
-- 职业技能施法事件
clicli.game:event('游戏-初始化', function()
    clicli.game:subscribe_event('技能-施法开始', function(trg, data)
        local unit = data.unit
        if unit and unit:has_tag('player_controlled') then
            ProfBase.on_ability_cast(unit, data.ability)
        end
    end)
end)
 
-- =========================================================
-- 玩家输入事件(键盘按键映射)
-- =========================================================
clicli.game:event('游戏-初始化', function()
    -- 刺杀键 (示例绑定)
    clicli.game:subscribe_event('键盘-按下', function(trg, data)
        local player = data.player
        if not player then return end
 
        local pd = nil
        for _, p in ipairs(PlayerMgr.get_all_player_units()) do
            if p.player == player then pd = p; break end
        end
        if not pd or not pd.alive then return end
 
        local key = data.key
 
        -- F键:刺杀最近目标
        if key == 'F' then
            local area = clicli.area.create_circle_area(pd.unit:get_point(), 3.0)
            local nearby = area:get_all_unit_in_area()
            area:remove()
 
            local best_target = nil
            for _, u in ipairs(nearby) do
                if u ~= pd.unit and u:is_alive() then
                    best_target = u
                    break
                end
            end
            if best_target then
                Assassination.attempt(pd.unit, best_target)
            end
 
        -- E键:互动/换装/藏尸
        elseif key == 'E' then
            -- 优先尝试藏尸
            if pd.unit:storage_get('is_dragging') then
                if not Corpse.try_hide(pd.unit) then
                    Corpse.drop_corpse(pd.unit)
                end
                return
            end
 
            -- 尝试换装(对附近尸体)
            local area = clicli.area.create_circle_area(pd.unit:get_point(), 2.5)
            local nearby = area:get_all_unit_in_area()
            area:remove()
            for _, u in ipairs(nearby) do
                if u:has_tag('corpse') and not u:has_tag('hidden') then
                    if Disguise.start_disguise(pd.unit, u) then
                        return
                    end
                end
            end
 
            -- 尝试互动点
            Disguise.try_player_interact(pd.unit)
 
        -- G键:拖拽尸体
        elseif key == 'G' then
            if pd.unit:storage_get('is_dragging') then
                Corpse.drop_corpse(pd.unit)
            else
                local area = clicli.area.create_circle_area(pd.unit:get_point(), 2.5)
                local nearby = area:get_all_unit_in_area()
                area:remove()
                for _, u in ipairs(nearby) do
                    if u:has_tag('corpse') and not u:has_tag('hidden') then
                        if Corpse.start_drag(pd.unit, u) then
                            break
                        end
                    end
                end
            end
        end
    end)
end)