Ejemplo n.º 1
0
 public void SetGuestStatus(Faction newHost, bool prisoner = false)
 {
     if (newHost != null)
     {
         Released = false;
     }
     if (newHost != HostFaction || prisoner != IsPrisoner)
     {
         if (!prisoner && pawn.Faction.HostileTo(newHost))
         {
             Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost);
         }
         else if (newHost != null && newHost == pawn.Faction && !prisoner)
         {
             Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction);
         }
         else
         {
             bool flag = prisoner && (!IsPrisoner || HostFaction != newHost);
             isPrisonerInt  = prisoner;
             hostFactionInt = newHost;
             pawn.ClearMind();
             if (flag)
             {
                 pawn.DropAndForbidEverything();
                 pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner);
                 if (newHost == Faction.OfPlayer)
                 {
                     Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedPrisoner);
                 }
                 if (pawn.Drafted)
                 {
                     pawn.drafter.Drafted = false;
                 }
                 float x = pawn.RecruitDifficulty(Faction.OfPlayer);
                 resistance  = StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                 resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                 resistance *= StartingResistanceRandomFactorRange.RandomInRange;
                 resistance  = (float)GenMath.RoundRandom(resistance);
             }
             PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
             pawn.health.surgeryBills.Clear();
             if (pawn.ownership != null)
             {
                 pawn.ownership.Notify_ChangedGuestStatus();
             }
             ReachabilityUtility.ClearCacheFor(pawn);
             if (pawn.Spawned)
             {
                 pawn.Map.mapPawns.UpdateRegistryForPawn(pawn);
                 pawn.Map.attackTargetsCache.UpdateTarget(pawn);
             }
             AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
             if (prisoner && pawn.playerSettings != null)
             {
                 pawn.playerSettings.Notify_MadePrisoner();
             }
         }
     }
 }
 public void SetGuestStatus(Faction newHost, bool prisoner = false)
 {
     if (newHost != null)
     {
         this.Released = false;
     }
     if (newHost == this.HostFaction && prisoner == this.IsPrisoner)
     {
         return;
     }
     if (!prisoner && this.pawn.Faction.HostileTo(newHost))
     {
         Log.Error("Tried to make " + this.pawn + " a guest of " + newHost + " but their faction " + this.pawn.Faction + " is hostile to " + newHost);
     }
     else if (newHost != null && newHost == this.pawn.Faction && !prisoner)
     {
         Log.Error("Tried to make " + this.pawn + " a guest of their own faction " + this.pawn.Faction);
     }
     else
     {
         bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost);
         this.isPrisonerInt  = prisoner;
         this.hostFactionInt = newHost;
         this.pawn.ClearMind(false);
         if (flag)
         {
             this.pawn.DropAndForbidEverything(false);
             Lord lord = this.pawn.GetLord();
             if (lord != null)
             {
                 lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner);
             }
             if (this.pawn.Drafted)
             {
                 this.pawn.drafter.Drafted = false;
             }
         }
         PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false);
         this.pawn.health.surgeryBills.Clear();
         if (this.pawn.ownership != null)
         {
             this.pawn.ownership.Notify_ChangedGuestStatus();
         }
         ReachabilityUtility.ClearCache();
         if (this.pawn.Spawned)
         {
             this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn);
             this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
         }
         AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn);
         if (prisoner && this.pawn.playerSettings != null)
         {
             this.pawn.playerSettings.Notify_MadePrisoner();
         }
     }
 }
Ejemplo n.º 3
0
        private Pawn GenerateTrader(IncidentParms parms, TraderKindDef traderKind)
        {
            Pawn pawn = PawnGenerator.GeneratePawn(this.traders.RandomElementByWeight((PawnGenOption x) => (float)x.selectionWeight).kind, parms.faction);

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            pawn.trader.traderKind = traderKind;
            this.PostGenerate(pawn);
            return(pawn);
        }
Ejemplo n.º 4
0
        private Pawn GenerateTrader(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(groupMaker.traders.RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind, parms.faction, PawnGenerationContext.NonPlayer, parms.tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, parms.inhabitants));

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, actAsIfSpawned: true);
            pawn.trader.traderKind = traderKind;
            parms.points          -= pawn.kindDef.combatPower;
            return(pawn);
        }
        public static TaleData_Trader GenerateRandom()
        {
            PawnKindDef pawnKindDef = DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef d) => d.trader).RandomElement();

            Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType));

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, actAsIfSpawned: true);
            return(GenerateFrom(pawn));
        }
