protected override Job TryGiveJob(Pawn pawn) { IntVec3 intVec = (IntVec3)pawn.mindState.duty.focus; if (intVec.IsValid && (float)intVec.DistanceToSquared(pawn.Position) < 100.0 && intVec.GetRoom(pawn.Map, RegionType.Set_Passable) == pawn.GetRoom(RegionType.Set_Passable) && intVec.WithinRegions(pawn.Position, pawn.Map, 9, TraverseMode.NoPassClosedDoors, RegionType.Set_Passable)) { pawn.GetLord().Notify_ReachedDutyLocation(pawn); return(null); } if (!intVec.IsValid) { IAttackTarget attackTarget = default(IAttackTarget); if (!(from x in pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn) where !x.ThreatDisabled() && x.Thing.Faction == Faction.OfPlayer && pawn.CanReach(x.Thing, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.PassAllDestroyableThings) select x).TryRandomElement <IAttackTarget>(out attackTarget)) { return(null); } intVec = attackTarget.Thing.Position; } if (!pawn.CanReach(intVec, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.PassAllDestroyableThings)) { return(null); } using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, intVec, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell)) { IntVec3 cellBeforeBlocker = default(IntVec3); Thing thing = path.FirstBlockingBuilding(out cellBeforeBlocker, pawn); if (thing != null) { Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, this.canMineMineables, this.canMineNonMineables); if (job != null) { return(job); } } } return(new Job(JobDefOf.Goto, intVec, 500, true)); }
protected override Job TryGiveJob(Pawn pawn) { IntVec3 intVec = pawn.mindState.duty.focus.Cell; if (intVec.IsValid && (float)intVec.DistanceToSquared(pawn.Position) < 100f && intVec.GetRoom(pawn.Map) == pawn.GetRoom() && intVec.WithinRegions(pawn.Position, pawn.Map, 9, TraverseMode.NoPassClosedDoors)) { pawn.GetLord().Notify_ReachedDutyLocation(pawn); return(null); } if (!intVec.IsValid) { if (!(from x in pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn) where !x.ThreatDisabled(pawn) && x.Thing.Faction == Faction.OfPlayer && pawn.CanReach(x.Thing, PathEndMode.OnCell, Danger.Deadly, canBash: false, TraverseMode.PassAllDestroyableThings) select x).TryRandomElement(out var result)) { return(null); } intVec = result.Thing.Position; } if (!pawn.CanReach(intVec, PathEndMode.OnCell, Danger.Deadly, canBash: false, TraverseMode.PassAllDestroyableThings)) { return(null); } using (PawnPath path = pawn.Map.pathFinder.FindPath(pawn.Position, intVec, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings))) { IntVec3 cellBefore; Thing thing = path.FirstBlockingBuilding(out cellBefore, pawn); if (thing != null) { Job job = DigUtility.PassBlockerJob(pawn, thing, cellBefore, canMineMineables, canMineNonMineables); if (job != null) { return(job); } } } return(JobMaker.MakeJob(JobDefOf.Goto, intVec, 500, checkOverrideOnExpiry: true)); }
public static Job PassBlockerJob(Pawn pawn, Thing blocker, IntVec3 cellBeforeBlocker, bool canMineMineables, bool canMineNonMineables) { if (StatDefOf.MiningSpeed.Worker.IsDisabledFor(pawn)) { canMineMineables = false; canMineNonMineables = false; } if (blocker.def.mineable) { if (canMineMineables) { return(DigUtility.MineOrWaitJob(pawn, blocker, cellBeforeBlocker)); } return(DigUtility.MeleeOrWaitJob(pawn, blocker, cellBeforeBlocker)); } else { if (pawn.equipment != null && pawn.equipment.Primary != null) { Verb primaryVerb = pawn.equipment.PrimaryEq.PrimaryVerb; if (primaryVerb.verbProps.ai_IsBuildingDestroyer && (!primaryVerb.IsIncendiary() || blocker.FlammableNow)) { return(new Job(JobDefOf.UseVerbOnThing) { targetA = blocker, verbToUse = primaryVerb, expiryInterval = JobGiver_AIFightEnemy.ExpiryInterval_ShooterSucceeded.RandomInRange }); } } if (canMineNonMineables) { return(DigUtility.MineOrWaitJob(pawn, blocker, cellBeforeBlocker)); } return(DigUtility.MeleeOrWaitJob(pawn, blocker, cellBeforeBlocker)); } }
// Token: 0x06000424 RID: 1060 RVA: 0x0002CE84 File Offset: 0x0002B284 protected override Job TryGiveJob(Pawn pawn) { if (pawn.Map == null || pawn.Map != Find.CurrentMap) { return(null); } IntVec3 c = IntVec3.Invalid; CompXenoEggLayer compEggLayer = pawn.TryGetComp <CompXenoEggLayer>(); if (compEggLayer == null || !compEggLayer.CanLayNow) { return(null); } if (!pawn.isXenomorph(out Comp_Xenomorph xenomorph)) { return(null); } else { c = xenomorph.HiveLoc; bool selected = pawn.Map != null?Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false; if (pawn.CanReach(c, PathEndMode.ClosestTouch, Danger.Deadly, true, TraverseMode.PassAllDestroyableThingsNotWater)) { using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell)) { IntVec3 cellBeforeBlocker; Thing thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn); if (thing != null) { Job job = DigUtility.PassBlockerJob(pawn, thing, cellBeforeBlocker, true, true); if (job != null) { return(job); } } } Log.Message("queen can reach eggsite"); Predicate <IntVec3> validator = delegate(IntVec3 y) { bool adjacent = c.AdjacentTo8WayOrInside(y); bool filled = y.Filled(pawn.Map); bool edifice = y.GetEdifice(pawn.Map).DestroyedOrNull(); bool building = y.GetFirstBuilding(pawn.Map).DestroyedOrNull(); bool thingA = y.GetFirstThing(pawn.Map, namedA).DestroyedOrNull(); bool thingB = y.GetFirstThing(pawn.Map, namedB).DestroyedOrNull(); return(!adjacent && !filled && edifice && building && thingA && thingB); }; bool b = RCellFinder.TryFindRandomCellNearWith(c, validator, pawn.Map, out IntVec3 lc, 6, 12); List <Thing> egglist = pawn.Map.listerThings.ThingsOfDef(XenomorphDefOf.RRY_EggXenomorphFertilized).FindAll(x => lc.InHorDistOf(x.Position, 9)); bool eggflag = egglist.CountAllowNull() < 40; if (pawn.GetLord() == null) { // Log.Message(string.Format("XenoLord TryFindGoodHiveLoc for {0} Cell Found: {1}, Allow: Fogged, Digging", pawn.LabelShortCap, c)); LordJob newJob = new LordJob_DefendAndExpandHiveLike(false, pawn.Faction, c, 40f); pawn.CreateNewLord(c, newJob); } return(new Job(XenomorphDefOf.RRY_Job_Xenomorph_LayEgg, lc)); } else { Log.Warning("queen couldnt reach eggsite"); } if (XenomorphKidnapUtility.TryFindGoodHiveLoc(pawn, out c)) { if (c != IntVec3.Invalid && pawn.CanReach(c, PathEndMode.ClosestTouch, Danger.Deadly, true, TraverseMode.PassAllDestroyableThings)) { Predicate <IntVec3> validator = delegate(IntVec3 y) { bool adjacent = c.AdjacentTo8WayOrInside(y); bool filled = y.Filled(pawn.Map); bool edifice = y.GetEdifice(pawn.Map).DestroyedOrNull(); bool building = y.GetFirstBuilding(pawn.Map).DestroyedOrNull(); bool thingA = y.GetFirstThing(pawn.Map, namedA).DestroyedOrNull(); bool thingB = y.GetFirstThing(pawn.Map, namedB).DestroyedOrNull(); return(!adjacent && !filled && edifice && building && thingA && thingB); }; bool b = RCellFinder.TryFindRandomCellNearWith(c, validator, pawn.Map, out IntVec3 lc, 6, 12); List <Thing> egglist = pawn.Map.listerThings.ThingsOfDef(XenomorphDefOf.RRY_EggXenomorphFertilized).FindAll(x => lc.InHorDistOf(x.Position, 9)); bool eggflag = egglist.CountAllowNull() < 40; return(new Job(XenomorphDefOf.RRY_Job_Xenomorph_LayEgg, lc)); } else { if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(string.Format("{0} something went wrong", this)); } } } else { if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(string.Format("{0} No Egglaying spot Found", this)); } c = pawn.Position; Predicate <IntVec3> validator = delegate(IntVec3 y) { bool adjacent = c.AdjacentTo8WayOrInside(y); bool filled = y.Filled(pawn.Map); bool edifice = y.GetEdifice(pawn.Map).DestroyedOrNull(); bool building = y.GetFirstBuilding(pawn.Map).DestroyedOrNull(); bool thingA = y.GetFirstThing(pawn.Map, namedA).DestroyedOrNull(); bool thingB = y.GetFirstThing(pawn.Map, namedB).DestroyedOrNull(); return(!adjacent && !filled && edifice && building && thingA && thingB); }; bool b = RCellFinder.TryFindRandomCellNearWith(c, validator, pawn.Map, out IntVec3 lc, 6, 12); List <Thing> egglist = pawn.Map.listerThings.ThingsOfDef(XenomorphDefOf.RRY_EggXenomorphFertilized).FindAll(x => lc.InHorDistOf(x.Position, 9)); bool eggflag = egglist.CountAllowNull() < 40; return(new Job(XenomorphDefOf.RRY_Job_Xenomorph_LayEgg, lc)); } } return(null); }