コード例 #1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Job result;

            if (pawn.playerSettings != null && pawn.playerSettings.UsesConfigurableHostilityResponse)
            {
                result = null;
            }
            else if (ThinkNode_ConditionalShouldFollowMaster.ShouldFollowMaster(pawn))
            {
                result = null;
            }
            else
            {
                if (pawn.Faction == null)
                {
                    List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (pawn.Position.InHorDistOf(list[i].Position, 18f))
                        {
                            if (SelfDefenseUtility.ShouldFleeFrom(list[i], pawn, false, false))
                            {
                                Job job = this.FleeJob(pawn, list[i]);
                                if (job != null)
                                {
                                    return(job);
                                }
                            }
                        }
                    }
                    Job job2 = this.FleeLargeFireJob(pawn);
                    if (job2 != null)
                    {
                        return(job2);
                    }
                }
                else if (pawn.GetLord() == null)
                {
                    List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                    for (int j = 0; j < potentialTargetsFor.Count; j++)
                    {
                        Thing thing = potentialTargetsFor[j].Thing;
                        if (pawn.Position.InHorDistOf(thing.Position, 18f))
                        {
                            if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, false, true))
                            {
                                Job job3 = this.FleeJob(pawn, thing);
                                if (job3 != null)
                                {
                                    return(job3);
                                }
                            }
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
コード例 #2
0
        public static bool ShouldStartFleeing(Pawn pawn)
        {
            List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);

            for (int i = 0; i < list.Count; i++)
            {
                if (SelfDefenseUtility.ShouldFleeFrom(list[i], pawn, true, false))
                {
                    return(true);
                }
            }
            bool   foundThreat = false;
            Region region      = pawn.GetRegion(RegionType.Set_Passable);

            if (region == null)
            {
                return(false);
            }
            RegionTraverser.BreadthFirstTraverse(region, (Region from, Region reg) => reg.portal == null || reg.portal.Open, delegate(Region reg)
            {
                List <Thing> list2 = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                for (int j = 0; j < list2.Count; j++)
                {
                    if (SelfDefenseUtility.ShouldFleeFrom(list2[j], pawn, true, true))
                    {
                        foundThreat = true;
                        break;
                    }
                }
                return(foundThreat);
            }, 9, RegionType.Set_Passable);
            return(foundThreat);
        }
コード例 #3
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (pawn.playerSettings != null && pawn.playerSettings.UsesConfigurableHostilityResponse)
     {
         return(null);
     }
     if (ThinkNode_ConditionalShouldFollowMaster.ShouldFollowMaster(pawn))
     {
         return(null);
     }
     if (pawn.Faction == null)
     {
         List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
         for (int i = 0; i < list.Count; i++)
         {
             if (pawn.Position.InHorDistOf(list[i].Position, 18f) && SelfDefenseUtility.ShouldFleeFrom(list[i], pawn, checkDistance: false, checkLOS: false))
             {
                 Job job = FleeJob(pawn, list[i]);
                 if (job != null)
                 {
                     return(job);
                 }
             }
         }
         Job job2 = FleeLargeFireJob(pawn);
         if (job2 != null)
         {
             return(job2);
         }
     }
     else if (pawn.GetLord() == null && (pawn.Faction != Faction.OfPlayer || !pawn.Map.IsPlayerHome) && (pawn.CurJob == null || !pawn.CurJobDef.neverFleeFromEnemies))
     {
         List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
         for (int j = 0; j < potentialTargetsFor.Count; j++)
         {
             Thing thing = potentialTargetsFor[j].Thing;
             if (!pawn.Position.InHorDistOf(thing.Position, 18f) || !SelfDefenseUtility.ShouldFleeFrom(thing, pawn, checkDistance: false, checkLOS: true))
             {
                 continue;
             }
             Pawn pawn2 = thing as Pawn;
             if (pawn2 == null || !pawn2.AnimalOrWildMan() || pawn2.Faction != null)
             {
                 Job job3 = FleeJob(pawn, thing);
                 if (job3 != null)
                 {
                     return(job3);
                 }
             }
         }
     }
     return(null);
 }
