Example #1
0
        public void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident)
        {
            if (!(worker is AnimalSpawnWorker spawnWorker))
            {
                return;
            }

            if (!_predators.TryRandomElement(out string predator))
            {
                predator = "Thrumbo";
            }

            ThingDef thing = ThingDef.Named(predator);
            var      power = 0.0f;

            if (thing?.race != null)
            {
                power += thing.tools.Sum(t => t.power);
                power /= thing.tools.Count;
            }

            spawnWorker.Quantity       = power > 18f ? 2 : 3;
            spawnWorker.SpawnManhunter = true;
            spawnWorker.AnimalDef      = PawnKindDef.Named(predator);
            spawnWorker.def            = IncidentDef.Named("HerdMigration");
            spawnWorker.Label          = "TwitchStoriesLetterLabelPredators".Localize();
            spawnWorker.Text           = "ManhunterPackArrived".LocalizeKeyed(spawnWorker.AnimalDef.GetLabelPlural());
        }
Example #2
0
        static bool Prefix(IncidentWorker __instance, ref bool __result, IncidentParms parms)
        {
            IncidentInterceptorUtility.CurrentIncidentDef = __instance.def;

            //TODO: This is for the ship part incident
            //I have no choice but do the patch like this
            //'cause the incidentworker for shippart is an internal class
            //and manual patching doesn't work
            var def = __instance.def;

            if (def != DefDatabase <IncidentDef> .GetNamed("PsychicEmanatorShipPartCrash") && def != DefDatabase <IncidentDef> .GetNamed("PoisonShipPartCrash"))
            {
                return(true);
            }
            if (IncidentInterceptorUtility.IsIntercepting_ShipPart == WorkerPatchType.ExecuteOrigin)
            {
                return(true);
            }
            else
            {
                if (!IncidentInterceptorUtility.Intercept_SkyFaller <InterceptedIncident_SkyFaller_ShipPartCrash>(__instance.def, parms))
                {
                    return(true);
                }
                __result = true;
                return(false);
            }
        }
Example #3
0
        public override void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident)
        {
            base.DoExtraSetup(worker, @params, incident);
            @params.raidStrategy = DefDatabase <RaidStrategyDef> .GetNamed("Siege");

            @params.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn;
        }
Example #4
0
 public override bool IsPossible()
 {
     worker       = new IncidentWorker_MakeGameConditionVEE();
     worker.def   = IncidentDef.Named("VEE_HailStorm");
     parms        = new IncidentParms();
     parms.target = Current.Game.RandomPlayerHomeMap;
     return(worker.CanFireNow(parms));
 }
Example #5
0
 public virtual void DoExtraSetup([NotNull] IncidentWorker worker, [NotNull] IncidentParms @params, StoreIncident incident)
 {
     @params.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
     worker.def              = RimWorld.IncidentDefOf.RaidEnemy;
     @params.faction         = Find.FactionManager.RandomEnemyFaction(minTechLevel: TechLevel.Industrial, allowNonHumanlike: false);
     @params.forced          = true;
     @params.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn;
 }
