From 444d7f597dc4fb50e01211703db2bc78a79b40a1 Mon Sep 17 00:00:00 2001 From: WhistleWind <69230920+HumabHatterZed@users.noreply.github.com> Date: Sat, 28 Nov 2026 18:16:55 -0800 Subject: [PATCH 1/2] Rewrite XML summary for class --- InscryptionCommunityPatch/Card/Part1SniperVisualizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InscryptionCommunityPatch/Card/Part1SniperVisualizer.cs b/InscryptionCommunityPatch/Card/Part1SniperVisualizer.cs index a4bea7ee..16fabaeb 100644 --- a/InscryptionCommunityPatch/Card/Part1SniperVisualizer.cs +++ b/InscryptionCommunityPatch/Card/Part1SniperVisualizer.cs @@ -5,7 +5,7 @@ namespace InscryptionCommunityPatch.Card; /// -/// Adds a Sniper Visualizer to Act 1. +/// Class for handling visual effects used by the Sniper ability in Act 1. /// public class Part1SniperVisualizer : ManagedBehaviour { From 1210b35cefaeb0c2cb269a161622cf707837cfbf Mon Sep 17 00:00:00 2001 From: WhistleWind <69230920+HumabHatterZed@users.noreply.github.com> Date: Sat, 28 Nov 2026 18:24:02 -0800 Subject: [PATCH 2/2] Add XML simplify some logic fix CardIsDeadOrHasRepulsive checking if the card can be killed for some reason fix opponent AI targeting the weakest cards instead of the strongest as intended --- .../Card/Vanilla Ability Patches/SniperFix.cs | 241 +++++++++++++++--- 1 file changed, 202 insertions(+), 39 deletions(-) diff --git a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/SniperFix.cs b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/SniperFix.cs index 1539c78e..771949b7 100644 --- a/InscryptionCommunityPatch/Card/Vanilla Ability Patches/SniperFix.cs +++ b/InscryptionCommunityPatch/Card/Vanilla Ability Patches/SniperFix.cs @@ -1,14 +1,18 @@ using DiskCardGame; using HarmonyLib; +using InscryptionAPI.Card; using InscryptionAPI.Helpers.Extensions; using System.Collections; using UnityEngine; namespace InscryptionCommunityPatch.Card; +/// +/// Patches to fix how the Sniper ability works outside Act 3. +/// Fixes visual indicators and opponent AI selection logic. +/// [HarmonyPatch] -public class SniperFix -{ +public class SniperFix { [HarmonyPatch(typeof(CombatPhaseManager), nameof(CombatPhaseManager.SlotAttackSequence))] [HarmonyPrefix] private static bool MaybeOverrideAttack(CombatPhaseManager __instance, ref IEnumerator __result, CardSlot slot) @@ -21,6 +25,11 @@ private static bool MaybeOverrideAttack(CombatPhaseManager __instance, ref IEnum return true; } + /// + /// The attack sequence called whenever a Sniper-bearing card attacks. + /// + /// The instance of to reference. + /// The of the card currently attacking. public static IEnumerator SniperAttack(CombatPhaseManager instance, CardSlot slot) { List opposingSlots = new(); // the slots to attacks @@ -46,6 +55,15 @@ public static IEnumerator SniperAttack(CombatPhaseManager instance, CardSlot slo visualizer?.VisualizeClearSniperAbility(); yield break; } + + /// + /// Handles what specific logic to run for the attacking card based on the side of the board it's on. + /// + /// The instance of to reference. + /// The visualiser class for handling the selection target icon(s). + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. public static IEnumerator DoSniperLogic( CombatPhaseManager instance, Part1SniperVisualizer visualizer, List opposingSlots, CardSlot attackingSlot, int numAttacks @@ -56,6 +74,15 @@ public static IEnumerator DoSniperLogic( else yield return PlayerSniperLogic(instance, visualizer, opposingSlots, attackingSlot, numAttacks); } + + /// + /// Calls after switching the current view to . + /// + /// The instance of to reference. + /// The visualiser class for handling the selection target icon(s). + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// The being attacked. public static IEnumerator DoAttackTargetSlotsLogic( CombatPhaseManager instance, Part1SniperVisualizer visualizer, List opposingSlots, CardSlot attackingSlot, CardSlot opposingSlot @@ -65,6 +92,14 @@ public static IEnumerator DoAttackTargetSlotsLogic( yield return instance.SlotAttackSlot(attackingSlot, opposingSlot, (opposingSlots.Count > 1) ? 0.1f : 0f); } + /// + /// The logic for handling player-controlled Sniper cards. + /// + /// The instance of to reference. + /// The visualiser class for handling the selection target icon(s). + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. public static IEnumerator PlayerSniperLogic( CombatPhaseManager instance, Part1SniperVisualizer visualizer, List opposingSlots, CardSlot attackingSlot, int numAttacks) @@ -95,16 +130,51 @@ public static IEnumerator PlayerSniperLogic( } } + /// + /// Retrieves the list of card slots that can be targeted by Sniper. + /// Defaults to all opposing slots. + /// + /// If the player is the one attacking or not. + /// The of the card currently attacking. + /// List of all card slots that can be targeted by Sniper. public static List GetValidTargets(bool playerIsAttacker, CardSlot attackingSlot) => BoardManager.Instance.GetSlotsCopy(!playerIsAttacker); + + /// + /// Callback method for whenever the player selects a to target for attack with Sniper. + /// + /// List of all slots that can be targeted for attack. + /// The being moused over. + /// The of the current attacking card. + /// + /// Adds to by default. Add/modify behaviour by patching this method. + /// public static void PlayerTargetSelectedCallback(List opposingSlots, CardSlot targetSlot, CardSlot attackingSlot) { opposingSlots.Add(targetSlot); } + + /// + /// Callback method for whenever the player's cursor hovers over a when selecting targets for Sniper. + /// + /// List of all slots that can be targeted for attack. + /// The being moused over. + /// The of the current attacking card. + /// + /// This is a stub method by default. Add behaviour by patching this method. + /// public static void PlayerSlotCursorEnterCallback(List opposingSlots, CardSlot targetSlot, CardSlot attackingSlot) { // empty on purpose } + /// + /// The logic for handling opponent-controlled Sniper cards. + /// + /// The instance of to reference. + /// The visualiser class for handling the selection target icon(s). + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. public static IEnumerator OpponentSniperLogic( CombatPhaseManager instance, Part1SniperVisualizer visualizer, List opposingSlots, CardSlot attackingSlot, int numAttacks) @@ -124,20 +194,33 @@ public static IEnumerator OpponentSniperLogic( yield return new WaitForSeconds(0.25f); } } + + /// + /// Determines what an opponent-controller Sniper card should attack. + /// + /// List of all slots that can be targeted for attack. + /// List of all player slots that can be targeted for attack. + /// The list of cards that can be attacked. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// public static CardSlot OpponentSelectTargetSlot(List opposingSlots, List playerSlots, List playerCards, CardSlot attackingSlot, int numAttacks ) { - bool anyCards = playerCards.Count > 0; - if (anyCards) + + if (playerCards.Count > 0) { - if (CanWin(opposingSlots, playerSlots, attackingSlot, numAttacks)) + if (CanWin(opposingSlots, playerSlots, attackingSlot, numAttacks)) { return GetFirstAvailableOpenSlot(opposingSlots, playerSlots, attackingSlot, numAttacks); + } else { - PlayableCard killable = GetStrongestKillableCard(anyCards, playerCards, opposingSlots, attackingSlot, numAttacks); - PlayableCard attackable = GetFirstStrongestAttackableCard(anyCards, playerCards, opposingSlots, attackingSlot, numAttacks); - PlayableCard noPref = GetFirstStrongestAttackableCardNoPreferences(anyCards, playerCards, opposingSlots, attackingSlot, numAttacks); + // re-check playerCards.Count just to account for the minute possibility of playerCards being modified by modders + // when calculating each possible target + PlayableCard killable = GetStrongestKillableCard(playerCards.Count > 0, playerCards, opposingSlots, attackingSlot, numAttacks); + PlayableCard attackable = GetFirstStrongestAttackableCard(playerCards.Count > 0, playerCards, opposingSlots, attackingSlot, numAttacks); + PlayableCard noPref = GetFirstStrongestAttackableCardNoPreferences(playerCards.Count > 0, playerCards, opposingSlots, attackingSlot, numAttacks); if (killable != null) return killable.Slot; @@ -151,12 +234,28 @@ public static CardSlot OpponentSelectTargetSlot(List opposingSlots, Li } return playerSlots[SeededRandom.Range(0, playerSlots.Count, SaveManager.SaveFile.GetCurrentRandomSeed() + GlobalTriggerHandler.Instance.NumTriggersThisBattle)]; } + + /// + /// Sorts the given list based on the given . + /// + /// + /// The unsorted list. + /// The comparison to use to sort . + /// A shallow, sorted copy of . public static List GetSorted(List unsorted, Comparison sort) { List toSort = new(unsorted); toSort.Sort(sort); return toSort; } + /// + /// Determines the first empty that can be targeted directly, accounting for Burrower cards. + /// + /// List of all slots that can be targeted for attack. + /// List of all player slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// The first empty that can be targeted to deal direct damage, or null if one can't be found. public static CardSlot GetFirstAvailableOpenSlot( List opposingSlots, List playerSlots, CardSlot slot, int numAttacks) @@ -167,58 +266,122 @@ public static CardSlot GetFirstAvailableOpenSlot( !CardIsDeadOrHasRepulsive(y.Card, opposingSlots, slot, numAttacks) && !slot.Card.CanAttackDirectly(y))); } - public static bool CanWin(List opposingSlots, List playerSlots, CardSlot slot, int numAttacks) - { + + /// + /// Determines if the opponent can win the battle by directly attacking the player. + /// + /// List of all slots that can be targeted for attack. + /// List of all player slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// True if the opponent can deal enough direct damage to the player in order to win. + public static bool CanWin(List opposingSlots, List playerSlots, CardSlot slot, int numAttacks) { return LifeManager.Instance != null && LifeManager.Instance.Balance - (numAttacks * slot.Card.Attack) <= -5 && GetFirstAvailableOpenSlot(opposingSlots, playerSlots, slot, numAttacks) != null; } + + /// + /// Determines if the given card can be killed by an opponent-controlled Sniper card. + /// + /// The being checked for kill-ability. Cannot be null. + /// The number of attacks that can be made. + /// The of the attacking card. + /// Nullable integer that takes priority over if not null. + /// True if can be killed by the attacking card. public static bool CanKillCard(PlayableCard pc, int numAttacks, CardSlot slot, int? overrideAttacks = null) { int realNumAttacks = overrideAttacks ?? numAttacks; - int availableAttacksToKill = pc.HasShield() ? realNumAttacks - 1 : realNumAttacks; + int availableAttacksToKill = realNumAttacks - pc.GetTotalShields(); return slot.Card.HasAbility(Ability.Deathtouch) && !pc.HasAbility(Ability.MadeOfStone) ? availableAttacksToKill > 0 : availableAttacksToKill * slot.Card.Attack >= pc.Health && !slot.Card.CanAttackDirectly(pc.Slot); } - public static int NumCardTargets(PlayableCard pc, List opposingSlots) - { - return opposingSlots.FindAll((x) => x != null && x.Card != null && x.Card == pc).Count; + + /// + /// Determines the number of times the given is present in . + /// + /// The to check for. + /// The list of card slots to check for . + /// The number of times appears in . + public static int NumCardTargets(PlayableCard pc, List opposingSlots) { + return pc == null ? 0 : opposingSlots.Count(x => x.Card == pc); } + + /// + /// Determines if the given is dead, null, or Repulsive. + /// + /// The being attacked. + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// True if is null, dead, or has the Repulsive sigil. public static bool CardIsDeadOrHasRepulsive(PlayableCard pc, List opposingSlots, CardSlot slot, int numAttacks) { - return pc == null || pc.Dead || pc.HasAbility(Ability.PreventAttack) || CanKillCard(pc, numAttacks, slot, NumCardTargets(pc, opposingSlots)); + return pc == null || pc.Dead || pc.HasAbility(Ability.PreventAttack); } - public static bool WillDieFromSharp(PlayableCard pc, CardSlot slot) - { - int attacksFromSpiky = pc.Info.Abilities.FindAll((Ability x) => x == Ability.Sharp).Count; - if (pc.HasAbility(Ability.Sharp) && attacksFromSpiky < 1) - attacksFromSpiky = 1; + + /// + /// Determines if the attacking card will die from Sharp Quills when striking . + /// + /// The being attacked. + /// The of the attacking card. + /// True if attacking will kill the attacking card. + public static bool WillDieFromSharp(PlayableCard pc, CardSlot slot) { + int attacksFromSpiky = pc.GetAbilityStacks(Ability.Sharp); if (slot.Card.HasShield()) - attacksFromSpiky--; + attacksFromSpiky -= slot.Card.GetTotalShields(); attacksFromSpiky = Mathf.Max(0, attacksFromSpiky); return pc.HasAbility(Ability.Deathtouch) ? attacksFromSpiky > 0 : attacksFromSpiky >= slot.Card.Health; } - public static PlayableCard GetFirstStrongestAttackableCard( - bool anyCards, - List playerCards, List opposingSlots, - CardSlot slot, int numAttacks) - { - if (!anyCards) - return null; - return GetSorted(playerCards.FindAll(x => !slot.Card.CanAttackDirectly(x.Slot) && !WillDieFromSharp(x, slot) && !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks)), (x, x2) => x.PowerLevel - x2.PowerLevel).FirstOrDefault(); - } + /// + /// Determines the strongest attackable, killable card in the given list of cards. + /// + /// If 's count is greater than 0. + /// The list of cards that can be attacked. + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// public static PlayableCard GetStrongestKillableCard(bool anyCards, List playerCards, List opposingSlots, - CardSlot slot, int numAttacks) - { - if (!anyCards) - return null; + CardSlot slot, int numAttacks) { + if (anyCards) { + return GetSorted(playerCards.FindAll((x) => !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks) && !WillDieFromSharp(x, slot) && CanKillCard(x, numAttacks, slot)), (x, x2) => x2.PowerLevel - x.PowerLevel).FirstOrDefault(); + } + return null; + } - return anyCards ? GetSorted(playerCards.FindAll((x) => CanKillCard(x, numAttacks, slot) && !WillDieFromSharp(x, slot) && !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks)), (x, x2) => x.PowerLevel - x2.PowerLevel).FirstOrDefault() : null; + /// + /// Determines the strongest attackable card in the given list of cards. + /// + /// If 's count is greater than 0. + /// The list of cards that can be attacked. + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// The determined to be the strongest attackable card, or null if is true. + public static PlayableCard GetFirstStrongestAttackableCard( + bool anyCards, + List playerCards, List opposingSlots, + CardSlot slot, int numAttacks) { + if (anyCards) { + return GetSorted(playerCards.FindAll(x => !slot.Card.CanAttackDirectly(x.Slot) && !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks) && !WillDieFromSharp(x, slot)), (x, x2) => x2.PowerLevel - x.PowerLevel).FirstOrDefault(); + } + return null; } + + /// + /// Determines the strongest attackable card in the given list of cards. Does not check . + /// + /// If 's count is greater than 0. + /// The list of cards that can be attacked. + /// List of all slots that can be targeted for attack. + /// The of the card currently attacking. + /// How many times the attacking card will attack. + /// The determined to be the strongest attackable card, or null if is true. public static PlayableCard GetFirstStrongestAttackableCardNoPreferences(bool anyCards, List playerCards, List opposingSlots, CardSlot slot, int numAttacks) @@ -226,14 +389,14 @@ public static PlayableCard GetFirstStrongestAttackableCardNoPreferences(bool any if (!anyCards) return null; - return GetSorted(playerCards.FindAll((x) => !slot.Card.CanAttackDirectly(x.Slot) && !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks)), (x, x2) => x.PowerLevel - x2.PowerLevel).FirstOrDefault(); + return GetSorted(playerCards.FindAll((x) => !slot.Card.CanAttackDirectly(x.Slot) && !CardIsDeadOrHasRepulsive(x, opposingSlots, slot, numAttacks)), (x, x2) => x2.PowerLevel - x.PowerLevel).FirstOrDefault(); } /// - /// Counts the number of times that a card with sniper should attack + /// Counts the number of times that a card with sniper should attack. /// - /// The card with sniper on it - /// An integer indicating the number of times the card should attack + /// The with the Sniper ability. + /// An integer indicating the number of times the card should attack. public static int GetAttackCount(PlayableCard card) { // Let's do this the easiest way possible