private void SpawnAdditonalPrisoners(Map map)
        {
            PrisonerWillingToJoinComp component = parent.GetComponent <PrisonerWillingToJoinComp>();
            List <Pawn> prisoner = map.mapPawns.AllPawnsSpawned.Where(p => p.kindDef == PawnKindDefOf.Slave || p.IsPrisoner).ToList();
            DamageInfo  info     = new DamageInfo(DamageDefOf.Blunt, 20, 0);

            info.SetAllowDamagePropagation(true);

            for (int i = 0; i < prisoner.ToList().Count; i++)
            {
                prisoner[i].SetFaction(ally);
                prisoner[i].guest.SetGuestStatus(map.ParentFaction, true);
                prisoner[i].mindState.WillJoinColonyIfRescued = true;
                Pawn pawn = component == null || !component.pawn.Any ? PrisonerWillingToJoinQuestUtility.GeneratePrisoner(map.Tile, map.ParentFaction) : component.pawn.Take(component.pawn[0]);
                pawn.mindState.WillJoinColonyIfRescued = true;

                pawn.SetFaction(ally);
                IntVec3 result = CellFinder.RandomSpawnCellForPawnNear(prisoner[i % prisoner.ToList().Count].CellsAdjacent8WayAndInside().Where(x => x.Standable(map) && x.Walkable(map)).RandomElement(), map);
                if (result == null)
                {
                    Log.Warning("spawn pawn cell null");
                }
                pawn.guest.SetGuestStatus(map.ParentFaction, true);
                GenSpawn.Spawn(pawn, result, map);
                if (pawn.equipment != null && pawn.equipment.AllEquipmentListForReading.Count > 0)
                {
                    pawn.equipment.DestroyAllEquipment();
                }
                pawn.TakeDamage(info);
                prisoner[i % prisoner.ToList().Count].TakeDamage(info);
            }
        }
        public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants)
        {
            base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants);
            Pawn pawn = PrisonerWillingToJoinQuestUtility.GeneratePrisoner(part.site.Tile, part.site.Faction);

            part.things = new ThingOwner <Pawn>(part, oneStackOnly: true);
            part.things.TryAdd(pawn);
            PawnRelationUtility.Notify_PawnsSeenByPlayer(Gen.YieldSingle(pawn), out string pawnRelationsInfo, informEvenIfSeenBefore: true, writeSeenPawnsNames: false);
            string output = pawnRelationsInfo.NullOrEmpty() ? "" : ((string)("\n\n" + "PawnHasTheseRelationshipsWithColonists".Translate(pawn.LabelShort, pawn) + "\n\n" + pawnRelationsInfo));

            slate.Set("prisoner", pawn);
            outExtraDescriptionRules.Add(new Rule_String("prisonerFullRelationInfo", output));
        }
Example #3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (viewer == null)
            {
                return(false);
            }

            Helper.Log("Executing viewer quest");
            int tile;

            if (!this.TryFindTile(out tile))
            {
                return(false);
            }
            Site site = SiteMaker.TryMakeSite_SingleSitePart(SiteCoreDefOf.PrisonerWillingToJoin, "PrisonerRescueQuestThreat", tile, null, true, null, true, null);

            if (site == null)
            {
                return(false);
            }
            site.sitePartsKnown = true;
            Pawn       pawn    = PrisonerWillingToJoinQuestUtility.GeneratePrisoner(tile, site.Faction);
            NameTriple oldName = pawn.Name as NameTriple;

            pawn.Name = new NameTriple(oldName.First, viewer.username.CapitalizeFirst(), oldName.Last);
            site.GetComponent <PrisonerWillingToJoinComp>().pawn.TryAdd(pawn, true);
            int randomInRange = SiteTuning.QuestSiteTimeoutDaysRange.RandomInRange;

            site.GetComponent <TimeoutComp>().StartTimeout(randomInRange * 60000);
            Find.WorldObjects.Add(site);
            string text;
            string label;

            this.GetLetterText(pawn, site, site.parts.FirstOrDefault <SitePart>(), randomInRange, out text, out label);
            Find.LetterStack.ReceiveLetter(label, text, this.def.letterDef, site, site.Faction, null);
            return(true);
        }
