コード例 #1
0
 public static void CheckPlantHarvested(Plant __instance)
 {
     if (__instance is Plant plant && Current.ProgramState == ProgramState.Playing)
     {
         foreach (var card in AchievementPointManager.GetCards <PlantTracker>())
         {
             if ((card.tracker as PlantTracker).Trigger(plant))
             {
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Pawn PopulationAdaptation event
 /// </summary>
 /// <param name="p"></param>
 /// <param name="ev"></param>
 public static void PawnJoinedFaction(Pawn p, PopAdaptationEvent ev)
 {
     foreach (var card in AchievementPointManager.GetCards <PawnJoinedTracker>())
     {
         try
         {
             if (ev == PopAdaptationEvent.GainedColonist && (card.tracker as PawnJoinedTracker).Trigger(p))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Helper Method for UnfinishedThing crafted Transpiler
 /// </summary>
 /// <param name="thing"></param>
 public static void ItemCraftedTrigger(Thing thing)
 {
     foreach (var card in AchievementPointManager.GetCards <ItemCraftTracker>())
     {
         try
         {
             if ((card.tracker as ItemCraftTracker).Trigger(thing))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Helper Method for MentalBreak Transpiler (Check if MentalBreak Initiated -> Trigger on Trackers)
 /// </summary>
 public static void MentalBreakTrigger(bool started, MentalBreakDef def)
 {
     foreach (var card in AchievementPointManager.GetCards <MentalBreakTracker>())
     {
         try
         {
             if (started && (card.tracker as MentalBreakTracker).Trigger(def))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// Any incident being triggered event
 /// </summary>
 /// <param name="parms"></param>
 /// <param name="__instance"></param>
 /// <param name="__result"></param>
 public static void IncidentTriggered(IncidentParms parms, IncidentWorker __instance, ref bool __result)
 {
     foreach (var card in AchievementPointManager.GetCards <IncidentTracker>())
     {
         try
         {
             if (__result && (card.tracker as IncidentTracker).Trigger(__instance.def, parms.target as Map))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #6
0
 /// <summary>
 /// ResearchProject event when project is finished
 /// </summary>
 /// <param name="proj"></param>
 /// <param name="doCompletionDialog"></param>
 /// <param name="researcher"></param>
 public static void ResearchProjectFinished(ResearchProjectDef proj, bool doCompletionDialog, Pawn researcher)
 {
     foreach (var card in AchievementPointManager.GetCards <ResearchTracker>())
     {
         try
         {
             if ((card.tracker as ResearchTracker).Trigger(proj))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #7
0
 /// <summary>
 /// Pawn Kill event triggered whenever a pawn is killed
 /// </summary>
 /// <param name="dinfo"></param>
 /// <param name="__instance"></param>
 /// <param name="exactCulprit"></param>
 public static void KillPawn(DamageInfo?dinfo, Pawn __instance, Hediff exactCulprit = null)
 {
     foreach (var card in AchievementPointManager.GetCards <KillTracker>())
     {
         try
         {
             if ((card.tracker as KillTracker).Trigger(__instance, dinfo))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #8
0
 /// <summary>
 /// Event whenever a Hediff gets added to a pawn
 /// </summary>
 /// <param name="dinfo"></param>
 public static void HediffAdded(Hediff hediff, BodyPartRecord part = null, DamageInfo?dinfo = null, DamageWorker.DamageResult result = null)
 {
     foreach (var card in AchievementPointManager.GetCards <HediffTracker>())
     {
         try
         {
             if ((card.tracker as HediffTracker).Trigger(hediff))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #9
0
 /// <summary>
 /// HelperMethod for LevelUp Mote Transpiler
 /// </summary>
 /// <param name="skill"></param>
 public static void LevelUpTrigger(SkillDef skill, int level)
 {
     foreach (var card in AchievementPointManager.GetCards <SkillTracker>())
     {
         try
         {
             if ((card.tracker as SkillTracker).Trigger(skill, level))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #10
0
 /// <summary>
 /// Event on immunity ticker
 /// </summary>
 /// <param name="pawn"></param>
 /// <param name="sick"></param>
 /// <param name="diseaseInstance"></param>
 public static void ImmunityTicking(Pawn pawn, bool sick, Hediff diseaseInstance, ImmunityRecord __instance)
 {
     foreach (var card in AchievementPointManager.GetCards <ImmunityHediffTracker>())
     {
         try
         {
             if ((card.tracker as ImmunityHediffTracker).Trigger(diseaseInstance, __instance.immunity))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #11
0
 /// <summary>
 /// Increment Event where Records are incremented by 1
 /// </summary>
 /// <param name="def"></param>
 /// <param name="__instance"></param>
 public static void RecordEvent(RecordDef def, Pawn_RecordsTracker __instance)
 {
     foreach (var card in AchievementPointManager.GetCards <RecordEventTracker>())
     {
         try
         {
             if ((card.tracker as RecordEventTracker).Trigger(def, __instance.pawn))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// Grab average mood of colony from History event which triggers every 60000 ticks
 /// </summary>
 /// <param name="__result"></param>
 public static void AverageMoodColony(float __result)
 {
     foreach (var card in AchievementPointManager.GetCards <MoodTracker>())
     {
         try
         {
             if ((card.tracker as MoodTracker).Trigger(__result))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #13
0
 /// <summary>
 /// DevMode event (when devMode is toggled)
 /// </summary>
 /// <param name="value"></param>
 public static void DevModeToggled(bool value)
 {
     foreach (var card in AchievementPointManager.GetCards <DevModeTracker>())
     {
         try
         {
             if ((card.tracker as DevModeTracker).Trigger(value))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #14
0
 /// <summary>
 /// Attaches to Quest End method to capture both quest and outcome
 /// </summary>
 /// <param name="outcome"></param>
 /// <param name="__instance"></param>
 /// <param name="sendLetter"></param>
 public static void QuestEnded(QuestEndOutcome outcome, Quest __instance, bool sendLetter = true)
 {
     foreach (var card in AchievementPointManager.GetCards <QuestTracker>())
     {
         try
         {
             if ((card.tracker as QuestTracker).Trigger(__instance, outcome))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
 public static void CheckItemCraftedMultiple(Pawn worker, List <Thing> things)
 {
     if (things != null && worker != null)
     {
         foreach (var card in AchievementPointManager.GetCards <ItemCraftTrackerMultipleSpartanFoundry>())
         {
             foreach (Thing thing in things)
             {
                 if (thing != null && card != null)
                 {
                     if ((card.tracker as ItemCraftTrackerMultipleSpartanFoundry).Trigger(thing))
                     {
                         card.UnlockCard();
                     }
                 }
             }
         }
     }
 }
 public static void CheckItemCraftedIngredients(Pawn worker, List <Thing> things)
 {
     if (things != null && worker != null)
     {
         foreach (var card in AchievementPointManager.GetCards <ItemCraftTrackerWithIngredientsAlpha>())
         {
             foreach (Thing thing in things)
             {
                 if (thing != null && card != null)
                 {
                     if ((card.tracker as ItemCraftTrackerWithIngredientsAlpha).Trigger(thing))
                     {
                         card.UnlockCard();
                     }
                 }
             }
         }
     }
 }
コード例 #17
0
 /// <summary>
 /// HelperMethod for Time based record event
 /// </summary>
 /// <param name="def"></param>
 /// <param name="pawn"></param>
 /// <param name="interval"></param>
 public static void RecordTimeEvent(RecordDef def, Pawn pawn, int interval)
 {
     foreach (var card in AchievementPointManager.GetCards <RecordTimeTracker>())
     {
         try
         {
             var tracker = card.tracker as RecordTimeTracker;
             if (tracker.def == def && tracker.Trigger(def, pawn, (float)interval))
             {
                 card.UnlockCard();
             }
         }
         catch (Exception ex)
         {
             Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
             card.UnlockCard();
         }
     }
 }
コード例 #18
0
 /// <summary>
 /// Animal being set to Bonded event
 /// </summary>
 /// <param name="humanlike"></param>
 /// <param name="animal"></param>
 /// <param name="baseChance"></param>
 /// <param name="__result"></param>
 public static void AnimalBondedEvent(Pawn humanlike, Pawn animal, float baseChance, ref bool __result)
 {
     if (__result)
     {
         foreach (var card in AchievementPointManager.GetCards <AnimalBondedTracker>())
         {
             try
             {
                 if ((card.tracker as AnimalBondedTracker).Trigger(animal.kindDef))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #19
0
 /// <summary>
 /// Hook onto LongTick for Trackers that need constant checking
 /// </summary>
 public static void SingleLongTickTracker()
 {
     if (Find.TickManager.TicksGame % 2000 == 0)
     {
         foreach (var card in AchievementPointManager.GetLongTickCards().Where(c => !c.unlocked))
         {
             try
             {
                 if (card.tracker.AttachToLongTick())
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.ErrorOnce($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}", card.GetHashCode() ^ 12351231);
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #20
0
 /// <summary>
 /// SettlementDefeated Event
 /// </summary>
 /// <param name="map"></param>
 /// <param name="faction"></param>
 /// <param name="__result"></param>
 /// <remarks>Only trigger on success</remarks>
 public static void SettlementDefeatedEvent(Map map, Faction faction, ref bool __result)
 {
     if (__result)
     {
         foreach (var card in AchievementPointManager.GetCards <SettlementDefeatTracker>())
         {
             try
             {
                 if ((card.tracker as SettlementDefeatTracker).Trigger(Find.World.worldObjects.SettlementAt(map.Tile)))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #21
0
 /// <summary>
 /// Hediff PawnDeath Event
 /// </summary>
 /// <param name="p"></param>
 /// <param name="ev"></param>
 /// <param name="dinfo"></param>
 public static void HediffDeathEvent(Hediff __instance, ref bool __result)
 {
     if (__result)
     {
         foreach (var card in AchievementPointManager.GetCards <HediffDeathTracker>())
         {
             try
             {
                 if ((card.tracker as HediffDeathTracker).Trigger(__instance))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #22
0
 /// <summary>
 /// TradeDeal event to retrieve what was exchanged
 /// </summary>
 /// <param name="actuallyTraded"></param>
 /// <param name="__result"></param>
 /// <param name="___tradeables"></param>
 public static void TradeDealComplete(bool __result, List <Tradeable> ___tradeables)
 {
     if (__result)
     {
         foreach (var card in AchievementPointManager.GetCards <TraderTracker>())
         {
             try
             {
                 if ((card.tracker as TraderTracker).Trigger(___tradeables))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #23
0
 /// <summary>
 /// Spawn event for Buildings
 /// </summary>
 /// <param name="newThing"></param>
 /// <param name="loc"></param>
 /// <param name="map"></param>
 /// <param name="rot"></param>
 /// <param name="wipeMode"></param>
 /// <param name="respawningAfterLoad"></param>
 public static void ThingBuildingSpawned(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
 {
     if (newThing is Building building && building.Faction == Faction.OfPlayer && Current.ProgramState == ProgramState.Playing)
     {
         foreach (var card in AchievementPointManager.GetCards <BuildingTracker>())
         {
             try
             {
                 if ((card.tracker as BuildingTracker).Trigger(building))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
コード例 #24
0
        static AchievementHarmony()
        {
            AchievementsMMD = ModLister.GetActiveModWithIdentifier(modIdentifier);

            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            CurrentVersion = $"{version.Major}.{version.Minor}.{version.Build}";
            Log.Message($"{AchievementPointManager.AchievementTag} version {CurrentVersion}");

            AchievementPointManager.OnStartUp();
            var harmony = new Harmony(modIdentifier);

            if (UtilityMethods.BaseModActive)
            {
                File.WriteAllText(VersionDir, CurrentVersion);

                harmony.PatchAll();
                /// <summary>
                /// Automated Patches by allowing user to specify MethodInfo.
                /// Solely for organization regarding Trackers
                /// </summary>
                foreach (TrackerBase tracker in AchievementPointManager.TrackersGenerated)
                {
                    if (tracker.MethodHook != null && tracker.PatchMethod != null)
                    {
                        if (TryRegisterPatch(tracker.MethodHook, tracker.PatchMethod))
                        {
                            switch (tracker.PatchType)
                            {
                            case PatchType.Prefix:
                                harmony.Patch(original: tracker.MethodHook,
                                              prefix: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Postfix:
                                harmony.Patch(original: tracker.MethodHook,
                                              postfix: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Transpiler:
                                harmony.Patch(original: tracker.MethodHook,
                                              transpiler: new HarmonyMethod(tracker.PatchMethod));
                                break;

                            case PatchType.Finalizer:
                                harmony.Patch(original: tracker.MethodHook,
                                              finalizer: new HarmonyMethod(tracker.PatchMethod));
                                break;
                            }
                        }
                    }
                }

                /* Additional Event Catches */
                harmony.Patch(original: AccessTools.Method(typeof(Thing), nameof(Thing.Kill)),
                              prefix: new HarmonyMethod(typeof(AchievementHarmony),
                                                        nameof(KillThing)));
                harmony.Patch(original: AccessTools.Method(typeof(Pawn_RecordsTracker), nameof(Pawn_RecordsTracker.AddTo)),
                              postfix: new HarmonyMethod(typeof(AchievementHarmony),
                                                         nameof(RecordAddToEvent)));

                /* Event thrown every Long Tick */
                harmony.Patch(original: AccessTools.Method(typeof(TickManager), nameof(TickManager.DoSingleTick)),
                              postfix: new HarmonyMethod(typeof(AchievementHarmony),
                                                         nameof(SingleLongTickTracker)));

                /* Debug Actions register in menu */
                harmony.Patch(original: AccessTools.Method(typeof(Dialog_DebugActionsMenu), "GenerateCacheForMethod"),
                              prefix: new HarmonyMethod(typeof(DebugActionsSetup),
                                                        nameof(DebugActionsSetup.GenerateCacheForVAEDebugActions)));
                harmony.Patch(original: AccessTools.Constructor(typeof(Dialog_DebugActionsMenu)),
                              prefix: new HarmonyMethod(typeof(DebugActionsSetup),
                                                        nameof(DebugActionsSetup.ClearCachedActions)));

                /* Debugging */
                //harmony.Patch(original: AccessTools.Method(typeof(DebugLoadIDsSavingErrorsChecker), nameof(DebugLoadIDsSavingErrorsChecker.RegisterDeepSaved)),
                //    prefix: new HarmonyMethod(typeof(AchievementHarmony),
                //    nameof(DebugTest)));
            }
        }