# 法力值

很多插件都有一套法力值系统，但是 **EcoX** 系列插件却没有，法力值是一套经典的服务器玩法，我们先从它下手吧！

## 任务

制作一套法力值系统。同时上一节所讲的末影弓释放“末影之箭”技能时消耗 **15** 点法力。

### 任务提示

使用 **CombatLogX** 的 `%combatlogx_in_combat%` 变量符判断玩家目前是否处于战斗状态。你也可以使用其他插件提供的变量符实现判断玩家释放处于战斗状态。

## 逐步分析

很显然法力值是一种新的属性，我们需要通过 **EcoSkills** 来实现它。同时消耗法力的物品通过 **EcoItems** 实现。

#### 什么都不管，我们先在 customstat.yml 文件添加如下内容：

```
  - id: mana
    name: "&#40ffe6✦ 法力"
    placeholder: "%level%"
    description: "&8增加 &a%placeholder%&8 点法力"
    stats-gui:
      enabled: true
      position:
        row: 4
        column: 7
      item:
        item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWQ1YTA5ODg0Y2I4M2VmNWM5MDhkZGRkMzg1ZjI0NmZlZmRlZTIyMTcxMmMwMTAxNzdmNTQzNzZkYTIzOGZkZCJ9fX0=
        name: "%stat%"
        lore:
          - "&f等级: &a%level%"
          - "&8&o%description%"
    effects:
      我们还不知道呢
    conditions: [ ]
```

除了 `effects`，其他选项的内容你应该“耳熟能详”，知道干什么了。如果不知道，请回顾 **技能与属性** 一节。

#### 法力值恢复

法力值不是用掉就彻底消失的，和血量一样，它是会恢复的。虽然我们已经注册了法力这个属性，但它的值我们还需要通过积分系统来记录，以便于我们了解当前的法力值。

通过技能列表我们很轻松的就可以找到 `give_points` 这个技能，它可以帮助我们让玩家恢复法力值，如果玩家目前没有法力值，将会注册法力值这个积分。

我们拟定该积分的id为 `g_mana`，于是，我们的第一个 `effects` 选项的值就这样诞生了：

```
      - id: give_points
        args:
          type: g_mana
          amount: 1
```

{% hint style="info" %}
想一想，为什么积分名称是 g\_mana，能直接填写 mana 吗？如果你不知道，请查看技能列表下的 **A** 一节。
{% endhint %}

#### BUG 发现之1

如果你跟着我的思路这样填写了，却发现玩家实际上根本没有恢复法力值，这是为什么？

因为 `give_points` 是触发技能，我们理想的状态是玩家每隔一小会恢复 1 点法力值，于是 `static_时长` 触发器就是我们的理想选择。请自己再添加这个触发器吧。

#### BUG 发现之2：条件的使用

现在法力值是恢复了，但它是不断增加的，并没有到一个值停下来！

这肯定不是我们想要看到的，我们是法力属性就是控制玩家的法力值上限，法力值超过法力属性的等级后，就不再增加，这时，条件的用处就出来了。配合任务提示的战斗状态，我们需要为这个技能制作两个条件：

* 玩家的法力值未达到法力属性等级值加上19的值。
* 玩家没有处于战斗状态。

{% hint style="info" %}
19+1 就是你希望的最开始玩家的法力值上限，之所以 +1 是因为法力属性的第一级就是 +1，属性没有 0 级。
{% endhint %}

#### 物品的制作

物品同样需要条件判断玩家当前法力值，同时还需要制作消耗法力值的技能。

以上的步骤就不再详细的给出说明，请自己按照教导自行制作，然后与所给的参考答案进行比较。

## 参考答案

### EcoSkills

在 EcoSkills 的自定义属性中添加如下属性：

```
  - id: mana
    name: "&#40ffe6✦ 法力"
    placeholder: "%level%"
    description: "&8增加 &a%placeholder%&8 点法力"
    stats-gui:
      enabled: true
      position:
        row: 4
        column: 7
      item:
        item: player_head texture:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWQ1YTA5ODg0Y2I4M2VmNWM5MDhkZGRkMzg1ZjI0NmZlZmRlZTIyMTcxMmMwMTAxNzdmNTQzNzZkYTIzOGZkZCJ9fX0=
        name: "%stat%"
        lore:
          - "&f等级: &a%level%"
          - "&8&o%description%"
    effects:
      - id: give_points
        args:
          type: g_mana
          amount: 1
        triggers:
          - static_20
        conditions:
          - id: below_points
            args:
              type: g_mana
              amount: '19 + %level%'
          - id: placeholder_contains
            args:
              placeholder: '%combatlogx_in_combat%'
              value: "Yes"
              ignore_case: true
    conditions: [ ]
```

### EcoItems

<pre><code>- id: ender_bow
  baseAttackSpeed: 1
  baseDamage: 1
  item:
    item: bow unbreakable hide_attributes
    lore:
    - '&#x26;7伤害: &#x26;c12❤'
    - ''
    - '&#x26;6&#x26;l技能: 末影之箭 &#x26;e(左键)'
    - '&#x26;7进入末影之箭状态后你接下来发射的一支箭将会'
    - '&#x26;7有范围伤害效果，伤害固定为 &#x26;c10 &#x26;7点.'
    - '&#x26;8消耗法力: &#x26;b15'
    - '&#x26;8冷却时间: &#x26;b15秒'
    - ''
    - '&#x26;9&#x26;l超稀有'
    displayName: '&#x26;9末影弓'
    recipe: []
    craftable: false
  fuels: []
  effects:
  - id: damage_multiplier
    args:
      multiplier: 2.0
    triggers:
    - bow_attack
<strong>  - id: run_chain_inline
</strong>    args:
      chain:
        effects:
          - id: shoot_arrow
            args:
              inherit_velocity: true 
              no_source: false
          - id: damage_nearby_entities
            args:
              damage: 11
              radius: 8 
              damage_as_player: false
              damage_self: false
            triggers:
              - projectile_hit
          - id: give_points
            args:
              type: g_mana
              amount: -15
          - id: send_message
            args:
              message: "&#x26;e你发动了技能: &#x26;6&#x26;l末影之箭!"
            action_bar: false
          - id: send_message
            args:
              message: "&#x26;e你接下来使用末影之弓发射的一支箭将有范围伤害效果!"
              action_bar: false
      cooldown: 15
    triggers:
      - alt_click
    conditions:
      - id: above_points
        args:
          type: g_mana
          amount: 15
          not-met-effects:
            - id: send_message
              args:
                message: "&#x26;c您当前的法力值不足，请等一会吧!"
  conditions: []
</code></pre>


---

# Agent Instructions: 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:

```
GET https://docs.superiormc.cn/ecox-doc/shi-zhan-xun-lian/fa-li-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
