132 - API文档汉化 - 自定义狙击逻辑

Updated 2 weeks ago

自定义狙击逻辑

虽然从技术上讲不属于官方API范畴,社区补丁仍为模组开发者提供了多项实用功能选项。

正如其名所示,InscryptionCommunityPatch.Card.SniperFix修复了狙击手(Sniper)能力在第一章中的使用问题。但它的功能不仅限于此——该补丁还将狙击能力的逻辑扩展为多个可重写方法,允许对狙击能力在游戏各环节的功能进行深度定制。

修改这些方法需要通过Harmony进行补丁注入。具体方法如下:

  • DoSniperLogic() - 控制使用玩家或对手的狙击逻辑
  • DoAttackTargetSlotsLogic() - 控制每个目标卡槽的攻击判定逻辑
  • GetValidTargets() - 返回玩家与对手可攻击的卡槽列表
  • PlayerTargetSelectedCallback() - 当玩家选定有效目标时触发
  • PlayerSlotCursorEnterCallback() - 当玩家光标进入卡槽时触发
  • OpponentSelectTarget() - 返回对手选择攻击的目标卡槽

例如,若需使具备狙击能力的卡牌可以攻击任意卡槽(包括己方战场卡槽),应执行以下代码:

[HarmonyPostfix, HarmonyPatch(typeof(SniperFix), nameof(SniperFix.GetValidTargets))]
private static void TargetAllSlots(ref List<CardSlot> __result, bool playerIsAttacker, CardSlot attackingSlot)
{
    __result = BoardManager.Instance.AllSlotsCopy; // 覆写默认有效目标列表
    __result.Remove(attackingSlot); // 移除当前攻击卡槽作为有效目标
}
Pages