Ejemplo n.º 1
0
        private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction)
        {
            Pawn pawn = pawns.RandomElement <Pawn>();
            Lord lord = pawn.GetLord();

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            TraderKindDef traderKindDef = IncidentWorker_SoraGoodseller.SoraTraderKindDef;

            pawn.trader.traderKind = traderKindDef;
            pawn.inventory.DestroyAll(DestroyMode.Vanish);
            foreach (Thing current in this.GenerateTraderThings(traderKindDef))
            {
                Pawn pawn2 = current as Pawn;
                if (pawn2 != null)
                {
                    if (pawn2.Faction != pawn.Faction)
                    {
                        pawn2.SetFaction(pawn.Faction, null);
                    }
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, 5);
                    GenSpawn.Spawn(pawn2, loc);
                    lord.AddPawn(pawn2);
                }
                else if (!pawn.inventory.container.TryAdd(current))
                {
                    current.Destroy(DestroyMode.Vanish);
                }
            }
            if (!pawn.inventory.container.Any((Thing x) => x.def.IsNutritionGivingIngestible && x.def.ingestible.preferability >= FoodPreferability.MealAwful))
            {
                PawnInventoryGenerator.GiveRandomFood(pawn);
            }
            return(true);
        }
Ejemplo n.º 2
0
        private bool TryConvertOnePawnToSmallTrader(Pawn pawn, Faction faction, Map map)
        {
            Lord lord = pawn.GetLord();

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            TraderKindDef traderKindDef = DefOfs.C_TraderKindDefs.Visitor_IoM_Wanderer;

            pawn.trader.traderKind = traderKindDef;
            pawn.inventory.DestroyAll(DestroyMode.Vanish);
            foreach (Thing current in TraderStockGenerator.GenerateTraderThings(traderKindDef, map))
            {
                Pawn pawn2 = current as Pawn;
                if (pawn2 != null)
                {
                    if (pawn2.Faction != pawn.Faction)
                    {
                        pawn2.SetFaction(pawn.Faction, null);
                    }
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, map, 5);
                    GenSpawn.Spawn(pawn2, loc, map);
                    lord.AddPawn(pawn2);
                }
                else if (!pawn.inventory.innerContainer.TryAdd(current, true))
                {
                    current.Destroy(DestroyMode.Vanish);
                }
            }
            PawnInventoryGenerator.GiveRandomFood(pawn);
            return(true);
        }
        private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction)
        {
            if (faction.def.visitorTraderKinds.NullOrEmpty <TraderKindDef>())
            {
                return(false);
            }
            Pawn pawn = pawns.RandomElement <Pawn>();
            Lord lord = pawn.GetLord();

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            TraderKindDef traderKindDef = faction.def.visitorTraderKinds.RandomElement <TraderKindDef>();

            pawn.trader.traderKind = traderKindDef;
            pawn.inventory.DestroyAll();
            foreach (Thing current in TraderStockGenerator.GenerateTraderThings(traderKindDef))
            {
                Pawn pawn2 = current as Pawn;
                if (pawn2 != null)
                {
                    if (pawn2.Faction != pawn.Faction)
                    {
                        pawn2.SetFaction(pawn.Faction);
                    }
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, 5);
                    GenSpawn.Spawn(pawn2, loc);
                    lord.AddPawn(pawn2);
                }
                else if (!pawn.inventory.container.TryAdd(current))
                {
                    current.Destroy();
                }
            }
            if (!pawn.inventory.container.Any((Thing x) => x.def.IsNutritionGivingIngestible && x.def.ingestible.preferability >= FoodPreferability.MealAwful))
            {
                PawnInventoryGenerator.GiveRandomFood(pawn);
            }

            CellFinder.RandomClosewalkCellNear(pawn.Position, 5);
            Thing thing = ThingMaker.MakeThing(ThingDef.Named("VehicleCart"));

            GenSpawn.Spawn(thing, pawn.Position);
            Job job = new Job(HaulJobDefOf.Mount);

            thing.SetFaction(faction);
            thing.SetForbidden(true);
            Find.Reservations.ReleaseAllForTarget(thing);
            job.targetA = thing;
            pawn.jobs.StartJob(job, JobCondition.InterruptForced);
            return(true);
        }
