예제 #1
0
        public static bool MovePawnToColony(Pawn pawn, Pawn inviter, Map destination)
        {
            Map map = destination;

            if (map.ParentFaction != Faction.OfPlayer)
            {
                if (inviter.IsCaravanMember() || PawnUtility.IsTravelingInTransportPodWorldObject(pawn) || inviter.Map.ParentFaction != Faction.OfPlayer)
                {
                    map = Find.AnyPlayerHomeMap;
                }
                else
                {
                    map = inviter.Map;
                }
            }

            if (!TryFindEntryCell(map, out IntVec3 cell))
            {
                return(false);
            }

            if (pawn.apparel.AnyApparelLocked)
            {
                var req = PawnGenerationRequest.MakeDefault();
                req.Tile = inviter.Map.Tile;
                PawnApparelGenerator.GenerateStartingApparelFor(pawn, req);
            }

            GenSpawn.Spawn(pawn, cell, map, WipeMode.Vanish);

            Letters.SendJoinLetter(pawn, inviter, map);

            return(true);
        }
예제 #2
0
        public static void FinalizeZombieGeneration(Zombie zombie)
        {
            var graphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(zombie.gender, zombie.story.SkinColor, zombie.story.crownType).GraphicPath;

            Traverse.Create(zombie.story).Field("headGraphicPath").SetValue(graphicPath);

            var request = new PawnGenerationRequest(zombie.kindDef);

            PawnApparelGenerator.GenerateStartingApparelFor(zombie, request);
            zombie.apparel.WornApparel.Do(apparel =>
            {
                Color[] colors =
                {
                    "442a0a".HexColor(),
                    "615951".HexColor(),
                    "1f4960".HexColor(),
                    "182a64".HexColor(),
                    "73000d".HexColor(),
                    "2c422a".HexColor(),
                    "332341".HexColor()
                };
                (colors.Clone() as Color[]).Do(c =>
                {
                    c.r *= Rand.Range(0.2f, 1f);
                    c.g *= Rand.Range(0.2f, 1f);
                    c.b *= Rand.Range(0.2f, 1f);
                    colors.Add(c);
                });
                colors.Add("000000".HexColor());

                apparel.SetColor(colors[Rand.Range(0, colors.Length)]);
            });
        }
예제 #3
0
 public static void DressPawnIfCold(Pawn pawn, int tile)
 {
     // Create warm apparel in case they freeze to death
     PawnApparelGenerator.GenerateStartingApparelFor(pawn, new PawnGenerationRequest(
                                                         pawn.kindDef, pawn.Faction, PawnGenerationContext.NonPlayer,
                                                         tile, false, false, false, false, true, false, 0f,
                                                         true, // "forceAddFreeWarmLayerIfNeeded": THIS IS THE MOST IMPORTANT VARIABLE
                                                         true, true, true, false, false, false, false, 0f, 0f, null, 0f, null, null, null, null,
                                                         new float?(0.0f), null, null, null, null, null, null, null, null, true, true, true));
 }
예제 #4
0
 private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request)
 {
     ProfilerThreadCheck.BeginSample("GenerateGearFor");
     ProfilerThreadCheck.BeginSample("GenerateStartingApparelFor");
     PawnApparelGenerator.GenerateStartingApparelFor(pawn, request);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.BeginSample("TryGenerateWeaponFor");
     PawnWeaponGenerator.TryGenerateWeaponFor(pawn);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.BeginSample("GenerateInventoryFor");
     PawnInventoryGenerator.GenerateInventoryFor(pawn, request);
     ProfilerThreadCheck.EndSample();
     ProfilerThreadCheck.EndSample();
 }
예제 #5
0
        public static Pawn GenerateNewTenant()
        {
            bool generation = true;
            Pawn newTenant  = null;

            while (generation)
            {
                string      race   = SettingsHelper.LatestVersion.AvailableRaces.RandomElement();
                PawnKindDef random = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.race.defName == race).RandomElement();

                if (random == null)
                {
                    return(null);
                }
                Faction faction = FactionUtility.DefaultFactionFrom(random.defaultFactionType);
                newTenant = PawnGenerator.GeneratePawn(random, faction);
                if (newTenant != null && !newTenant.Dead && !newTenant.IsDessicated() && !newTenant.AnimalOrWildMan())
                {
                    {
                        if (SettingsHelper.LatestVersion.SimpleClothing)
                        {
                            FloatRange range = newTenant.kindDef.apparelMoney;
                            newTenant.kindDef.apparelMoney = new FloatRange(SettingsHelper.LatestVersion.SimpleClothingMin, SettingsHelper.LatestVersion.SimpleClothingMax);
                            PawnApparelGenerator.GenerateStartingApparelFor(newTenant, new PawnGenerationRequest(random));
                            newTenant.kindDef.apparelMoney = range;
                        }
                        RemoveExpensiveItems(newTenant);
                        newTenant.GetTenantComponent().IsTenant      = true;
                        newTenant.GetTenantComponent().HiddenFaction = faction;
                        newTenant.SetFaction(Faction.OfAncients);
                        if (SettingsHelper.LatestVersion.Weapons)
                        {
                            List <Thing> ammo = newTenant.inventory.innerContainer.Where(x => x.def.defName.Contains("Ammunition")).ToList();
                            foreach (Thing thing in ammo)
                            {
                                newTenant.inventory.innerContainer.Remove(thing);
                            }
                        }
                        newTenant.DestroyOrPassToWorld();
                        generation = false;
                    }
                }
            }
            return(newTenant);
        }