コード例 #4
0
            internal bool <> m__0(Region reg)
            {
                List <Thing> list = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);

                for (int i = 0; i < list.Count; i++)
                {
                    if (SelfDefenseUtility.ShouldFleeFrom(list[i], this.pawn, true, true))
                    {
                        this.foundThreat = true;
                        break;
                    }
                }
                return(this.foundThreat);
            }
コード例 #5
0
        private Job TryGetFleeJob(Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                return(null);
            }
            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing);
                    }
                }
                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing2);
                    }
                }
                if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                {
                    Log.Warning(pawn.LabelShort + " decided to flee but there is no any threat around.");
                    return(null);
                }
                c = CellFinderLoose.GetFleeDest(pawn, JobGiver_ConfigurableHostilityResponse.tmpThreats, 23f);
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
            }
            return(new Job(JobDefOf.FleeAndCower, c));
        }
コード例 #6
0
 protected override IEnumerable <Toil> MakeNewToils()
 {
     foreach (Toil toil in base.MakeNewToils())
     {
         yield return(toil);
     }
     yield return(new Toil
     {
         defaultCompleteMode = ToilCompleteMode.Delay,
         defaultDuration = 1200,
         tickAction = delegate
         {
             if (this.$this.pawn.IsHashIntervalTick(35) && SelfDefenseUtility.ShouldStartFleeing(this.$this.pawn))
             {
                 this.$this.EndJobWith(JobCondition.InterruptForced);
             }
         }
     });
 }
コード例 #7
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            foreach (Toil item in base.MakeNewToils())
            {
                yield return(item);
            }
            Toil toil = new Toil();

            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 1200;
            toil.tickAction          = delegate
            {
                if (pawn.IsHashIntervalTick(35) && SelfDefenseUtility.ShouldStartFleeing(pawn))
                {
                    EndJobWith(JobCondition.InterruptForced);
                }
            };
            yield return(toil);
        }
コード例 #8
0
            internal bool <> m__0(Region reg)
            {
                List <Thing> list = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);

                for (int i = 0; i < list.Count; i++)
                {
                    Thing thing = list[i];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, this.pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing);
                        Log.Warning(string.Format("  Found a viable threat {0}; tests are {1}, {2}, {3}", new object[]
                        {
                            thing.LabelShort,
                            thing.Map.attackTargetsCache.Debug_CheckIfInAllTargets(thing as IAttackTarget),
                            thing.Map.attackTargetsCache.Debug_CheckIfHostileToFaction(this.pawn.Faction, thing as IAttackTarget),
                            thing is IAttackTarget
                        }), false);
                    }
                }
                return(false);
            }
コード例 #9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            using (IEnumerator <Toil> enumerator = base.MakeNewToils().GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    Toil toil = enumerator.Current;
                    yield return(toil);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield return(new Toil
            {
                defaultCompleteMode = ToilCompleteMode.Delay,
                defaultDuration = 1200,
                tickAction = delegate
                {
                    if (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_00e1: stateMachine*/)._0024this.pawn.IsHashIntervalTick(35) && SelfDefenseUtility.ShouldStartFleeing(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_00e1: stateMachine*/)._0024this.pawn))
                    {
                        ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_00e1: stateMachine*/)._0024this.EndJobWith(JobCondition.InterruptForced);
                    }
                }
            });

            /*Error: Unable to find new state assignment for yield return*/;
IL_011b:
            /*Error near IL_011c: Unexpected return in MoveNext()*/;
        }