Ejemplo n.º 4
0
        public override void GenerateRect(Stencil s)
        {
            s.FillTerrain(GenCity.RandomFloor(s.map));
            var pawn = (Pawn)null;

            if (!s.map.ParentFaction.HostileTo(Faction.OfPlayer))
            {
                pawn = GenCity.SpawnInhabitant(s.Coords(s.RandX / 2, s.RandZ / 2), s.map);
                var traderKind = DefDatabase <TraderKindDef> .AllDefs.RandomElement();

                pawn.mindState.wantsToTradeWithColony = true;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
                pawn.trader.traderKind = traderKind;
                pawn.inventory.DestroyAll();
                var parms = new ThingSetMakerParams {
                    traderDef     = traderKind,
                    tile          = s.map.Tile,
                    makingFaction = s.map.ParentFaction,
                };
                foreach (var item in ThingSetMakerDefOf.TraderStock.root.Generate(parms))
                {
                    if (!(item is Pawn) && !pawn.inventory.innerContainer.TryAdd(item))
                    {
                        item.Destroy();
                    }
                }

                PawnInventoryGenerator.GiveRandomFood(pawn);
            }

            for (var dir = 0; dir < 4; dir++)
            {
                if (s.Chance(standChance))
                {
                    var sStand = s.Rotate(dir).Move(Mathf.RoundToInt(s.RandX / 2F), s.MaxZ - s.RandInclusive(0, 2)).Bound(-1, 0, 1, 0);
                    sStand.FillTerrain(GenCity.RandomFloor(s.map, true));
                    var wallStuff = GenCity.RandomWallStuff(s.map);
                    sStand.Spawn(sStand.MinX - 1, 0, ThingDefOf.Wall, wallStuff);
                    sStand.Spawn(sStand.MaxX + 1, 0, ThingDefOf.Wall, wallStuff);
                    sStand.Expand(1).FillRoof(RoofDefOf.RoofConstructed);
                    // if (pawn != null) {
                    //     var itemPos = sStand.Coords(sStand.RandX, sStand.RandZ);
                    //     var item = pawn.inventory.innerContainer.FirstOrDefault();
                    //     if (item != null) {
                    //         pawn.inventory.innerContainer.TryDrop(item, itemPos, s.map, ThingPlaceMode.Direct, out var result);
                    //         item.SetOwnedByCity(true, s.map);
                    //     }
                    // }
                }
            }
        }
Ejemplo n.º 5
0
        public void Hatch()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(this.Props.hatcherPawn, this.hatcheeFaction, PawnGenerationContext.NonPlayer, -1, false, true, false, false, true, false, 1f, false, true, true, false, false, false, false, false, 0, null, 1, null, null, null, null, null);
            Pawn hatchling = PawnGenerator.GeneratePawn(request);

            hatchling.SetFactionDirect(Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Horrors")));
            PawnUtility.TrySpawnHatchedOrBornPawn(hatchling, this.parent);
            PawnInventoryGenerator.GenerateInventoryFor(hatchling, request);
            PawnWeaponGenerator.TryGenerateWeaponFor(hatchling, request);
            Lord lord = CreateNewLord();

            lord.AddPawn(hatchling);
            this.parent.Destroy(DestroyMode.Vanish);
        }
