private IncidentParms IncidentParms(Map map, TargetInfo target) { IncidentParms parms = StorytellerUtility.DefaultParmsNow(category, map); parms.points = points >= 0 ? points : parms.points; parms.faction = Faction; parms.forced = true; parms.raidStrategy = raidStrategy; parms.raidArrivalMode = arriveMode; parms.spawnCenter = positionFilter.FindCell(map, spawnSettings.spawnList); if (type == IncidentType.Reward) { if (spawnSettings.mode == SpawnMode.Target) { parms.spawnCenter = target.Cell; } } if (type == IncidentType.Raid) { parms.points = spawnSettings.spawnList.Sum(tv => tv.PawnKindDef.combatPower); parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms); } parms.points *= pointMultiplier; return(parms); }
private void TryExecute(Map map, IncidentParms parms, ObjectiveDef def, IncidentCondition?condition) { LookTargets targets = new LookTargets(); string label = ""; string message = ""; if (type == IncidentType.Research) { StringBuilder sb = new StringBuilder(); foreach (ResearchProjectDef project in researchUnlocks) { sb.Append(" - " + project.LabelCap); Find.ResearchManager.FinishProject(project); } label = "ResearchIncident_SMO".Translate(); message = "ResearchIncidentDesc_SMO".Translate(sb.ToString()); } if (type == IncidentType.Reward) { SpawnMode mode = spawnSettings.mode; if (mode == SpawnMode.Target) { SpawnAround(parms.spawnCenter, map, ref targets, out bool p); } if (mode == SpawnMode.Stockpile) { List <Thing> things = SpawnThings(out List <List <Thing> > list, ref targets); List <IntVec3> cells = new List <IntVec3>(); List <Zone> zones = map.zoneManager.AllZones; for (int i = 0; i < zones.Count; i++) { Zone zone = zones[i]; if (zone is Zone_Stockpile) { cells.AddRange(zone.Cells.Where(c => c.GetFirstItem(map) == null)); } } if (cells.Count < things.Count) { IntVec3 cell = IntVec3.Invalid; if (map.areaManager.Home?.ActiveCells.Count() > 0) { PositionFilter filter = new PositionFilter(); filter.homeArea = AreaCheck.Prefer; filter.roofs = AreaCheck.Avoid; cell = filter.FindCell(map, spawnSettings.spawnList); } cell = cell.IsValid ? cell : parms.spawnCenter; DropPodUtility.DropThingGroupsNear(cell, map, list, 140, false, true, true); } else { foreach (Thing thing in things) { IntVec3 cell = cells.RandomElement(); cells.Remove(cell); targets.targets.Add(GenSpawn.Spawn(thing, cells.RandomElement(), map)); } } } if (mode == SpawnMode.DropPod) { SpawnDropPod(parms.spawnCenter, map, ref targets); } if (condition.Value == IncidentCondition.Started) { label = "StartingItems_SMO".Translate(); message = "StartingItemsDesc_SMO".Translate("'" + def.LabelCap + "'"); } if (condition.Value == IncidentCondition.Finished || condition == null) { label = "Reward_SMO".Translate(); if (def != null) { message = "RewardDesc_SMO".Translate("'" + def.LabelCap + "'"); } } } if (type == IncidentType.Appear) { SpawnAround(parms.spawnCenter, map, ref targets, out bool p); label = p ? "AppearPlural_SMO".Translate() : "Appear_SMO".Translate(); message = p ? "AppearDescPlural_SMO".Translate() : "AppearDesc_SMO".Translate(targets); } if (type == IncidentType.Skyfaller) { int count = 0; foreach (ThingSkyfaller skyfaller in spawnSettings.skyfallers) { if (Rand.Chance(skyfaller.chance)) { count++; targets.targets.Add(SkyfallerMaker.SpawnSkyfaller(skyfaller.skyfaller, skyfaller.def, parms.spawnCenter, map)); } } bool plural = count > 1; label = plural ? "Skyfaller_SMO".Translate() : "SkyfallerPlural_SMO".Translate(); message = plural ? "SkyfallerDesc_SMO".Translate() : "SkyfallerDescPlural_SMO".Translate(); } if (type == IncidentType.Raid) { List <Pawn> raiders = new List <Pawn>(); foreach (ThingValue tv in spawnSettings.spawnList) { if (Rand.Chance(tv.chance)) { for (int i = 0; i < tv.value; i++) { Pawn pawn = PawnGenerator.GeneratePawn(tv.PawnKindDef, parms.faction); raiders.Add(pawn); targets.targets.Add(pawn); } } } parms.raidArrivalMode.Worker.Arrive(raiders, parms); parms.raidStrategy.Worker.MakeLords(parms, raiders); Find.StoryWatcher.statsRecord.numRaidsEnemy++; label = "Raid_SMO".Translate(); message = "RaidDesc_SMO".Translate(PawnKinds); } Find.LetterStack.ReceiveLetter(letterLabel ?? label, letterDesc ?? message, letterDef, targets, type == IncidentType.Raid ? Faction : null, null); }