Ejemplo n.º 1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil followAndAttack = new Toil();

            followAndAttack.tickAction = delegate()
            {
                Pawn  actor  = followAndAttack.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(TargetIndex.A).Thing;
                Pawn  pawn   = thing as Pawn;
                bool  flag   = this.pawn.Faction != Faction.OfPlayer;
                bool  flag2  = flag;
                if (flag2)
                {
                    actor.mindState.mentalStateHandler.TryStartMentalState(DefDatabase <MentalStateDef> .GetNamed("MurderousRage", true), null, false, false, null);
                }
                bool flag3 = thing != actor.pather.Destination.Thing || (!this.pawn.pather.Moving && !GenAdj.AdjacentTo8WayOrInside(this.pawn.Position, thing));
                bool flag4 = flag3;
                if (flag4)
                {
                    actor.pather.StartPath(thing, PathEndMode.Touch);
                }
                else
                {
                    bool flag5 = GenAdj.AdjacentTo8WayOrInside(this.pawn.Position, thing);
                    bool flag6 = flag5;
                    if (flag6)
                    {
                        bool flag7 = thing is Pawn && pawn.Downed && !curJob.killIncappedTarget;
                        bool flag8 = flag7;
                        if (flag8)
                        {
                            this.EndJobWith(JobCondition.Succeeded);
                        }
                        bool flag9  = actor.meleeVerbs.TryMeleeAttack(thing, null, false);
                        bool flag10 = flag9;
                        if (flag10)
                        {
                            this.numMeleeAttacksLanded += 1;
                            bool flag11 = this.numMeleeAttacksLanded >= curJob.maxNumMeleeAttacks;
                            bool flag12 = flag11;
                            if (flag12)
                            {
                                this.EndJobWith(JobCondition.Succeeded);
                            }
                        }
                    }
                }
            };
            followAndAttack.defaultCompleteMode = ToilCompleteMode.Never;
            ToilFailConditions.EndOnDespawnedOrNull <Toil>(followAndAttack, TargetIndex.A, JobCondition.Succeeded);
            ToilFailConditions.FailOn <Toil>(followAndAttack, new Func <bool>(this.hunterIsKilled));
            yield return(followAndAttack);

            yield break;
        }
        public static bool CanPotentiallyLinkTo_Static(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot, ThingDef myDef, IntVec3 myPos, Rot4 myRot)
        {
            CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>();

            if (compProperties.mustBePlacedAdjacent)
            {
                CellRect rect  = GenAdj.OccupiedRect(myPos, myRot, myDef.size);
                CellRect rect2 = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size);
                if (!GenAdj.AdjacentTo8WayOrInside(rect, rect2))
                {
                    return(false);
                }
            }
            if (compProperties.mustBePlacedAdjacentCardinalToBedHead)
            {
                if (!myDef.IsBed)
                {
                    return(false);
                }
                CellRect other = GenAdj.OccupiedRect(facilityPos, facilityRot, facilityDef.size);
                bool     flag  = false;
                int      sleepingSlotsCount = BedUtility.GetSleepingSlotsCount(myDef.size);
                for (int i = 0; i < sleepingSlotsCount; i++)
                {
                    IntVec3 sleepingSlotPos = BedUtility.GetSleepingSlotPos(i, myPos, myRot, myDef.size);
                    if (sleepingSlotPos.IsAdjacentToCardinalOrInside(other))
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    return(false);
                }
            }
            if (!compProperties.mustBePlacedAdjacent && !compProperties.mustBePlacedAdjacentCardinalToBedHead)
            {
                Vector3 a = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude);
                Vector3 b = Gen.TrueCenter(facilityPos, facilityRot, facilityDef.size, facilityDef.Altitude);
                if (Vector3.Distance(a, b) > compProperties.maxDistance)
                {
                    return(false);
                }
            }
            return(true);
        }