Пример #1
0
        public void SpawnAround(IntVec3 root, Map map, ref LookTargets lastThing, out bool plural)
        {
            List <Thing> things = SpawnThings(out List <List <Thing> > list, ref lastThing);

            plural = things.Count > 1;
            if (spawnSettings.mode == SpawnMode.Scatter)
            {
                List <IntVec3> cells = positionFilter.FindCells(map, things.Count, spawnSettings.spawnList);
                for (int i = 0; i < things.Count; i++)
                {
                    GenSpawn.Spawn(things[i], cells[i], map);
                }
                return;
            }
            foreach (Thing thing in things)
            {
                GenPlace.TryPlaceThing(thing, root, map, ThingPlaceMode.Near);
                lastThing = thing;
            }
        }
        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 + "\n");
                    Find.ResearchManager.FinishProject(project);
                }
                label   = "ResearchIncident_SMO".Translate();
                message = "ResearchIncidentDesc_SMO".Translate(sb.ToString());
            }
            if (type == IncidentType.Reward)
            {
                List <Thing> things = SpawnThings(out List <List <Thing> > groups, ref targets);
                SpawnMode    mode   = spawnSettings.mode;
                if (mode == SpawnMode.Target)
                {
                    SpawnAround(parms.spawnCenter, map, things, ref targets, out bool p);
                }
                if (mode == SpawnMode.Stockpile)
                {
                    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, groups, 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, groups);
                }
                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)
            {
                List <Thing> things = SpawnThings(out List <List <Thing> > groups, ref targets);
                SpawnAround(parms.spawnCenter, map, things, ref targets, out bool p);
                label   = p ? "AppearPlural_SMO".Translate() : "Appear_SMO".Translate();
                message = p ? "AppearDescPlural_SMO".Translate() : "AppearDesc_SMO".Translate(targets.targets?[0].Thing.LabelCap);
            }
            if (type == IncidentType.Skyfaller)
            {
                int count      = 0;
                var sortedList = spawnSettings.skyfallers.OrderBy(x => x.chance).ToArray();
                for (int i = 0; i < sortedList.Count(); i++)
                {
                    ThingSkyfaller skyfaller = sortedList[i];
                    if (Rand.Chance(skyfaller.chance) || (spawnSettings.singleChance && i == sortedList.Count() - 1))
                    {
                        List <IntVec3> pos = positionFilter.FindCells(map, skyfaller.amount, null, spawnSettings.skyfallers.ThingDefs());
                        for (int ii = 0; ii < skyfaller.amount; ii++)
                        {
                            count++;
                            Skyfaller skyfallerThing = SkyfallerMaker.SpawnSkyfaller(skyfaller.skyfallerDef, skyfaller.innerThing, pos[ii], map);
                            targets.targets.Add(skyfallerThing.innerContainer[0]);
                        }
                        if (spawnSettings.singleChance)
                        {
                            break;
                        }
                    }
                }
                bool plural = count > 1;
                label   = !plural ? "Skyfaller_SMO".Translate() : "SkyfallerPlural_SMO".Translate();
                message = !plural ? "SkyfallerDesc_SMO".Translate(targets.targets?[0].Thing.LabelCap) : "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);
                raidSettings.MakeLords(parms, map, 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);
        }