-- ========================================================= -- 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)