Example #6
0
 public override bool IsPossible()
 {
     worker       = new EarthQuake();
     worker.def   = IncidentDef.Named("VEE_Earthquake");
     parms        = new IncidentParms();
     parms.target = Current.Game.RandomPlayerHomeMap;
     return(worker.CanFireNow(parms));
 }
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            ToolkitPatchLogger.Log(incidentDef.defName, "Checking if possible..");
            this.separateChannel = separateChannel;
            this.Viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 3)
            {
                Toolkit.client.SendMessage($"@{viewer.username} syntax is {this.storeIncident.syntax}", separateChannel);
                return(false);
            }

            if (!VariablesHelpers.PointsWagerIsValid(
                    command[2],
                    viewer,
                    ref pointsWager,
                    ref storeIncident,
                    separateChannel
                    ))
            {
                return(false);
            }

            ToolkitPatchLogger.Log(incidentDef.defName, $"Got the points wager of '{pointsWager}' and incident of '{storeIncident.abbreviation}:{storeIncident.defName}'");

            target = Current.Game.AnyPlayerHomeMap;
            if (target == null)
            {
                return(false);
            }

            ToolkitPatchLogger.Log(incidentDef.defName, $"Target found '{target.Tile}'");

            parms        = StorytellerUtility.DefaultParmsNow(categoryDef, target);
            parms.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, parms.points);
            if (raidStratDef != null)
            {
                parms.raidStrategy = raidStratDef;
            }
            if (pawnArrivalModeDef != null)
            {
                parms.raidArrivalMode = pawnArrivalModeDef;
            }

            worker     = Activator.CreateInstance <T>();
            worker.def = incidentDef;

            bool success = worker.CanFireNow(parms);

            if (!success)
            {
                WorkerCanFireCheck.CheckDefaultFireNowConditions(worker, parms, incidentDef);
            }

            ToolkitPatchLogger.Log(incidentDef.defName, $"Can fire with params '{parms.ToString()}' on worker {worker.ToString()}? {success}");

            return(success);
        }
 public override bool IsPossible()
 {
     worker       = new IncidentWorker_DrunkMuffalos();
     worker.def   = IncidentDef.Named("DrunkMuffalos");
     parms        = new IncidentParms();
     parms.target = Current.Game.RandomPlayerHomeMap;
     parms.points = StorytellerUtility.DefaultThreatPointsNow(parms.target);
     return(worker.CanFireNow(parms));
 }
Example #9
0
 // Stops incident from happening if setting is inactive.
 static bool Prefix(ref IncidentWorker __instance, ref bool __result)
 {
     if (!ToggleManager.IsActive(Format(__instance.def)))
     {
         __result = false;
         return(false);
     }
     return(true);
 }
        public override bool IsPossible(string message, Viewer viewer, bool separateChannel = false)
        {
            this.separateChannel = separateChannel;
            this.Viewer          = viewer;
            string[] command = message.Split(' ');
            if (command.Length < 3)
            {
                VariablesHelpers.ViewerDidWrongSyntax(viewer.username, storeIncident.syntax, separateChannel);
                return(false);
            }

            if (!VariablesHelpers.PointsWagerIsValid(
                    command[2],
                    viewer,
                    ref pointsWager,
                    ref storeIncident,
                    separateChannel
                    ))
            {
                ToolkitPatchLogger.Log(LOGGER_NAME, "Cannot fire custom manhunter. No valid points wagered");
                return(false);
            }

            target = Current.Game.AnyPlayerHomeMap;
            if (target == null)
            {
                ToolkitPatchLogger.Log(LOGGER_NAME, "Cannot fire custom manhunter. No valid tile");
                return(false);
            }

            parms        = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.RaidBeacon, target);
            parms.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, parms.points);

            IEnumerable <string> animals = Settings.AnimalMap.Where(x => x.Value).Select(x => x.Key);

            ToolkitPatchLogger.Log(LOGGER_NAME, $"{animals.Count()}/{Settings.AnimalMap.Count} animals for selection.");

            string animal = animals.RandomElement();

            ToolkitPatchLogger.Log(LOGGER_NAME, $"Chose animal {animal} for the attack beast");

            ThingDef def = ThingDef.Named(animal);

            worker     = new CustomManhunterIncidentWorker(PawnKindDef.Named(animal));
            worker.def = IncidentDef.Named("BeastAttack");

            bool success = worker.CanFireNow(parms);

            if (!success)
            {
                WorkerCanFireCheck.CheckDefaultFireNowConditions(worker, parms, worker.def);
            }

            return(success);
        }