Ejemplo n.º 6
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();
 }
        public static void SpawnStartingColonists()
        {
            foreach (Pawn current in MapInitParams.colonists)
            {
                current.psychology.thoughts.GainThought(ThoughtDef.Named("NewColonyOptimism"));
                current.SetFactionDirect(Faction.OfColony);
                current.AddAndRemoveComponentsAsAppropriate();
                PawnInventoryGenerator.GiveAppropriateKeysTo(current);
            }
            EnsureAllWorkTypesAreAssigned();
            bool startedDirectInEditor = MapInitParams.StartedDirectInEditor;
            List <List <Thing> > list  = new List <List <Thing> >();

            foreach (Pawn current2 in MapInitParams.colonists)
            {
                list.Add(new List <Thing>
                {
                    current2
                });
            }
            int num = 0;

            foreach (StartingItemRecord current3 in StartingItems)
            {
                Thing thing = ThingMaker.MakeThing(current3.thingDef);
                thing.SetFactionDirect(Faction.OfColony);
                list[num].Add(thing);
                num++;
                if (num >= list.Count)
                {
                    num = 0;
                }
            }
            bool canInstaDropDuringInit = startedDirectInEditor;

            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, list, 110, canInstaDropDuringInit, true);
            List <Thing> list2 = new List <Thing>();

            for (int i = 0; i < 16; i++)
            {
                Thing item = ThingMaker.MakeThing(ThingDef.Named("MealSurvivalPack"));
                list2.Add(item);
            }
            List <List <Thing> > list3 = new List <List <Thing> >();

            list3.Add(list2);
            canInstaDropDuringInit = startedDirectInEditor;
            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot + new IntVec3(7, 0, 7), list3, 110, canInstaDropDuringInit, true);
        }
Ejemplo n.º 8
0
        public void Hatch()
        {
            var request = new PawnGenerationRequest(Props.hatcherPawn, hatcheeFaction, PawnGenerationContext.NonPlayer,
                                                    -1, false, true, false, false, true, false, 1f, false, true, true, false);
            var hatchling = PawnGenerator.GeneratePawn(request);

            hatchling.SetFactionDirect(Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Horrors")));
            PawnUtility.TrySpawnHatchedOrBornPawn(hatchling, parent);
            PawnInventoryGenerator.GenerateInventoryFor(hatchling, request);
            PawnWeaponGenerator.TryGenerateWeaponFor(hatchling, request);
            var lord = CreateNewLord();

            lord.AddPawn(hatchling);
            parent.Destroy();
        }
        public static void SpawnStuff()
        {
            foreach (Pawn current in ModdedMapInitParams.colonists)
            {
                current.psychology.thoughts.GainThought(ThoughtDef.Named("NewColonyOptimism"));
                current.SetFactionDirect(Faction.OfColony);
                current.AddAndRemoveComponentsAsAppropriate();
                PawnInventoryGenerator.GiveAppropriateKeysTo(current);
            }
            EnsureAllWorkTypesAreAssigned();
            bool canInstaDropDuringInit = ModdedMapInitParams.StartedDirectInEditor;

            List <List <Thing> > list = new List <List <Thing> >();

            foreach (Pawn current2 in ModdedMapInitParams.colonists)
            {
                list.Add(new List <Thing>
                {
                    current2
                });
            }

            DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot, list, 110, canInstaDropDuringInit, false);

            List <Thing> list2 = new List <Thing>();

            for (int i = 0; i < 16; i++)
            {
                Thing item = ThingMaker.MakeThing(ThingDef.Named("MealSurvivalPack"));
                list2.Add(item);
            }

            List <List <Thing> > list3 = new List <List <Thing> >();

            list3.Add(list2);

            try
            {
                DropPodUtility.DropThingGroupsNear(MapGenerator.PlayerStartSpot + new IntVec3(7, 0, 7), list3, 110, canInstaDropDuringInit, true);
            }
            catch (Exception e)
            {
                Log.Message(e.Message);
            }
        }
Ejemplo n.º 10
0
        private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction, Map map)
        {
            if (faction.def.visitorTraderKinds.NullOrEmpty <TraderKindDef>())
            {
                return(false);
            }
            Pawn pawn = pawns.RandomElement <Pawn>();
            Lord lord = pawn.GetLord();

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            TraderKindDef traderKindDef = faction.def.visitorTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality);

            pawn.trader.traderKind = traderKindDef;
            pawn.inventory.DestroyAll(DestroyMode.Vanish);
            ThingSetMakerParams parms = default(ThingSetMakerParams);

            parms.traderDef     = traderKindDef;
            parms.tile          = new int?(map.Tile);
            parms.makingFaction = faction;
            foreach (Thing thing in ThingSetMakerDefOf.TraderStock.root.Generate(parms))
            {
                Pawn pawn2 = thing as Pawn;
                if (pawn2 != null)
                {
                    if (pawn2.Faction != pawn.Faction)
                    {
                        pawn2.SetFaction(pawn.Faction, null);
                    }
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, map, 5, null);
                    GenSpawn.Spawn(pawn2, loc, map, WipeMode.Vanish);
                    lord.AddPawn(pawn2);
                }
                else if (!pawn.inventory.innerContainer.TryAdd(thing, true))
                {
                    thing.Destroy(DestroyMode.Vanish);
                }
            }
            PawnInventoryGenerator.GiveRandomFood(pawn);
            return(true);
        }