Example #4
0
        public override void Notify_GeneratedByQuestGen(
            [NotNull] SitePart part,
            [NotNull] Slate slate,
            [NotNull] List <Rule> outExtraDescriptionRules,
            Dictionary <string, string> outExtraDescriptionConstants
            )
        {
            base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants);

            Pawn pawn  = null;
            var  isNew = false;

            if (!QueuedViewers.TryDequeue(out KidnapReport report))
            {
                report = null;
            }
            else
            {
                pawn = CommandBase.GetOrFindPawn(report.Viewer, true);

                if (!pawn.IsKidnapped())
                {
                    pawn = null;
                }
            }

            pawn ??= report?.GetMostRecentKidnapping();
            pawn ??= report?.GetPawns().RandomElementWithFallback();

            if (pawn == null)
            {
                pawn  = PrisonerWillingToJoinQuestUtility.GeneratePrisoner(part.site.Tile, part.site.Faction);
                isNew = true;
            }

            if (pawn != null)
            {
                pawn.SetFaction(part.site.Faction);
                pawn.guest.SetGuestStatus(part.site.Faction, GuestStatus.Prisoner);
                pawn.mindState.WillJoinColonyIfRescued = true;

                if (pawn.Dead)
                {
                    pawn.TryResurrect();
                }

                PawnApparelGenerator.GenerateStartingApparelFor(
                    pawn,
                    new PawnGenerationRequest(pawn.kindDef, pawn.Faction, PawnGenerationContext.NonPlayer, part.site.Tile, forceAddFreeWarmLayerIfNeeded: true)
                    );
            }

            part.things = new ThingOwner <Pawn>(part, true, isNew ? LookMode.Deep : LookMode.Reference);
            part.things.TryAdd(pawn);

            PawnRelationUtility.Notify_PawnsSeenByPlayer(Gen.YieldSingle(pawn), out string pawnRelationsInfo, true, false);

            string output = pawnRelationsInfo.NullOrEmpty() ? "" : $"\n\n{"PawnHasRelationshipsWithColonists".Translate(pawn?.LabelShort, pawn)}\n\n{pawnRelationsInfo}";

            slate.Set("prisoner", pawn);

            outExtraDescriptionRules.Add(new Rule_String("prisonerFullRelationInfo", output));
        }
Example #5
0
        protected override void ScatterAt(IntVec3 c, Map map, int stackCount = 1)
        {
            int      randomInRange1 = SettlementSizeRange.RandomInRange;
            int      randomInRange2 = SettlementSizeRange.RandomInRange;
            CellRect cellRect       = new CellRect(map.Center.x - (randomInRange1 / 2), map.Center.z - (randomInRange2 / 2), randomInRange1, randomInRange2);

            cellRect.ClipInsideMap(map);

            BaseGen.globalSettings.minBuildings = 1;
            BaseGen.globalSettings.minBarracks  = 1;
            BaseGen.symbolStack.Push("settlement", new ResolveParams
            {
                rect    = cellRect,
                faction = map.ParentFaction == null || map.ParentFaction == Faction.OfPlayer ? Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Undefined) : map.ParentFaction
            });

            for (int i = 0; i < 3; i++)
            {
                if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(map.AllCells.Where(x => x.Walkable(map) && !x.Fogged(map)).RandomElement(), map, 25, out IntVec3 v))
                {
                    Log.Error("genstep: didnt find random cell " + i + "index");
                    return;
                }
                CellRect var  = CellRect.CenteredOn(v, 8, 8).ClipInsideMap(map);
                Pawn     pawn = map.Parent.GetComponent <PrisonerWillingToJoinComp>() == null || !map.Parent.GetComponent <PrisonerWillingToJoinComp>().pawn.Any ? PrisonerWillingToJoinQuestUtility.GeneratePrisoner(map.Tile, map.ParentFaction) : map.Parent.GetComponent <PrisonerWillingToJoinComp>().pawn.Take(map.Parent.GetComponent <PrisonerWillingToJoinComp>().pawn[0]);
                if (pawn.equipment != null && pawn.equipment.AllEquipmentListForReading.Count > 0)
                {
                    pawn.equipment.DestroyAllEquipment();
                }
                BaseGen.globalSettings.map = map;
                BaseGen.symbolStack.Push("prisonCell", new ResolveParams
                {
                    rect    = var,
                    faction = map.ParentFaction
                });
                BaseGen.Generate();
                pawn.guest.SetGuestStatus(map.ParentFaction, true);
                BaseGen.globalSettings.map = map;
                BaseGen.symbolStack.Push("pawn", new ResolveParams
                {
                    rect              = new CellRect(var.CenterCell.x, var.CenterCell.z, 1, 1).ClipInsideMap(map),
                    faction           = map.ParentFaction,
                    singlePawnToSpawn = pawn,
                    postThingSpawn    = x =>
                    {
                        MapGenerator.rootsToUnfog.Add(x.Position);
                        ((Pawn)x).mindState.WillJoinColonyIfRescued = true;
                    }
                });
                BaseGen.Generate();
                MapGenerator.SetVar("RectOfInterest", var);
                RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(x =>
                                                                       !x.Roofed(map) && x.IsValid, map, out IntVec3 k);
                k.ClampInsideMap(map);
                MapGenerator.rootsToUnfog.Add(k);
            }
        }