添加新能力
以下示例默认已经在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 { public override PowerType Type => PowerType.Buff; public override PowerStackType StackType => PowerStackType.Counter; 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 ); } }
[RegisterPower]会自动注册能力。
继承的是ModPowerTemplate。
AssetProfile里的IconPath和BigIconPath分别对应能力的小图和大图。
示例演示了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。
最终项目参考 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