@@ -402,17 +402,18 @@ private static bool GetLearnedAbilitesReplacement(bool opponentUsable, int minPo
402402 }
403403
404404 #region Rulebook Description
405+ public const string SIGILCOST = "[sigilcost:" ;
405406 [ HarmonyPostfix , HarmonyPatch ( typeof ( AbilityInfo ) , nameof ( AbilityInfo . ParseAndTranslateDescription ) ) ]
406407 private static void CleanUpParsedDescription ( ref string __result )
407408 {
408- while ( __result . Contains ( "[sigilcost:" ) )
409+ while ( __result . Contains ( SIGILCOST ) )
409410 {
410- string textToCheck = __result . Substring ( __result . IndexOf ( "[sigilcost:" ) ) ;
411+ string textToCheck = __result . Substring ( __result . IndexOf ( SIGILCOST ) ) ;
411412 if ( ! textToCheck . Contains ( "]" ) )
412413 break ;
413414
414415 textToCheck = textToCheck . Substring ( 0 , textToCheck . IndexOf ( "]" ) + 1 ) ;
415- __result = __result . Replace ( textToCheck , textToCheck . Replace ( "[sigilcost:" , "" ) . Replace ( "]" , "" ) ) ;
416+ __result = __result . Replace ( textToCheck , textToCheck . Replace ( SIGILCOST , "" ) . Replace ( "]" , "" ) ) ;
416417 }
417418 }
418419
@@ -449,9 +450,9 @@ private static bool ResetAlteredDescriptions(bool shown)
449450
450451 internal static string ParseAndUpdateDescription ( string description , ExtendedActivatedAbilityBehaviour ability )
451452 {
452- while ( description . Contains ( "[sigilcost:" ) )
453+ while ( description . Contains ( SIGILCOST ) )
453454 {
454- int startIndex = description . IndexOf ( "[sigilcost:" ) ;
455+ int startIndex = description . IndexOf ( SIGILCOST ) ;
455456 string textToChange = description . Substring ( startIndex ) ;
456457 if ( ! textToChange . Contains ( "]" ) )
457458 break ;
@@ -537,34 +538,30 @@ internal static string ParseAndUpdateDescription(string description, ExtendedAct
537538 }
538539
539540 [ HarmonyPatch ( typeof ( RuleBookInfo ) , "ConstructPageData" , new Type [ ] { typeof ( AbilityMetaCategory ) } ) ]
540- [ HarmonyPostfix ]
541+ [ HarmonyPostfix , HarmonyPriority ( 100 ) ]
541542 private static void FixRulebook ( AbilityMetaCategory metaCategory , RuleBookInfo __instance , ref List < RuleBookPageInfo > __result )
542543 {
543544 //InscryptionAPIPlugin.Logger.LogInfo($"In rulebook patch: I see {NewAbilities.Count}");
544- if ( NewAbilities . Count <= 0 )
545- return ;
546-
547- foreach ( PageRangeInfo pageRangeInfo in __instance . pageRanges )
545+ if ( NewAbilities . Count > 0 )
548546 {
549- // regular abilities
550- if ( pageRangeInfo . type != PageRangeType . Abilities )
551- continue ;
552-
553- int insertPosition = __result . FindLastIndex ( rbi => rbi . pagePrefab == pageRangeInfo . rangePrefab ) + 1 ;
554- int curPageNum = ( int ) Ability . NUM_ABILITIES ;
555- List < FullAbility > abilitiesToAdd = NewAbilities . Where ( x => __instance . AbilityShouldBeAdded ( ( int ) x . Id , metaCategory ) ) . ToList ( ) ;
556- //InscryptionAPIPlugin.Logger.LogInfo($"Adding {abilitiesToAdd.Count} out of {NewAbilities.Count} abilities to rulebook");
557- foreach ( FullAbility fab in abilitiesToAdd )
547+ foreach ( PageRangeInfo pageRangeInfo in __instance . pageRanges )
558548 {
559- RuleBookPageInfo info = new ( )
549+ if ( pageRangeInfo . type == PageRangeType . Abilities ) // regular abilities
560550 {
561- pagePrefab = pageRangeInfo . rangePrefab ,
562- headerText = string . Format ( Localization . Translate ( "APPENDIX XII, SUBSECTION I - MOD ABILITIES {0}" ) , curPageNum )
563- } ;
564- __instance . FillAbilityPage ( info , pageRangeInfo , ( int ) fab . Id ) ;
565- __result . Insert ( insertPosition , info ) ;
566- curPageNum += 1 ;
567- insertPosition += 1 ;
551+ int curPageNum = ( int ) Ability . NUM_ABILITIES ;
552+ int insertPosition = __result . FindLastIndex ( rbi => rbi . pagePrefab == pageRangeInfo . rangePrefab ) + 1 ;
553+ List < FullAbility > abilitiesToAdd = NewAbilities . Where ( x => __instance . AbilityShouldBeAdded ( ( int ) x . Id , metaCategory ) ) . ToList ( ) ;
554+ foreach ( FullAbility fab in abilitiesToAdd )
555+ {
556+ RuleBookPageInfo info = new ( ) ;
557+ info . pagePrefab = pageRangeInfo . rangePrefab ;
558+ info . headerText = string . Format ( Localization . Translate ( "APPENDIX XII, SUBSECTION I - MOD ABILITIES {0}" ) , curPageNum ) ;
559+ __instance . FillAbilityPage ( info , pageRangeInfo , ( int ) fab . Id ) ;
560+ __result . Insert ( insertPosition , info ) ;
561+ curPageNum ++ ;
562+ insertPosition ++ ;
563+ }
564+ }
568565 }
569566 }
570567 }
0 commit comments