예제 #6
0
        private static void GenerateStartingApparelFor_Coping(Pawn pawn, Pawn sourcePawn, bool forceApparel)
        {
            if ((sourcePawn != null) &&
                ((forceApparel) ||
                 (sourcePawn.RaceProps.Humanlike && pawn.RaceProps.Humanlike) ||
                 (sourcePawn.def == pawn.def)))
            {
                if (sourcePawn.apparel == null || sourcePawn.apparel.WornApparelCount == 0)
                {
                    return;
                }

                while (sourcePawn.apparel.WornApparel.Any())
                {
                    Apparel ap;
                    sourcePawn.apparel.TryDrop(sourcePawn.apparel.WornApparel.First(),
                                               out ap);
                    pawn.apparel.Wear(ap);
                }

                //using (IEnumerator<Apparel> enumerator = .GetEnumerator())
                //{
                //    while (enumerator.MoveNext())
                //    {
                //        Apparel apparel = (Apparel)enumerator.Current;
                //        Apparel apparel2;
                //        if (apparel.def.MadeFromStuff)
                //            apparel2 = (Apparel)ThingMaker.MakeThing(apparel.def, apparel.Stuff);
                //        else
                //            apparel2 = (Apparel)ThingMaker.MakeThing(apparel.def, null);
                //        apparel2.DrawColor = new Color(apparel.DrawColor.r, apparel.DrawColor.g, apparel.DrawColor.b, apparel.DrawColor.a);
                //        pawn.apparel.Wear(apparel2, true);
                //    }
                //}
            }
            else
            {
                PawnApparelGenerator.GenerateStartingApparelFor(pawn);
            }
        }
예제 #7
0
파일: Utility.cs 프로젝트: emipa606/Tenants
    private static Pawn GenerateNewTenant()
    {
        var  generation   = true;
        Pawn newTenant    = null;
        var  currentRaces = SettingsHelper.LatestVersion.AvailableRaces;

        if (currentRaces == null || currentRaces.Count == 0)
        {
            currentRaces = DefDatabase <PawnKindDef> .AllDefsListForReading
                           .Where(x => x.race != null && x.RaceProps.Humanlike && x.RaceProps.IsFlesh &&
                                  x.RaceProps.ResolvedDietCategory != DietCategory.NeverEats).Select(s => s.race.defName)
                           .Distinct().ToList();
        }

        while (generation)
        {
            var race   = currentRaces.RandomElement();
            var random = DefDatabase <PawnKindDef> .AllDefsListForReading.Where(x => x.race.defName == race)
                         .RandomElement();

            if (random == null)
            {
                return(null);
            }

            var faction = FactionUtility.DefaultFactionFrom(random.defaultFactionType);
            if (faction == null)
            {
                continue;
            }

            if (faction.def.pawnGroupMakers.NullOrEmpty())
            {
                continue;
            }

            newTenant = PawnGenerator.GeneratePawn(random, faction);
            if (newTenant == null || newTenant.Dead || newTenant.IsDessicated() || newTenant.AnimalOrWildMan())
            {
                continue;
            }

            if (newTenant.royalty != null && !SettingsHelper.LatestVersion.RoyaltyTenants &&
                (newTenant.royalty.CanRequireBedroom() || newTenant.royalty.CanRequireThroneroom()))
            {
                continue;
            }

            if (SettingsHelper.LatestVersion.SimpleClothing)
            {
                var range = newTenant.kindDef.apparelMoney;
                newTenant.kindDef.apparelMoney = new FloatRange(SettingsHelper.LatestVersion.SimpleClothingMin,
                                                                SettingsHelper.LatestVersion.SimpleClothingMax);
                PawnApparelGenerator.GenerateStartingApparelFor(newTenant, new PawnGenerationRequest(random));
                newTenant.kindDef.apparelMoney = range;
            }

            RemoveExpensiveItems(newTenant);
            newTenant.GetTenantComponent().IsTenant      = true;
            newTenant.GetTenantComponent().HiddenFaction = faction;
            newTenant.SetFaction(null);
            if (SettingsHelper.LatestVersion.Weapons)
            {
                var ammo = newTenant.inventory.innerContainer.Where(x => x.def.defName.Contains("Ammunition"))
                           .ToList();
                foreach (var thing in ammo)
                {
                    newTenant.inventory.innerContainer.Remove(thing);
                }
            }

            newTenant.DestroyOrPassToWorld();
            generation = false;
        }

        return(newTenant);
    }
예제 #8
0
 private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request)
 {
     PawnApparelGenerator.GenerateStartingApparelFor(pawn, request);
     PawnWeaponGenerator.TryGenerateWeaponFor(pawn);
     PawnInventoryGenerator.GenerateInventoryFor(pawn, request);
 }
예제 #9
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));
        }