コード例 #10
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    enumerator = base.< MakeNewToils > __BaseCallProxy0().GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 1u:
                    break;

                case 2u:
                    this.$PC = -1;
                    return(false);

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        toil          = enumerator.Current;
                        this.$current = toil;
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                }
                Toil cower = new Toil();

                cower.defaultCompleteMode = ToilCompleteMode.Delay;
                cower.defaultDuration     = 1200;
                cower.tickAction          = delegate()
                {
                    if (this.pawn.IsHashIntervalTick(35) && SelfDefenseUtility.ShouldStartFleeing(this.pawn))
                    {
                        base.EndJobWith(JobCondition.InterruptForced);
                    }
                };
                this.$current = cower;
                if (!this.$disposing)
                {
                    this.$PC = 2;
                }
                return(true);
            }
コード例 #11
0
        private Job TryGetFleeJob(Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                return(null);
            }
            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing);
                    }
                }
                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing2);
                    }
                }
                if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                {
                    Log.Error(pawn.LabelShort + " decided to flee but there is not any threat around.", false);
                    Region region = pawn.GetRegion(RegionType.Set_Passable);
                    if (region == null)
                    {
                        return(null);
                    }
                    RegionTraverser.BreadthFirstTraverse(region, (Region from, Region reg) => reg.door == null || reg.door.Open, delegate(Region reg)
                    {
                        List <Thing> list2 = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                        for (int k = 0; k < list2.Count; k++)
                        {
                            Thing thing3 = list2[k];
                            if (SelfDefenseUtility.ShouldFleeFrom(thing3, pawn, false, false))
                            {
                                JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing3);
                                Log.Warning(string.Format("  Found a viable threat {0}; tests are {1}, {2}, {3}", new object[]
                                {
                                    thing3.LabelShort,
                                    thing3.Map.attackTargetsCache.Debug_CheckIfInAllTargets(thing3 as IAttackTarget),
                                    thing3.Map.attackTargetsCache.Debug_CheckIfHostileToFaction(pawn.Faction, thing3 as IAttackTarget),
                                    thing3 is IAttackTarget
                                }), false);
                            }
                        }
                        return(false);
                    }, 9, RegionType.Set_Passable);
                    if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                    {
                        return(null);
                    }
                }
                c = CellFinderLoose.GetFleeDest(pawn, JobGiver_ConfigurableHostilityResponse.tmpThreats, 23f);
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
            }
            return(new Job(JobDefOf.FleeAndCower, c));
        }
コード例 #12
0
        private Job TryGetFleeJob(Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                return(null);
            }
            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                tmpThreats.Clear();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, checkDistance: false, checkLOS: false))
                    {
                        tmpThreats.Add(thing);
                    }
                }
                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, checkDistance: false, checkLOS: false))
                    {
                        tmpThreats.Add(thing2);
                    }
                }
                if (!tmpThreats.Any())
                {
                    Log.Error(pawn.LabelShort + " decided to flee but there is not any threat around.");
                    Region region = pawn.GetRegion();
                    if (region == null)
                    {
                        return(null);
                    }
                    RegionTraverser.BreadthFirstTraverse(region, (Region from, Region reg) => reg.door == null || reg.door.Open, delegate(Region reg)
                    {
                        List <Thing> list2 = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                        for (int k = 0; k < list2.Count; k++)
                        {
                            Thing thing3 = list2[k];
                            if (SelfDefenseUtility.ShouldFleeFrom(thing3, pawn, checkDistance: false, checkLOS: false))
                            {
                                tmpThreats.Add(thing3);
                                Log.Warning($"  Found a viable threat {thing3.LabelShort}; tests are {thing3.Map.attackTargetsCache.Debug_CheckIfInAllTargets(thing3 as IAttackTarget)}, {thing3.Map.attackTargetsCache.Debug_CheckIfHostileToFaction(pawn.Faction, thing3 as IAttackTarget)}, {thing3 is IAttackTarget}");
                            }
                        }
                        return(false);
                    }, 9);
                    if (!tmpThreats.Any())
                    {
                        return(null);
                    }
                }
                c = CellFinderLoose.GetFleeDest(pawn, tmpThreats);
                tmpThreats.Clear();
            }
            return(JobMaker.MakeJob(JobDefOf.FleeAndCower, c));
        }