Ejemplo n.º 11
0
        private static void GenerateInventoryFor_Coping(Pawn pawn, Pawn sourcePawn)
        {
            if ((sourcePawn != null) &&
                ((sourcePawn.RaceProps.Humanlike && pawn.RaceProps.Humanlike) ||
                 (sourcePawn.def == pawn.def)))
            {
                if (sourcePawn.inventory == null)
                {
                    return;
                }

                while (sourcePawn.inventory.container.Any())
                {
                    Thing thing = sourcePawn.inventory.container.First();
                    sourcePawn.inventory.container.TransferToContainer(thing, pawn.inventory.container, thing.stackCount);
                    //sourcePawn.inventory.container.TryDrop(sourcePawn.inventory.container.Contents.First<Thing>(), out thing);
                    //pawn.inventory.container.TryAdd(thing);
                }
            }
            else
            {
                PawnInventoryGenerator.GenerateInventoryFor(pawn);
            }
        }
Ejemplo n.º 12
0
        public static ReanimatedPawn DoGenerateZombiePawnFromSource(Pawn sourcePawn, bool isBerserk = true,
                                                                    bool oathOfHastur = false)
        {
            var pawnKindDef   = PawnKindDef.Named("ReanimatedCorpse");
            var factionDirect = isBerserk
                ? Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile)
                : Faction.OfPlayer;
            var pawn = (ReanimatedPawn)ThingMaker.MakeThing(pawnKindDef.race);

            try
            {
                pawn.kindDef = pawnKindDef;
                pawn.SetFactionDirect(factionDirect);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                pawn.gender = sourcePawn.gender;
                pawn.ageTracker.AgeBiologicalTicks    = sourcePawn.ageTracker.AgeBiologicalTicks;
                pawn.ageTracker.AgeChronologicalTicks = sourcePawn.ageTracker.AgeChronologicalTicks;
                pawn.workSettings = new Pawn_WorkSettings(pawn);
                if (pawn.workSettings != null && sourcePawn.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }

                pawn.needs.SetInitialLevels();
                //Add hediffs?
                //Add relationships?
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.melanin   = sourcePawn.story.melanin;
                    pawn.story.crownType = sourcePawn.story.crownType;
                    pawn.story.hairColor = sourcePawn.story.hairColor;
                    pawn.story.childhood = sourcePawn.story.childhood;
                    pawn.story.adulthood = sourcePawn.story.adulthood;
                    pawn.story.bodyType  = sourcePawn.story.bodyType;
                    pawn.story.hairDef   = sourcePawn.story.hairDef;
                    if (!oathOfHastur)
                    {
                        foreach (var current in sourcePawn.story.traits.allTraits)
                        {
                            pawn.story.traits.GainTrait(current);
                        }
                    }
                    else
                    {
                        pawn.story.traits.GainTrait(new Trait(TraitDef.Named("Cults_OathtakerHastur2"), 0, true));
                        pawn.story.traits.GainTrait(new Trait(TraitDefOf.Psychopath, 0, true));

                        SkillFixer(pawn, sourcePawn);
                        RelationshipFixer(pawn, sourcePawn);
                        AddedPartFixer(pawn, sourcePawn);
                    }

                    //pawn.story.GenerateSkillsFromBackstory();
                    var nameTriple = sourcePawn.Name as NameTriple;
                    if (!oathOfHastur)
                    {
                        pawn.Name = new NameTriple(nameTriple?.First,
                                                   string.Concat("* ", "Reanimated".Translate(), " ", nameTriple?.Nick, " *"),
                                                   nameTriple?.Last);
                    }
                    else
                    {
                        pawn.Name = nameTriple;
                    }
                }

                var headGraphicPath = sourcePawn.story.HeadGraphicPath;
                typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic)
                ?.SetValue(pawn.story, headGraphicPath);
                GenerateZombieApparelFromSource(pawn, sourcePawn);
                var con = new PawnGenerationRequest();
                PawnInventoryGenerator.GenerateInventoryFor(pawn, con);
                GiveZombieSkinEffect(pawn, sourcePawn as ReanimatedPawn, oathOfHastur);
                if (isBerserk)
                {
                    pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk);
                }

                //Log.Message(pawn.Name.ToStringShort);
                return(pawn);
            }
            catch (Exception e)
            {
                Utility.DebugReport(e.ToString());
            }

            return(null);
        }
