Beispiel #1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            this.ResolveRaidPoints(parms);
            if (this.disableEvent)
            {
                return(false);
            }
            if (!this.TryResolveRaidFaction(parms))
            {
                return(false);
            }
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            this.ResolveRaidStrategy(parms, combat);
            this.ResolveRaidArriveMode(parms);
            if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            parms.points = IncidentWorker_Raid.AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms, false);
            List <Pawn>         list        = PawnGroupMakerUtility.GeneratePawns(defaultPawnGroupMakerParms, true).ToList <Pawn>();
            List <string>       viewernames = Viewers.ParseViewersFromJsonAndFindActiveViewers();

            if (list.Count > 0 && viewernames != null)
            {
                int count        = 0;
                int totalviewers = viewernames.Count();
                foreach (Pawn pawn in list)
                {
                    if (count == list.Count() || viewernames.NullOrEmpty() || pawn.RaceProps.IsMechanoid)
                    {
                        continue;
                    }
                    int        thisviewer = Verse.Rand.Range(0, viewernames.Count());
                    NameTriple name       = pawn.Name as NameTriple;
                    NameTriple newname    = new NameTriple(name.First, viewernames[thisviewer], name.Last);
                    if (!newname.UsedThisGame || ToolkitSettings.RepeatViewerNames)
                    {
                        pawn.Name = newname;
                    }

                    viewernames.RemoveAt(thisviewer);
                    count++;
                }
            }
            if (list.Count == 0)
            {
                Log.Error("Got no pawns spawning raid from parms " + parms, false);
                return(false);
            }
            parms.raidArrivalMode.Worker.Arrive(list, parms);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Points = " + parms.points.ToString("F0"));
            foreach (Pawn current in list)
            {
                string str = (current.equipment == null || current.equipment.Primary == null) ? "unarmed" : current.equipment.Primary.LabelCap;
                stringBuilder.AppendLine(current.KindLabel + " - " + str);
            }
            string letterLabel = this.GetLetterLabel(parms);
            string letterText  = this.GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true);
            List <TargetInfo> list2 = new List <TargetInfo>();

            if (parms.pawnGroups != null)
            {
                List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups);
                List <Pawn>         list4 = list3.MaxBy((List <Pawn> x) => x.Count);
                if (list4.Any <Pawn>())
                {
                    list2.Add(list4[0]);
                }
                for (int i = 0; i < list3.Count; i++)
                {
                    if (list3[i] != list4)
                    {
                        if (list3[i].Any <Pawn>())
                        {
                            list2.Add(list3[i][0]);
                        }
                    }
                }
            }
            else if (list.Any <Pawn>())
            {
                list2.Add(list[0]);
            }

            Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), list2, parms.faction, stringBuilder.ToString());
            parms.raidStrategy.Worker.MakeLords(parms, list);
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            this.ResolveRaidPoints(parms);
            if (!this.TryResolveRaidFaction(parms))
            {
                return(false);
            }
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            this.ResolveRaidStrategy(parms, combat);
            this.ResolveRaidArriveMode(parms);
            parms.raidStrategy.Worker.TryGenerateThreats(parms);
            if (!parms.raidArrivalMode.Worker.TryResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            parms.points = IncidentWorker_Raid.AdjustedRaidPoints(parms.points, parms.raidArrivalMode, parms.raidStrategy, parms.faction, combat);
            List <Pawn> list = parms.raidStrategy.Worker.SpawnThreats(parms);

            if (list == null)
            {
                list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms(combat, parms, false), true).ToList <Pawn>();
                if (list.Count == 0)
                {
                    Log.Error("Got no pawns spawning raid from parms " + parms, false);
                    return(false);
                }
                parms.raidArrivalMode.Worker.Arrive(list, parms);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Points = " + parms.points.ToString("F0"));
            foreach (Pawn pawn in list)
            {
                string str = (pawn.equipment != null && pawn.equipment.Primary != null) ? pawn.equipment.Primary.LabelCap : "unarmed";
                stringBuilder.AppendLine(pawn.KindLabel + " - " + str);
            }
            TaggedString baseLetterLabel = this.GetLetterLabel(parms);
            TaggedString baseLetterText  = this.GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref baseLetterLabel, ref baseLetterText, this.GetRelatedPawnsInfoLetterText(parms), true, true);
            List <TargetInfo> list2 = new List <TargetInfo>();

            if (parms.pawnGroups != null)
            {
                List <List <Pawn> > list3 = IncidentParmsUtility.SplitIntoGroups(list, parms.pawnGroups);
                List <Pawn>         list4 = list3.MaxBy((List <Pawn> x) => x.Count);
                if (list4.Any <Pawn>())
                {
                    list2.Add(list4[0]);
                }
                for (int i = 0; i < list3.Count; i++)
                {
                    if (list3[i] != list4 && list3[i].Any <Pawn>())
                    {
                        list2.Add(list3[i][0]);
                    }
                }
            }
            else if (list.Any <Pawn>())
            {
                foreach (Pawn t in list)
                {
                    list2.Add(t);
                }
            }
            base.SendStandardLetter(baseLetterLabel, baseLetterText, this.GetLetterDef(), parms, list2, Array.Empty <NamedArgument>());
            parms.raidStrategy.Worker.MakeLords(parms, list);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j].apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            return(true);
        }
