Refactor: NPC perception rules out of AiHandler, split NpcAiService / NpcHelperService

未关闭
#492 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp, unity
领域
game-dev

调研方向

Start with the design skill and the review findings A3 and A4 from split/09-perceptions; then trace perception handling across AiHandler, NpcAiService, and NpcHelperService. Map the proposed service responsibilities and Reflex registration before implementation. Done means the responsibilities are moved as described with no behavior change; the performance notes are optional.

由索引模型根据 Issue 内容生成。

描述

improvement

Follow-up from the review of split/09-perceptions (architecture-reviewer findings A3 + A4).

Problem

  • AiHandler (adapter, ~720 lines) decides AI rules: loop rate, daily-state check, CallStateEnd, looking away
    (ForgetHeroAfterLookingAway changes AttitudeTemp), PERC_MOVENPC, PERC_ASSESSBODY. None of it is testable
    without a scene, and following one perception means reading AiHandler, NpcAiService and NpcHelperService.
  • NpcAiService (~1,100 lines) and NpcHelperService (~620 lines) each took on a new responsibility: passive
    perception broadcast/delivery, the body search, sight lines through alpha-tested polygons, Wld_DetectItem.

Proposal

  • NpcPerceptionService (new): passive perception broadcast + delivery, ExecutePassivePerception,
    FindClosestSensedBody, and the body of ExecuteActivePerceptions (incl. PERC_MOVENPC, PERC_ASSESSBODY,
    looking away).
  • NpcSightDomain (new, owned by NpcHelperService): CanSee/CanSense, IsSightBlocked, see-through caches.
  • NpcAiService keeps the state lifecycle and also gets CallStateEnd, the loop-rate and daily-state checks.
  • AiHandler keeps only the Unity part: _npcPerceptionService.TickPerceptions(NpcData) and the state calls.
  • Wld_DetectItem and the item distances could move to a Wld_*/item service.

Plan with the design skill first (new service + Reflex registration), then implement. No behaviour change.

Related performance notes from the same review (can be done during the move):

  • FindClosestSensedBody walks the whole NpcCache with a raycast per candidate on every perception tick.
  • Wld_DetectItem walks the whole VobCache per call.
主要语言
C#
星标
33
派生
1
平均合并
1 天 21 小时
30 天内合并 PR
56

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Gothic-Unity-Project/Gothic-Unity 的其他 Issue

查看 Gothic-Unity-Project/Gothic-Unity 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。