Ejemplo n.º 13
0
        public static Zombie DoGenerateZombiePawnFromSource(Pawn sourcePawn, string pawnKind, string factionName)
        {
            PawnKindDef pawnKindDef   = PawnKindDef.Named(pawnKind);
            Faction     factionDirect = Find.FactionManager.FirstFactionOfDef(FactionDef.Named(factionName));
            Zombie      pawn          = (Zombie)ThingMaker.MakeThing(pawnKindDef.race, null);

            try
            {
                pawn.kindDef = pawnKindDef;
                pawn.SetFactionDirect(factionDirect);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                pawn.gender = sourcePawn.gender;
                pawn.ageTracker.AgeBiologicalTicks    = sourcePawn.ageTracker.AgeBiologicalTicks;
                pawn.ageTracker.AgeChronologicalTicks = sourcePawn.ageTracker.AgeChronologicalTicks;
                pawn.workSettings = new Pawn_WorkSettings(pawn);
                if (pawn.workSettings != null && sourcePawn.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }

                pawn.needs.SetInitialLevels();
                //Add hediffs?
                //Add relationships?
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.melanin   = sourcePawn.story.melanin;
                    pawn.story.crownType = sourcePawn.story.crownType;
                    pawn.story.hairColor = sourcePawn.story.hairColor;
                    pawn.story.childhood = sourcePawn.story.childhood;
                    pawn.story.adulthood = sourcePawn.story.adulthood;
                    pawn.story.bodyType  = sourcePawn.story.bodyType;
                    pawn.story.hairDef   = sourcePawn.story.hairDef;

                    SkillFixer(pawn, sourcePawn);
                    RelationshipFixer(pawn, sourcePawn);
                    AddedPartFixer(pawn, sourcePawn);
                    //pawn.story.GenerateSkillsFromBackstory();
                    NameTriple nameTriple = sourcePawn.Name as NameTriple;
                    pawn.Name = new NameTriple(nameTriple.First, string.Concat(new string[]
                    {
                        "* ",
                        Translator.Translate("RE_Zombie"),
                        " ",
                        nameTriple.Nick,
                        " *"
                    }), nameTriple.Last);
                }
                string headGraphicPath = sourcePawn.story.HeadGraphicPath;
                typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(pawn.story, headGraphicPath);
                GenerateZombieApparelFromSource(pawn, sourcePawn);
                PawnGenerationRequest con = new PawnGenerationRequest();
                PawnInventoryGenerator.GenerateInventoryFor(pawn, con);
                GiveZombieSkinEffect(pawn, sourcePawn as Zombie);
                //if (isBerserk)
                //{
                //    pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk);
                //}
                //Log.Message(pawn.Name.ToStringShort);
                return(pawn);
            }
            catch (Exception e)
            {
                //Cthulhu.Utility.DebugReport(e.ToString());
            }
            return(null);
        }
