134 - API文档汉化 - 卡槽修改功能

Updated 6 days ago

卡槽修改功能

本API现已支持为卡牌卡槽添加能力与行为!这类“卡槽修改功能”的实现方式与印记高度相似——您只需将修改逻辑编码为SlotModificationBehaviour的子类,并为新卡槽设计专属美术素材。

创建卡槽纹理与精灵

在3D游戏区域中,卡槽纹理尺寸为154x226像素。您可以选择为所有区域创建统一纹理,或分别为莱西、P03、格里魔拉和蔓尼菲科设计独立纹理。

2D游戏区域的卡槽纹理尺寸为44x58像素。2D对战存在五种主题风格(自然(Nature)、科技(Tech)、亡灵(Undead)、法师(Wizard)及终局(Finale)),且鼠标悬停时卡槽外观会发生变化。此外,您可能需要为对手卡槽设计不同于玩家卡槽的纹理(这在“自然”主题中尤为常见,因为爪痕图标在对手侧朝下而玩家侧朝上)。为适配这些不同组合,SlotModificationManager提供多种纹理配置选项:

  • 若提供44x58纹理,管理器将自动生成10种变体,根据各主题配色(标准状态与高亮/悬停状态)进行重新着色。所有黑色与透明像素将保持原样,其余像素将被替换为主题对应颜色。
  • 若提供220x116纹理,管理器会将其切割为10个精灵图(两行五列)。首行为标准卡槽,次行为悬停卡槽。列序依次为:自然、亡灵、科技、法师、终局。
  • 若提供220x232纹理,处理逻辑同上,但第三、四行将用于对手卡槽。

创建卡槽修改行为

您需要创建SlotModificationBehaviour的子类来实现卡槽逻辑,并可在此过程中添加API接口触发器。例如:

此卡槽会在每回合结束时对其中卡牌造成1点伤害:

class SharpSlotBehaviour : SlotModificationBehaviour
{
    public override bool RespondsToTurnEnd(bool playerTurnEnd) => playerTurnEnd == Slot.IsPlayerSlot;

    public override IEnumerator OnTurnEnd(bool playerTurnEnd)
    {
        if (Slot.Card != null)
            yield return Slot.Card.TakeDamage(1, null);
    }
}

此卡槽会为其中卡牌增加1点被动攻击力:

public class BuffSlot : SlotModificationBehaviour, IPassiveAttackBuff
{
    public int GetPassiveAttackBuff(PlayableCard target)
    {
        return Slot.Card == target ? 1 : 0;
    }
}

若需使卡槽赋予其中卡牌额外能力,可使用辅助类SlotModificationGainAbilityBehaviour

public class SharpQuillsSlot : SlotModificationGainAbilityBehaviour
{ 
    protected override Ability AbilityToGain => Ability.Sharp;
}

如需在卡槽创建或移除时执行操作,请分别重写SetupCleanup方法,常用于添加视觉特效:

public class AwesomeLookingSlot : SlotModificationBehaviour
{
    public override IEnumerator Setup()
    {
        yield return ShowSomeAwesomeVisuals();
    }

    public override IEnumerator Cleanup(SlotModificationManager.ModificationType replacement)
    {
        yield return DestroyMyAwesomeVisuals();
    }
}

注册卡槽修改功能

该模式与创建新印记高度相似,需调用SlotModificationManager进行注册并存储返回结果:

public static readonly SlotModificationManager.ModificationType SharpQuillsSlot = SlotModificationManager.New(
    "MyPluginGuid",
    "SharpQuillsSlot",
    typeof(SharpQuillsSlot),
    TextureHelper.GetImageAsTexture("my_3d_card_slot.png", typeof(SharpQuillsSlot).Assembly),
    TextureHelper.GetImageAsTexture("my_2d_card_slot.png", typeof(SharpQuillsSlot).Assembly)
)

激活卡槽修改功能

通常您会在其他印记中创建卡槽修改功能。以下示例展示了一个在卡牌死亡时激活卡槽的自定义印记,通过扩展方法SetSlotModification实现:

public class LeaveSharpBehindBehaviour : AbilityBehaviour
{
    public override bool RespondsToPreDeathAnimation(bool wasSacrifice) => Card.OnBoard;

    public override IEnumerator OnPreDeathAnimation(bool wasSacrifice)
    {
        // SharpQuillSlot即SlotModificationManager返回的ID
        yield return Card.Slot.SetSlotModification(SharpQuillsSlot);
    }
}