Exemplo n.º 1
0
        private void OnSapienceLevelChanges()
        {
            SapienceTracker fTracker = pawn.GetSapienceTracker();

            if (fTracker == null)
            {
                Log.Error($"{pawn.Name} has the sapience need but not tracker!");
                return;
            }

            fTracker.SapienceLevel = _currentLevel;

            if (pawn.needs != null)
            {
                pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
            else
            {
                Log.Warning($"{pawn.Name} does not have needs!");
            }

            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);

            if (pawn.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar?.MarkColonistsDirty();
            }

            SapienceLevelChanged?.Invoke(this, pawn, _currentLevel);
        }
        /// <summary>
        /// enter the given sapience state
        /// </summary>
        /// <param name="stateDef">The state definition.</param>
        /// <param name="initialLevel">The initial level.</param>
        public void EnterState([NotNull] SapienceStateDef stateDef, float initialLevel)
        {
            _sapienceState?.Exit();
            _sapienceState = stateDef.CreateState();


            //need to refresh comps and needs for pawn here
            Pawn.needs?.AddOrRemoveNeedsAsAppropriate();
            _sapienceState.Init(this);
            SapienceLevel = FormerHumanUtilities.GetQuantizedSapienceLevel(initialLevel);
            PawnComponentsUtility.AddAndRemoveDynamicComponents(Pawn);
            var sNeed = SapienceNeed;

            sNeed?.SetSapience(initialLevel);
            _sapienceState.Enter();

            if (Pawn.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar?.MarkColonistsDirty();
            }

            //initialize work settings if they have it
            Pawn.workSettings?.EnableAndInitializeIfNotAlreadyInitialized();

            //interrupts any jobs in case this changes their intelligence
            Pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced);
        }
Exemplo n.º 3
0
        public static void Arrive(this Pawn pawn)
        {
            try
            {
                pawn.PocketHeadgear();
            }
            catch (Exception e)
            {
                Log.Error($"Failed to pocket headgear:\n{e}");
            }

            // Save trader info
            bool          trader        = pawn.mindState?.wantsToTradeWithColony == true;
            TraderKindDef traderKindDef = trader ? pawn.trader.traderKind : null;

            pawn.guest?.SetGuestStatus(Faction.OfPlayer);

            // Restore trader info
            if (trader)
            {
                pawn.mindState.wantsToTradeWithColony = trader;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
                pawn.trader.traderKind = traderKindDef;
            }

            pawn.GetComp <CompGuest>()?.Arrive();
        }