Ejemplo n.º 6
0
        public static TaleData_Trader GenerateRandom()
        {
            PawnKindDef pawnKindDef = (from d in DefDatabase <PawnKindDef> .AllDefs
                                       where d.trader
                                       select d).RandomElement <PawnKindDef>();
            Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType));

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            return(TaleData_Trader.GenerateFrom(pawn));
        }
        private Pawn GenerateTrader(PawnGroupMakerParms parms, PawnGroupMaker groupMaker, TraderKindDef traderKind)
        {
            PawnKindDef           kind    = groupMaker.traders.RandomElementByWeight((PawnGenOption x) => x.selectionWeight).kind;
            Faction               faction = parms.faction;
            int                   tile    = parms.tile;
            PawnGenerationRequest request = new PawnGenerationRequest(kind, faction, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, false, 1f, false, true, true, parms.inhabitants, false, false, false, null, null, null, null, null, null, null, null);
            Pawn                  pawn    = PawnGenerator.GeneratePawn(request);

            pawn.mindState.wantsToTradeWithColony = true;
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
            pawn.trader.traderKind = traderKind;
            parms.points          -= pawn.kindDef.combatPower;
            return(pawn);
        }
Ejemplo n.º 8
0
 public static void AddComponentsForSpawn(Pawn pawn)
 {
     if (pawn.rotationTracker == null)
     {
         pawn.rotationTracker = new Pawn_RotationTracker(pawn);
     }
     if (pawn.pather == null)
     {
         pawn.pather = new Pawn_PathFollower(pawn);
     }
     if (pawn.thinker == null)
     {
         pawn.thinker = new Pawn_Thinker(pawn);
     }
     if (pawn.jobs == null)
     {
         pawn.jobs = new Pawn_JobTracker(pawn);
     }
     if (pawn.stances == null)
     {
         pawn.stances = new Pawn_StanceTracker(pawn);
     }
     if (pawn.natives == null)
     {
         pawn.natives = new Pawn_NativeVerbs(pawn);
     }
     if (pawn.filth == null)
     {
         pawn.filth = new Pawn_FilthTracker(pawn);
     }
     if (pawn.RaceProps.intelligence <= Intelligence.ToolUser)
     {
         if (pawn.caller == null)
         {
             pawn.caller = new Pawn_CallTracker(pawn);
         }
     }
     if (pawn.RaceProps.IsFlesh)
     {
         if (pawn.interactions == null)
         {
             pawn.interactions = new Pawn_InteractionsTracker(pawn);
         }
     }
     PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true);
 }
        private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction, Map map)
        {
            bool result;

            if (faction.def.visitorTraderKinds.NullOrEmpty <TraderKindDef>())
            {
                result = false;
            }
            else
            {
                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.traderFaction = 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);
                result = true;
            }
            return(result);
        }
