Reme

添加新能力

以下示例默认已经在Entry.Init()中调用了RitsuLibFramework.EnsureGodotScriptsRegistered(...)ModTypeDiscoveryHub.RegisterModAssembly(...),否则自动注册不会生效。

代码

新建类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using MegaCrit.Sts2.Core.Commands;
using MegaCrit.Sts2.Core.Entities.Powers;
using MegaCrit.Sts2.Core.GameActions.Multiplayer;
using MegaCrit.Sts2.Core.Models.Cards;
using STS2RitsuLib.Interop.AutoRegistration;
using STS2RitsuLib.Scaffolding.Content;

namespace Test.Scripts;

[RegisterPower]
public class TestPower : ModPowerTemplate
{
// 类型,Buff或Debuff
public override PowerType Type => PowerType.Buff;
// 叠加类型,Counter表示可叠加,Single表示不可叠加
public override PowerStackType StackType => PowerStackType.Counter;

// 自定义图标路径。1:1即可。原版游戏大图256x256,小图64x64。
public override PowerAssetProfile AssetProfile => new(
IconPath: "res://Test/images/powers/test_power.png",
BigIconPath: "res://Test/images/powers/test_power.png"
);

// 抽牌后给予玩家力量
public override async Task AfterCardDrawn(PlayerChoiceContext choiceContext, CardModel card, bool fromHandDraw)
{
await PowerCmd.Apply<StrengthPower>(Owner, Amount, Owner, null);
// await PowerCmd.Apply<StrengthPower>(choiceContext, Owner, Amount, Owner, null); // 测试版
}
}
  • [RegisterPower]会自动注册能力。
  • 继承的是ModPowerTemplate
  • AssetProfile里的IconPathBigIconPath分别对应能力的小图和大图。
  • 示例演示了AfterCardDrawn钩子,你想监听别的时机时,直接继续重写对应方法即可。

文本

添加json,{ModId}/localization/{Language}/powers.json

1
2
3
4
5
{
"TEST_POWER_TEST_POWER.description": "每次抽牌时,获得一点[gold]力量[/gold]。",
"TEST_POWER_TEST_POWER.smartDescription": "每次抽牌时,获得[blue]{Amount}[/blue]点[gold]力量[/gold]。",
"TEST_POWER_TEST_POWER.title": "邪火"
}

smartDescription可以使用{Amount}来显示当前层数。

然后使用PowerCmd.Apply<TestPower>(...)给予即可。或者使用控制台power TEST_POWER_TEST_POWER 1 0

alt text

最终项目参考

1
2
3
4
5
6
7
8
9
10
11
Test
├── Scripts
│ ├── Entry.cs
│ └── TestPower.cs
└── Test
├── images
│ └── powers
│ └── test_power.png
└── localization
└── zhs
└── powers.json
Author: Reme
Link:https://glitchedreme.github.io/SlayTheSpire2ModdingTutorials/docs/04-ritsulib/04-05-add-power/
版权声明:本文采用 CC BY-NC-SA 4.0 CN 协议进行许可