@@ -717,9 +717,13 @@ public static void AddShieldCount(this PlayableCard card, int amount, bool updat
717717 /// <param name="updateDisplay">Whether to update the card's display, meaning sigil stack numbers and any shield effects.</param>
718718 public static void AddShieldCount ( this PlayableCard card , int amount , Ability ability , bool updateDisplay = true )
719719 {
720- Type behav = AbilityManager . AllAbilities . Find ( x => x . Id == ability ) . AbilityBehavior ;
721- DamageShieldBehaviour component = card . GetComponent ( behav ) as DamageShieldBehaviour ;
722- component ? . AddShields ( amount , updateDisplay ) ;
720+ DamageShieldBehaviour component = card . GetShieldBehaviour ( ability ) ;
721+ if ( component == null )
722+ {
723+ InscryptionAPIPlugin . Logger . LogError ( $ "[AddShieldCount] DamageShieldBehaviour of Ability [{ ability } ] not found!") ;
724+ return ;
725+ }
726+ component . AddShields ( amount , updateDisplay ) ;
723727 }
724728 /// <summary>
725729 /// Increases the amount of shields a specific ability's AbilityBehaviour is currently giving.
@@ -749,9 +753,13 @@ public static void RemoveShieldCount(this PlayableCard card, int amount, bool up
749753 /// <param name="updateDisplay">Whether to update the card's display, meaning sigil stack numbers and any shield effects.</param>
750754 public static void RemoveShieldCount ( this PlayableCard card , int amount , Ability ability , bool updateDisplay = true )
751755 {
752- Type behav = AbilityManager . AllAbilities . Find ( x => x . Id == ability ) . AbilityBehavior ;
753- DamageShieldBehaviour component = card . GetComponent ( behav ) as DamageShieldBehaviour ;
754- component ? . RemoveShields ( amount , updateDisplay ) ;
756+ DamageShieldBehaviour component = card . GetShieldBehaviour ( ability ) ;
757+ if ( component == null )
758+ {
759+ InscryptionAPIPlugin . Logger . LogError ( $ "[RemoveShieldCount] DamageShieldBehaviour of Ability [{ ability } ] not found!") ;
760+ return ;
761+ }
762+ component . RemoveShields ( amount , updateDisplay ) ;
755763 }
756764 public static void RemoveShieldCount < T > ( this PlayableCard card , int amount , bool updateDisplay = true ) where T : DamageShieldBehaviour
757765 {
@@ -786,13 +794,32 @@ public static int GetTotalShields(this PlayableCard card)
786794
787795 return totalShields ;
788796 }
797+
798+ /// <summary>
799+ /// Retrieves the current value of a DamageShieldBehaviour's NumShield.
800+ /// </summary>
801+ /// <typeparam name="T"></typeparam>
802+ /// <param name="card"></param>
803+ /// <returns>The current value of the DamageShieldBehaviour's NumShield.</returns>
789804 public static int GetShieldCount < T > ( this PlayableCard card ) where T : DamageShieldBehaviour
790805 {
791806 T comp = card . GetComponent < T > ( ) ;
792- if ( comp != null )
793- return comp . NumShields ;
807+ return comp ? . NumShields ?? 0 ;
808+ }
794809
795- return 0 ;
810+ /// <summary>
811+ /// Retrieves the DamageShieldBehaviour component corresponding to the given Ability, or null if it does not exist.
812+ /// </summary>
813+ /// <param name="card"></param>
814+ /// <param name="ability"></param>
815+ /// <returns>The DamageShieldBehaviour component of the given Ability, or null if it does not exist.</returns>
816+ public static DamageShieldBehaviour GetShieldBehaviour ( this PlayableCard card , Ability ability )
817+ {
818+ Type type = ShieldManager . AllShieldAbilities . AbilityByID ( ability ) ? . AbilityBehavior ;
819+ if ( type == null )
820+ return null ;
821+
822+ return card . GetComponent ( type ) as DamageShieldBehaviour ;
796823 }
797824 /// <summary>
798825 /// A variant of ResetShield that only resets shields belonging is a certain ability.
@@ -806,8 +833,32 @@ public static void ResetShield(this PlayableCard card, Ability ability)
806833 if ( com . Ability == ability )
807834 com . ResetShields ( false ) ;
808835 }
836+ card . Status . lostShield = false ;
837+ }
809838
810- card . ResetShield ( ) ;
839+ public static bool IsShieldAbility ( this Ability ability )
840+ {
841+ return ShieldManager . AllShieldInfos . AbilityByID ( ability ) != null ;
842+ }
843+ public static bool IsShieldAbility ( this AbilityInfo abilityInfo )
844+ {
845+ return ShieldManager . AllShieldInfos . Contains ( abilityInfo ) ;
846+ }
847+ /// <summary>
848+ /// Returns whether or not the PlayableCard has an Ability that overrides DamageShieldBehaviour.
849+ /// </summary>
850+ /// <param name="card">The PlayableCard object to check.</param>
851+ public static bool HasShieldAbility ( this PlayableCard card )
852+ {
853+ return card . AllAbilities ( ) . Exists ( x => x . IsShieldAbility ( ) ) ;
854+ }
855+ /// <summary>
856+ /// Returns whether or not the CardInfo has an Ability that overrides DamageShieldBehaviour.
857+ /// </summary>
858+ /// <param name="cardInfo">The CardInfo object to check.</param>
859+ public static bool HasShieldAbility ( this CardInfo cardInfo )
860+ {
861+ return cardInfo . Abilities . Exists ( x => x . IsShieldAbility ( ) ) ;
811862 }
812863
813864 #endregion
0 commit comments