Beispiel #3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 spawnSpot;

            if (!this.TryFindSpawnSpot(map, out spawnSpot))
            {
                return(false);
            }
            Faction faction;

            if (!this.TryFindEnemyFaction(out faction))
            {
                return(false);
            }
            int           @int      = Rand.Int;
            IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map);

            raidParms.forced             = true;
            raidParms.faction            = faction;
            raidParms.raidStrategy       = RaidStrategyDefOf.ImmediateAttack;
            raidParms.raidArrivalMode    = PawnsArrivalModeDefOf.EdgeWalkIn;
            raidParms.spawnCenter        = spawnSpot;
            raidParms.points             = Mathf.Max(raidParms.points * IncidentWorker_RefugeeChased.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat));
            raidParms.pawnGroupMakerSeed = new int?(@int);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false);

            defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat);
            IEnumerable <PawnKindDef> pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms);
            PawnGenerationRequest     request   = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, null, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            Pawn refugee = PawnGenerator.GeneratePawn(request);

            refugee.relations.everSeenByPlayer = true;
            string text = "RefugeeChasedInitial".Translate(refugee.Name.ToStringFull, refugee.story.Title, faction.def.pawnsPlural, faction.Name, refugee.ageTracker.AgeBiologicalYears, PawnUtility.PawnKindsToCommaList(pawnKinds, true), refugee.Named("PAWN"));

            text = text.AdjustedFor(refugee, "PAWN");

            if (Quote != null)
            {
                text += "\n\n";
                text += Quote;
            }

            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, refugee);
            DiaNode   diaNode   = new DiaNode(text);
            DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate());

            diaOption.action = delegate
            {
                GenSpawn.Spawn(refugee, spawnSpot, map, WipeMode.Vanish);
                refugee.SetFaction(Faction.OfPlayer, null);
                CameraJumper.TryJump(refugee);
                QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_RefugeeChased.RaidDelay.RandomInRange, 0);
                Find.Storyteller.incidentQueue.Add(qi);
            };
            diaOption.resolveTree = true;
            diaNode.options.Add(diaOption);
            string    text2      = "RefugeeChasedRejected".Translate(refugee.LabelShort, refugee);
            DiaNode   diaNode2   = new DiaNode(text2);
            DiaOption diaOption2 = new DiaOption("OK".Translate());

            diaOption2.resolveTree = true;
            diaNode2.options.Add(diaOption2);
            DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate());

            diaOption3.action = delegate
            {
                Find.WorldPawns.PassToWorld(refugee, PawnDiscardDecideMode.Decide);
            };
            diaOption3.link = diaNode2;
            diaNode.options.Add(diaOption3);
            string title = "RefugeeChasedTitle".Translate(map.Parent.Label);

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, true, true, title));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, title, faction));
            return(true);
        }