Ejemplo n.º 14
0
        private static void GiveItems(IEnumerable <Pawn> visitors)
        {
            foreach (var visitor in visitors)
            {
                PawnInventoryGenerator.GiveRandomFood(visitor);
                if (Rand.Value < 0.5f)
                {
                    visitor.TryGiveBackpack();
                }


                float totalValue = 0;

                // Money
                //Log.Message("Goodwill: "+visitor.Faction.ColonyGoodwill);
                var amountS = Mathf.RoundToInt(Rand.Gaussian(visitor.Faction.PlayerGoodwill, visitor.Faction.PlayerGoodwill) * 2) + Rand.Range(0, 50);
                if (amountS > Rand.Range(10, 50))
                {
                    var money = CreateRandomItem(visitor, ThingDefOf.Silver);
                    money.stackCount = amountS;

                    var spaceFor = visitor.GetInventorySpaceFor(money);
                    if (spaceFor > 0)
                    {
                        money.stackCount = Mathf.Min(spaceFor, amountS);
                        var success = visitor.inventory.GetInnerContainer().TryAdd(money);
                        if (success)
                        {
                            totalValue += money.MarketValue * money.stackCount;
                        }
                        else if (!money.Destroyed)
                        {
                            money.Destroy();
                        }
                    }
                }



                // Items
                float maxValue = (visitor.Faction.PlayerGoodwill + 10) * Rand.Range(3, 5);
                float value    = maxValue - totalValue;
                int   curCount = 0;
                while (value > 100 && curCount < 200)
                {
                    //Log.Message("Total is now " + totalValue + ", space left is " + space);
                    curCount++;

                    bool     apparel = Rand.Value < 0.5f;
                    ThingDef thingDef;
                    do
                    {
                        thingDef = GetRandomItem(visitor.Faction.def.techLevel);
                    }while (thingDef != null && apparel && thingDef.IsApparel);
                    if (thingDef == null)
                    {
                        break;
                    }

                    //var amount = Mathf.Min(Mathf.RoundToInt(Mathf.Abs(Rand.Gaussian(1, thingDef.stackLimit/2f))),
                    //    thingDef.stackLimit);
                    //if (amount <= 0) continue;

                    var item = CreateRandomItem(visitor, thingDef);

                    //Log.Message(item.Label + " has this value: " + item.MarketValue);
                    if (item.Destroyed)
                    {
                        continue;
                    }

                    if (item.MarketValue >= value)
                    {
                        item.Destroy();
                        continue;
                    }

                    if (item.MarketValue < 1)
                    {
                        item.Destroy();
                        continue;
                    }
                    var uniquesAmount = item.TryGetComp <CompQuality>() != null ? 1 : item.def.stackLimit;
                    var maxItems      = Mathf.Min(Mathf.FloorToInt(value / item.MarketValue), item.def.stackLimit, uniquesAmount);
                    var minItems      = Mathf.Max(1, Mathf.CeilToInt(Rand.Range(50, 100) / item.MarketValue));

                    if (maxItems < 1 || minItems > maxItems)
                    {
                        item.Destroy();
                        continue;
                    }

                    //Log.Message("Can fit " + maxItems+" of "+item.Label);
                    item.stackCount = Rand.RangeInclusive(minItems, maxItems);
                    //Log.Message("Added " + item.stackCount + " with a value of " + (item.MarketValue * item.stackCount));

                    var spaceFor = visitor.GetInventorySpaceFor(item);
                    if (spaceFor > 0)
                    {
                        item.stackCount = Mathf.Min(spaceFor, item.stackCount);
                        var success = visitor.inventory.GetInnerContainer().TryAdd(item);
                        if (success)
                        {
                            totalValue += item.MarketValue * item.stackCount;
                        }
                        else if (!item.Destroyed)
                        {
                            item.Destroy();
                        }
                    }
                    value = maxValue - totalValue;
                }
            }
        }
