Exemplo n.º 1
0
 public static void MindStatePostLoadInit(Pawn_MindState mindState)
 {
     if (mindState.inspirationHandler == null)
     {
         mindState.inspirationHandler = new InspirationHandler(mindState.pawn);
     }
 }
 // Token: 0x0600000A RID: 10 RVA: 0x000023A8 File Offset: 0x000005A8
 public static void JobFailIfHid(Pawn seer, Pawn target, Job cur)
 {
     if (seer != null && target != null && cur != null && cur.def != CamoAIUtility.CamoPauseJobDef() && seer.Spawned && target.Spawned && (seer?.Map) != null && (target?.Map) != null && seer.Map == target.Map)
     {
         bool flag;
         if (seer == null)
         {
             flag = (null != null);
         }
         else
         {
             Pawn_MindState mindState = seer.mindState;
             flag = ((mindState?.meleeThreat) != null);
         }
         if (!flag)
         {
             if (CamoAIUtility.CanSeeSimply(seer, target))
             {
                 if (CamoUtility.IsTargetHidden(target, seer))
                 {
                     CamoAIUtility.CorrectLordForCamo(seer, target);
                     return;
                 }
             }
             else
             {
                 CamoAIUtility.CorrectLordForCamo(seer, target);
             }
         }
     }
 }
Exemplo n.º 3
0
        public static bool get_Inspired(Pawn __instance, ref bool __result)
        {
            Pawn_MindState mindState = __instance.mindState;

            __result = !__instance.Dead && mindState != null && mindState.inspirationHandler.Inspired;
            return(false);
        }
Exemplo n.º 4
0
        public static bool get_InAggroMentalState(Pawn __instance, ref bool __result)
        {
            Pawn_MindState mindState = __instance.mindState;

            __result = !__instance.Dead && mindState.mentalStateHandler.InMentalState && mindState.mentalStateHandler.CurStateDef.IsAggro;
            return(false);
        }
Exemplo n.º 5
0
 public static void Postfix(Pawn_MindState __instance)
 {
     if (__instance.pawn.NoOverlapAdjustedIsHashIntervalTick(100))
     {
         if (__instance.pawn.Spawned)
         {
             int regionsToScan = __instance.anyCloseHostilesRecently ? 24 : 18;
             __instance.anyCloseHostilesRecently = PawnUtility.EnemiesAreNearby(__instance.pawn, regionsToScan, true);
         }
         else
         {
             __instance.anyCloseHostilesRecently = false;
         }
     }
     if (TickUtility.NoOverlapTickMod(123) && __instance.pawn.Spawned && __instance.pawn.RaceProps.IsFlesh && __instance.pawn.needs.mood != null)
     {
         TerrainDef terrain = __instance.pawn.Position.GetTerrain(__instance.pawn.Map);
         if (terrain.traversedThought != null)
         {
             __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(terrain.traversedThought);
         }
         WeatherDef curWeatherLerped = __instance.pawn.Map.weatherManager.CurWeatherLerped;
         if (curWeatherLerped.exposedThought != null && !__instance.pawn.Position.Roofed(__instance.pawn.Map))
         {
             __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(curWeatherLerped.exposedThought);
         }
     }
 }
Exemplo n.º 6
0
        public static bool TryIssueJobPackage(ThinkNode_ForbidOutsideFlagRadius __instance, ref ThinkResult __result, Pawn pawn, JobIssueParams jobParams)
        {
            __result = ThinkResult.NoJob;
            if (pawn == null)
            {
                return(false);
            }
            Pawn_MindState mindState = pawn.mindState;

            if (mindState == null)
            {
                return(false);
            }
            try
            {
                if (__instance.maxDistToSquadFlag > 0.0)
                {
                    if (mindState.maxDistToSquadFlag > 0.0)
                    {
                        Log.Error("Squad flag was not reset properly; raiders may behave strangely");
                    }
                    pawn.mindState.maxDistToSquadFlag = __instance.maxDistToSquadFlag;
                }
                __result = TryIssueJobPackage2(__instance, pawn, jobParams);
                return(false);
            }
            finally
            {
                pawn.mindState.maxDistToSquadFlag = -1f;
            }
        }
