66
77namespace API . Patches
88{
9- [ HarmonyPatch ( typeof ( CardTriggerHandler ) , "AddAbility" , new Type [ ] { typeof ( Ability ) } ) ]
10- public class CardTriggerHandler_AddAbility
9+ [ HarmonyPatch ( typeof ( CardTriggerHandler ) , "AddAbility" , new [ ] { typeof ( Ability ) } ) ]
10+ public class CardTriggerHandler_AddAbility_Ability
1111 {
1212 public static bool Prefix ( Ability ability , CardTriggerHandler __instance )
1313 {
@@ -19,7 +19,7 @@ public static bool Prefix(Ability ability, CardTriggerHandler __instance)
1919 Predicate < Tuple < Ability , AbilityBehaviour > > checkAbilityExists = tuple =>
2020 tuple . Item1 == ability || AbilityCanStackAndIsNotPassive ( ability ) ;
2121
22- // return true if the ability is equal to pair item1 OR if ability cannot stack and is passive
22+ // return true if the ability is equal to the ability in the pair OR if ability cannot stack and is passive
2323 if ( ! __instance . triggeredAbilities . Exists ( checkAbilityExists ) )
2424 {
2525 NewAbility newAbility = NewAbility . abilities . Find ( ( NewAbility x ) => x . ability == ability ) ;
@@ -37,9 +37,40 @@ public static bool Prefix(Ability ability, CardTriggerHandler __instance)
3737 return false ;
3838 }
3939
40- public static bool AbilityCanStackAndIsNotPassive ( Ability ability )
40+ private static bool AbilityCanStackAndIsNotPassive ( Ability ability )
4141 {
4242 return AbilitiesUtil . GetInfo ( ability ) . canStack && ! AbilitiesUtil . GetInfo ( ability ) . passive ;
4343 }
4444 }
45+
46+ [ HarmonyPatch ( typeof ( CardTriggerHandler ) , "AddAbility" , new [ ] { typeof ( SpecialTriggeredAbility ) } ) ]
47+ public class CardTriggerHandler_AddAbility_SpecialTriggeredAbility
48+ {
49+ public static bool Prefix ( SpecialTriggeredAbility ability , CardTriggerHandler __instance )
50+ {
51+ Plugin . Log . LogInfo ( $ "Attempting to add spec ability to card trigger handler [{ ability } ]") ;
52+ if ( ( int ) ability < 99 )
53+ {
54+ return true ;
55+ }
56+ // return true if the ability is equal to the ability in the pair OR if ability cannot stack and is passive
57+ if ( ! __instance . specialAbilities . Exists ( ab => ab . Item1 == ability ) )
58+ {
59+ Plugin . Log . LogInfo ( $ "-> spec ability does not exist yet, adding") ;
60+ NewSpecialAbility newAbility = NewSpecialAbility . specialAbilities
61+ . Find ( x => x . specialTriggeredAbility == ability ) ;
62+ Type type = newAbility . abilityBehaviour ;
63+ Component baseC = ( Component ) __instance ;
64+ SpecialCardBehaviour item = baseC . gameObject . GetComponent ( type ) as SpecialCardBehaviour ;
65+ if ( item == null )
66+ {
67+ item = baseC . gameObject . AddComponent ( type ) as SpecialCardBehaviour ;
68+ }
69+
70+ __instance . specialAbilities . Add ( new Tuple < SpecialTriggeredAbility , SpecialCardBehaviour > ( ability , item ) ) ;
71+ }
72+
73+ return false ;
74+ }
75+ }
4576}
0 commit comments