Example #11
0
 [HarmonyPriority(10000)]  // be sure to patch before other mod so def is not null
 public static bool IncidentWorker_Prefix(IncidentWorker __instance, IncidentParms parms, ref bool __result)
 {
     //Log.Message("def " + __instance.def);
     if (__instance.def == null)
     {
         Traverse.Create(root: __instance).Field(name: "def").SetValue(IncidentDefOf.RaidEnemy);
         __instance.def = IncidentDefOf.RaidEnemy;
     }
     //Log.Message("def tale " + __instance.def.tale);
     //Log.Message("def category tale " + __instance.def.category.tale);
     return(true);
 }
        public override bool IsPossible()
        {
            worker     = new IncidentWorker_GiveQuest();
            worker.def = IncidentDef.Named("GiveQuest_Settlers_Wanted");
            worker.def.questScriptDef = DefDatabase <QuestScriptDef> .GetNamed("Settlers_Wanted");

            parms = new IncidentParms();
            parms.questScriptDef = DefDatabase <QuestScriptDef> .GetNamed("Settlers_Wanted");

            parms.points = StorytellerUtility.DefaultThreatPointsNow(Current.Game.RandomPlayerHomeMap);
            parms.forced = true;
            return(worker.CanFireNow(parms));
        }
        static bool Prefix(IncidentWorker __instance, ref bool __result, IncidentParms parms)
        {
            if (PES_Settings.DebugModeOn)
            {
                Messages.Message("-=PS=- Caught Patch_IncidentWorker_TryExecute Prefix", MessageTypeDefOf.NeutralEvent, true);
                Log.Message("-=PS=- Patch_IncidentWorker_TryExecute Prefix", false);
                IncidentInterceptorUtility.DebugParms(parms, __instance.ToString());
            }
            if (parms.quest != null || parms.questScriptDef != null)
            {
                Log.Message("-=PS=- It's a quest! Bailout! MAYDAY!", false);
                return(true);
            }
            if (__instance.def == null)
            {
                Log.Error("-=PS=- __instance.def=NULL", false);
                Log.Error("   PS=- Returning true", false);
                return(true);
            }
            Log.Message("   PS=- __instance.def= " + __instance.def.ToString(), false);
            if (__instance.def.ToString() == "RRY_PowerCut_Xenomorph")              //Lt.Bob - Handling for AvP powercut event
            {
                Log.Message("-=PS=- AVP PowerCut event", false);
                Log.Message("   PS=- Returning true", false);
                return(true);
            }

            //TODO: This is for the ship part incident
            //I have no choice but do the patch like this
            //'cause the incidentworker for shippart is an internal class
            //and manual patching doesn't work
            var def = __instance.def;

            if (def != DefDatabase <IncidentDef> .GetNamed("PsychicEmanatorShipPartCrash") && def != DefDatabase <IncidentDef> .GetNamed("DefoliatorShipPartCrash"))            //Lt. Bob: 1.1 - Replaced PoisonShipPartCrash with DefoliatorShipPartCrash
            {
                return(true);
            }
            if (IncidentInterceptorUtility.IsIntercepting_ShipPart == WorkerPatchType.ExecuteOrigin)
            {
                return(true);
            }
            else
            {
                if (!IncidentInterceptorUtility.Intercept_SkyFaller <InterceptedIncident_SkyFaller_ShipPartCrash>(__instance.def, parms))
                {
                    return(true);
                }
                __result = true;
                return(false);
            }
        }
Example #14
0
        public static bool Prefix(IncidentWorker __instance, bool __result, ref IncidentParms parms)
        {
            if (!SpotterUtility.IncidentIsQueued(parms, __instance.def))
            {
                if (parms == null)
                {
                    parms = new IncidentParms();
                }

                return(!SpotterUtility.TryScanForMotion(parms, __instance.def));
            }

            return(true);
        }
 public static bool Prefix(IncidentWorker __instance, IncidentParms parms)
 {
     if (__instance.def.category == IncidentCategoryDefOf.ThreatBig)
     {
         var options = Find.Storyteller.def.GetModExtension <StorytellerDefExtension>();
         if (options != null && options.storytellerThreat != null &&
             options.storytellerThreat.disableThreatsAtPopulationCount >= Find.ColonistBar.Entries.Where(x => x.pawn != null &&
                                                                                                         !x.pawn.Dead && x.pawn.Faction == Faction.OfPlayer).Count())
         {
             return(false);
         }
     }
     return(true);
 }
 public static bool Prefix(IncidentWorker __instance, ref bool __result, IncidentParms parms)
 {
     if (IncidentInterceptorUtility.isIntercepting_Alphabeavers == WorkerPatchType.ExecuteOrigin)
     {
         return(true);
     }
     if (IncidentInterceptorUtility.isIntercepting_Alphabeavers == WorkerPatchType.Forestall)
     {
         IncidentInterceptorUtility.CreateIncidentCaravan_Animal <InterceptedIncident_AnimalHerd_Alphabeavers>(__instance.def, parms);
         __result = true;
     }
     else
     {
         __result = IncidentInterceptorUtility.tmpIncident.SubstituionWorkerExecution();
     }
     return(false);
 }
