@@ -11,8 +11,7 @@ namespace InscryptionAPI.Triggers;
1111[ HarmonyPatch ]
1212internal static class CustomTriggerPatches
1313{
14- [ HarmonyPatch ( typeof ( PlayerHand ) , nameof ( PlayerHand . AddCardToHand ) ) ]
15- [ HarmonyPostfix ]
14+ [ HarmonyPostfix , HarmonyPatch ( typeof ( PlayerHand ) , nameof ( PlayerHand . AddCardToHand ) ) ]
1615 private static IEnumerator TriggerOnAddedToHand ( IEnumerator result , PlayableCard card )
1716 {
1817 yield return result ;
@@ -21,17 +20,16 @@ private static IEnumerator TriggerOnAddedToHand(IEnumerator result, PlayableCard
2120 yield break ;
2221 }
2322
24- [ HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . DoCombatPhase ) ) ]
25- [ HarmonyPostfix ]
23+ #region Combat Triggers
24+ [ HarmonyPostfix , HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . DoCombatPhase ) ) ]
2625 private static IEnumerator TriggerOnBellRung ( IEnumerator result , bool playerIsAttacker )
2726 {
2827 yield return CustomTriggerFinder . TriggerAll < IOnBellRung > ( false , x => x . RespondsToBellRung ( playerIsAttacker ) , x => x . OnBellRung ( playerIsAttacker ) ) ;
2928 yield return result ;
3029 yield break ;
3130 }
3231
33- [ HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . SlotAttackSequence ) ) ]
34- [ HarmonyPostfix ]
32+ [ HarmonyPostfix , HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . SlotAttackSequence ) ) ]
3533 private static IEnumerator TriggerOnSlotAttackSequence ( IEnumerator result , CardSlot slot )
3634 {
3735 yield return CustomTriggerFinder . TriggerAll < IOnPreSlotAttackSequence > ( false , x => x . RespondsToPreSlotAttackSequence ( slot ) , x => x . OnPreSlotAttackSequence ( slot ) ) ;
@@ -40,22 +38,22 @@ private static IEnumerator TriggerOnSlotAttackSequence(IEnumerator result, CardS
4038 yield break ;
4139 }
4240
43- [ HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . SlotAttackSlot ) ) ]
44- [ HarmonyPostfix ]
41+ [ HarmonyPostfix , HarmonyPatch ( typeof ( CombatPhaseManager ) , nameof ( CombatPhaseManager . SlotAttackSlot ) ) ]
4542 private static IEnumerator TriggerOnPostSingularSlotAttackSlot ( IEnumerator result , CardSlot attackingSlot , CardSlot opposingSlot )
4643 {
4744 yield return result ;
4845 yield return CustomTriggerFinder . TriggerAll < IOnPostSingularSlotAttackSlot > ( false , x => x . RespondsToPostSingularSlotAttackSlot ( attackingSlot , opposingSlot ) , x => x . OnPostSingularSlotAttackSlot ( attackingSlot , opposingSlot ) ) ;
4946 yield break ;
5047 }
48+ #endregion
5149
50+ #region Scale Patch
5251 private static Type scaleChangedCoroutine ;
5352 private static FieldInfo scaleChangedDamage ;
5453 private static FieldInfo scaleChangedToPlayer ;
5554 private static FieldInfo scaleChangedNumWeights ;
5655
57- [ HarmonyPatch ( typeof ( LifeManager ) , nameof ( LifeManager . ShowDamageSequence ) ) ]
58- [ HarmonyPostfix ]
56+ [ HarmonyPostfix , HarmonyPatch ( typeof ( LifeManager ) , nameof ( LifeManager . ShowDamageSequence ) ) ]
5957 private static IEnumerator TriggerOnScalesChanged ( IEnumerator result , int damage , int numWeights , bool toPlayer )
6058 {
6159 int initialDamage = damage ;
@@ -82,18 +80,10 @@ private static IEnumerator TriggerOnScalesChanged(IEnumerator result, int damage
8280 x . OnPostScalesChanged ( damage , toPlayer , initialDamage , initialToPlayer ) ) ;
8381 yield break ;
8482 }
83+ #endregion
8584
86- [ HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . DoUpkeepPhase ) ) ]
87- [ HarmonyPostfix ]
88- private static IEnumerator TriggerOnUpkeepInHand ( IEnumerator result , bool playerUpkeep )
89- {
90- yield return result ;
91- yield return CustomTriggerFinder . TriggerInHand < IOnUpkeepInHand > ( x => x . RespondsToUpkeepInHand ( playerUpkeep ) , x => x . OnUpkeepInHand ( playerUpkeep ) ) ;
92- yield break ;
93- }
94-
95- [ HarmonyPatch ( typeof ( BoardManager ) , nameof ( BoardManager . ResolveCardOnBoard ) ) ]
96- [ HarmonyPostfix ]
85+ #region Resolve and Slot Assignment
86+ [ HarmonyPostfix , HarmonyPatch ( typeof ( BoardManager ) , nameof ( BoardManager . ResolveCardOnBoard ) ) ]
9787 private static IEnumerator TriggerOnOtherCardResolveInHand ( IEnumerator result , PlayableCard card , bool resolveTriggers = true )
9888 {
9989 yield return result ;
@@ -104,30 +94,7 @@ private static IEnumerator TriggerOnOtherCardResolveInHand(IEnumerator result, P
10494 yield break ;
10595 }
10696
107- [ HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . PlayerTurn ) ) ]
108- [ HarmonyPostfix ]
109- private static IEnumerator TriggerOnTurnEndInHandPlayer ( IEnumerator result )
110- {
111- yield return result ;
112- yield return CustomTriggerFinder . TriggerInHand < IOnTurnEndInHand > ( x => x . RespondsToTurnEndInHand ( true ) , x => x . OnTurnEndInHand ( true ) ) ;
113- yield break ;
114- }
115-
116- [ HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . OpponentTurn ) ) ]
117- [ HarmonyPostfix ]
118- private static IEnumerator TriggerOnTurnEndInHandOpponent ( IEnumerator result , TurnManager __instance )
119- {
120- bool turnSkipped = __instance . Opponent . SkipNextTurn ;
121- yield return result ;
122- if ( ! turnSkipped )
123- {
124- yield return CustomTriggerFinder . TriggerInHand < IOnTurnEndInHand > ( x => x . RespondsToTurnEndInHand ( false ) , x => x . OnTurnEndInHand ( false ) ) ;
125- }
126- yield break ;
127- }
128-
129- [ HarmonyPatch ( typeof ( BoardManager ) , nameof ( BoardManager . AssignCardToSlot ) ) ]
130- [ HarmonyPostfix ]
97+ [ HarmonyPostfix , HarmonyPatch ( typeof ( BoardManager ) , nameof ( BoardManager . AssignCardToSlot ) ) ]
13198 private static IEnumerator TriggerOnOtherCardAssignedToSlotInHand ( IEnumerator result , PlayableCard card , bool resolveTriggers )
13299 {
133100 CardSlot slot2 = card . Slot ;
@@ -147,11 +114,12 @@ private static IEnumerator TriggerOnOtherCardAssignedToSlotInHand(IEnumerator re
147114 }
148115 yield break ;
149116 }
117+ #endregion
150118
119+ #region OnDie
151120 private static FieldInfo triggerField ;
152121
153- [ HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . Die ) ) ]
154- [ HarmonyPostfix ]
122+ [ HarmonyPostfix , HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . Die ) ) ]
155123 private static IEnumerator TriggerDeathTriggers ( IEnumerator result , PlayableCard __instance , bool wasSacrifice , PlayableCard killer = null )
156124 {
157125 CardSlot slotBeforeDeath = __instance . Slot ;
@@ -180,6 +148,7 @@ private static IEnumerator TriggerDeathTriggers(IEnumerator result, PlayableCard
180148 }
181149 yield break ;
182150 }
151+ #endregion
183152
184153 [ HarmonyPatch ( typeof ( ConsumableItemSlot ) , nameof ( ConsumableItemSlot . ConsumeItem ) ) ]
185154 [ HarmonyPostfix ]
@@ -228,6 +197,7 @@ private static IEnumerator TriggerItemUse(IEnumerator result, ConsumableItemSlot
228197 yield break ;
229198 }
230199
200+ #region Passive Stat Buffs
231201 [ HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . GetPassiveAttackBuffs ) ) ]
232202 [ HarmonyPostfix ]
233203 private static void PassiveAttackBuffs ( PlayableCard __instance , ref int __result )
@@ -257,7 +227,9 @@ private static void PassiveHealthBuffs(PlayableCard __instance, ref int __result
257227 }
258228 __result = dummyResult ;
259229 }
230+ #endregion
260231
232+ #region GetOpposingSlots
261233 [ HarmonyPatch ( typeof ( PlayableCard ) , nameof ( PlayableCard . GetOpposingSlots ) ) ]
262234 [ HarmonyPrefix ]
263235 private static bool OpposingSlotsPrefix ( PlayableCard __instance , ref List < CardSlot > __result , ref int __state )
@@ -330,12 +302,11 @@ private static bool OpposingSlotsPrefix(PlayableCard __instance, ref List<CardSl
330302 private static void OpposingSlots ( PlayableCard __instance , ref List < CardSlot > __result , int __state )
331303 {
332304 List < CardSlot > original = new ( __result ) ;
333- bool isAttackingDefaultSlot = ! __instance . HasTriStrike ( ) && ! __instance . HasAbility ( Ability . SplitStrike ) ;
334305 CardSlot defaultslot = __instance . Slot . opposingSlot ;
306+ bool isAttackingDefaultSlot = ! __instance . HasTriStrike ( ) && ! __instance . HasAbility ( Ability . SplitStrike ) ;
335307
336- List < CardSlot > alteredOpposings = new ( ) ;
337308 bool removeDefaultAttackSlot = false ;
338-
309+ List < CardSlot > alteredOpposings = new ( ) ;
339310 foreach ( IGetOpposingSlots component in CustomTriggerFinder . FindTriggersOnCard < IGetOpposingSlots > ( __instance ) )
340311 {
341312 if ( ( component as TriggerReceiver ) != null && component . RespondsToGetOpposingSlots ( ) )
@@ -350,6 +321,7 @@ private static void OpposingSlots(PlayableCard __instance, ref List<CardSlot> __
350321
351322 if ( isAttackingDefaultSlot && removeDefaultAttackSlot )
352323 __result . Remove ( defaultslot ) ;
324+
353325 bool didRemoveOriginalSlot = __instance . HasAbility ( Ability . SplitStrike ) && ( ! __instance . HasTriStrike ( ) || removeDefaultAttackSlot ) ;
354326 List < ISetupAttackSequence > all = CustomTriggerFinder . FindGlobalTriggers < ISetupAttackSequence > ( true ) . ToList ( ) ;
355327 all . RemoveAll ( x => ( x as TriggerReceiver ) == null ) ;
@@ -389,6 +361,33 @@ private static void OpposingSlots(PlayableCard __instance, ref List<CardSlot> __
389361 }
390362 __result . Sort ( ( CardSlot a , CardSlot b ) => a . Index - b . Index ) ;
391363 }
364+ #endregion
365+
366+ #region Upkeep and TurnEnd
367+ [ HarmonyPostfix , HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . DoUpkeepPhase ) ) ]
368+ private static IEnumerator TriggerOnUpkeepInHand ( IEnumerator result , bool playerUpkeep ) {
369+ yield return result ;
370+ yield return CustomTriggerFinder . TriggerInHand < IOnUpkeepInHand > ( x => x . RespondsToUpkeepInHand ( playerUpkeep ) , x => x . OnUpkeepInHand ( playerUpkeep ) ) ;
371+ yield break ;
372+ }
373+
374+ [ HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . PlayerTurn ) ) ]
375+ [ HarmonyPostfix ]
376+ private static IEnumerator TriggerOnTurnEndInHandPlayer ( IEnumerator result ) {
377+ yield return result ;
378+ yield return CustomTriggerFinder . TriggerInHand < IOnTurnEndInHand > ( x => x . RespondsToTurnEndInHand ( true ) , x => x . OnTurnEndInHand ( true ) ) ;
379+ yield break ;
380+ }
381+
382+ [ HarmonyPostfix , HarmonyPatch ( typeof ( TurnManager ) , nameof ( TurnManager . OpponentTurn ) ) ]
383+ private static IEnumerator TriggerOnTurnEndInHandOpponent ( IEnumerator result , TurnManager __instance ) {
384+ bool turnSkipped = __instance . Opponent . SkipNextTurn ;
385+ yield return result ;
386+ if ( ! turnSkipped ) {
387+ yield return CustomTriggerFinder . TriggerInHand < IOnTurnEndInHand > ( x => x . RespondsToTurnEndInHand ( false ) , x => x . OnTurnEndInHand ( false ) ) ;
388+ }
389+ yield break ;
390+ }
392391
393392 [ HarmonyTranspiler ]
394393 [ HarmonyPatch ( typeof ( TurnManager ) , "PlayerTurn" , MethodType . Enumerator ) ]
@@ -423,6 +422,7 @@ private static IEnumerator TriggerOnTurnEndInQueueCoro(IEnumerator originalTrigg
423422 yield return trigger . OnTurnEndInQueue ( playerTurn ) ;
424423 }
425424 }
425+ #endregion
426426
427427 [ HarmonyPatch ( typeof ( GlobalTriggerHandler ) , nameof ( GlobalTriggerHandler . TriggerNonCardReceivers ) ) , HarmonyPostfix ]
428428 private static IEnumerator TriggerSlotModificationHandlers ( IEnumerator sequence , bool beforeCards , Trigger trigger , params object [ ] otherArgs )
0 commit comments