Ejemplo n.º 15
0
        public static Pawn DoGeneratePawnFromSource(Pawn sourcePawn, bool isBerserk = true, bool oathOfHastur = false)
        {
            PawnKindDef pawnKindDef   = sourcePawn.kindDef;
            Faction     factionDirect = isBerserk ? Find.FactionManager.FirstFactionOfDef(FactionDefOf.SpacerHostile) : Faction.OfPlayer;
            Pawn        pawn          = (Pawn)ThingMaker.MakeThing(pawnKindDef.race);

            try
            {
                pawn.kindDef = pawnKindDef;
                pawn.SetFactionDirect(factionDirect);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                pawn.gender = sourcePawn.gender;
                pawn.ageTracker.AgeBiologicalTicks    = sourcePawn.ageTracker.AgeBiologicalTicks;
                pawn.ageTracker.AgeChronologicalTicks = sourcePawn.ageTracker.AgeChronologicalTicks;
                pawn.workSettings = new Pawn_WorkSettings(pawn);
                if (pawn.workSettings != null && sourcePawn.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }

                pawn.needs.SetInitialLevels();
                //Add hediffs?
                //Add relationships?
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.melanin   = sourcePawn.story.melanin;
                    pawn.story.crownType = sourcePawn.story.crownType;
                    pawn.story.hairColor = sourcePawn.story.hairColor;
                    pawn.story.childhood = sourcePawn.story.childhood;
                    pawn.story.adulthood = sourcePawn.story.adulthood;
                    pawn.story.bodyType  = sourcePawn.story.bodyType;
                    pawn.story.hairDef   = sourcePawn.story.hairDef;
                    foreach (Trait current in sourcePawn.story.traits.allTraits)
                    {
                        pawn.story.traits.GainTrait(current);
                    }

                    SkillFixer(pawn, sourcePawn);
                    RelationshipFixer(pawn, sourcePawn);
                    AddedPartFixer(pawn, sourcePawn);
                    //pawn.story.GenerateSkillsFromBackstory();
                    NameTriple nameTriple = sourcePawn.Name as NameTriple;
                    //if (!oathOfHastur)
                    //{
                    //    pawn.Name = new NameTriple(nameTriple.First, string.Concat(new string[]
                    //        {
                    //        "* ",
                    //        Translator.Translate("Reanimated"),
                    //        " ",
                    //        nameTriple.Nick,
                    //        " *"
                    //        }), nameTriple.Last);
                    //}
                    pawn.Name = nameTriple;
                }
                string headGraphicPath = sourcePawn.story.HeadGraphicPath;
                typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(pawn.story, headGraphicPath);
                GenerateApparelFromSource(pawn, sourcePawn);
                PawnGenerationRequest con = new PawnGenerationRequest();
                PawnInventoryGenerator.GenerateInventoryFor(pawn, con);
                if (isBerserk)
                {
                    pawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk);
                }
                //Log.Message(pawn.NameStringShort);
                return(pawn);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
                //Cthulhu.Utility.DebugReport(e.ToString());
            }
            return(null);
        }
