> For the complete documentation index, see [llms.txt](https://hamsterbaron.gitbook.io/hamsterbaron/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hamsterbaron.gitbook.io/hamsterbaron/mechanic-guides/action/selector.md).

# 目标选择器

## 目标选择器的用途

在设计机制时，常会遇到希望一部分动作只作用于特定对象或由特定对象所执行。例如，Minecraft 的指令系统会提供执行者的信息，原版提供了<kbd>/execute</kbd>指令以方便上述目标，配合占位符与变量能够实现指令执行者以及执行位置的转变。但在复杂的设计中，这无疑会降低指令动作可读性并提高不必要的性能损耗。此外，服务器中还常涉及执行权限的问题。为解决这类问题，Arcana 给大多数动作提供了目标选择器。

该目标选择器与 Minecraft 自带的目标选择器略有区别，围绕 TacZ 模组的可能用途以设计，精简了参数部分。绝大部分需要作用于目标的动作都可以使用目标选择器来选取传入的目标。

***

## 应用目标选择器

目标选择器可在技能配置时以下区域使用：

* Condition 区域中 Variables 条件
* Action 区域中 作用对象为实体的全部动作

> 在动作块中使用时，目标选择器如返回多个对象，则执行至本条动作的时候将会依次对全部返回的对象进行动作。例如，使用一个效果为扣除 5 点 MaxHP 的 Modify（属性编辑器）技能，并指定了子弹命中的全部目标作为选择器返回对象，则子弹只要命中目标，就会减少目标的血量上限。

***

## 目标选择器格式

一个合法的目标选择器应拥有正确的模式名`name`和模式的必需参数。此处提供一份完整的格式示例（假设该字段位于某一需要执行对象的动作中）：

```yaml
- !<SomeAction>
  # Other Parameter
  selector:
    name: "SelectorName"
    source: null
    params:{
      type: "player"
      # Other Params ...
    }
    args:
    - "$Arg1"
    - "$Arg2"
    # Other Arguments ...
```

其中，`source`与`params`均为一个行内映射(flow mapping)，是存储多组键值对的映射，在格式上均需如上文示例中用大括号`{}`括起。`args`即占位符，可在`params`中需要使用变量时插入

***

## 目标选择器参数

当前 Arcana 共提供四种不同的选择器，每种选择器有不同的可配置附加参数。以下是对于当前已提供的目标选择器的配置说明。

* self 模式

允许的参数：无

* target 模式

允许的参数：<mark style="color:orange;">`limit`</mark> <mark style="color:orange;">`type`</mark> <mark style="color:orange;">`explosionOnly`</mark>

* bullet 模式

允许的参数：<mark style="color:orange;">`limit`</mark> <mark style="color:orange;">`type`</mark> <mark style="color:orange;">`at`</mark> <mark style="color:orange;">`radius`</mark> <mark style="color:orange;">`explosionOnly`</mark>&#x20;

* raycast 模式

允许的参数：<mark style="color:orange;">`limit`</mark> <mark style="color:orange;">`type`</mark> <mark style="color:orange;">`fov`</mark> <mark style="color:orange;">`maxDistance`</mark>

{% hint style="info" %}
**开发须知**：当在一个需要返回目标的技能中未配置任何目标选择器，则默认为"self"模式
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hamsterbaron.gitbook.io/hamsterbaron/mechanic-guides/action/selector.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
