@@ -23,9 +23,9 @@ public static class ShieldManager
2323 public static List < FullAbility > AllShieldAbilities { get ; internal set ; } = new ( AllAbilities ) ;
2424 public static List < AbilityInfo > AllShieldInfos { get ; internal set ; } = AllShieldAbilities . Select ( x => x . Info ) . ToList ( ) ;
2525
26-
2726 public static IEnumerator TriggerBreakShield ( PlayableCard target , int damage , PlayableCard attacker )
2827 {
28+ //InscryptionAPIPlugin.Logger.LogDebug("[TriggerBreakShield] Begin");
2929 BreakShield ( target , damage , attacker ) ;
3030
3131 List < IShieldPreventedDamage > shieldTriggers = CustomTriggerFinder . FindTriggersOnBoard < IShieldPreventedDamage > ( false ) . ToList ( ) ;
@@ -56,9 +56,11 @@ public static void BreakShield(PlayableCard target, int damage, PlayableCard att
5656 DamageShieldBehaviour shield = Array . Find ( target . GetComponents < DamageShieldBehaviour > ( ) , x => x . HasShields ( ) ) ;
5757 if ( shield != null )
5858 {
59+ //InscryptionAPIPlugin.Logger.LogDebug("[BreakShield] Found DamageShieldBehaviour");
5960 CardModificationInfo info = target . TemporaryMods . Find ( x => x . abilities != null && x . abilities . Contains ( shield . Ability ) ) ;
6061 if ( info != null )
6162 {
63+ //InscryptionAPIPlugin.Logger.LogDebug("[BreakShield] CardModInfo found for behaviour");
6264 target . RemoveTemporaryMod ( info , false ) ; // RemoveShields is called here in a patch
6365 info . abilities . Remove ( shield . Ability ) ;
6466 target . AddTemporaryMod ( info ) ;
@@ -71,6 +73,7 @@ public static void BreakShield(PlayableCard target, int damage, PlayableCard att
7173 target . Anim . StrongNegationEffect ( ) ;
7274 if ( target . GetTotalShields ( ) == 0 ) // if we removed the last shield
7375 {
76+ //InscryptionAPIPlugin.Logger.LogDebug("[BreakShield] TotalShields == 0");
7477 target . Status . lostShield = true ;
7578 if ( target . Info . HasBrokenShieldPortrait ( ) )
7679 target . SwitchToPortrait ( target . Info . BrokenShieldPortrait ( ) ) ;
@@ -85,73 +88,37 @@ private static void PreventShieldReset(Latch __instance, ref bool __result, Play
8588 if ( __instance is LatchDeathShield && card . HasShield ( ) )
8689 __result = true ;
8790 }
91+
8892 [ HarmonyPrefix , HarmonyPatch ( typeof ( LatchDeathShield ) , nameof ( LatchDeathShield . OnSuccessfullyLatched ) ) ]
8993 private static bool PreventShieldReset ( PlayableCard target )
9094 {
91- target . UpdateFaceUpOnBoardEffects ( ) ;
92- return false ; // latch death shield doesn't reset shields
95+ target . UpdateFaceUpOnBoardEffects ( ) ; // latch death shield doesn't reset shields
96+ return false ;
9397 }
9498
9599 /// <summary>
96- /// The new version of PlayableCard.HasShield implementing the new shield logic .
100+ /// Modified version of PlayableCard.HasShield that replaces the original method's result .
97101 /// </summary>
98- public static bool NewHasShield ( PlayableCard instance ) => instance . GetTotalShields ( ) > 0 && ! instance . Status . lostShield ;
102+ public static bool NewHasShield ( PlayableCard instance )
103+ {
104+ return instance . GetTotalShields ( ) > 0 && ! instance . Status . lostShield ;
105+ }
99106
100107 [ HarmonyPostfix , HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . HasShield ) ) ]
101- private static void ReplaceHasShieldBool ( PlayableCard __instance , ref bool __result ) => __result = NewHasShield ( __instance ) ;
108+ private static void ReplaceHasShieldBool ( PlayableCard __instance , ref bool __result )
109+ {
110+ __result = NewHasShield ( __instance ) ;
111+ }
102112
103113 [ HarmonyPrefix , HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . ResetShield ) , new Type [ ] { } ) ]
104114 private static void ResetModShields ( PlayableCard __instance ) // runs before the base ResetShield logic
105115 {
106116 foreach ( DamageShieldBehaviour com in __instance . GetComponents < DamageShieldBehaviour > ( ) )
107117 com . ResetShields ( false ) ;
108118
109- // if we're using the broken shield portrait, reset to the default portrait - if we're MudTurtle
119+ // if we're using the broken shield portrait, reset to the default portrait
110120 if ( __instance . Info . name == "MudTurtle" || ( __instance . Info . BrokenShieldPortrait ( ) != null && __instance . RenderInfo . portraitOverride == __instance . Info . BrokenShieldPortrait ( ) ) )
111121 __instance . SwitchToDefaultPortrait ( ) ;
112-
113- __instance . Status . lostShield = false ;
114- }
115-
116- [ HarmonyTranspiler , HarmonyPatch ( typeof ( ShieldGeneratorItem ) , nameof ( ShieldGeneratorItem . ActivateSequence ) , MethodType . Enumerator ) ]
117- private static IEnumerable < CodeInstruction > DontResetOnActivate ( IEnumerable < CodeInstruction > instructions )
118- {
119- List < CodeInstruction > codes = new ( instructions ) ;
120- int index = codes . FindIndex ( x => x . operand ? . ToString ( ) == "DiskCardGame.BoardManager get_Instance()" ) ;
121- if ( index > 0 )
122- {
123- MethodBase method = AccessTools . Method ( typeof ( ShieldManager ) , nameof ( ShieldManager . EmptyList ) ) ;
124- codes . RemoveRange ( index , 2 ) ;
125- codes . Insert ( index , new ( OpCodes . Callvirt , method ) ) ;
126- }
127- return codes ;
128- }
129- [ HarmonyTranspiler , HarmonyPatch ( typeof ( ShieldGems ) , nameof ( ShieldGems . OnResolveOnBoard ) , MethodType . Enumerator ) ]
130- private static IEnumerable < CodeInstruction > DontResetOnResolve ( IEnumerable < CodeInstruction > instructions )
131- {
132- List < CodeInstruction > codes = new ( instructions ) ;
133- int index = codes . FindLastIndex ( x => x . operand ? . ToString ( ) == "0.25" ) - 4 ;
134- if ( index > 0 )
135- {
136- MethodBase method = AccessTools . Method ( typeof ( ShieldManager ) , nameof ( ShieldManager . EmptyList ) ) ;
137- codes . RemoveRange ( index , 2 ) ;
138- codes . Insert ( index , new ( OpCodes . Callvirt , method ) ) ;
139- }
140- return codes ;
141- }
142-
143- [ HarmonyTranspiler , HarmonyPatch ( typeof ( RandomCardGainsShieldEffect ) , nameof ( RandomCardGainsShieldEffect . Execute ) , MethodType . Enumerator ) ]
144- private static IEnumerable < CodeInstruction > DontResetOnExecute ( IEnumerable < CodeInstruction > instructions )
145- {
146- List < CodeInstruction > codes = new ( instructions ) ;
147- int index = codes . FindLastIndex ( x => x . opcode == OpCodes . Newobj ) ;
148- if ( index > 0 )
149- {
150- MethodBase method = AccessTools . Method ( typeof ( ShieldManager ) , nameof ( ShieldManager . EmptyList ) ) ;
151- codes . RemoveRange ( index , 4 ) ;
152- codes . Insert ( index , new ( OpCodes . Callvirt , method ) ) ;
153- }
154- return codes ;
155122 }
156123
157124 [ HarmonyTranspiler , HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . UpdateFaceUpOnBoardEffects ) ) ]
@@ -209,7 +176,7 @@ private static IEnumerable<CodeInstruction> RemoveSingleHiddenStacks(IEnumerable
209176 return codes ;
210177 }
211178
212- private static List < CardSlot > EmptyList ( ) => new ( ) ; // for transpiler logic (why can't i just pass an empty list?)
179+ private static List < CardSlot > EmptyList ( ) => new ( ) ; // for transpiler logic
213180
214181 private static List < Ability > HiddensOnlyRemoveStacks ( List < Ability > abilities , List < Ability > hiddenAbilities )
215182 {
@@ -222,49 +189,42 @@ private static List<Ability> HiddensOnlyRemoveStacks(List<Ability> abilities, Li
222189 }
223190 private static void CorrectHiddenAbilityRender ( PlayableCard card )
224191 {
225- foreach ( DamageShieldBehaviour com in card . GetComponents < DamageShieldBehaviour > ( ) . Where ( x => x . initialised ) )
226- {
227- if ( com . HasShields ( ) )
228- {
229- if ( com . Ability . GetHideSingleStacks ( ) )
230- {
231- // if there are more hidden shields than there should be
232- if ( card . Status . hiddenAbilities . Count ( x => x == com . Ability ) >= com . NumShields )
233- {
234- for ( int i = 0 ; i < com . NumShields ; i ++ )
235- {
236- card . Status . hiddenAbilities . Remove ( com . Ability ) ;
237- }
238- }
239- }
240- else
241- {
242- card . Status . hiddenAbilities . Remove ( com . Ability ) ;
243- }
244- break ;
245- }
246- else
247- {
248- if ( com . Ability . GetHideSingleStacks ( ) )
249- {
250- card . AddShieldCount ( 1 , Ability . DeathShield ) ;
251- int shieldsLost = com . StartingNumShields - com . NumShields ;
252- if ( card . Status . hiddenAbilities . Count ( x => x == com . Ability ) < shieldsLost )
253- {
254- for ( int i = 0 ; i < shieldsLost ; i ++ )
255- {
256- //Debug.Log($"{com.StartingNumShields} {com.NumShields} {shieldsLost} Add hidden");
257- card . Status . hiddenAbilities . Add ( com . Ability ) ;
258- }
259- }
260- }
261- else if ( ! card . Status . hiddenAbilities . Contains ( com . Ability ) )
262- {
263- card . Status . hiddenAbilities . Add ( com . Ability ) ;
264- }
265- break ;
266- }
267- }
192+ //foreach (DamageShieldBehaviour com in card.GetComponents<DamageShieldBehaviour>().Where(x => x.initialised))
193+ //{
194+ // if (com.HasShields())
195+ // {
196+ // if (com.Ability.GetHideSingleStacks())
197+ // {
198+ // // if there are more hidden shields than there should be
199+ // while (card.Status.hiddenAbilities.Count(x => x == com.Ability) > com.NumShields)
200+ // {
201+ // card.Status.hiddenAbilities.Remove(com.Ability);
202+ // }
203+ // }
204+ // else
205+ // {
206+ // card.Status.hiddenAbilities.RemoveAll(x => x == com.Ability);
207+ // }
208+ // break;
209+ // }
210+ // else
211+ // {
212+ // if (com.Ability.GetHideSingleStacks())
213+ // {
214+ // int shieldsLost = com.StartingNumShields - com.NumShields;
215+ // while (card.Status.hiddenAbilities.Count(x => x == com.Ability) < shieldsLost)
216+ // {
217+ // //Debug.Log($"{com.StartingNumShields} {com.NumShields} {shieldsLost} Add hidden");
218+ // card.Status.hiddenAbilities.Add(com.Ability);
219+ // }
220+ // }
221+ // else if (!card.Status.hiddenAbilities.Contains(com.Ability))
222+ // {
223+ // card.Status.hiddenAbilities.Add(com.Ability);
224+ // }
225+ // break;
226+ // }
227+ //}
268228
269229 if ( card . Info . HasBrokenShieldPortrait ( ) && card . RenderInfo . portraitOverride == card . Info . BrokenShieldPortrait ( ) && card . HasShield ( ) )
270230 {
0 commit comments