protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; PawnKindDef bossKind = def.pawnKind; PawnKindDef animalKind = GetAnimalKind(parms.points, map.Tile); if (bossKind == null || animalKind == null || ManhunterPackIncidentUtility.GetAnimalsCount(animalKind, (parms.points * PointsFactor) - bossKind.combatPower) <= 0) { return(false); } IntVec3 result = parms.spawnCenter; if (!result.IsValid && !RCellFinder.TryFindRandomPawnEntryCell(out result, map, CellFinder.EdgeRoadChance_Animal)) { return(false); } List <Pawn> list = ManhunterPackIncidentUtility.GenerateAnimals(bossKind, map.Tile, bossKind.combatPower, 1); list.AddRange(ManhunterPackIncidentUtility.GenerateAnimals(animalKind, map.Tile, (parms.points * PointsFactor) - bossKind.combatPower, parms.pawnCount)); Rot4 rot = Rot4.FromAngleFlat((map.Center - result).AngleFlat); for (int i = 0; i < list.Count; i++) { Pawn pawn = list[i]; IntVec3 loc = CellFinder.RandomClosewalkCellNear(result, map, 10); QuestUtility.AddQuestTag(GenSpawn.Spawn(pawn, loc, map, rot), parms.questTag); pawn.health.AddHediff(HediffDefOf.Scaria); pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent); pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + Rand.Range(AnimalsStayDurationMin, AnimalsStayDurationMax); } TaggedString labelString = null; if (def.letterLabel != null) { labelString = def.letterLabel; } else { labelString = "LetterLabelManhunterPackArrived".Translate(); } TaggedString textString = null; if (def.letterText != null) { textString = def.letterText; } else { textString = "ManhunterPackArrived".Translate(animalKind.GetLabelPlural()); } SendStandardLetter(labelString, textString, LetterDefOf.ThreatBig, parms, list[0]); Find.TickManager.slower.SignalForceNormalSpeedShort(); LessonAutoActivator.TeachOpportunity(ConceptDefOf.ForbiddingDoors, OpportunityType.Critical); LessonAutoActivator.TeachOpportunity(ConceptDefOf.AllowedAreas, OpportunityType.Important); return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { Map map = (Map)parms.target; IntVec3 intVec; if (!RCellFinder.TryFindRandomPawnEntryCell(out intVec, map, CellFinder.EdgeRoadChance_Animal, false, null)) { Helper.Log($"Cant fire custom manhunter. No edge road chance entry cell"); return(false); } int count = ManhunterPackIncidentUtility.GetAnimalsCount(PawnKindDef, parms.points); ToolkitPatchLogger.Log(LOGGER_NAME, $"Spawning {count} beasts based {parms.points}"); for (int i = 0; i < count; i++) { var loc = CellFinder.RandomClosewalkCellNear(intVec, map, 12, null); var pawn = PawnGenerator.GeneratePawn(PawnKindDef, null); GenSpawn.Spawn(pawn, loc, map, Rot4.Random, WipeMode.Vanish, false); pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Manhunter); } var text = "CustomManhunterEnteringLabel".Translate(PawnKindDef.GetLabelPlural(-1)); Find.LetterStack.ReceiveLetter("CustomManhunterStoriesLetterLabel".Translate(), text, LetterDefOf.NegativeEvent, new TargetInfo(intVec, map, false), null, null); 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 < 4) { Toolkit.client.SendMessage($"@{viewer.username} syntax is {this.storeIncident.syntax}", separateChannel); return(false); } if (!VariablesHelpers.PointsWagerIsValid( command[3], viewer, ref pointsWager, ref storeIncident, separateChannel )) { return(false); } string animalKind = command[2].ToLower(); List <PawnKindDef> allAnimals = DefDatabase <PawnKindDef> .AllDefs.Where( s => s.RaceProps.Animal && string.Join("", s.defName.Split(' ')).ToLower() == animalKind ).ToList(); if (allAnimals.Count < 1) { Toolkit.client.SendMessage($"@{viewer.username} no animal {animalKind} found.", separateChannel); return(false); } target = Current.Game.AnyPlayerHomeMap; if (target == null) { return(false); } float points = IncidentHelper_PointsHelper.RollProportionalGamePoints(storeIncident, pointsWager, StorytellerUtility.DefaultThreatPointsNow(target)); pawnKind = allAnimals[0]; int num = ManhunterPackIncidentUtility.GetAnimalsCount(pawnKind, points); worker = new IncidentWorker_SpecificAnimalsWanderIn(null, pawnKind, true, num, false, true); worker.def = IncidentDef.Named("FarmAnimalsWanderIn"); float defaultThreatPoints = StorytellerUtility.DefaultSiteThreatPointsNow(); parms = StorytellerUtility.DefaultParmsNow(worker.def.category, target); parms.points = points; return(worker.CanFireNow(parms)); }
protected override void RunInt() { Slate slate = QuestGen.slate; Map map = QuestGen.slate.Get <Map>("map"); float points = QuestGen.slate.Get("points", 0f); QuestPart_Incident questPart_Incident = new QuestPart_Incident(); questPart_Incident.incident = IncidentDefOf.ManhunterPack; IncidentParms incidentParms = new IncidentParms(); incidentParms.forced = true; incidentParms.target = map; incidentParms.points = points; incidentParms.questTag = QuestGenUtility.HardcodedTargetQuestTagWithQuestID(tag.GetValue(slate)); incidentParms.spawnCenter = walkInSpot.GetValue(slate) ?? QuestGen.slate.Get <IntVec3?>("walkInSpot") ?? IntVec3.Invalid; incidentParms.pawnCount = animalCount.GetValue(slate); if (ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(points, map.Tile, out var animalKind)) { incidentParms.pawnKind = animalKind; } slate.Set("animalKindDef", animalKind); int num = ((incidentParms.pawnCount > 0) ? incidentParms.pawnCount : ManhunterPackIncidentUtility.GetAnimalsCount(animalKind, points)); QuestGen.slate.Set("animalCount", num); if (!customLetterLabel.GetValue(slate).NullOrEmpty() || customLetterLabelRules.GetValue(slate) != null) { QuestGen.AddTextRequest("root", delegate(string x) { incidentParms.customLetterLabel = x; }, QuestGenUtility.MergeRules(customLetterLabelRules.GetValue(slate), customLetterLabel.GetValue(slate), "root")); } if (!customLetterText.GetValue(slate).NullOrEmpty() || customLetterTextRules.GetValue(slate) != null) { QuestGen.AddTextRequest("root", delegate(string x) { incidentParms.customLetterText = x; }, QuestGenUtility.MergeRules(customLetterTextRules.GetValue(slate), customLetterText.GetValue(slate), "root")); } questPart_Incident.SetIncidentParmsAndRemoveTarget(incidentParms); questPart_Incident.inSignal = QuestGenUtility.HardcodedSignalWithQuestID(inSignal.GetValue(slate)) ?? QuestGen.slate.Get <string>("inSignal"); QuestGen.quest.AddPart(questPart_Incident); List <Rule> rules = new List <Rule> { new Rule_String("animalKind_label", animalKind.label), new Rule_String("animalKind_labelPlural", animalKind.GetLabelPlural(num)) }; QuestGen.AddQuestDescriptionRules(rules); QuestGen.AddQuestNameRules(rules); }
static bool Prefix(ref IncidentParms parms) { Map map = (Map)parms.target; // Set downstream methods to toggle on preferences for avoiding deep water PawnKindDef animalKind = parms.pawnKind; if ((animalKind == null && !ManhunterPackIncidentUtility.TryFindManhunterAnimalKind(parms.points, map.Tile, out animalKind)) || ManhunterPackIncidentUtility.GetAnimalsCount(animalKind, parms.points) == 0) { return(true); } // Set the animal manually since we need to know ahead of time to determine if it swims parms.pawnKind = animalKind; // Check if the animal involved prefers to swim over walk if (animalKind.race.GetStatValueAbstract(StatDefOf.MoveSpeed) >= animalKind.race.GetStatValueAbstract(StatDef.Named(SwimmingLoader.SwimStat)) + 0.001) { DeepWaterNotPreferredForTryFindRandomPawnEntryCell.PreferNonDeepWater = true; } return(true); }