Files
ArachnaeSwarm/Source/Documents/design_doc_tracking_charge.md
2025-09-07 15:28:24 +08:00

97 lines
6.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 设计文档:跟踪冲撞技能 (Tracking Charge)
**版本:** 0.1
## 1. 概述
本文档旨在详细说明一个新的 RimWorld 技能:“跟踪冲撞”。该技能允许一个 Pawn施法者像制导导弹一样冲向一个目标 Pawn。在飞行过程中它会对路径上接触到的所有敌对单位和可破坏建筑造成伤害。伤害值会随着飞行距离的增加而累积。当撞击到主目标后施法者会因惯性继续向前滑行一小段距离。
## 2. 核心功能需求
* **技能类型**: 主动施放的 targeted ability。
* **移动方式**: 动态追踪曲线移动,而非直线或抛物线。
* **伤害机制**:
* **路径伤害**: 对飞行路径上碰撞到的所有有效目标(敌方、中立、可破坏建筑)造成伤害。
* **累积伤害**: 总伤害 = 基础伤害 + (飞行距离 * 每米伤害增量)。
* **主目标伤害**: 与路径伤害计算方式相同。
* **最终效果**: 撞击主目标后,追踪停止,施法者沿最后的方向继续滑行一小段距离后停下。
## 3. 技术架构
我们将采用基于自定义 `PawnFlyer` 的核心架构。这种方法将移动和效果逻辑封装在一个临时的 `Thing` 中,而施法者 Pawn 本身在技能持续期间会从地图上暂时移除。
### 3.1. 核心组件
| 组件名称 (C# Class) | 类型 | 职责 |
| ---------------------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `Verb_CastAbilityTrackingCharge` | `Verb` | **技能启动器**: 验证目标,从 `CompProperties` 读取配置,创建并初始化 `PawnFlyer_TrackingCharge`。 |
| `PawnFlyer_TrackingCharge` | `PawnFlyer` | **核心逻辑处理器**: 接收来自 `Verb` 的参数,实现追踪、碰撞、伤害、惯性等所有动态逻辑。 |
| `CompProperties_TrackingCharge` | `CompProperties_AbilityEffect` | **XML配置接口**: 在 `AbilityDef``<comps>` 中定义技能的所有可调参数,如伤害、速度、惯性等。 |
| `CompAbilityEffect_TrackingCharge` | `CompAbilityEffect` | **数据容器**: 作为一个轻量级的组件,其主要作用是让 `CompProperties_TrackingCharge` 能被游戏正确加载。它本身不执行复杂逻辑。 |
### 3.2. 设计决策:配置的分层与传递
* **采纳的方案 (混合模式)**: 我们将采用一种既符合直觉又技术稳健的混合模式。
1. **配置集中在 `AbilityDef`**: 使用 `CompProperties_TrackingCharge` (继承自 `CompProperties_AbilityEffect`) 来存放所有技能参数。这使得 Mod 用户可以在 `AbilityDef``<comps>` 节点中方便地调整一切,符合 RimWorld 的标准实践。
2. **`Verb` 作为数据中介**: `Verb_CastAbilityTrackingCharge` 在施法时,会从 `this.ability.def` 中轻松获取到 `CompProperties_TrackingCharge` 的实例,读取所有配置参数。
3. **`PawnFlyer` 接收参数**: `Verb` 在创建 `PawnFlyer_TrackingCharge` 实例后,会通过一个自定义的初始化方法(例如 `Initialize(...)`),将所有读取到的参数“注入”到 `PawnFlyer` 实例中。
* **优点**: 这个方案完美地解决了您的顾虑。配置的**易用性**(在 `AbilityDef` 中)和逻辑的**清晰性**`PawnFlyer` 负责执行)都得到了保证。
### 3.3. 数据流与交互
```mermaid
graph TD
subgraph Player Action
A[玩家选择目标并施放技能] --> B(AbilityDef);
end
subgraph XML Definitions
B -- contains --> E[CompProperties_TrackingCharge];
B -- uses --> C(VerbDef);
C -- verbClass --> D[Verb_CastAbilityTrackingCharge];
F(ThingDef for Flyer) -- thingClass --> G[PawnFlyer_TrackingCharge];
end
subgraph C# Logic
D -- 1. Reads Params from --> E;
D -- 2. Creates --> G;
D -- 3. Injects Params into --> G;
G -- 4. Executes Tick Logic --> H{追踪 & 碰撞};
H -- 5. Applies Damage to --> I[Things on Path];
G -- 6. Handles Inertia & Self-Destructs --> J[Final Position];
end
PlayerInput([施法者 Pawn]) -- temporarily removed --> G;
G -- places back --> PlayerInput;
```
## 4. 详细实现步骤
### 步骤 1: 创建 C# 类骨架 (最终版)
* **文件**: `CompProperties_TrackingCharge.cs`
* **继承**: `Verse.CompProperties_AbilityEffect`
* **职责**: 定义所有可在 XML 中配置的技能参数。
* **示例字段**: `public float homingSpeed;`, `public float initialDamage;`, `public float damagePerTile;`, `public float inertiaDistance;`, `public DamageDef collisionDamageDef;`, `public ThingDef flyerDef;` (用于指定飞行器的ThingDef)。
* **文件**: `CompAbilityEffect_TrackingCharge.cs`
* **继承**: `Verse.CompAbilityEffect`
* **职责**: 轻量级组件,其存在是为了让 `CompProperties_TrackingCharge` 能被游戏正确加载和访问。
* **文件**: `Verb_CastAbilityTrackingCharge.cs`
* **继承**: `Verse.Verb_CastAbility`
* **职责**:
1.`TryCastShot()` 中,从 `this.ability.GetComp<CompAbilityEffect_TrackingCharge>().Props` 获取配置。
2. 调用 `PawnFlyer.MakeFlyer(Props.flyerDef, ...)` 创建 `PawnFlyer_TrackingCharge` 实例。
3. **将配置参数设置到 `PawnFlyer` 的公共字段上**
4. 调用 `flyer.Launch()` 启动。
* **文件**: `PawnFlyer_TrackingCharge.cs`
* **继承**: `Verse.PawnFlyer`
* **职责**:
1. 定义一系列**公共字段** (`public float homingSpeed;` 等) 来接收来自 `Verb` 的参数。
2.`Tick()` 中实现所有核心的追踪、碰撞和伤害逻辑。
* **注意**: **不**创建自定义的 `Initialize()` 方法,也**不**重写 `Launch()` 来接收参数,以保持设计的简洁和标准。
---
> **下一步**: 设计文档已最终确定。我将开始实施 **步骤 1**,为您创建这四个 C# 类的代码框架。