Exemplo n.º 7
0
 public BossMindState(Pawn_MindState state)
 {
     foreach (FieldInfo field in state.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
     {
         field.SetValue(this, field.GetValue(state));
     }
 }
 // Token: 0x0600000C RID: 12 RVA: 0x00002524 File Offset: 0x00000724
 public static void CorrectJob(Pawn seer, Pawn target)
 {
     if (seer != null && target != null && (seer?.Map) != null && (target?.Map) != null && seer.Map == target.Map)
     {
         bool flag;
         if (seer == null)
         {
             flag = (null != null);
         }
         else
         {
             Pawn_MindState mindState = seer.mindState;
             flag = ((mindState?.meleeThreat) != null);
         }
         if (!flag && ThingCompUtility.TryGetComp <PawnCamoData>(seer).LastCamoCorrectTick + 120 <= Find.TickManager.TicksGame && seer.Spawned && target.Spawned)
         {
             bool flag2;
             if (seer == null)
             {
                 flag2 = (null != null);
             }
             else
             {
                 Pawn_JobTracker jobs = seer.jobs;
                 flag2 = ((jobs?.curJob) != null);
             }
             if (flag2 && seer.jobs.curJob.def != CamoAIUtility.CamoPauseJobDef() && seer.jobs.curJob.AnyTargetIs(target))
             {
                 ThingCompUtility.TryGetComp <PawnCamoData>(seer).LastCamoCorrectTick = Find.TickManager.TicksGame;
                 CamoAIUtility.RemoveTarget(seer, target);
             }
         }
     }
 }
    // Verse.AI.Pawn_MindState
    public static bool StartManhunterBecauseOfPawnAction_PreFix(Pawn_MindState __instance)
    {
        if (__instance.pawn is PawnWebSpinner p && p.CurJob?.def == ROMADefOf.ROMA_SpinPrey)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 10
0
            public static void Postfix(ref Pawn_MindState __instance)
            {
                if (!__instance.pawn.IsGuest())
                {
                    return;
                }

                __instance.pawn.ConvertToTrader(false);
            }
        public static bool PreFix(ref Toil __result, TargetIndex targetInd, Action hitAction)
        {
            Toil followAndAttack = new Toil();

            followAndAttack.tickAction = delegate()
            {
                Pawn      actor     = followAndAttack.actor;
                Job       curJob    = actor.jobs.curJob;
                JobDriver curDriver = actor.jobs.curDriver;
                Thing     thing     = curJob.GetTarget(targetInd).Thing;
                Pawn      pawn      = thing as Pawn;
                if (thing.Spawned && !ReachabilityImmediate.CanReachImmediate(actor, pawn, PathEndMode.Touch))
                {
                    bool flag;
                    if (actor == null)
                    {
                        flag = (null != null);
                    }
                    else
                    {
                        Pawn_MindState mindState = actor.mindState;
                        flag = ((mindState?.meleeThreat) != null);
                    }
                    if (!flag && pawn != null && pawn != null && CamoUtility.IsTargetHidden(pawn, actor))
                    {
                        CamoAIUtility.CorrectJob(actor, pawn);
                    }
                }
                if (!thing.Spawned)
                {
                    curDriver.ReadyForNextToil();
                    return;
                }
                if (thing != actor.pather.Destination.Thing || (!actor.pather.Moving && !ReachabilityImmediate.CanReachImmediate(actor, thing, PathEndMode.Touch)))
                {
                    actor.pather.StartPath(thing, PathEndMode.Touch);
                    return;
                }
                if (ReachabilityImmediate.CanReachImmediate(actor, thing, PathEndMode.Touch))
                {
                    if (pawn != null && pawn.Downed && !curJob.killIncappedTarget)
                    {
                        curDriver.ReadyForNextToil();
                        return;
                    }
                    hitAction();
                }
            };
            followAndAttack.defaultCompleteMode = ToilCompleteMode.Never;
            __result = followAndAttack;
            return(false);
        }
        //internal void Notify_DangerousExploderAboutToExplode(Thing exploder)
        public static void Postfix(Pawn_MindState __instance, Thing exploder)
        {
            if (!Mod.settings.dodgeGrenade)
            {
                return;
            }

            //Just copy-paste vanilla but do it for drafted now.
            if ((int)__instance.pawn.RaceProps.intelligence >= 2 && __instance.pawn.Drafted)
            {
                __instance.knownExploder = exploder;
                __instance.pawn.jobs.CheckForJobOverride();
            }
        }
Exemplo n.º 13
0
        public static bool DontFlee(Pawn_MindState __instance)

        {
            bool flagDoesCReatureNotFlee = AnimalCollectionClass.nofleeing_animals.Contains(__instance.pawn);

            if (flagDoesCReatureNotFlee)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 14
0
            private static void Prefix(Pawn_MindState __instance)
            {
                Pawn pawn = __instance?.pawn;

                // Early state?
                if (pawn == null)
                {
                    return;
                }
                if (pawn.Faction?.def?.defName == null)
                {
                    return;
                }

                // Not ours; short-circuit
                if (!pawn.Faction.def.defName.Contains("FactionBlender"))
                {
                    return;
                }

                // Already warned about it; short-circuit
                if (hasWarnedAboutMisbehavingPawn.ContainsKey(pawn.ToString()))
                {
                    return;
                }

                // Check the current job for hostilities
                Job job = pawn.CurJob;

                if (
                    job != null && TryCheckFriendlyFaction(pawn, job.targetA.Thing) && (
                        job.def == JobDefOf.AttackMelee || job.def == JobDefOf.AttackStatic || job.def == JobDefOf.Hunt || job.def == JobDefOf.Ignite ||
                        job.def == JobDefOf.Ingest || job.def == JobDefOf.Kidnap || job.def == JobDefOf.PredatorHunt || job.def == JobDefOf.Slaughter
                        )
                    )
                {
                    // Warn about it
                    Pawn tPawn = job.targetA.Thing as Pawn;
                    Base.Instance.ModLogger.Warning(
                        "Friendly faction attack (" + job.def.ToString() + ") between " + pawn.ToString() + " and " + tPawn.ToString() + ".  " +
                        "The pawn type may need to be blacklisted in the Faction Blender configuration.  " +
                        "(Race: " + pawn.kindDef.race.defName + ", defaultFactionType: " + pawn.kindDef.defaultFactionType + ")"
                        );
                    hasWarnedAboutMisbehavingPawn.Add(pawn.ToString(), true);
                }

                return;
            }
Exemplo n.º 15
0
 public static bool MindStateTick(Pawn_MindState __instance)
 {
     if (__instance.wantsToTradeWithColony)
     {
         TradeUtility.CheckInteractWithTradersTeachOpportunity(__instance.pawn);
     }
     if (__instance.meleeThreat != null && !__instance.MeleeThreatStillThreat)
     {
         __instance.meleeThreat = null;
     }
     __instance.mentalStateHandler.MentalStateHandlerTick();
     __instance.mentalBreaker.MentalBreakerTick();
     __instance.inspirationHandler.InspirationHandlerTick();
     if (!__instance.pawn.GetPosture().Laying())
     {
         __instance.applyBedThoughtsTick = 0;
     }
     if (__instance.pawn.IsHashIntervalTick(100))
     {
         __instance.anyCloseHostilesRecently = __instance.pawn.Spawned && PawnUtility.EnemiesAreNearby(__instance.pawn, __instance.anyCloseHostilesRecently ? 24 : 18, true);
     }
     if (__instance.WillJoinColonyIfRescued && __instance.AnythingPreventsJoiningColonyIfRescued)
     {
         __instance.WillJoinColonyIfRescued = false;
     }
     if (__instance.pawn.Spawned && __instance.pawn.IsWildMan() && (!__instance.WildManEverReachedOutside && __instance.pawn.GetRoom(RegionType.Set_Passable) != null) && __instance.pawn.GetRoom(RegionType.Set_Passable).TouchesMapEdge)
     {
         __instance.WildManEverReachedOutside = true;
     }
     if (Find.TickManager.TicksGame % 123 == 0 && __instance.pawn.Spawned && (__instance.pawn.RaceProps.IsFlesh && __instance.pawn.needs.mood != null))
     {
         TerrainDef terrain = __instance.pawn.Position.GetTerrain(__instance.pawn.Map);
         if (terrain.traversedThought != null)
         {
             __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(terrain.traversedThought);
         }
         WeatherDef curWeatherLerped = __instance.pawn.Map.weatherManager.CurWeatherLerped;
         if (curWeatherLerped.exposedThought != null && !__instance.pawn.Position.Roofed(__instance.pawn.Map))
         {
             __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(curWeatherLerped.exposedThought);
         }
     }
     //dirty hack for easy speedup - i'm sure this breaks things like pawn conversation interval.
     //if (GenLocalDate.DayTick((Thing)__instance.pawn) != 0)
     //	return;
     __instance.interactionsToday = 0;
     return(false);
 }
        private static bool MindStateTick(Pawn_MindState __instance)
        {
            if (Find.TickManager.TicksGame % 123 == 0)
            {
                return(true);
            }

            bool callOrig = __instance.pawn.IsHashIntervalTick(5);

            if (!callOrig && GenLocalDate.DayTick(__instance.pawn) == 0)
            {
                __instance.interactionsToday = 0;
            }

            return(callOrig);
        }
Exemplo n.º 17
0
            static void Postfix(ref DamageInfo __state, ref Pawn_MindState __instance)
            {
                if (!Settings.fight_back || !__state.Def.externalViolence)
                {
                    return;
                }

                Pawn defender = __instance.pawn;
                Pawn attacker = __state.Instigator as Pawn;

                if (defender == null || attacker == null || !defender.RaceProps.Animal || defender.Dead || defender.Downed /*|| defender.InMentalState*/ || defender.mindState.meleeThreat == null)
                {
                    return;
                }

                if (defender.CurJob != null && (defender.CurJob.def == JobDefOf.AttackMelee || defender.CurJob.def == JobDefOf.AttackStatic || defender.CurJob.def == JobDefOf.PredatorHunt))
                {
                    return;
                }

                // chance to try fight back any attacker
                bool fight = Rand.Chance(defender.RaceProps.manhunterOnDamageChance);

                //Log.Message("Debug: " + defender + " is attacked. Manhunter chance: " + defender.RaceProps.manhunterOnDamageChance + ", result: " + fight);

                // chance to fight back attacker who is not much stronger
                if (!fight)
                {
                    float powerRatio = 10 * (defender.kindDef.combatPower * defender.health.summaryHealth.SummaryHealthPercent * defender.ageTracker.CurLifeStage.bodySizeFactor)
                                       / (attacker.kindDef.combatPower * attacker.health.summaryHealth.SummaryHealthPercent * attacker.ageTracker.CurLifeStage.bodySizeFactor);
                    fight = Rand.Chance(powerRatio);
                    //Log.Message("Debug: " + defender + " is failed to manhunter. Power ratio: " + powerRatio + ", result: " + fight);
                }

                if (fight)
                {
                    //Messages.Message("Debug: " + defender + " is fighting back.", defender, MessageSound.Silent);
                    defender.jobs.StopAll();
                    defender.jobs.StartJob(
                        new Job(JobDefOf.AttackMelee, attacker)
                    {
                        maxNumMeleeAttacks = 1,
                        expiryInterval     = 200
                    });
                }
            }
Exemplo n.º 18
0
        public static bool TryGiveJob(JobGiver_ExitMap __instance, ref Job __result, Pawn pawn)
        {
            Pawn_MindState mindState = pawn.mindState;
            bool           canDig    = __instance.forceCanDig ||
                                       (mindState != null && mindState.duty != null) &&
                                       mindState.duty.canDig &&
                                       !pawn.CanReachMapEdge() ||
                                       __instance.forceCanDigIfCantReachMapEdge && !pawn.CanReachMapEdge() ||
                                       __instance.forceCanDigIfAnyHostileActiveThreat && pawn.Faction != null &&
                                       GenHostility.AnyHostileActiveThreatTo(pawn.Map, pawn.Faction, true);
            IntVec3 dest;

            if (!__instance.TryFindGoodExitDest(pawn, canDig, out dest))
            {
                __result = null;
                return(false);
            }
            if (canDig)
            {
                using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, (LocalTargetInfo)dest, TraverseParms.For(pawn, mode: TraverseMode.PassAllDestroyableThings)))
                {
                    IntVec3 cellBefore;
                    Thing   blocker = path.FirstBlockingBuilding(out cellBefore, pawn);
                    if (blocker != null)
                    {
                        Job job = DigUtility.PassBlockerJob(pawn, blocker, cellBefore, true, true);
                        if (job != null)
                        {
                            __result = job;
                            return(false);
                        }
                    }
                }
            }
            Job job1 = JobMaker.MakeJob(JobDefOf.Goto, (LocalTargetInfo)dest);

            job1.exitMapOnArrival = true;
            job1.failIfCantJoinOrCreateCaravan = __instance.failIfCantJoinOrCreateCaravan;
            job1.locomotionUrgency             = PawnUtility.ResolveLocomotion(pawn, __instance.defaultLocomotion, LocomotionUrgency.Jog);
            job1.expiryInterval = __instance.jobMaxDuration;
            job1.canBashDoors   = __instance.canBash;
            __result            = job1;
            return(false);
        }
        static bool Prefix(Pawn_MindState __instance, ref DamageInfo dinfo)
        {
            if (__instance.pawn.AnimalOrWildMan() && dinfo.Instigator is Pawn_Zombiefied)
            {
                __instance.mentalStateHandler.Notify_DamageTaken(dinfo);

                /*
                 * if (dinfo.Def.ExternalViolenceFor(__instance.pawn))
                 * {
                 *  __instance.lastHarmTick = Find.TickManager.TicksGame;
                 *  if (__instance.pawn.GetPosture() != PawnPosture.Standing)
                 *  {
                 *      __instance.lastDisturbanceTick = Find.TickManager.TicksGame;
                 *  }
                 * }
                 */
                return(false);
            }
            return(true);
        }
Exemplo n.º 20
0
 public static void Postfix(Pawn_MindState __instance)
 {
     if (AdrenalineSettings.npcUse)
     {
         var pawn = __instance.pawn;
         // Try to inject nearby adrenaline items if the pawn is downed, not a player pawn, is at least a tooluser, is capable of manipulation and moving, and can gain an adrelaine hediff
         if (pawn.IsHashIntervalTick(60) && pawn.Downed && pawn.Faction != Faction.OfPlayer && pawn.RaceProps.intelligence >= Intelligence.ToolUser &&
             pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Moving))
         {
             var extraRaceProps = pawn.def.GetModExtension <ExtendedRaceProperties>() ?? ExtendedRaceProperties.defaultValues;
             if (extraRaceProps.adrenalineRushHediff != null)
             {
                 var adrenalineHediff = pawn.health.hediffSet.GetFirstHediffOfDef(extraRaceProps.adrenalineRushHediff);
                 if ((adrenalineHediff == null || adrenalineHediff.CurStageIndex < adrenalineHediff.def.stages.Count - 1) &&
                     AdrenalineUtility.AnyNearbyAdrenaline(pawn, extraRaceProps.RelevantConsumablesDowned, out List <Thing> adrenalineThings))
                 {
                     adrenalineThings.First().Ingested(pawn, 0);
                 }
             }
         }
     }
 }
        // Token: 0x06000003 RID: 3 RVA: 0x00002164 File Offset: 0x00000364
        public static bool IsMeleeProcess(Pawn seer, Pawn target)
        {
            if (seer.CurrentEffectiveVerb.IsMeleeAttack)
            {
                bool flag;
                if (seer == null)
                {
                    flag = (null != null);
                }
                else
                {
                    Pawn_MindState mindState = seer.mindState;
                    flag = ((mindState?.enemyTarget) != null);
                }
                if (flag)
                {
                    return(true);
                }
            }
            bool flag2;

            if (seer == null)
            {
                flag2 = (null != null);
            }
            else
            {
                Pawn_MindState mindState2 = seer.mindState;
                flag2 = ((mindState2?.meleeThreat) != null);
            }
            if (!flag2)
            {
                return(false);
            }
            return(true);
        }
        // Token: 0x0600000E RID: 14 RVA: 0x00002640 File Offset: 0x00000840
        public static bool StillMeleeThreat(Pawn seer, Pawn target)
        {
            bool result = false;

            if (seer != null && target != null && (seer?.Map) != null && (target?.Map) != null && seer.Map == target.Map)
            {
                Pawn pawn;
                if (seer == null)
                {
                    pawn = null;
                }
                else
                {
                    Pawn_MindState mindState = seer.mindState;
                    pawn = (mindState?.meleeThreat);
                }
                Pawn pawn2 = pawn;
                if (pawn2 != null && pawn2 == target && pawn2.Spawned && !pawn2.Downed && seer.Spawned && Find.TickManager.TicksGame <= seer.mindState.lastMeleeThreatHarmTick + 83 && (float)(seer.Position - pawn2.Position).LengthHorizontalSquared <= 7f && GenSight.LineOfSight(seer.Position, pawn2.Position, seer.Map, false, null, 0, 0))
                {
                    result = true;
                }
            }
            return(result);
        }
 // Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
 public static void CorrectLordForCamo(Pawn seer, Pawn target)
 {
     if (seer == null || target == null || (seer?.Map) == null || (target?.Map) == null || seer.Map != target.Map || seer.IsColonist)
     {
         return;
     }
     if (seer.RaceProps.IsMechanoid)
     {
         return;
     }
     if (!WildManUtility.AnimalOrWildMan(seer) || seer.RaceProps.FleshType != FleshTypeDefOf.Insectoid)
     {
         CamoAIUtility.CorrectLordForCamoAction(seer, target, seer.Map.IsPlayerHome);
         return;
     }
     if (seer != null)
     {
         Pawn_MindState mindState = seer.mindState;
         if (mindState != null)
         {
             _ = mindState.duty;
         }
     }
 }