Ejemplo n.º 10
0
        private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction, Map map)
        {
            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.RandomElementByWeight((TraderKindDef traderDef) => traderDef.commonality);

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

            parms.traderDef     = traderKindDef;
            parms.tile          = map.Tile;
            parms.traderFaction = faction;
            foreach (Thing item in ItemCollectionGeneratorDefOf.TraderStock.Worker.Generate(parms))
            {
                Pawn pawn2 = item 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);
                    lord.AddPawn(pawn2);
                }
                else if (!pawn.inventory.innerContainer.TryAdd(item, true))
                {
                    item.Destroy(DestroyMode.Vanish);
                }
            }
            PawnInventoryGenerator.GiveRandomFood(pawn);
            return(true);
        }
 public static void CreateInitialComponents(Pawn pawn)
 {
     if (pawn.ageTracker == null)
     {
         pawn.ageTracker = new Pawn_AgeTracker(pawn);
     }
     if (pawn.health == null)
     {
         pawn.health = new Pawn_HealthTracker(pawn);
     }
     if (pawn.records == null)
     {
         pawn.records = new Pawn_RecordsTracker(pawn);
     }
     if (pawn.inventory == null)
     {
         pawn.inventory = new Pawn_InventoryTracker(pawn);
     }
     if (pawn.meleeVerbs == null)
     {
         pawn.meleeVerbs = new Pawn_MeleeVerbs(pawn);
     }
     if (pawn.verbTracker == null)
     {
         pawn.verbTracker = new VerbTracker(pawn);
     }
     if (pawn.carryTracker == null)
     {
         pawn.carryTracker = new Pawn_CarryTracker(pawn);
     }
     if (pawn.needs == null)
     {
         pawn.needs = new Pawn_NeedsTracker(pawn);
     }
     if (pawn.mindState == null)
     {
         pawn.mindState = new Pawn_MindState(pawn);
     }
     if (pawn.RaceProps.ToolUser)
     {
         if (pawn.equipment == null)
         {
             pawn.equipment = new Pawn_EquipmentTracker(pawn);
         }
         if (pawn.apparel == null)
         {
             pawn.apparel = new Pawn_ApparelTracker(pawn);
         }
     }
     if (pawn.RaceProps.Humanlike)
     {
         if (pawn.ownership == null)
         {
             pawn.ownership = new Pawn_Ownership(pawn);
         }
         if (pawn.skills == null)
         {
             pawn.skills = new Pawn_SkillTracker(pawn);
         }
         if (pawn.story == null)
         {
             pawn.story = new Pawn_StoryTracker(pawn);
         }
         if (pawn.guest == null)
         {
             pawn.guest = new Pawn_GuestTracker(pawn);
         }
         if (pawn.guilt == null)
         {
             pawn.guilt = new Pawn_GuiltTracker();
         }
         if (pawn.workSettings == null)
         {
             pawn.workSettings = new Pawn_WorkSettings(pawn);
         }
     }
     if (pawn.RaceProps.IsFlesh && pawn.relations == null)
     {
         pawn.relations = new Pawn_RelationsTracker(pawn);
     }
     PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
 }
        public void SetGuestStatus(Faction newHost, bool prisoner = false)
        {
            if (newHost != null)
            {
                this.Released = false;
            }
            if (newHost == this.HostFaction && prisoner == this.IsPrisoner)
            {
                return;
            }
            if (!prisoner && this.pawn.Faction.HostileTo(newHost))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to make ",
                    this.pawn,
                    " a guest of ",
                    newHost,
                    " but their faction ",
                    this.pawn.Faction,
                    " is hostile to ",
                    newHost
                }), false);
                return;
            }
            if (newHost != null && newHost == this.pawn.Faction && !prisoner)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to make ",
                    this.pawn,
                    " a guest of their own faction ",
                    this.pawn.Faction
                }), false);
                return;
            }
            bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost);

            this.isPrisonerInt  = prisoner;
            this.hostFactionInt = newHost;
            this.pawn.ClearMind(false);
            if (flag)
            {
                this.pawn.DropAndForbidEverything(false);
                Lord lord = this.pawn.GetLord();
                if (lord != null)
                {
                    lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner, null);
                }
                if (newHost == Faction.OfPlayer)
                {
                    Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(this.pawn, PopAdaptationEvent.GainedPrisoner);
                }
                if (this.pawn.Drafted)
                {
                    this.pawn.drafter.Drafted = false;
                }
                float x = this.pawn.RecruitDifficulty(Faction.OfPlayer);
                this.resistance  = Pawn_GuestTracker.StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                this.resistance *= Pawn_GuestTracker.StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                this.resistance *= Pawn_GuestTracker.StartingResistanceRandomFactorRange.RandomInRange;
                this.resistance  = (float)GenMath.RoundRandom(this.resistance);
            }
            PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false);
            this.pawn.health.surgeryBills.Clear();
            if (this.pawn.ownership != null)
            {
                this.pawn.ownership.Notify_ChangedGuestStatus();
            }
            ReachabilityUtility.ClearCacheFor(this.pawn);
            if (this.pawn.Spawned)
            {
                this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn);
                this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
            }
            AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn);
            if (prisoner && this.pawn.playerSettings != null)
            {
                this.pawn.playerSettings.Notify_MadePrisoner();
            }
        }
Ejemplo n.º 13
0
        public void SetGuestStatus(Faction newHost, bool prisoner = false)
        {
            if (newHost != null)
            {
                Released = false;
            }
            if (newHost == HostFaction && prisoner == IsPrisoner)
            {
                return;
            }
            if (!prisoner && pawn.Faction.HostileTo(newHost))
            {
                Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost);
                return;
            }
            if (newHost != null && newHost == pawn.Faction && !prisoner)
            {
                Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction);
                return;
            }
            bool num = prisoner && (!IsPrisoner || HostFaction != newHost);

            isPrisonerInt = prisoner;
            Faction faction = hostFactionInt;

            hostFactionInt = newHost;
            Pawn obj = pawn;
            bool clearMentalState = prisoner;

            obj.ClearMind(newHost != null, clearInspiration: false, clearMentalState);
            if (num)
            {
                pawn.DropAndForbidEverything();
                pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner);
                if (pawn.Drafted)
                {
                    pawn.drafter.Drafted = false;
                }
                float x = pawn.RecruitDifficulty(Faction.OfPlayer);
                resistance  = StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                resistance *= StartingResistanceRandomFactorRange.RandomInRange;
                if (pawn.royalty != null)
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (mostSeniorTitle != null)
                    {
                        resistance *= mostSeniorTitle.def.recruitmentResistanceFactor;
                        resistance += mostSeniorTitle.def.recruitmentResistanceOffset;
                    }
                }
                resistance = GenMath.RoundRandom(resistance);
            }
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
            pawn.health.surgeryBills.Clear();
            if (pawn.ownership != null)
            {
                pawn.ownership.Notify_ChangedGuestStatus();
            }
            ReachabilityUtility.ClearCacheFor(pawn);
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.UpdateRegistryForPawn(pawn);
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (prisoner && pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_MadePrisoner();
            }
            if (faction != hostFactionInt)
            {
                QuestUtility.SendQuestTargetSignals(pawn.questTags, "ChangedHostFaction", pawn.Named("SUBJECT"), hostFactionInt.Named("FACTION"));
            }
        }