Ejemplo n.º 16
0
        //public static bool Zombify(ReanimatedPawn pawn)
        //{
        //    if (pawn.Drawer == null)
        //    {
        //        return false;
        //    }
        //    if (pawn.Drawer.renderer == null)
        //    {
        //        return false;
        //    }
        //    if (pawn.Drawer.renderer.graphics == null)
        //    {
        //        return false;
        //    }
        //    if (!pawn.Drawer.renderer.graphics.AllResolved)
        //    {
        //        pawn.Drawer.renderer.graphics.ResolveAllGraphics();
        //    }
        //    if (pawn.Drawer.renderer.graphics.headGraphic == null)
        //    {
        //        return false;
        //    }
        //    if (pawn.Drawer.renderer.graphics.nakedGraphic == null)
        //    {
        //        return false;
        //    }
        //    if (pawn.Drawer.renderer.graphics.headGraphic.path == null)
        //    {
        //        return false;
        //    }
        //    if (pawn.Drawer.renderer.graphics.nakedGraphic.path == null)
        //    {
        //        return false;
        //    }
        //    GiveZombieSkinEffect(pawn);
        //    return true;
        //}

        // Credit goes to Justin C for the Zombie Apocalypse code.
        // Taken from Verse.ZombieMod_Utility
        public static Pawn GenerateClonePawnFromSource(Pawn sourcePawn)
        {
            PawnKindDef pawnKindDef   = PawnKindDef.Named("ReanimatedCorpse");
            Faction     factionDirect = Find.FactionManager.FirstFactionOfDef(FactionDefOf.SpacerHostile);
            Pawn        pawn          = (Pawn)ThingMaker.MakeThing(pawnKindDef.race);

            pawn.kindDef = pawnKindDef;
            pawn.SetFactionDirect(factionDirect);
            pawn.pather     = new Pawn_PathFollower(pawn);
            pawn.ageTracker = new Pawn_AgeTracker(pawn);
            pawn.health     = new Pawn_HealthTracker(pawn);
            pawn.jobs       = new Pawn_JobTracker(pawn);
            pawn.mindState  = new Pawn_MindState(pawn);
            pawn.filth      = new Pawn_FilthTracker(pawn);
            pawn.needs      = new Pawn_NeedsTracker(pawn);
            pawn.stances    = new Pawn_StanceTracker(pawn);
            pawn.natives    = new Pawn_NativeVerbs(pawn);
            PawnComponentsUtility.CreateInitialComponents(pawn);
            if (pawn.RaceProps.ToolUser)
            {
                pawn.equipment    = new Pawn_EquipmentTracker(pawn);
                pawn.carryTracker = new Pawn_CarryTracker(pawn);
                pawn.apparel      = new Pawn_ApparelTracker(pawn);
                pawn.inventory    = new Pawn_InventoryTracker(pawn);
            }
            if (pawn.RaceProps.Humanlike)
            {
                pawn.ownership    = new Pawn_Ownership(pawn);
                pawn.skills       = new Pawn_SkillTracker(pawn);
                pawn.relations    = new Pawn_RelationsTracker(pawn);
                pawn.story        = new Pawn_StoryTracker(pawn);
                pawn.workSettings = new Pawn_WorkSettings(pawn);
            }
            if (pawn.RaceProps.intelligence <= Intelligence.ToolUser)
            {
                pawn.caller = new Pawn_CallTracker(pawn);
            }
            //pawn.gender = Gender.None;
            pawn.gender = sourcePawn.gender;
            //Cthulhu.Utility.GenerateRandomAge(pawn, pawn.Map);
            pawn.ageTracker.AgeBiologicalTicks = sourcePawn.ageTracker.AgeBiologicalTicks;
            pawn.ageTracker.BirthAbsTicks      = sourcePawn.ageTracker.BirthAbsTicks;

            pawn.needs.SetInitialLevels();
            if (pawn.RaceProps.Humanlike)
            {
                string headGraphicPath = sourcePawn.story.HeadGraphicPath;
                typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(pawn.story, headGraphicPath);
                pawn.story.melanin   = sourcePawn.story.melanin;
                pawn.story.crownType = sourcePawn.story.crownType;
                pawn.story.hairColor = sourcePawn.story.hairColor;
                NameTriple name = sourcePawn.Name as NameTriple;
                pawn.Name            = name;
                pawn.story.childhood = sourcePawn.story.childhood;
                pawn.story.adulthood = sourcePawn.story.adulthood;
                pawn.story.hairDef   = sourcePawn.story.hairDef;
                foreach (Trait current in sourcePawn.story.traits.allTraits)
                {
                    pawn.story.traits.GainTrait(current);
                }
                //pawn.story.GenerateSkillsFromBackstory();
            }
            GenerateApparelFromSource(pawn, sourcePawn);
            PawnGenerationRequest con = new PawnGenerationRequest();

            PawnInventoryGenerator.GenerateInventoryFor(pawn, con);
            Graphic nakedBodyGraphic = GraphicGetter_NakedHumanlike.GetNakedBodyGraphic(sourcePawn.story.bodyType, ShaderDatabase.CutoutSkin, sourcePawn.story.SkinColor);
            Graphic headGraphic      = GraphicDatabase.Get <Graphic_Multi>(sourcePawn.story.HeadGraphicPath, ShaderDatabase.CutoutSkin, Vector2.one, sourcePawn.story.SkinColor);
            Graphic hairGraphic      = GraphicDatabase.Get <Graphic_Multi>(sourcePawn.story.hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, sourcePawn.story.hairColor);

            pawn.Drawer.renderer.graphics.headGraphic  = headGraphic;
            pawn.Drawer.renderer.graphics.nakedGraphic = nakedBodyGraphic;
            pawn.Drawer.renderer.graphics.hairGraphic  = hairGraphic;
            return(pawn);
        }
Ejemplo n.º 17
0
 private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request)
 {
     PawnApparelGenerator.GenerateStartingApparelFor(pawn, request);
     PawnWeaponGenerator.TryGenerateWeaponFor(pawn);
     PawnInventoryGenerator.GenerateInventoryFor(pawn, request);
 }