Exemplo n.º 24
0
        static bool Prefix(Pawn_MindState __instance)
        {
            if (!__instance.pawn.NonHumanlikeOrWildMan() && (UmbrellaDefMethods.HasUmbrella(__instance.pawn) || (RimbrellasMod.settings.cowboyHatsPreventSoakingWet && UmbrellaDefMethods.HasCowboyHat(__instance.pawn))))
            {
                if (__instance.wantsToTradeWithColony)
                {
                    TradeUtility.CheckInteractWithTradersTeachOpportunity(__instance.pawn);
                }
                if (__instance.meleeThreat != null && !__instance.MeleeThreatStillThreat)
                {
                    __instance.meleeThreat = null;
                }
                __instance.mentalStateHandler.MentalStateHandlerTick();
                __instance.mentalBreaker.MentalBreakerTick();
                __instance.inspirationHandler.InspirationHandlerTick();
                if (!__instance.pawn.GetPosture().Laying())
                {
                    __instance.applyBedThoughtsTick = 0;
                }
                if (__instance.pawn.IsHashIntervalTick(100))
                {
                    if (__instance.pawn.Spawned)
                    {
                        int regionsToScan = __instance.anyCloseHostilesRecently ? 24 : 18;
                        __instance.anyCloseHostilesRecently = PawnUtility.EnemiesAreNearby(__instance.pawn, regionsToScan, passDoors: true);
                    }
                    else
                    {
                        __instance.anyCloseHostilesRecently = false;
                    }
                }
                if (__instance.WillJoinColonyIfRescued && __instance.AnythingPreventsJoiningColonyIfRescued)
                {
                    __instance.WillJoinColonyIfRescued = false;
                }
                if (__instance.pawn.Spawned && __instance.pawn.IsWildMan() && !__instance.WildManEverReachedOutside && __instance.pawn.GetRoom() != null && __instance.pawn.GetRoom().TouchesMapEdge)
                {
                    __instance.WildManEverReachedOutside = true;
                }
                if (Find.TickManager.TicksGame % 123 == 0 && __instance.pawn.Spawned && __instance.pawn.RaceProps.IsFlesh && __instance.pawn.needs.mood != null)
                {
                    __instance.pawn.Drawer.renderer.graphics.ResolveAllGraphics();

                    TerrainDef terrain = __instance.pawn.Position.GetTerrain(__instance.pawn.Map);
                    if (terrain.traversedThought != null)
                    {
                        __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(terrain.traversedThought);
                    }

                    /*WeatherDef curWeatherLerped = __instance.pawn.Map.weatherManager.CurWeatherLerped;
                     * if (curWeatherLerped.exposedThought != null && !__instance.pawn.Position.Roofed(__instance.pawn.Map)) {
                     *      __instance.pawn.needs.mood.thoughts.memories.TryGainMemoryFast(curWeatherLerped.exposedThought);
                     * }*///this code would assign the Soaking Wet thought to a pawn outside in the rain, but we've already checked that the pawn has an umbrella
                }
                if (GenLocalDate.DayTick(__instance.pawn) == 0)
                {
                    __instance.interactionsToday = 0;
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 25
0
        public override void PawnDied(Corpse corpse)
        {
            PawnGenerationRequest pawnGenerationRequest;
            PawnKindDef           pawnKindDef = corpse.InnerPawn.kindDef;
            Pawn           pawn        = corpse.InnerPawn;
            IntVec3        position    = corpse.Position;
            Map            map         = corpse.Map;
            Faction        faction     = pawn.Faction;
            float          bioyears    = pawn.ageTracker.AgeBiologicalYears;
            float          chronoyears = pawn.ageTracker.AgeChronologicalYears;
            Pawn_MindState mind        = pawn.mindState;
            Pawn           newPawn1    = null;
            Pawn           newPawn2    = null;
            bool           spawn       = false;
            Lord           lord        = pawn.GetLord();
            List <Thing>   spawned     = new List <Thing>();

            if (map != null)
            {
                if (corpse.InnerPawn.kindDef == AdeptusPawnKindDefOf.OG_Chaos_Deamon_Lessar_Horror_Blue)
                {
                    spawn       = true;
                    pawnKindDef = AdeptusPawnKindDefOf.OG_Chaos_Deamon_Lessar_Horror_Brimstone;
                }
                else if (corpse.InnerPawn.kindDef == AdeptusPawnKindDefOf.OG_Chaos_Deamon_Lessar_Horror_Pink)
                {
                    spawn       = true;
                    pawnKindDef = AdeptusPawnKindDefOf.OG_Chaos_Deamon_Lessar_Horror_Blue;
                }
                if (spawn)
                {
                    pawnGenerationRequest = new PawnGenerationRequest(pawnKindDef, corpse.InnerPawn.Faction, PawnGenerationContext.NonPlayer, -1, true, false, true, false, true, true, 20f, fixedBiologicalAge: bioyears, fixedChronologicalAge: chronoyears);
                    newPawn1 = PawnGenerator.GeneratePawn(pawnGenerationRequest);
                    newPawn2 = PawnGenerator.GeneratePawn(pawnGenerationRequest);
                    spawned  = new List <Thing>()
                    {
                        newPawn1,
                        newPawn2
                    };
                    if (pawn.Faction != null)
                    {
                        if (map.mapPawns.SpawnedPawnsInFaction(pawn.Faction).Any((Pawn p) => p != newPawn1 && p != newPawn2 && p.GetLord() != null))
                        {
                            bool validator(Thing p) => p != newPawn1 && p != newPawn2 && ((Pawn)p).GetLord() != null;

                            Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(position, map.mapPawns.SpawnedPawnsInFaction(newPawn1.Faction), 99999f, validator, null);
                            lord = p2.GetLord();
                        }
                    }
                    if (lord == null)
                    {
                        try
                        {
                            LordJob_AssaultColony lordJob = new LordJob_AssaultColony(faction, false, false);
                            lord = LordMaker.MakeNewLord((pawn.Faction), lordJob, map, null);
                        }
                        catch
                        {
                            //    newPawn1.mindState.mentalStateHandler.TryStartMentalState(OGChaosDeamonDefOf.MentalState_OGChaosDeamon);
                            //    newPawn2.mindState.mentalStateHandler.TryStartMentalState(OGChaosDeamonDefOf.MentalState_OGChaosDeamon);
                        }
                    }
                    else
                    {
                        try
                        {
                            newPawn1.mindState.duty = new PawnDuty(DutyDefOf.AssaultColony);
                            newPawn2.mindState.duty = new PawnDuty(DutyDefOf.AssaultColony);
                        }
                        catch
                        {
                            //    newPawn1.mindState.mentalStateHandler.TryStartMentalState(OGChaosDeamonDefOf.MentalState_OGChaosDeamon);
                            //    newPawn2.mindState.mentalStateHandler.TryStartMentalState(OGChaosDeamonDefOf.MentalState_OGChaosDeamon);
                        }
                    }
                    if (spawn)
                    {
                        Pawn p = (Pawn)GenClosest.ClosestThing_Global(position, map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, null, null);
                        if (p.InMentalState)
                        {
                            if (p.MentalStateDef == MentalStateDefOf.PanicFlee || p.GetLord() == null || p.GetLord().Map == null)
                            {
                                spawn = false;
                            }
                        }
                    }
                    if (spawn && pawnKindDef != corpse.InnerPawn.kindDef && lord != null && map != null)
                    {
                        if (newPawn1 != null)
                        {
                            GenSpawn.Spawn(newPawn1, position, map, 0);
                            if (lord != null)
                            {
                                lord.AddPawn(newPawn1);
                            }
                        }
                        if (newPawn2 != null)
                        {
                            GenSpawn.Spawn(newPawn2, position, map, 0);
                            if (lord != null)
                            {
                                lord.AddPawn(newPawn2);
                            }
                        }
                    }
                }
            }
            if (position != null && map != null)
            {
                GenExplosion.DoExplosion(position, map, 1.9f, AdeptusDamageDefOf.OG_Chaos_Deamon_WarpfireDeath, corpse.InnerPawn, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, spawned);
            }
            base.PawnDied(corpse);
        }
        // Token: 0x0600000B RID: 11 RVA: 0x0000244C File Offset: 0x0000064C
        public static void RemoveTarget(Pawn seer, Pawn target)
        {
            if (seer.pather.Moving)
            {
                bool flag;
                if (seer == null)
                {
                    flag = (null != null);
                }
                else
                {
                    Pawn_JobTracker jobs = seer.jobs;
                    flag = ((jobs?.curJob) != null);
                }
                if (flag && seer.jobs.curJob.AnyTargetIs(target))
                {
                    seer.jobs.curDriver.Notify_PatherFailed();
                    bool flag2;
                    if (seer == null)
                    {
                        flag2 = (null != null);
                    }
                    else
                    {
                        Pawn_PathFollower pather = seer.pather;
                        flag2 = ((pather?.curPath) != null);
                    }
                    if (flag2)
                    {
                        seer.pather.ResetToCurrentPosition();
                        seer.pather.curPath.ReleaseToPool();
                    }
                }
            }
            bool flag3;

            if (seer == null)
            {
                flag3 = (null != null);
            }
            else
            {
                Pawn_MindState mindState = seer.mindState;
                flag3 = ((mindState?.enemyTarget) != null);
            }
            if (flag3)
            {
                seer.mindState.enemyTarget = null;
            }
            bool flag4;

            if (seer == null)
            {
                flag4 = (null != null);
            }
            else
            {
                Pawn_MindState mindState2 = seer.mindState;
                flag4 = ((mindState2?.meleeThreat) != null);
            }
            if (!flag4)
            {
                CamoAIUtility.StopCurJobAndWait(seer);
            }
        }
Exemplo n.º 27
0
        // Token: 0x06000021 RID: 33 RVA: 0x00003600 File Offset: 0x00001800
        internal static void DoCamoMote(Thing thing, Thing ghost, bool hidden, int chance, float camoEff, float scaler)
        {
            bool flag  = true;
            bool flag2 = false;

            if (CamoUtility.IsDebugMode() && Controller.Settings.ShowMoteMsgs && thing != null && (thing?.Map) != null && thing.Spawned)
            {
                if (flag)
                {
                    if (thing is Pawn)
                    {
                        flag2 = (ghost is Pawn && GenHostility.HostileTo(thing, ghost) && (!(thing.Position == ghost.Position) && !thing.Position.InHorDistOf(ghost.Position, CamoUtility.NotPossibleMinDist)));
                    }
                }
                else
                {
                    flag2 = true;
                }
                if (flag2 && CamoUtility.IsValidThingForCamo(thing))
                {
                    Vector3 vector = thing.Position.ToVector3();
                    _ = Color.cyan;
                    string text;
                    Color  color;
                    if (hidden)
                    {
                        text  = TranslatorFormattedStringExtensions.Translate("CompCamo.CannotSee", chance.ToString(), GenText.ToStringPercent(camoEff), GenText.ToStringPercent(scaler));
                        color = Color.green;
                    }
                    else
                    {
                        text  = TranslatorFormattedStringExtensions.Translate("CompCamo.CanSee", chance.ToString(), GenText.ToStringPercent(camoEff), GenText.ToStringPercent(scaler));
                        color = Color.red;
                    }
                    MoteMaker.ThrowText(vector, thing.Map, text, color, -1f);
                    if (CamoUtility.IsDebugMode())
                    {
                        string text2 = text;
                        bool   flag3;
                        if (!(thing is Pawn pawn))
                        {
                            flag3 = (null != null);
                        }
                        else
                        {
                            Pawn_JobTracker jobs = pawn.jobs;
                            flag3 = ((jobs?.curJob) != null);
                        }
                        if (flag3)
                        {
                            text2 = text2 + ", CJ: " + (thing as Pawn).jobs.curJob.def.defName;
                            string str  = text2;
                            string str2 = ", ET:";
                            bool   flag4;
                            if (!(thing is Pawn pawn2))
                            {
                                flag4 = (null != null);
                            }
                            else
                            {
                                Pawn_MindState mindState = pawn2.mindState;
                                flag4 = ((mindState?.enemyTarget) != null);
                            }
                            string str3;
                            if (!flag4)
                            {
                                str3 = "null";
                            }
                            else
                            {
                                Thing enemyTarget = (thing as Pawn).mindState.enemyTarget;
                                str3 = (enemyTarget?.LabelShortCap);
                            }
                            text2 = str + str2 + str3;
                            string str4 = text2;
                            string str5 = ", MT:";
                            bool   flag5;
                            if (!(thing is Pawn pawn3))
                            {
                                flag5 = (null != null);
                            }
                            else
                            {
                                Pawn_MindState mindState2 = pawn3.mindState;
                                flag5 = ((mindState2?.meleeThreat) != null);
                            }
                            string str6;
                            if (!flag5)
                            {
                                str6 = "null";
                            }
                            else
                            {
                                Pawn meleeThreat = (thing as Pawn).mindState.meleeThreat;
                                str6 = (meleeThreat?.LabelShortCap);
                            }
                            text2 = str4 + str5 + str6;
                        }
                        Log.Message(text2, false);
                    }
Exemplo n.º 28
0
 public static bool MindStateTick(Pawn_MindState __instance)
 {
     return(__instance.pawn.IsHashIntervalTick(5));
 }
Exemplo n.º 29
0
 public static bool MentalStateBecauseRecruitAttempted_Prefix(ref bool __result, Pawn_MindState __instance, Pawn tamer)
 {
     if (tamer?.story?.traits != null && tamer.story.traits.HasTrait(SyrTraitDefOf.SYR_AnimalAffinity))
     {
         __result = false;
         return(false);
     }
     else
     {
         return(true);
     }
 }
 public override void PostExposeData(object obj)
 {
     if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         Game game = obj as Game;
         if (game != null && game.battleLog == null)
         {
             game.battleLog = new BattleLog();
         }
         BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = obj as BattleLogEntry_MeleeCombat;
         if (battleLogEntry_MeleeCombat != null)
         {
             if (battleLogEntry_MeleeCombat.RuleDef == null)
             {
                 RulePackDef value  = null;
                 RulePackDef value2 = null;
                 Scribe_Defs.Look(ref value, "outcomeRuleDef");
                 Scribe_Defs.Look(ref value2, "maneuverRuleDef");
                 if (value != null && value2 != null)
                 {
                     foreach (RulePackDef item in DefDatabase <RulePackDef> .AllDefsListForReading)
                     {
                         if (!item.include.NullOrEmpty() && item.include.Count == 2 && ((item.include[0] == value && item.include[1] == value2) || (item.include[1] == value && item.include[0] == value2)))
                         {
                             battleLogEntry_MeleeCombat.RuleDef = item;
                             break;
                         }
                     }
                 }
             }
             if (battleLogEntry_MeleeCombat.def == null)
             {
                 battleLogEntry_MeleeCombat.def = LogEntryDefOf.MeleeAttack;
             }
         }
     }
     if (Scribe.mode == LoadSaveMode.PostLoadInit)
     {
         Map map = obj as Map;
         if (map != null && map.pawnDestinationReservationManager == null)
         {
             map.pawnDestinationReservationManager = new PawnDestinationReservationManager();
         }
         Pawn pawn = obj as Pawn;
         if (pawn != null && pawn.Spawned && pawn.rotationTracker == null)
         {
             pawn.rotationTracker = new Pawn_RotationTracker(pawn);
         }
         Pawn_MindState pawn_MindState = obj as Pawn_MindState;
         if (pawn_MindState != null && pawn_MindState.inspirationHandler == null)
         {
             pawn_MindState.inspirationHandler = new InspirationHandler(pawn_MindState.pawn);
         }
         ImportantPawnComp importantPawnComp = obj as ImportantPawnComp;
         if (importantPawnComp != null && importantPawnComp.pawn == null)
         {
             importantPawnComp.pawn = new ThingOwner <Pawn>(importantPawnComp, oneStackOnly: true);
         }
         Pawn_RecordsTracker pawn_RecordsTracker = obj as Pawn_RecordsTracker;
         if (pawn_RecordsTracker != null && Find.TaleManager.AnyTaleConcerns(pawn_RecordsTracker.pawn))
         {
             pawn_RecordsTracker.AccumulateStoryEvent(StoryEventDefOf.TaleCreated);
         }
         WorldPawns worldPawns = obj as WorldPawns;
         if (worldPawns != null && worldPawns.gc == null)
         {
             worldPawns.gc = new WorldPawnGC();
         }
         GameCondition gameCondition = obj as GameCondition;
         if (gameCondition != null && !gameCondition.Permanent && gameCondition.Duration > 1000000000)
         {
             gameCondition.Permanent = true;
         }
         Building_TurretGun building_TurretGun = obj as Building_TurretGun;
         if (building_TurretGun != null && building_TurretGun.gun == null)
         {
             building_TurretGun.MakeGun();
         }
     }
 }