Exemplo n.º 4
0
        static bool Prefix(ref PawnGroupKindWorker_Trader __instance, ref Pawn __result, PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            if (parms.faction == FactionColonies.getPlayerColonyFaction())
            {
                List <PawnKindDef> list = new List <PawnKindDef>();
                foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs)
                {
                    list.Add(def.race.AnyPawnKind);
                }

                Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(list.RandomElement(), parms.faction, PawnGenerationContext.NonPlayer, parms.tile, false, false, false, false, true, false, 1f, false, true, true, true, parms.inhabitants, false, false, false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null));
                pawn.mindState.wantsToTradeWithColony = true;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
                pawn.trader.traderKind = traderKind;
                parms.points          -= pawn.kindDef.combatPower;
                __result = pawn;


                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void PrepForMapGen()
        {
            while (this.startingAndOptionalPawns.Count > this.startingPawnCount)
            {
                PawnComponentsUtility.RemoveComponentsOnDespawned(this.startingAndOptionalPawns[this.startingPawnCount]);
                Find.WorldPawns.PassToWorld(this.startingAndOptionalPawns[this.startingPawnCount], PawnDiscardDecideMode.KeepForever);
                this.startingAndOptionalPawns.RemoveAt(this.startingPawnCount);
            }
            List <Pawn> list = this.startingAndOptionalPawns;

            foreach (Pawn pawn in list)
            {
                pawn.SetFactionDirect(Faction.OfPlayer);
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
            }
            foreach (Pawn pawn2 in list)
            {
                pawn2.workSettings.DisableAll();
            }
            using (IEnumerator <WorkTypeDef> enumerator3 = DefDatabase <WorkTypeDef> .AllDefs.GetEnumerator())
            {
                while (enumerator3.MoveNext())
                {
                    WorkTypeDef w = enumerator3.Current;
                    if (w.alwaysStartActive)
                    {
                        foreach (Pawn pawn3 in from col in list
                                 where !col.story.WorkTypeIsDisabled(w)
                                 select col)
                        {
                            pawn3.workSettings.SetPriority(w, 3);
                        }
                    }
                    else
                    {
                        bool flag = false;
                        foreach (Pawn pawn4 in list)
                        {
                            if (!pawn4.story.WorkTypeIsDisabled(w) && pawn4.skills.AverageOfRelevantSkillsFor(w) >= 6f)
                            {
                                pawn4.workSettings.SetPriority(w, 3);
                                flag = true;
                            }
                        }
                        if (!flag)
                        {
                            IEnumerable <Pawn> source = from col in list
                                                        where !col.story.WorkTypeIsDisabled(w)
                                                        select col;
                            if (source.Any <Pawn>())
                            {
                                Pawn pawn5 = source.InRandomOrder(null).MaxBy((Pawn c) => c.skills.AverageOfRelevantSkillsFor(w));
                                pawn5.workSettings.SetPriority(w, 3);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 // From GameInitData.PrepForMapGen() with a change to make an error into a warning.
 public void PrepForMapGen()
 {
     //foreach (Pawn current in this.startingPawns) {
     foreach (Pawn current in Find.GameInitData.startingPawns)
     {
         current.SetFactionDirect(Faction.OfPlayer);
         PawnComponentsUtility.AddAndRemoveDynamicComponents(current, false);
     }
     //foreach (Pawn current2 in this.startingPawns) {
     foreach (Pawn current2 in Find.GameInitData.startingPawns)
     {
         current2.workSettings.DisableAll();
     }
     foreach (WorkTypeDef w in DefDatabase <WorkTypeDef> .AllDefs)
     {
         if (w.alwaysStartActive)
         {
             //foreach (Pawn current3 in from col in this.startingPawns
             foreach (Pawn current3 in from col in Find.GameInitData.startingPawns
                      where !col.story.WorkTypeIsDisabled(w)
                      select col)
             {
                 current3.workSettings.SetPriority(w, 3);
             }
         }
         else
         {
             bool flag = false;
             //foreach (Pawn current4 in this.startingPawns) {
             foreach (Pawn current4 in Find.GameInitData.startingPawns)
             {
                 if (!current4.story.WorkTypeIsDisabled(w) && current4.skills.AverageOfRelevantSkillsFor(w) >= 6f)
                 {
                     current4.workSettings.SetPriority(w, 3);
                     flag = true;
                 }
             }
             if (!flag)
             {
                 //IEnumerable<Pawn> source = from col in this.startingPawns
                 IEnumerable <Pawn> source = from col in Find.GameInitData.startingPawns
                                             where !col.story.WorkTypeIsDisabled(w)
                                             select col;
                 if (source.Any <Pawn>())
                 {
                     Pawn pawn = source.InRandomOrder(null).MaxBy((Pawn c) => c.skills.AverageOfRelevantSkillsFor(w));
                     pawn.workSettings.SetPriority(w, 3);
                 }
                 else if (w.requireCapableColonist)
                 {
                     // EdB: Show warning instead of an error.
                     //Log.Error("No colonist could do requireCapableColonist work type " + w);
                     Log.Warning("No colonist can do what is thought to be a required work type " + w.gerundLabel);
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 public void PrepForMapGen()
 {
     while (this.startingPawns.Count > this.startingPawnCount)
     {
         PawnComponentsUtility.RemoveComponentsOnDespawned(this.startingPawns[this.startingPawnCount]);
         Find.WorldPawns.PassToWorld(this.startingPawns[this.startingPawnCount], PawnDiscardDecideMode.KeepForever);
         this.startingPawns.RemoveAt(this.startingPawnCount);
     }
     foreach (Pawn startingPawn in this.startingPawns)
     {
         startingPawn.SetFactionDirect(Faction.OfPlayer);
         PawnComponentsUtility.AddAndRemoveDynamicComponents(startingPawn, false);
     }
     foreach (Pawn startingPawn2 in this.startingPawns)
     {
         startingPawn2.workSettings.DisableAll();
     }
     foreach (WorkTypeDef allDef in DefDatabase <WorkTypeDef> .AllDefs)
     {
         if (allDef.alwaysStartActive)
         {
             foreach (Pawn item in from col in this.startingPawns
                      where !col.story.WorkTypeIsDisabled(allDef)
                      select col)
             {
                 item.workSettings.SetPriority(allDef, 3);
             }
         }
         else
         {
             bool flag = false;
             foreach (Pawn startingPawn3 in this.startingPawns)
             {
                 if (!startingPawn3.story.WorkTypeIsDisabled(allDef) && startingPawn3.skills.AverageOfRelevantSkillsFor(allDef) >= 6.0)
                 {
                     startingPawn3.workSettings.SetPriority(allDef, 3);
                     flag = true;
                 }
             }
             if (!flag)
             {
                 IEnumerable <Pawn> source = from col in this.startingPawns
                                             where !col.story.WorkTypeIsDisabled(allDef)
                                             select col;
                 if (source.Any())
                 {
                     Pawn pawn = source.InRandomOrder(null).MaxBy((Pawn c) => c.skills.AverageOfRelevantSkillsFor(allDef));
                     pawn.workSettings.SetPriority(allDef, 3);
                 }
                 else if (allDef.requireCapableColonist)
                 {
                     Log.Error("No colonist could do requireCapableColonist work type " + allDef);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 // Replace colonists in the "GameInitData" with the customized colonists and do any necessary
 // pawn setup that we might have skipped when creating the custom colonists.
 public void ReplaceColonists()
 {
     Find.GameInitData.startingPawns = PrepareCarefully.Instance.Colonists;
     // TODO: Alpha 14
     // Used to do this in Alpha 13.  Still necessary?
     foreach (Pawn current in Find.GameInitData.startingPawns)
     {
         PawnComponentsUtility.AddAndRemoveDynamicComponents(current, false);
     }
 }
Exemplo n.º 11
0
        public void PrepForMapGen()
        {
            while (startingAndOptionalPawns.Count > startingPawnCount)
            {
                PawnComponentsUtility.RemoveComponentsOnDespawned(startingAndOptionalPawns[startingPawnCount]);
                Find.WorldPawns.PassToWorld(startingAndOptionalPawns[startingPawnCount], PawnDiscardDecideMode.KeepForever);
                startingAndOptionalPawns.RemoveAt(startingPawnCount);
            }
            List <Pawn> list = startingAndOptionalPawns;

            foreach (Pawn item in list)
            {
                item.SetFactionDirect(Faction.OfPlayer);
                PawnComponentsUtility.AddAndRemoveDynamicComponents(item);
            }
            foreach (Pawn item2 in list)
            {
                item2.workSettings.DisableAll();
            }
            foreach (WorkTypeDef allDef in DefDatabase <WorkTypeDef> .AllDefs)
            {
                if (allDef.alwaysStartActive)
                {
                    foreach (Pawn item3 in from col in list
                             where !col.story.WorkTypeIsDisabled(allDef)
                             select col)
                    {
                        item3.workSettings.SetPriority(allDef, 3);
                    }
                }
                else
                {
                    bool flag = false;
                    foreach (Pawn item4 in list)
                    {
                        if (!item4.story.WorkTypeIsDisabled(allDef) && item4.skills.AverageOfRelevantSkillsFor(allDef) >= 6f)
                        {
                            item4.workSettings.SetPriority(allDef, 3);
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        IEnumerable <Pawn> source = from col in list
                                                    where !col.story.WorkTypeIsDisabled(allDef)
                                                    select col;
                        if (source.Any())
                        {
                            Pawn pawn = source.InRandomOrder().MaxBy((Pawn c) => c.skills.AverageOfRelevantSkillsFor(allDef));
                            pawn.workSettings.SetPriority(allDef, 3);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private static bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction)
        {
            if (faction.def.visitorTraderKinds.NullOrEmpty())
            {
                return(false);
            }
            Pawn pawn = pawns.RandomElement();
            Lord lord = pawn.GetLord();

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

            pawn.trader.traderKind = traderKindDef;
            pawn.inventory.DestroyAll();

            pawn.TryGiveBackpack();

            foreach (Thing current in TraderStockGenerator.GenerateTraderThings(traderKindDef, lord.Map))
            {
                Pawn slave = current as Pawn;
                if (slave != null)
                {
                    if (slave.Faction != pawn.Faction)
                    {
                        slave.SetFaction(pawn.Faction);
                    }
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, lord.Map, 5);
                    GenSpawn.Spawn(slave, loc, lord.Map);
                    lord.AddPawn(slave);
                }
                else
                {
                    var spaceFor = pawn.GetInventorySpaceFor(current);

                    if (current.Destroyed)
                    {
                        continue;
                    }
                    if (spaceFor <= 0)
                    {
                        current.Destroy();
                        continue;
                    }
                    current.stackCount = spaceFor;

                    // Core stuff
                    if (!pawn.inventory.GetInnerContainer().TryAdd(current))
                    {
                        current.Destroy();
                    }
                }
            }
            return(true);
        }
Exemplo n.º 13
0
 private void OnSapienceLevelChanged()
 {
     _lastStage = CurStageIndex;
     if (pawn != null)
     //if the stage changed make sure we check dynamic components
     {
         PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
         //check needs to
         pawn.needs?.AddOrRemoveNeedsAsAppropriate();
     }
 }
Exemplo n.º 14
0
 // Token: 0x060000FE RID: 254 RVA: 0x0000A1E8 File Offset: 0x000085E8
 public static void AddComponentsForResurrection(Pawn pawn)
 {
     pawn.carryTracker = new Pawn_CarryTracker(pawn);
     pawn.needs        = new Pawn_NeedsTracker(pawn);
     pawn.mindState    = new Pawn_MindState(pawn);
     if (pawn.RaceProps.Humanlike)
     {
         pawn.workSettings = new Pawn_WorkSettings(pawn);
         pawn.workSettings.EnableAndInitialize();
     }
     PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
 }
Exemplo n.º 15
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);
                    //     }
                    // }
                }
            }
        }
        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);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Exits the current sapience state.
 /// </summary>
 /// <param name="recalculateComps">if set to <c>true</c> dynamic components will be recalculated after exiting the state.</param>
 public void ExitState(bool recalculateComps = true)
 {
     if (_sapienceState == null)
     {
         DebugLogUtils.Warning($"trying to exit sapience state in {Pawn.Name} but they aren't in one");
         return;
     }
     _sapienceState.Exit();
     _sapienceState = null;
     if (recalculateComps)
     {
         PawnComponentsUtility.AddAndRemoveDynamicComponents(Pawn);
     }
 }
Exemplo n.º 18
0
        /* Private Methods */


        private Pawn GenerateVendor(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind, bool subtractPoints)
        {
            if (subtractPoints)
            {
                if (parms.points < _DefOf.CarnyTrader.combatPower * 2)
                {
                    return(null);
                }
                else
                {
                    parms.points -= _DefOf.CarnyTrader.combatPower * 2;
                }
            }

            // Generate new vendor
            PawnGenerationRequest request = new PawnGenerationRequest(
                _DefOf.CarnyTrader,
                parms.faction,
                PawnGenerationContext.NonPlayer,
                parms.tile,
                false,
                false,
                false,
                false,
                true,
                false,
                1f,
                true, // Force free warm layers if needed
                true,
                true,
                parms.inhabitants,
                false,
                null, // Consider adding predicate for backstory here
                null,
                null,
                null,
                null,
                null
                );

            var vendor = PawnGenerator.GeneratePawn(request);

            vendor.mindState.wantsToTradeWithColony = true;

            PawnComponentsUtility.AddAndRemoveDynamicComponents(vendor, true);
            vendor.trader.traderKind = traderKind;

            return(vendor);
        }
Exemplo n.º 19
0
        public static void Ressurrect(Pawn pawn, Thing thing)
        {
            if (thing is HoloEmitter)
            {
                if (pawn.Corpse.holdingOwner != null)
                {
                    pawn.Corpse.GetDirectlyHeldThings().TryTransferToContainer(pawn, pawn.Corpse.holdingOwner, true);
                }
                else if (pawn.Corpse.Spawned)
                {
                    ResurrectionUtility.Resurrect(pawn);
                    PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
                    PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
                    CompOsiris.FixPawnRelationships(pawn);
                    pawn.health.Reset();
                    if (pawn.Corpse != null && pawn.Corpse.Spawned)
                    {
                        pawn.Corpse.DeSpawn();
                    }
                    GenSpawn.Spawn(pawn, pawn.Corpse.Position, pawn.Corpse.Map);
                    GiveSideEffects(pawn);
                }
                if (pawn.Corpse != null)
                {
                    pawn.Corpse.Destroy(DestroyMode.Vanish);
                }
            }
            else
            {
                ResurrectionUtility.Resurrect(pawn);
                PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
                CompOsiris.FixPawnRelationships(pawn);
                pawn.health.Reset();
                if (pawn.Corpse != null && pawn.Corpse.Spawned)
                {
                    pawn.Corpse.DeSpawn();
                }
                GenSpawn.Spawn(pawn, thing.Position, thing.Map);
                GiveSideEffects(pawn);

                Building_Casket building_Casket = thing as Building_Casket;
                if (building_Casket != null)
                {
                    building_Casket.GetDirectlyHeldThings().Clear();
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>Adds the hediff if not permanently feral.</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="hediff">The hediff.</param>
        public static void AddHediffIfNotPermanentlyFeral(Pawn pawn, HediffDef hediff)
        {
            if (!pawn.health.hediffSet.HasHediff(HediffDef.Named("PermanentlyFeral")) && !pawn.health.hediffSet.HasHediff(hediff))
            // If a pawn does not have the PermanentlyFeral hediff nor the provided hediff...
            {
                Hediff xhediff = HediffMaker.MakeHediff(hediff, pawn);     // ...create an initialized version of the provided hediff...
                xhediff.Severity = Rand.Range(0.00f, 1.00f);               // ...set it to a random severity...
                pawn.health.AddHediff(xhediff);                            // ...then apply it..
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn); //make sure they have all the dynamic comps they need

                //make sure it has a name
                if (pawn.Name == null)
                {
                    pawn.Name = new NameSingle(pawn.LabelShort);
                }

                FormerHumanUtilities.TryAssignBackstoryToTransformedPawn(pawn, null); //try to assign them a background if they're sapient
            }
        }
Exemplo n.º 21
0
        public static void Arrive(this Pawn pawn)
        {
            pawn.PocketHeadgear();

            // Save trader info
            bool          trader        = pawn.mindState.wantsToTradeWithColony;
            TraderKindDef traderKindDef = trader?pawn.trader.traderKind:null;

            pawn.guest.SetGuestStatus(Faction.OfPlayer);

            // Restore trader info
            if (trader)
            {
                pawn.mindState.wantsToTradeWithColony = trader;
                PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
                pawn.trader.traderKind = traderKindDef;
            }

            pawn.GetComp <CompGuest>().Arrive();
        }
Exemplo n.º 22
0
        private void SetHumanoidSapience([NotNull] Pawn humanoid, [NotNull] Pawn animal)
        {
            PawnComponentsUtility.AddAndRemoveDynamicComponents(humanoid);
            try
            {
                humanoid.needs.AddOrRemoveNeedsAsAppropriate();
            }
            catch (Exception e)
            {
                Log.Message($"caught {e.GetType().Name} \n{e}");
            }
            var hSapienceTracker = humanoid.GetSapienceTracker();
            var aSapienceTracker = animal.GetSapienceTracker();

            if (hSapienceTracker == null || aSapienceTracker == null)
            {
                return;
            }
            GiveRevertedPawnSapienceState(humanoid, aSapienceTracker.Sapience);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
 internal static void _CreateInitialComponents(Pawn pawn)
 {
     pawn.ageTracker   = new Pawn_AgeTracker(pawn);
     pawn.health       = new Pawn_HealthTracker(pawn);
     pawn.records      = new Pawn_RecordsTracker(pawn);
     pawn.inventory    = new Pawn_InventoryTracker(pawn);
     pawn.meleeVerbs   = new Pawn_MeleeVerbs(pawn);
     pawn.verbTracker  = new VerbTracker(pawn);
     pawn.carryTracker = new Pawn_CarryTracker(pawn);
     pawn.needs        = new Pawn_NeedsTracker(pawn);
     pawn.mindState    = new Pawn_MindState(pawn);
     if (pawn.RaceProps.ToolUser)
     {
         pawn.equipment = new Pawn_EquipmentTracker(pawn);
         pawn.apparel   = new Pawn_ApparelTracker(pawn);
     }
     if (pawn.RaceProps.Humanlike)
     {
         pawn.ownership    = new Pawn_Ownership(pawn);
         pawn.skills       = new Pawn_SkillTracker(pawn);
         pawn.story        = new Pawn_StoryTracker(pawn);
         pawn.guest        = new Pawn_GuestTracker(pawn);
         pawn.guilt        = new Pawn_GuiltTracker();
         pawn.workSettings = new Pawn_WorkSettings(pawn);
         if (PsychologyBase.ActivateKinsey())
         {
             PsychologyPawn realPawn = pawn as PsychologyPawn;
             if (realPawn != null)
             {
                 realPawn.sexuality = new Pawn_SexualityTracker(realPawn);
             }
         }
     }
     if (pawn.RaceProps.IsFlesh)
     {
         pawn.relations = new Pawn_RelationsTracker(pawn);
     }
     PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
 }
Exemplo n.º 25
0
        private void OnSapienceLevelChanges()
        {
            var fHediff  = pawn.health.hediffSet.GetFirstHediffOfDef(TfHediffDefOf.TransformedHuman) as FormerHuman;
            var fTracker = pawn.GetFormerHumanTracker();

            if (fTracker == null)
            {
                return;
            }
            fTracker.SapienceLevel = _currentLevel;
            if (fHediff == null)
            {
                return;
            }

            switch (_currentLevel)
            {
            case SapienceLevel.Sapient:
            case SapienceLevel.MostlySapient:
            case SapienceLevel.Conflicted:
            case SapienceLevel.MostlyFeral:
                fHediff.Severity = 1;
                break;

            case SapienceLevel.Feral:
                fHediff.Severity = 0.5f;
                break;

            case SapienceLevel.PermanentlyFeral:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            pawn.needs?.AddOrRemoveNeedsAsAppropriate();
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
            fHediff.NotifySapienceLevelChanges();
        }
Exemplo n.º 26
0
        internal void MakePermanentlyFeral()
        {
            Hediff fHediff;

            if (StateDef.forcedHediff != null)
            {
                fHediff = Pawn.health.hediffSet.GetFirstHediffOfDef(StateDef.forcedHediff);
            }
            else
            {
                fHediff = null;
            }

            //transfer relationships back if possible
            var  gComp = Find.World.GetComponent <PawnmorphGameComp>();
            Pawn oPawn = gComp.GetTransformedPawnContaining(Pawn)?.Item1?.OriginalPawns.FirstOrDefault();

            if (oPawn == Pawn)
            {
                oPawn = null;
            }

            Pawn_RelationsTracker aRelations = Pawn.relations;

            if (aRelations != null && oPawn != null)
            {
                FormerHumanUtilities.TransferRelationsToOriginal(oPawn, Pawn);
            }

            Pawn.health.AddHediff(TfHediffDefOf.PermanentlyFeral);
            if (fHediff != null)
            {
                Pawn.health.RemoveHediff(fHediff);
            }

            var             loader     = Find.World.GetComponent <PawnmorphGameComp>();
            TransformedPawn inst       = loader.GetTransformedPawnContaining(Pawn)?.Item1;
            var             singleInst = inst as TransformedPawnSingle; //hacky, need to come up with a better solution

            foreach (Pawn instOriginalPawn in inst?.OriginalPawns ?? Enumerable.Empty <Pawn>()
                     ) //needed to handle merges correctly
            {
                ReactionsHelper.OnPawnPermFeral(instOriginalPawn, Pawn,
                                                singleInst?.reactionStatus ?? FormerHumanReactionStatus.Wild);
            }

            //remove the original and destroy the pawns
            foreach (Pawn instOriginalPawn in inst?.OriginalPawns ?? Enumerable.Empty <Pawn>())
            {
                instOriginalPawn.Destroy();
            }

            if (inst != null)
            {
                loader.RemoveInstance(inst);
            }

            if (inst != null || Pawn.Faction == Faction.OfPlayer)
            {
                Find.LetterStack.ReceiveLetter("LetterHediffFromPermanentTFLabel".Translate(Pawn.LabelShort).CapitalizeFirst(),
                                               "LetterHediffFromPermanentTF".Translate(Pawn.LabelShort).CapitalizeFirst(),
                                               LetterDefOf.NegativeEvent, Pawn);
            }

            Pawn.needs?.AddOrRemoveNeedsAsAppropriate(); //make sure any comps get added/removed as appropriate
            PawnComponentsUtility.AddAndRemoveDynamicComponents(Pawn);
        }
Exemplo n.º 27
0
        public override void SetFaction(Faction newFaction, Pawn recruiter = null)
        {
            var       x             = this.kindDef;
            AlienPawn temprecruitee = this as AlienPawn;

            if (newFaction == base.Faction)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Used ChangePawnFactionTo to change ",
                    this,
                    " to same faction ",
                    newFaction
                }));
                return;
            }
            if (this.guest != null)
            {
                this.guest.SetGuestStatus(null, false);
            }
            Find.MapPawns.DeRegisterPawn(this);
            Find.PawnDestinationManager.RemovePawnFromSystem(this);
            Find.DesignationManager.RemoveAllDesignationsOn(this, false);
            if (newFaction == Faction.OfPlayer || base.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar.MarkColonistsListDirty();
            }
            Lord lord = this.GetLord();

            if (lord != null)
            {
                lord.Notify_PawnLost(this, PawnLostCondition.ChangedFaction);
            }
            base.SetFaction(newFaction, null);
            PawnComponentsUtility.AddAndRemoveDynamicComponents(this, false);
            if (base.Faction != null && base.Faction.IsPlayer)
            {
                if (this.workSettings != null)
                {
                    this.workSettings.EnableAndInitialize();
                }
                Find.Storyteller.intenderPopulation.Notify_PopulationGained();
            }
            if (this.Drafted)
            {
                this.drafter.Drafted = false;
            }
            Reachability.ClearCache();
            this.health.surgeryBills.Clear();
            if (base.Spawned)
            {
                Find.MapPawns.RegisterPawn(this);
            }
            this.GenerateNecessaryName();
            if (this.playerSettings != null)
            {
                this.playerSettings.medCare = ((!this.RaceProps.Humanlike) ? (this.playerSettings.medCare = MedicalCareCategory.NoMeds) : MedicalCareCategory.Best);
            }
            this.ClearMind(true);
            if (!this.Dead && this.needs.mood != null)
            {
                this.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
            Find.AttackTargetsCache.UpdateTarget(this);
            Find.GameEnder.CheckGameOver();
            temprecruitee.kindDef = x;
        }
Exemplo n.º 28
0
 public static void ConvertToTrader(this Pawn pawn, bool actAsIfSpawned)
 {
     pawn.mindState.wantsToTradeWithColony = true;
     PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, actAsIfSpawned);
     pawn.trader.traderKind = traderKindDef;
 }
Exemplo n.º 29
0
        public static void SetFaction(this Pawn pawn, Faction newFaction, Pawn recruiter = null)
        {
            if (newFaction == pawn.Faction)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Used ChangePawnFactionTo to change ",
                    pawn,
                    " to same faction ",
                    newFaction
                }));
                return;
            }
            if (pawn.guest != null)
            {
                pawn.guest.SetGuestStatus(null, false);
            }
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.DeRegisterPawn(pawn);
                pawn.Map.pawnDestinationManager.RemovePawnFromSystem(pawn);
                pawn.Map.designationManager.RemoveAllDesignationsOn(pawn, false);
            }
            if (newFaction == Faction.OfPlayer || pawn.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar.MarkColonistsDirty();
            }
            Lord lord = pawn.GetLord();

            if (lord != null)
            {
                lord.Notify_PawnLost(pawn, PawnLostCondition.ChangedFaction);
            }
            if (pawn.Faction != null && pawn.Faction.leader == pawn)
            {
                pawn.Faction.Notify_LeaderLost();
            }
            if (newFaction == Faction.OfPlayer && pawn.RaceProps.Humanlike)
            {
                pawn.kindDef = newFaction.def.basicMemberKind;
            }

            // Call base SetFaction directly - horrible mojo warning
            MethodInfo method = typeof(Thing).GetMethod("SetFaction", BindingFlags.Public | BindingFlags.Instance);
            IntPtr     fptr   = method.MethodHandle.GetFunctionPointer();

            ((Action <Faction, Pawn>)Activator.CreateInstance(typeof(Action <Faction, Pawn>), pawn, fptr))(newFaction, null);

            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
            if (pawn.Faction != null && pawn.Faction.IsPlayer)
            {
                if (pawn.workSettings != null)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                Find.Storyteller.intenderPopulation.Notify_PopulationGained();
            }
            if (pawn.Drafted)
            {
                pawn.drafter.Drafted = false;
            }
            ReachabilityUtility.ClearCache();
            pawn.health.surgeryBills.Clear();
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.RegisterPawn(pawn);
            }
            pawn.GenerateNecessaryName();
            if (pawn.playerSettings != null)
            {
                Pawn_PlayerSettings_Detour.ResetPPSMedicalCare(pawn.playerSettings, pawn);
            }
            pawn.ClearMind(true);
            if (!pawn.Dead && pawn.needs.mood != null)
            {
                pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
            if (pawn.Spawned)
            {
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            Find.GameEnder.CheckGameOver();
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (pawn.needs != null)
            {
                pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
            if (pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_FactionChanged();
            }
        }
        protected override void FinalizeDesignationSucceeded()
        {
            base.FinalizeDesignationSucceeded();

            CompSkyMind        csm           = target.TryGetComp <CompSkyMind>();
            CompAndroidState   cas           = target.TryGetComp <CompAndroidState>();
            string             surrogateName = target.LabelShortCap;
            CompSurrogateOwner cso           = null;

            if (cas.externalController != null)
            {
                surrogateName = cas.externalController.LabelShortCap;
                cso           = cas.externalController.TryGetComp <CompSurrogateOwner>();
            }

            Lord clord        = target.GetLord();
            int  nbp          = Utils.GCATPP.getNbHackingPoints();
            int  nbpToConsume = 0;

            //Check points
            switch (hackType)
            {
            case 1:
                nbpToConsume = Settings.costPlayerVirus;
                break;

            case 2:
                nbpToConsume = Settings.costPlayerExplosiveVirus;
                break;

            case 3:
                nbpToConsume = Settings.costPlayerHackTemp;
                break;

            case 4:
                nbpToConsume = Settings.costPlayerHack;
                break;
            }

            if (nbpToConsume > nbp)
            {
                Messages.Message("ATPP_CannotHackNotEnoughtHackingPoints".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }

            //Si faction alliée ou neutre ==> pénalitée
            if (target.Faction.RelationKindWith(Faction.OfPlayer) != FactionRelationKind.Hostile)
            {
                target.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -1 * Rand.Range(5, 36));
            }

            //Application effet
            switch (hackType)
            {
            case 1:
            case 2:

                csm.Hacked = hackType;
                //Surrogate va attaquer la colonnie
                target.SetFactionDirect(Faction.OfAncients);
                LordJob_AssistColony lordJob;
                Lord lord = null;

                IntVec3 fallbackLocation;
                RCellFinder.TryFindRandomSpotJustOutsideColony(target.PositionHeld, target.Map, out fallbackLocation);

                target.mindState.Reset();
                target.mindState.duty = null;
                target.jobs.StopAll();
                target.jobs.ClearQueuedJobs();
                target.ClearAllReservations();
                if (target.drafter != null)
                {
                    target.drafter.Drafted = false;
                }

                lordJob = new LordJob_AssistColony(Faction.OfAncients, fallbackLocation);
                if (lordJob != null)
                {
                    lord = LordMaker.MakeNewLord(Faction.OfAncients, lordJob, Current.Game.CurrentMap, null);
                }

                if (clord != null)
                {
                    if (clord.ownedPawns.Contains(target))
                    {
                        clord.Notify_PawnLost(target, PawnLostCondition.IncappedOrKilled, null);
                    }
                }

                lord.AddPawn(target);

                //Si virus explosive enclenchement de la détonnation
                if (hackType == 2)
                {
                    csm.infectedExplodeGT = Find.TickManager.TicksGame + (Settings.nbSecExplosiveVirusTakeToExplode * 60);
                }
                break;

            case 3:
            case 4:
                bool    wasPrisonner = target.IsPrisoner;
                Faction prevFaction  = target.Faction;
                target.SetFaction(Faction.OfPlayer);

                if (target.workSettings == null)
                {
                    target.workSettings = new Pawn_WorkSettings(target);
                    target.workSettings.EnableAndInitialize();
                }

                if (clord != null)
                {
                    if (clord.ownedPawns.Contains(target))
                    {
                        clord.Notify_PawnLost(target, PawnLostCondition.ChangedFaction, null);
                    }
                }

                if (cso != null)
                {
                    cso.disconnectControlledSurrogate(null);
                }

                if (hackType == 4)
                {
                    //Contorle definitif on jerte l'externalController
                    if (cas != null)
                    {
                        cas.externalController = null;
                    }
                }

                target.Map.attackTargetsCache.UpdateTarget(target);
                PawnComponentsUtility.AddAndRemoveDynamicComponents(target, false);
                Find.ColonistBar.MarkColonistsDirty();

                if (hackType == 3)
                {
                    csm.Hacked          = hackType;
                    csm.hackOrigFaction = prevFaction;
                    if (wasPrisonner)
                    {
                        csm.hackWasPrisoned = true;
                    }
                    else
                    {
                        csm.hackWasPrisoned = false;
                    }
                    csm.hackEndGT = Find.TickManager.TicksGame + (Settings.nbSecDurationTempHack * 60);
                }
                else
                {
                    //Si le surrogate quon veux controlé est infecté alors on enleve l'infection et on reset ses stats
                    if (csm.Infected != -1)
                    {
                        csm.Infected = -1;

                        if (target.skills != null && target.skills.skills != null)
                        {
                            foreach (var sr in target.skills.skills)
                            {
                                sr.levelInt = 0;
                            }
                        }
                    }
                }


                break;
            }

            Utils.GCATPP.decHackingPoints(nbpToConsume);

            Utils.soundDefSurrogateHacked.PlayOneShot(null);

            //Notif d'applciation de l'effet
            Messages.Message("ATPP_SurrogateHackOK".Translate(surrogateName), target, MessageTypeDefOf.PositiveEvent);

            //ANimation sonore et visuelle
            Utils.soundDefSurrogateConnection.PlayOneShot(null);
            MoteMaker.ThrowDustPuffThick(pos.ToVector3Shifted(), cmap, 4.0f, Color.red);

            Find.DesignatorManager.Deselect();
        }