Example #17
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();
         }
     }
 }
        public override bool IsPossible()
        {
            Log("Checking if possible..");
            worker     = Activator.CreateInstance <T>();
            worker.def = incidentDef;

            Map map = Helper.AnyPlayerMap;

            if (map != null)
            {
                parms        = StorytellerUtility.DefaultParmsNow(incidentCategoryDef, map);
                parms.forced = shouldForceFire;

                return(worker.CanFireNow(parms));
            }

            return(false);
        }
        public static void Postfix(IncidentWorker __instance, ref float __result)
        {
            IncidentDef incidentDef = __instance.def;

            if (incidentDef.defName.Contains("OGN_MonolithAppears"))
            {
                if (!AMAMod.settings.AllowNecronMonolith)
                {
                    __result = 0f;
                }
            }
            if (incidentDef.defName.Contains("OG_Chaos_Deamon"))
            {
                if (incidentDef.defName.Contains("Warpstorm_Deamonic"))
                {
                    if (!AMAMod.settings.AllowWarpstorm)
                    {
                        __result = 0f;
                    }
                }
                if (incidentDef.defName.Contains("Deamonic_Incursion"))
                {
                    if (!AMAMod.settings.AllowChaosDeamonicIncursion)
                    {
                        __result = 0f;
                    }
                }
                if (incidentDef.defName.Contains("Daemonic_Infestation"))
                {
                    if (!AMAMod.settings.AllowChaosDeamonicInfestation)
                    {
                        __result = 0f;
                    }
                }
            }
            if (incidentDef.defName.Contains("OG_Ork_Rok_Crash"))
            {
                if (!AMAMod.settings.AllowOrkRok)
                {
                    __result = 0f;
                }
            }
        }
Example #20
0
        public static bool Prefix(IncidentWorker __instance, bool __result, ref IncidentParms parms)
        {
            if (__instance.def.category == IncidentCategoryDefOf.AllyAssistance)
            {
                return(true);
            }

            if (SpotterUtility.IncidentIsQueued(parms, __instance.def))
            {
                return(true);
            }

            if (parms == null)
            {
                parms = new IncidentParms();
            }

            return(!SpotterUtility.TryScanForMotion(parms, __instance.def));
        }
Example #21
0
        public override bool IsPossible()
        {
            ToolkitPatchLogger.Log(incidentDef.defName, "Checking if possible..");
            worker     = Activator.CreateInstance <T>();
            worker.def = incidentDef;

            parms        = StorytellerUtility.DefaultParmsNow(category, target);
            parms.forced = shouldForceFire;

            bool success = worker.CanFireNow(parms);

            if (!success)
            {
                WorkerCanFireCheck.CheckDefaultFireNowConditions(worker, parms, incidentDef);
            }

            ToolkitPatchLogger.Log(incidentDef.defName, $"Can fire with params '{parms.ToString()}' on worker {worker.ToString()}? {success}");

            return(success);
        }
Example #22
0
        public override bool IsPossible()
        {
            if (!Data.TryGetValue(storeIncident.defName, out IIncidentData data))
            {
                return(false);
            }

            _worker = Activator.CreateInstance(data.WorkerClass) as IncidentWorker;
            Map map = Find.RandomPlayerHomeMap;

            if (map == null || _worker == null)
            {
                return(false);
            }

            _params        = StorytellerUtility.DefaultParmsNow(data.ResolveCategory(_worker, storeIncident), map);
            _params.forced = true;

            data.DoExtraSetup(_worker, _params, storeIncident);

            return(_worker.CanFireNow(_params));
        }
