# 尸体与藏尸系统 ## corpse.lua ```lua local CONST = require 'config.const' local Balance = require 'config.balance' local Suspicion = require 'systems.suspicion' local M = {} ----------------------------------------------------------- -- 开始拖拽尸体 ----------------------------------------------------------- function M.start_drag(player_unit, corpse_unit) if not corpse_unit:has_tag('corpse') then return false end if not player_unit:is_in_radius(corpse_unit, 2.0) then return false end if player_unit:storage_get('is_dragging') then return false end if player_unit:storage_get('is_disguising') then return false end player_unit:storage_set('is_dragging', true) player_unit:storage_set('dragged_corpse', corpse_unit) -- 降低移速 player_unit:add_attr('移动速度', -Balance.DRAG_SPEED_PENALTY, '增益') -- 尸体跟随玩家 corpse_unit:follow(player_unit, 0.5, 1.5, 3.0, 180, true) -- 拖拽期间持续增加怀疑值 local drag_timer = y3.timer.loop(1.0, function() if not player_unit:storage_get('is_dragging') then return end Suspicion.add(player_unit, Balance.SUS_DRAGGING) end, '拖拽怀疑值') player_unit:storage_set('drag_timer', drag_timer) return true end ----------------------------------------------------------- -- 释放尸体(不在藏尸点) ----------------------------------------------------------- function M.drop_corpse(player_unit) if not player_unit:storage_get('is_dragging') then return end local corpse = player_unit:storage_get('dragged_corpse') if corpse and corpse:is_exist() then corpse:stop() end M.cleanup_drag(player_unit) end ----------------------------------------------------------- -- 藏尸 ----------------------------------------------------------- function M.try_hide(player_unit) if not player_unit:storage_get('is_dragging') then return false end local pos = player_unit:get_point() local hide_spots = y3.area.get_circle_areas_by_tag('hide_spot') for _, area in ipairs(hide_spots) do if area:is_point_in_area(pos) then -- 检查容量 local capacity = area:kv_load('capacity', 'integer') or 1 local used = area:kv_load('used', 'integer') or 0 if used >= capacity then -- 满了,继续检查其他点 else -- 藏尸成功 local corpse = player_unit:storage_get('dragged_corpse') if corpse and corpse:is_exist() then corpse:add_tag('hidden') corpse:remove() end area:kv_save('used', used + 1) M.cleanup_drag(player_unit) -- 加分 local PlayerMgr = require 'core.player_manager' PlayerMgr.add_score(player_unit:get_owner(), Balance.SCORE_HIDE_CORPSE) return true end end end return false end ----------------------------------------------------------- -- 清理拖拽状态 ----------------------------------------------------------- function M.cleanup_drag(player_unit) player_unit:storage_set('is_dragging', false) player_unit:storage_set('dragged_corpse', nil) player_unit:add_attr('移动速度', Balance.DRAG_SPEED_PENALTY, '增益') local drag_timer = player_unit:storage_get('drag_timer') if drag_timer then drag_timer:remove() player_unit:storage_set('drag_timer', nil) end end ----------------------------------------------------------- -- 尸体发现检测(每2秒扫描一次) ----------------------------------------------------------- function M.start_discovery_scan() y3.timer.loop(2.0, function() local PlayerMgr = require 'core.player_manager' for _, pd in ipairs(PlayerMgr.get_all_player_units()) do if pd.alive then M.check_discovery(pd.unit) end end end, '尸体发现扫描') end function M.check_discovery(player_unit) local pos = player_unit:get_point() local area = y3.area.create_circle_area(pos, Balance.CORPSE_DISCOVER_RANGE) local units = area:get_all_unit_in_area() area:remove() for _, u in ipairs(units) do if u:has_tag('corpse') and not u:has_tag('hidden') and not u:has_tag('discovered') then u:add_tag('discovered') M.on_corpse_discovered(u, player_unit) end end end function M.on_corpse_discovered(corpse, discoverer) -- 全局通知(通过UI系统) local Notify = require 'ui.notification' Notify.broadcast('发现尸体', corpse:get_point()) -- 触发附近NPC恐慌 local NpcMgr = require 'core.npc_manager' NpcMgr.trigger_panic(corpse:get_point(), Balance.PANIC_RADIUS) end return M ``` --- ## 藏尸点编辑器配置 | 编辑器操作 | 说明 | |-----------|------| | 放置圆形区域(半径2m) | 藏尸触发范围 | | 添加标签 `hide_spot` | 代码识别 | | 设置KV `capacity` = 整数 | 可容纳尸体数量 | | 设置KV `used` = 0 | 初始已使用数量 | 示例: - 垃圾桶:capacity=1 - 灌木丛:capacity=2 - 下水道入口:capacity=3