public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null) { foreach (IntVec3 c in GenAdj.CellsOccupiedBy(loc, rot, checkingDef.Size)) { if (!map.terrainGrid.TerrainAt(c).IsWater) { return(new AcceptanceReport("VPE_NeedsWater".Translate())); } } foreach (Thing generator in GenRadial.RadialDistinctThingsAround(loc, map, 40, true)) { Building generatorBuilding = generator as Building; if (generatorBuilding != null && generatorBuilding.def.defName == "VFE_TidalGenerator") { return(new AcceptanceReport("VPE_NeedsDistance".Translate())); } Thing generatorBuildingBlueprint = generator as Thing; if (generatorBuildingBlueprint != null && (generatorBuildingBlueprint.def.IsBlueprint || generatorBuildingBlueprint.def.IsFrame) && generatorBuildingBlueprint.def.entityDefToBuild.defName == "VFE_TidalGenerator") { return(new AcceptanceReport("VPE_NeedsDistance".Translate())); } } return(true); }
private FloatMenuOption EnterOption(Pawn pawn, bool first) { FloatMenuOption option = new FloatMenuOption("CheckInsideLuke".Translate(), null); if (!GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, CollectThingsRadius, false).Where(x => x.Faction == Faction.OfPlayer).Any()) { return(option); } option.action = delegate { DiaOption diaOption = new DiaOption("CheckInsideLuke_OK".Translate()); diaOption.resolveTree = true; diaOption.action = () => DoEnter(first); DiaOption diaOption2 = new DiaOption("CheckInsideLuke_NO".Translate()); diaOption2.resolveTree = true; DiaNode diaNode = new DiaNode("CheckInsideLuke_Info".Translate(CollectThingsRadius)); diaNode.options.Add(diaOption); diaNode.options.Add(diaOption2); Dialog_NodeTree dialog_NodeTree = new Dialog_NodeTree(diaNode, delayInteractivity: true); Find.WindowStack.Add(dialog_NodeTree); }; return(option); }
public override Job TryGiveJob(Pawn pawn) { if (!JoyUtility.EnjoyableOutsideNow(pawn.Map)) { return(null); } pawns.Clear(); foreach (Thing thing in GenRadial.RadialDistinctThingsAround(pawn.Position, pawn.Map, this.def.searchDistance, true)) { Pawn targetPawn = thing as Pawn; if (targetPawn != null && targetPawn.RaceProps.Animal) { pawns.Add(targetPawn); } } if (pawns.Any()) { Pawn target = pawns.RandomElement(); return(new Job(IdleJobDefOf.IdleJob_ObservingAnimal, target) { locomotionUrgency = LocomotionUrgency.Walk }); } return(null); }
public List <Thing> GetForCell(IntVec3 cell, float radius, List <MeditationFocusOffsetPerBuilding> defs, Thing forThing = null) { CellRequest key = new CellRequest(cell, radius, defs, forThing); if (!requestCache.TryGetValue(key, out var value)) { value = new List <Thing>(); foreach (Thing t2 in GenRadial.RadialDistinctThingsAround(cell, map, radius, useCenter: false)) { if (defs.Any((MeditationFocusOffsetPerBuilding d) => d.building == t2.def) && t2.GetRoom() == cell.GetRoom(map) && t2 != forThing) { value.Add(t2); } } value.SortBy(delegate(Thing t) { float num = t.Position.DistanceTo(cell); MeditationFocusOffsetPerBuilding meditationFocusOffsetPerBuilding = defs.FirstOrDefault((MeditationFocusOffsetPerBuilding d) => d.building == t.def); if (meditationFocusOffsetPerBuilding != null) { num -= meditationFocusOffsetPerBuilding.offset * 100000f; } return(num); }); requestCache[key] = value; } return(value); }
public override void CompTick() { base.CompTick(); if (Find.TickManager.TicksGame == nextTest) { foreach (var thing in GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, Props.radius, true)) { if (thing is Pawn pawn) { float adjustedSeverity = Props.severityIncrease; if (!Props.stats.NullOrEmpty()) { foreach (StatDef stat in Props.stats) { adjustedSeverity *= pawn.GetStatValue(stat); } } if (pawn.health.hediffSet.HasHediff(Props.hediffDef) && adjustedSeverity > 0f) { pawn.health.hediffSet.GetFirstHediffOfDef(Props.hediffDef).Severity += adjustedSeverity; } else if (adjustedSeverity > 0f) { Hediff hediff = HediffMaker.MakeHediff(Props.hediffDef, pawn); hediff.Severity = adjustedSeverity; pawn.health.AddHediff(hediff); } } } nextTest += Props.tickRate; } }
private void FindAvailableNearbyResources(Thing firstFoundResource, Pawn pawn, out int resTotalAvailable) { int num = Mathf.Min(firstFoundResource.def.stackLimit, pawn.carryTracker.MaxStackSpaceEver(firstFoundResource.def)); resTotalAvailable = 0; resourcesAvailable.Clear(); resourcesAvailable.Add(firstFoundResource); resTotalAvailable += firstFoundResource.stackCount; if (resTotalAvailable >= num) { return; } foreach (Thing item in GenRadial.RadialDistinctThingsAround(firstFoundResource.Position, firstFoundResource.Map, 5f, useCenter: false)) { if (resTotalAvailable >= num) { break; } if (item.def == firstFoundResource.def && GenAI.CanUseItemForWork(pawn, item)) { resourcesAvailable.Add(item); resTotalAvailable += item.stackCount; } } }
public static bool CanSpawnAt(IntVec3 c, Map map, int minProximityToArtificialStructures = 40, int minProximityToCenter = 0, int minFertileUnroofedCells = 22, int maxFertileUnroofedCellRadius = 10) { if (!c.Standable(map) || c.Fogged(map) || !c.GetRoom(map).PsychologicallyOutdoors) { return(false); } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.growDays > 10f) { return(false); } List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { if (thingList[i].def == ThingDefOf.Plant_TreeAnima) { return(false); } } if (minProximityToCenter > 0 && map.Center.InHorDistOf(c, minProximityToCenter)) { return(false); } if (!map.reachability.CanReachFactionBase(c, map.ParentFaction)) { return(false); } TerrainDef terrain = c.GetTerrain(map); if (terrain.avoidWander || terrain.fertility <= 0f) { return(false); } if (c.Roofed(map)) { return(false); } if (minProximityToArtificialStructures != 0 && GenRadial.RadialDistinctThingsAround(c, map, minProximityToArtificialStructures, useCenter: false).Any(MeditationUtility.CountsAsArtificialBuilding)) { return(false); } int num = GenRadial.NumCellsInRadius(maxFertileUnroofedCellRadius); int num2 = 0; for (int j = 0; j < num; j++) { IntVec3 c2 = c + GenRadial.RadialPattern[j]; if (!c2.Roofed(map) && c2.GetTerrain(map).fertility > 0f) { num2++; } if (num2 >= minFertileUnroofedCells) { return(true); } } return(false); }
/// <summary>called every once and a while</summary> public override void TickRare() { if (!Spawned || !LoadedModManager.GetMod <PawnmorpherMod>().GetSettings <PawnmorpherSettings>().enableMutagenMeteor) { return; } IEnumerable <Thing> enumerable = GenRadial.RadialDistinctThingsAround(Position, Map, 2.5f, true); var mutagen = MutagenDefOf.defaultMutagen; foreach (Thing thing in enumerable) { if (thing is Pawn pawn) { MutatePawn(pawn, mutagen); } else if (thing is Plant plant) { if (Rand.Value >= _p) { continue; } PMPlantUtilities.TryMutatePlant(plant); } } }
public void LinkToNearbyBuildings() { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, range, true)) { CompResonancePowerPlant comp = thing.TryGetComp <CompResonancePowerPlant>(); if (comp != null) { if (comp.AddLink(parent)) { linkedBuildings.Add(comp.parent); currentPowerEfficiency += additionalEfficiency; } } } foreach (Thing thing in GenRadial.RadialDistinctThingsAround(parent.Position + parent.Rotation.FacingCell, parent.Map, range, true)) { CompResonancePowerPlant comp = thing.TryGetComp <CompResonancePowerPlant>(); if (comp != null) { if (comp.AddLink(parent)) { linkedBuildings.Add(comp.parent); currentPowerEfficiency += additionalEfficiency; } } } }
public override void CompTick() { base.CompTick(); if (AnimalBehaviours_Settings.flagEffecters) { tickCounter++; //Only do anything every tickInterval if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; //Null map check. Also will only work if pawn is not dead or downed if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; //Only work on colonists, unless notOnlyAffectColonists if (pawn != null && (pawn.IsColonist || Props.notOnlyAffectColonists)) { //Only work on not dead, not downed, not psychically immune colonists if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { FleckMaker.AttachedOverlay(this.parent, DefDatabase <FleckDef> .GetNamed("PsycastPsychicEffect"), Vector3.zero, 1f, -1f); pawn.health.AddHediff(HediffDef.Named(Props.hediff)); } } } } tickCounter = 0; } } }
public override void CompTick() { base.CompTick(); tickCounter++; if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; if (pawn != null && !pawn.AnimalOrWildMan() && pawn.RaceProps.IsFlesh) { if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { if (Props.showEffect) { Find.TickManager.slower.SignalForceNormalSpeedShort(); SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(this.parent.Position, this.parent.Map, false)); MoteMaker.MakeAttachedOverlay(this.parent, ThingDef.Named("Mote_PsycastPsychicEffect"), Vector3.zero, 1f, -1f); } if (pawn.needs != null && pawn.needs.mood != null) { pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named(Props.thoughtDef), null); } } } } } tickCounter = 0; } }
public override void CompTick() { base.CompTick(); tickCounter++; if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; if (pawn != null && pawn.IsColonist) { if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { Find.TickManager.slower.SignalForceNormalSpeedShort(); SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(this.parent.Position, this.parent.Map, false)); MoteMaker.MakeAttachedOverlay(this.parent, ThingDef.Named("Mote_PsycastPsychicEffect"), Vector3.zero, 1f, -1f); pawn.mindState.mentalStateHandler.TryStartMentalState(DefDatabase <MentalStateDef> .GetNamed(Props.mentalState, true), null, true, false, null, false); } } } } tickCounter = 0; } }
public override void CompPostTick(ref float severityAdjustment) { base.CompPostTick(ref severityAdjustment); if (Find.TickManager.TicksGame >= nextSpreadingTick) { if (this.Pawn.Map != null) { foreach (var thing in GenRadial.RadialDistinctThingsAround(this.Pawn.Position, this.Pawn.Map, Props.radiusToSpread, true)) { if (thing is Pawn pawn && pawn != this.Pawn && (!Props.requiresLineOfSightToSpread || GenSight.LineOfSight(Pawn.Position, pawn.Position, pawn.Map))) { TrySpreadDiseaseOn(pawn); } } } else if (this.Pawn.GetCaravan() is Caravan caravan) { foreach (var pawn in caravan.PawnsListForReading) { TrySpreadDiseaseOn(pawn); } } nextSpreadingTick = Find.TickManager.TicksGame + Props.spreadingTickInterval.RandomInRange; } if (Props.fleckDefOnPawn != null && Find.TickManager.TicksGame >= nextFleckSpawnTick && this.Pawn.Map != null) { var pawn = Pawn; ThrowFleck(pawn.Drawer.DrawPos + pawn.Drawer.renderer.BaseHeadOffsetAt(pawn.Rotation) + pawn.Rotation.FacingCell.ToVector3() * 0.21f + BreathOffset , pawn.Map, pawn.Rotation.AsAngle, pawn.Drawer.tweener.LastTickTweenedVelocity); nextFleckSpawnTick = Find.TickManager.TicksGame + Props.fleckSpawnInterval.RandomInRange; } }
// Token: 0x0600003E RID: 62 RVA: 0x00003354 File Offset: 0x00001554 public static Thing MentalDetect(ThingWithComps securityThing, float radius) { var DetectThings = GenRadial .RadialDistinctThingsAround(securityThing.Position, securityThing.Map, radius, true).ToList(); if (DetectThings.Count <= 0) { return(null); } foreach (var mentalDetect in DetectThings) { if (mentalDetect is not Pawn || (mentalDetect as Pawn).IsBurning() || (mentalDetect as Pawn).Dead || (mentalDetect as Pawn).Downed || !(mentalDetect as Pawn).Awake()) { continue; } if ((mentalDetect as Pawn).IsPrisoner && PrisonBreakUtility.IsPrisonBreaking(mentalDetect as Pawn)) { return(mentalDetect); } if ((mentalDetect as Pawn).IsColonist && (mentalDetect as Pawn).InMentalState) { return(mentalDetect); } } return(null); }
public override void CompTick() { base.CompTick(); if (AnimalBehaviours_Settings.flagEffecters) { tickCounter++; //Only do anything every tickInterval if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; //Null map check. Also will only work if pawn is not dead or downed if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; //Only work on colonists, unless notOnlyAffectColonists if (pawn != null && (pawn.IsColonist || Props.notOnlyAffectColonists)) { //Only work on not dead, not downed, not psychically immune colonists if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { Find.TickManager.slower.SignalForceNormalSpeedShort(); SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(this.parent.Position, this.parent.Map, false)); FleckMaker.AttachedOverlay(this.parent, DefDatabase <FleckDef> .GetNamed("PsycastPsychicEffect"), Vector3.zero, 1f, -1f); pawn.mindState.mentalStateHandler.TryStartMentalState(DefDatabase <MentalStateDef> .GetNamed(Props.mentalState, true), null, true, false, null, false); } } } } tickCounter = 0; } } }
public override void CompTick() { base.CompTick(); tickCounter++; if (this.parent is Pawn pawn && pawn != null & pawn.health != null) { float mechaniteGeneration = pawn.health.capacities.GetLevel(PawnCapacityDefOf.TM_MechaniteGeneration); bool isAwake = !pawn.Dead && !pawn.Downed && pawn.Map != null && !pawn.stances.stunner.Stunned && pawn.TryGetComp <CompCanBeDormant>().Awake; if (mechaniteGeneration > 0 && isAwake && tickCounter >= (this.Props.mechaniteSpawnRate / mechaniteGeneration)) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(pawn.Position, pawn.Map, Props.mechaniteRange, true)) { if (thing != null && thing is Pawn targetPawn && targetPawn.health != null) { if (targetPawn.RaceProps.IsMechanoid && targetPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.MechanoidMechanitesHediff)) == null) { targetPawn.health.AddHediff(HediffDef.Named(this.Props.MechanoidMechanitesHediff), null, null); break; } if (targetPawn.RaceProps.Humanlike && targetPawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.NonMechanoidMechanitesHediff)) == null && Rand.Value <= this.Props.nonMechanoidChance) { targetPawn.health.AddHediff(HediffDef.Named(this.Props.NonMechanoidMechanitesHediff), null, null); string message = "TM_NonMechanoidContractedMechanites".Translate(targetPawn.Label, pawn.Label); Messages.Message(message, MessageTypeDefOf.NegativeEvent); break; } } } tickCounter = 0; } } }
private void FindAvailableNearbyResources(Thing firstFoundResource, Pawn pawn, out int resTotalAvailable) { int num = Mathf.Min(firstFoundResource.def.stackLimit, pawn.carryTracker.MaxStackSpaceEver(firstFoundResource.def)); resTotalAvailable = 0; WorkGiver_ConstructDeliverResources.resourcesAvailable.Clear(); WorkGiver_ConstructDeliverResources.resourcesAvailable.Add(firstFoundResource); resTotalAvailable += firstFoundResource.stackCount; if (resTotalAvailable < num) { foreach (Thing current in GenRadial.RadialDistinctThingsAround(firstFoundResource.Position, firstFoundResource.Map, 5f, false)) { if (resTotalAvailable >= num) { break; } if (current.def == firstFoundResource.def) { if (GenAI.CanUseItemForWork(pawn, current)) { WorkGiver_ConstructDeliverResources.resourcesAvailable.Add(current); resTotalAvailable += current.stackCount; } } } } }
static bool GenerateRandomMinTicksToNextLovinPrefix(JobDriver_Lovin __instance, Pawn pawn) { TargetIndex PartnerInd = (TargetIndex)PartnerIndinfo.GetValue(__instance); Pawn partner = (Pawn)(Thing)__instance.job.GetTarget(PartnerInd); if (partner == null) { Log.Message("partner null error"); } else { Log.Message("partner = " + partner.Name); } foreach (Thing Wpawn in GenRadial.RadialDistinctThingsAround(pawn.Position, pawn.Map, 6f, useCenter: true)) { Pawn wpawn = Wpawn as Pawn; if (wpawn != null) { if (wpawn != pawn && wpawn != partner && wpawn.gender != Gender.None) // { if (wpawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight)) { wpawn.needs?.mood?.thoughts?.memories?.TryGainMemory(thoughtdefof.FP_WatchSomeLov); } } } } return(true); }
public override void CompTick() { base.CompTick(); tickCounter++; if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; if (pawn != null && pawn.IsColonist) { if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { MoteMaker.MakeAttachedOverlay(this.parent, ThingDef.Named("Mote_PsycastPsychicEffect"), Vector3.zero, 1f, -1f); pawn.health.AddHediff(HediffDef.Named(Props.hediff)); } } } } tickCounter = 0; } }
// Token: 0x06000022 RID: 34 RVA: 0x00003324 File Offset: 0x00001524 public override void Tick() { base.Tick(); if (!Spawned || !this.IsHashIntervalTick(inspirationTicks)) { return; } var things = GenRadial.RadialDistinctThingsAround(this.TrueCenter().ToIntVec3(), Map, 10f, false) .ToList(); if (things.Count <= 0) { return; } foreach (var thing in things) { Pawn p; if ((p = thing as Pawn) == null || !IsValidForInspiration(thing, this) || !IsInspired(25) || p.mindState.inspirationHandler.Inspired) { continue; } var IDef = (from x in DefDatabase <InspirationDef> .AllDefsListForReading where x.Worker.InspirationCanOccur(p) select x).RandomElementByWeightWithFallback(x => x.Worker.CommonalityFor(p)); p.mindState.inspirationHandler.TryStartInspiration(IDef); } }
public static void DrawLinesToPotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { nearDrowingList.Clear(); Vector3 pointingPos = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); foreach (Thing thing in GenRadial.RadialDistinctThingsAround(myPos, map, range, true)) { CompResonancePowerPlant comp = thing.TryGetComp <CompResonancePowerPlant>(); if (comp != null) { nearDrowingList.Add(comp); } } foreach (Thing thing in GenRadial.RadialDistinctThingsAround(myPos + myRot.FacingCell, map, range, true)) { CompResonancePowerPlant comp = thing.TryGetComp <CompResonancePowerPlant>(); if (comp != null) { nearDrowingList.Add(comp); } } foreach (CompResonancePowerPlant comp in nearDrowingList) { if (comp.CanBeActive) { GenDraw.DrawLineBetween(pointingPos, comp.parent.TrueCenter()); } else { GenDraw.DrawLineBetween(pointingPos, comp.parent.TrueCenter(), CompAffectedByFacilities.InactiveFacilityLineMat); } } }
// Token: 0x06000077 RID: 119 RVA: 0x00004B80 File Offset: 0x00002D80 private void FindAvailableNearbyResources(Thing firstFoundResource, Pawn pawn, out int resTotalAvailable) { int num = Mathf.Min(firstFoundResource.def.stackLimit, pawn.carryTracker.MaxStackSpaceEver(firstFoundResource.def)); resTotalAvailable = 0; WorkGiver_WPConstructDeliverResources.resourcesAvailable.Clear(); WorkGiver_WPConstructDeliverResources.resourcesAvailable.Add(firstFoundResource); resTotalAvailable += firstFoundResource.stackCount; bool flag = resTotalAvailable < num; if (flag) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(firstFoundResource.Position, firstFoundResource.Map, 5f, false)) { bool flag2 = resTotalAvailable >= num; if (flag2) { break; } bool flag3 = thing.def == firstFoundResource.def && GenAI.CanUseItemForWork(pawn, thing); if (flag3) { WorkGiver_WPConstructDeliverResources.resourcesAvailable.Add(thing); resTotalAvailable += thing.stackCount; } } } }
// Token: 0x06000078 RID: 120 RVA: 0x00004C7C File Offset: 0x00002E7C private HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable) { neededTotal = need.count; HashSet <Thing> hashSet = new HashSet <Thing>(); Thing thing = (Thing)c; foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, true)) { bool flag = neededTotal >= resTotalAvailable; if (flag) { break; } bool flag2 = this.IsNewValidNearbyNeeder(thing2, hashSet, c, pawn); if (flag2) { Blueprint blueprint = thing2 as Blueprint; bool flag3 = blueprint == null || !WorkGiver_WPConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint); if (flag3) { int num = GenConstruct.AmountNeededByOf((IConstructible)thing2, need.thingDef); bool flag4 = num > 0; if (flag4) { hashSet.Add(thing2); neededTotal += num; } } } } Blueprint blueprint2 = c as Blueprint; bool flag5 = blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef && canRemoveExistingFloorUnderNearbyNeeders && neededTotal < resTotalAvailable; if (flag5) { foreach (Thing thing3 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, false)) { bool flag6 = this.IsNewValidNearbyNeeder(thing3, hashSet, c, pawn); if (flag6) { Blueprint blueprint3 = thing3 as Blueprint; bool flag7 = blueprint3 != null; if (flag7) { Job job = this.RemoveExistingFloorJob(pawn, blueprint3); bool flag8 = job != null; if (flag8) { jobToMakeNeederAvailable = job; return(hashSet); } } } } } jobToMakeNeederAvailable = null; return(hashSet); }
public override void CompTick() { base.CompTick(); if (AnimalBehaviours_Settings.flagEffecters) { tickCounter++; //Only do anything every tickInterval if (tickCounter > Props.tickInterval) { thisPawn = this.parent as Pawn; //Null map check. Also will only work if pawn is not dead or downed, and if needsToBeTamed is true, that the animal is tamed if (thisPawn != null && thisPawn.Map != null && !thisPawn.Dead && !thisPawn.Downed && (!Props.needsToBeTamed || (Props.needsToBeTamed && thisPawn.Faction != null && thisPawn.Faction.IsPlayer))) { foreach (Thing thing in GenRadial.RadialDistinctThingsAround(thisPawn.Position, thisPawn.Map, Props.radius, true)) { Pawn pawn = thing as Pawn; //It won't affect animals, cause they don't have Thoughts, or mechanoids, or itself if (pawn != null && !pawn.AnimalOrWildMan() && pawn.RaceProps.IsFlesh && pawn != this.parent) { //Only work on not dead, not downed, not psychically immune pawns if (!pawn.Dead && !pawn.Downed && pawn.GetStatValue(StatDefOf.PsychicSensitivity, true) > 0f) { //Only show an effect if the user wants it to, or it gets obnoxious if (Props.showEffect) { Find.TickManager.slower.SignalForceNormalSpeedShort(); SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(this.parent.Position, this.parent.Map, false)); FleckMaker.AttachedOverlay(this.parent, DefDatabase <FleckDef> .GetNamed("PsycastPsychicEffect"), Vector3.zero, 1f, -1f); } if (!Props.conditionalOnWellBeing) { //Apply thought pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named(Props.thoughtDef), null); } else { bool wellbeingAffectedFlag = thisPawn.needs.food.Starving || (thisPawn.health.hediffSet.PainTotal > 0); if (wellbeingAffectedFlag) { pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(ThoughtDef.Named(Props.thoughtDef)); pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named(Props.thoughtDefWhenSuffering), null); } else { pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named(Props.thoughtDef), null); } } //Find.HistoryEventsManager.RecordEvent(new HistoryEvent(DefDatabase<HistoryEventDef>.GetNamed("AA_DisgustEvent"), pawn.Named(HistoryEventArgsNames.Doer)), true); } } } } tickCounter = 0; } } }
public static void DrawMeditationSpotOverlay(IntVec3 center, Map map) { GenDraw.DrawRadiusRing(center, FocusObjectSearchRadius); foreach (Thing item in GenRadial.RadialDistinctThingsAround(center, map, FocusObjectSearchRadius, useCenter: false)) { if (!(item is Building_Throne) && item.def != ThingDefOf.Wall && item.TryGetComp <CompMeditationFocus>() != null && GenSight.LineOfSight(center, item.Position, map)) { GenDraw.DrawLineBetween(center.ToVector3() + new Vector3(0.5f, 0f, 0.5f), item.TrueCenter(), SimpleColor.White); } } }
private Thing NextTarget(Thing currentTarget) { var things = GenRadial.RadialDistinctThingsAround(currentTarget.PositionHeld, Map, Props.bounceRange, false) .Where(t => (Props.targetFriendly || t.HostileTo(this.launcher)) && IsValidTarget(t)).Except(new[] { this, usedTarget.Thing }); things = things.Except(prevTargets); things = things.OrderBy(t => t.Position.DistanceTo(Holder.Position)); var target = things.FirstOrDefault(); return(target); }
private void DoEnter(bool first) { if (first) { generator = MapGenDefGetter; IntVec3 mapSize = new IntVec3(generator.size.x, 1, generator.size.z); mapHolder = (RandomPlaceWorldObject)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.RandomPlace); mapHolder.Tile = parent.Tile; Find.WorldObjects.Add(mapHolder); PreMapGenerate(mapHolder); Map map = null; LongEventHandler.QueueLongEvent(delegate { map = Verse.MapGenerator.GenerateMap(mapSize, mapHolder, MapGeneratorDefOfLocal.EmptyMap); LongEventHandler.ExecuteWhenFinished(delegate { PostMapGenerate(map, mapHolder); MapGeneratorHandler.GenerateMap(generator, map, out List <Pawn> pawns, ClearMap, SetTerrain, Fog, UnFogRooms, SpawnPawns, CreateRoof, GeneratePlants, forceFaction, forceLord, BreakdownBuildings); var things = GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, CollectThingsRadius, false).Where(x => x.Faction == Faction.OfPlayer); foreach (var t in things) { t.DeSpawn(); GenSpawn.Spawn(t, generator.PawnsSpawnPos, map); } PostMapDefGenerate(map, mapHolder); if (OneUse) { parent.Destroy(); } }); }, "GeneratingMapForNewEncounter", doAsynchronously: false, null); } else { var things = GenRadial.RadialDistinctThingsAround(parent.Position, parent.Map, CollectThingsRadius, false).Where(x => x.Faction == Faction.OfPlayer); foreach (var t in things) { t.DeSpawn(); GenSpawn.Spawn(t, generator.PawnsSpawnPos, mapHolder.Map); } } }
private static HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable) { neededTotal = need.count; HashSet <Thing> hashSet = new HashSet <Thing>(); Thing thing = (Thing)c; foreach (Thing item in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, useCenter: true)) { if (neededTotal >= resTotalAvailable) { break; } if (IsNewValidNearbyNeeder(item, hashSet, c, pawn)) { Blueprint blueprint = item as Blueprint; if (blueprint == null || !ShouldRemoveExistingFloorFirst(pawn, blueprint)) { int num = GenConstruct.AmountNeededByOf((IConstructible)item, need.thingDef); if (num > 0) { hashSet.Add(item); neededTotal += num; } } } } Blueprint blueprint2 = c as Blueprint; if (((blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef) & canRemoveExistingFloorUnderNearbyNeeders) && neededTotal < resTotalAvailable) { foreach (Thing item2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, useCenter: false)) { if (IsNewValidNearbyNeeder(item2, hashSet, c, pawn)) { Blueprint blueprint3 = item2 as Blueprint; if (blueprint3 != null) { Job job = RemoveExistingFloorJob(pawn, blueprint3); if (job != null) { jobToMakeNeederAvailable = job; return(hashSet); } } } } } jobToMakeNeederAvailable = null; return(hashSet); }
protected virtual void Impact(Thing hitThing) { CompExplosiveCE comp = this.TryGetComp <CompExplosiveCE>(); if (comp != null && ExactPosition.ToIntVec3().IsValid) { comp.Explode(launcher, ExactPosition, Find.CurrentMap); } //Spawn things if not an explosive but preExplosionSpawnThingDef != null if (Controller.settings.EnableAmmoSystem && Controller.settings.ReuseNeolithicProjectiles && comp == null && Position.IsValid && def.projectile.preExplosionSpawnChance > 0 && def.projectile.preExplosionSpawnThingDef != null && Rand.Value < def.projectile.preExplosionSpawnChance) { var thingDef = def.projectile.preExplosionSpawnThingDef; if (thingDef.IsFilth && Position.Walkable(this.Map)) { FilthMaker.MakeFilth(Position, Map, thingDef, 1); } else { Thing reusableAmmo = ThingMaker.MakeThing(thingDef, null); reusableAmmo.stackCount = 1; reusableAmmo.SetForbidden(true, false); GenPlace.TryPlaceThing(reusableAmmo, Position, Map, ThingPlaceMode.Near, null); LessonAutoActivator.TeachOpportunity(CE_ConceptDefOf.CE_ReusableNeolithicProjectiles, reusableAmmo, OpportunityType.GoodToKnow); } } // Opt-out for things without explosionRadius if (def.projectile.explosionRadius > 0 && ExactPosition.y < SuppressionRadius) { // Apply suppression around impact area var suppressThings = GenRadial.RadialDistinctThingsAround(ExactPosition.ToIntVec3(), Map, SuppressionRadius + def.projectile.explosionRadius, true); foreach (Thing thing in suppressThings) { Pawn pawn = thing as Pawn; if (pawn != null) { ApplySuppression(pawn); } } } Destroy(); }
private void ApplyGoodwillImpact(LocalTargetInfo target, int radius) { affectedFactionCache.Clear(); foreach (Thing item in GenRadial.RadialDistinctThingsAround(target.Cell, parent.pawn.Map, radius, useCenter: true)) { Pawn pawn; if ((pawn = (item as Pawn)) != null && item.Faction != null && item.Faction != parent.pawn.Faction && !item.Faction.HostileTo(parent.pawn.Faction) && !affectedFactionCache.Contains(item.Faction) && (base.Props.applyGoodwillImpactToLodgers || !pawn.IsQuestLodger())) { affectedFactionCache.Add(item.Faction); item.Faction.TryAffectGoodwillWith(parent.pawn.Faction, base.Props.goodwillImpact, canSendMessage: true, canSendHostilityLetter: true, "GoodwillChangedReason_UsedAbility".Translate(parent.def.LabelCap, pawn.LabelShort), pawn); } } affectedFactionCache.Clear(); }