Example #23
0
        public override bool CanHappen(string msg, Viewer viewer)
        {
            if (!Data.TryGetValue(storeIncident.defName, out _data))
            {
                return(false);
            }

            if (!_data.UseStoryteller)
            {
                string rawPoints = CommandFilter.Parse(msg).Skip(2).FirstOrDefault();

                if (rawPoints.NullOrEmpty() || !VariablesHelpers.PointsWagerIsValid(rawPoints, viewer, ref _wager, ref storeIncident))
                {
                    return(false);
                }
            }

            Map map = Find.RandomPlayerHomeMap;

            _worker = Activator.CreateInstance(_data.WorkerClass) as IncidentWorker;

            if (_worker == null || map == null)
            {
                return(false);
            }

            _params = StorytellerUtility.DefaultParmsNow(_data.ResolveCategory(_worker, storeIncident), map);

            if (!_data.UseStoryteller)
            {
                _params.points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, _wager, _params.points);
            }

            _params.forced = true;
            _data.DoExtraSetup(_worker, _params, storeIncident);

            return(_worker.CanFireNow(_params));
        }
        public static bool Prefix(IncidentWorker __instance, ref bool __result, IncidentParms parms)
        {
            if (PES_Settings.DebugModeOn)
            {
                Log.Message("-=PS=- Patch_IncidentWorker_Alphabeavers_TryExecuteWorker Prefix", false);
                IncidentInterceptorUtility.DebugParms(parms, __instance.ToString());
            }

            if (IncidentInterceptorUtility.isIntercepting_Alphabeavers == WorkerPatchType.ExecuteOrigin)
            {
                return(true);
            }
            if (IncidentInterceptorUtility.isIntercepting_Alphabeavers == WorkerPatchType.Forestall)
            {
                IncidentInterceptorUtility.CreateIncidentCaravan_Animal <InterceptedIncident_AnimalHerd_Alphabeavers>(__instance.def, parms);
                __result = true;
            }
            else
            {
                __result = IncidentInterceptorUtility.tmpIncident.SubstituionWorkerExecution();
            }
            return(false);
        }
        public override bool IsPossible()
        {
            ToolkitPatchLogger.Log(incidentDef.defName, "Checking if possible..");
            worker     = GetWorker();
            worker.def = incidentDef;

            if (target != null)
            {
                parms        = StorytellerUtility.DefaultParmsNow(incidentCategoryDef, target);
                parms.forced = shouldForceFire;

                bool success = worker.CanFireNow(parms);
                if (!success)
                {
                    WorkerCanFireCheck.CheckDefaultFireNowConditions(worker, parms, incidentDef);
                }
                ToolkitPatchLogger.Log(incidentDef.defName, $"Can fire with params '{parms.ToString()}' on worker {worker.ToString()}? {success}");
                return(success);
            }

            ToolkitPatchLogger.ErrorLog(incidentDef.defName, $"Failed to get target. Cannot fire");
            return(false);
        }
Example #26
0
 public void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident)
 {
     // A random disease incident doesn't need to do any extra setup.
     // This method exists solely because of the interface it implements.
 }
Example #27
0
        public IncidentCategoryDef ResolveCategory([NotNull] IncidentWorker worker, StoreIncident incident)
        {
            worker.def = DefDatabase <IncidentDef> .AllDefs.Where(i => i.workerClass.IsAssignableFrom(typeof(IncidentWorker_DiseaseHuman))).RandomElement();

            return(worker.def.category);
        }
Example #28
0
 public void DoExtraSetup([NotNull] IncidentWorker worker, IncidentParms @params, StoreIncident incident)
 {
     worker.def = RimWorld.IncidentDefOf.TraderCaravanArrival;
 }
Example #29
0
 public IncidentCategoryDef ResolveCategory(IncidentWorker worker, StoreIncident incident) => IncidentCategoryDefOf.Misc;
 public Vote_RaidStrategy(Dictionary <int, RaidStrategyDef> allStrategies, StorytellerPack pack, IncidentWorker worker, StorytellerComp comp, IncidentParms parms, string title = null) : base(new List <int>(allStrategies.Keys))
 {
     this.title         = title;
     this.allStrategies = allStrategies;
     this.pack          = pack;
     this.worker        = worker;
     this.parms         = parms;
     this.comp          = comp;
 }