internal bool <> m__0(Region x) { FacilitiesUtility.visited.Add(x); List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial); for (int i = 0; i < list.Count; i++) { if (!FacilitiesUtility.processed.Contains(list[i])) { FacilitiesUtility.processed.Add(list[i]); CompFacility compFacility = list[i].TryGetComp <CompFacility>(); CompAffectedByFacilities compAffectedByFacilities = list[i].TryGetComp <CompAffectedByFacilities>(); if (compFacility != null) { compFacility.Notify_LOSBlockerSpawnedOrDespawned(); this.facilitiesProcessed++; } if (compAffectedByFacilities != null) { compAffectedByFacilities.Notify_LOSBlockerSpawnedOrDespawned(); this.affectedByFacilitiesProcessed++; } } } return(this.facilitiesProcessed >= this.facilitiesToProcess && this.affectedByFacilitiesProcessed >= this.affectedByFacilitiesToProcess); }
public bool CanPotentiallyLinkTo(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation)) { return(false); } if (!this.IsPotentiallyValidFacilityForMe(facilityDef, facilityPos, facilityRot)) { return(false); } int num = 0; bool flag = false; for (int i = 0; i < this.linkedFacilities.Count; i++) { if (this.linkedFacilities[i].def == facilityDef) { num++; if (this.IsBetter(facilityDef, facilityPos, facilityRot, this.linkedFacilities[i])) { flag = true; break; } } } if (flag) { return(true); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); return(num + 1 <= compProperties.maxSimultaneous); }
private void FacilityChanged() { CompFacility compFacility = this.TryGetComp <CompFacility>(); CompAffectedByFacilities compAffectedByFacilities = this.TryGetComp <CompAffectedByFacilities>(); compFacility?.Notify_ThingChanged(); compAffectedByFacilities?.Notify_ThingChanged(); }
public bool IsValidFacilityForMe(Thing facility) { if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility, base.parent.def, base.parent.Position, base.parent.Rotation)) { return(false); } return(true); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; bool flag = false; switch (num) { case 0u: if (!this.parent.Spawned) { return(false); } potentialThings = CompAffectedByFacilities.PotentialThingsToLinkTo(this.parent.def, this.parent.Position, this.parent.Rotation, this.parent.Map); enumerator = potentialThings.GetEnumerator(); num = 4294967293u; break; case 1u: break; default: return(false); } try { switch (num) { } while (enumerator.MoveNext()) { th = enumerator.Current; if (base.CanLinkTo(th)) { this.$current = th; if (!this.$disposing) { this.$PC = 1; } flag = true; return(true); } } } finally { if (!flag) { if (enumerator != null) { enumerator.Dispose(); } } } this.$PC = -1; return(false); }
public static void DrawLinesToPotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { Vector3 a = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); foreach (Thing item in CompAffectedByFacilities.PotentialThingsToLinkTo(myDef, myPos, myRot, map)) { GenDraw.DrawLineBetween(a, item.TrueCenter()); } }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { _003CPotentialThingsToLinkTo_003Ec__Iterator1 _003CPotentialThingsToLinkTo_003Ec__Iterator = (_003CPotentialThingsToLinkTo_003Ec__Iterator1) /*Error near IL_0034: stateMachine*/; CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities != null) { IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = Gen.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = (from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()) select x).ThenBy(delegate(Thing x) { IntVec3 position2 = x.Position; return(position2.x); }).ThenBy(delegate(Thing x) { IntVec3 position = x.Position; return(position.z); }); foreach (Thing item in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(item, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = item.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(item.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[item.def] < facilityProps.maxSimultaneous) { goto IL_0232; } continue; } CompAffectedByFacilities.alreadyReturnedCount.Add(item.def, 0); goto IL_0232; } continue; IL_0232: Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = item.def] = dictionary[def] + 1; yield return(item); /*Error: Unable to find new state assignment for yield return*/; } } yield break; IL_02b1: /*Error near IL_02b2: Unexpected return in MoveNext()*/; }
private bool AmIActiveForAnyone() { for (int i = 0; i < linkedBuildings.Count; i++) { CompAffectedByFacilities compAffectedByFacilities = linkedBuildings[i].TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities.IsFacilityActive(parent)) { return(true); } } return(false); }
public static bool CanPotentiallyLinkTo_Static(Thing facility, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { if (!CompAffectedByFacilities.CanPotentiallyLinkTo_Static(facility.def, facility.Position, facility.Rotation, myDef, myPos, myRot)) { return(false); } if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility, myDef, myPos, myRot)) { return(false); } return(true); }
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null) { Map currentMap = Find.CurrentMap; if (def.HasComp(typeof(CompAffectedByFacilities))) { CompAffectedByFacilities.DrawLinesToPotentialThingsToLinkTo(def, center, rot, currentMap); } else { CompFacility.DrawLinesToPotentialThingsToLinkTo(def, center, rot, currentMap); } }
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot) { Map visibleMap = Find.VisibleMap; if (def.HasComp(typeof(CompAffectedByFacilities))) { CompAffectedByFacilities.DrawLinesToPotentialThingsToLinkTo(def, center, rot, visibleMap); } else { CompFacility.DrawLinesToPotentialThingsToLinkTo(def, center, rot, visibleMap); } }
private void FacilityChanged() { CompFacility compFacility = this.TryGetComp <CompFacility>(); CompAffectedByFacilities compAffectedByFacilities = this.TryGetComp <CompAffectedByFacilities>(); if (compFacility != null) { compFacility.Notify_ThingChanged(); } if (compAffectedByFacilities != null) { compAffectedByFacilities.Notify_ThingChanged(); } }
private float DrawResearchBenchRequirements(ResearchProjectDef project, Rect rect) { float xMin = rect.xMin; float yMin = rect.yMin; if (project.requiredResearchBuilding != null) { bool present = false; List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { if (maps[i].listerBuildings.allBuildingsColonist.Find((Building x) => x.def == project.requiredResearchBuilding) != null) { present = true; break; } } Widgets.LabelCacheHeight(ref rect, "RequiredResearchBench".Translate() + ":"); rect.xMin += 6f; rect.yMin += rect.height; SetPrerequisiteStatusColor(present, project); rect.height = Text.CalcHeight(project.requiredResearchBuilding.LabelCap, rect.width - 24f - 6f); Widgets.HyperlinkWithIcon(rect, new Dialog_InfoCard.Hyperlink(project.requiredResearchBuilding)); rect.yMin += rect.height + 4f; GUI.color = Color.white; rect.xMin = xMin; } if (!project.requiredResearchFacilities.NullOrEmpty()) { Widgets.LabelCacheHeight(ref rect, "RequiredResearchBenchFacilities".Translate() + ":"); rect.yMin += rect.height; Building_ResearchBench building_ResearchBench = FindBenchFulfillingMostRequirements(project.requiredResearchBuilding, project.requiredResearchFacilities); CompAffectedByFacilities bestMatchingBench = null; if (building_ResearchBench != null) { bestMatchingBench = building_ResearchBench.TryGetComp <CompAffectedByFacilities>(); } rect.xMin += 6f; for (int j = 0; j < project.requiredResearchFacilities.Count; j++) { DrawResearchBenchFacilityRequirement(project.requiredResearchFacilities[j], bestMatchingBench, project, ref rect); rect.yMin += rect.height; } rect.yMin += 4f; } GUI.color = Color.white; rect.xMin = xMin; return(rect.yMin - yMin); }
public override void PostDrawExtraSelectionOverlays() { for (int i = 0; i < linkedBuildings.Count; i++) { CompAffectedByFacilities compAffectedByFacilities = linkedBuildings[i].TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities.IsFacilityActive(parent)) { GenDraw.DrawLineBetween(parent.TrueCenter(), linkedBuildings[i].TrueCenter()); } else { GenDraw.DrawLineBetween(parent.TrueCenter(), linkedBuildings[i].TrueCenter(), CompAffectedByFacilities.InactiveFacilityLineMat); } } }
public static void NotifyFacilitiesAboutChangedLOSBlockers(List <Region> affectedRegions) { if (FacilitiesUtility.working) { Log.Warning("Tried to update facilities while already updating."); } else { FacilitiesUtility.working = true; try { FacilitiesUtility.visited.Clear(); for (int i = 0; i < affectedRegions.Count; i++) { if (!FacilitiesUtility.visited.Contains(affectedRegions[i])) { RegionTraverser.BreadthFirstTraverse(affectedRegions[i], (Region from, Region r) => !FacilitiesUtility.visited.Contains(r), delegate(Region x) { FacilitiesUtility.visited.Add(x); List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial); for (int j = 0; j < list.Count; j++) { CompFacility compFacility = list[j].TryGetComp <CompFacility>(); CompAffectedByFacilities compAffectedByFacilities = list[j].TryGetComp <CompAffectedByFacilities>(); if (compFacility != null) { compFacility.Notify_LOSBlockerSpawnedOrDespawned(); } if (compAffectedByFacilities != null) { compAffectedByFacilities.Notify_LOSBlockerSpawnedOrDespawned(); } } return(false); }, FacilitiesUtility.RegionsToSearch, RegionType.Set_Passable); } } } finally { FacilitiesUtility.working = false; FacilitiesUtility.visited.Clear(); } } }
private float DrawResearchBenchRequirements(ResearchProjectDef project, Rect rect) { float yMin = rect.yMin; if (project.requiredResearchBuilding != null) { bool present = false; List <Map> maps = Find.Maps; int num = 0; while (num < maps.Count) { if (maps[num].listerBuildings.allBuildingsColonist.Find((Building x) => x.def == project.requiredResearchBuilding) == null) { num++; continue; } present = true; break; } Widgets.LabelCacheHeight(ref rect, "RequiredResearchBench".Translate() + ":", true, false); rect.yMin += rect.height; this.SetPrerequisiteStatusColor(present, project); Widgets.LabelCacheHeight(ref rect, " " + project.requiredResearchBuilding.LabelCap, true, false); rect.yMin += rect.height; GUI.color = Color.white; } if (!project.requiredResearchFacilities.NullOrEmpty()) { Widgets.LabelCacheHeight(ref rect, "RequiredResearchBenchFacilities".Translate() + ":", true, false); rect.yMin += rect.height; Building_ResearchBench building_ResearchBench = this.FindBenchFulfillingMostRequirements(project.requiredResearchBuilding, project.requiredResearchFacilities); CompAffectedByFacilities bestMatchingBench = null; if (building_ResearchBench != null) { bestMatchingBench = building_ResearchBench.TryGetComp <CompAffectedByFacilities>(); } for (int i = 0; i < project.requiredResearchFacilities.Count; i++) { this.DrawResearchBenchFacilityRequirement(project.requiredResearchFacilities[i], bestMatchingBench, project, ref rect); rect.yMin += 15f; } } GUI.color = Color.white; return(rect.yMin - yMin); }
private bool IsPotentiallyValidFacilityForMe(ThingDef facilityDef, IntVec3 facilityPos, Rot4 facilityRot) { if (!CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facilityDef, facilityPos, facilityRot, this.parent.def, this.parent.Position, this.parent.Rotation, this.parent.Map)) { return(false); } CompProperties_Facility compProperties = facilityDef.GetCompProperties <CompProperties_Facility>(); if (compProperties.canLinkToMedBedsOnly) { Building_Bed building_Bed = this.parent as Building_Bed; if (building_Bed == null || !building_Bed.Medical) { return(false); } } return(true); }
public static void DrawLinesToPotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompProperties_Facility compProperties = myDef.GetCompProperties <CompProperties_Facility>(); Vector3 a = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); for (int i = 0; i < compProperties.linkableBuildings.Count; i++) { foreach (Thing item in map.listerThings.ThingsOfDef(compProperties.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = item.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanPotentiallyLinkTo(myDef, myPos, myRot)) { GenDraw.DrawLineBetween(a, item.TrueCenter()); compAffectedByFacilities.DrawRedLineToPotentiallySupplantedFacility(myDef, myPos, myRot); } } } }
public static IEnumerable <Thing> PotentialThingsToLinkTo(ThingDef myDef, IntVec3 myPos, Rot4 myRot, Map map) { CompAffectedByFacilities.alreadyReturnedCount.Clear(); CompProperties_AffectedByFacilities myProps = myDef.GetCompProperties <CompProperties_AffectedByFacilities>(); if (myProps.linkableFacilities == null) { yield break; } IEnumerable <Thing> candidates = Enumerable.Empty <Thing>(); for (int i = 0; i < myProps.linkableFacilities.Count; i++) { candidates = candidates.Concat(map.listerThings.ThingsOfDef(myProps.linkableFacilities[i])); } Vector3 myTrueCenter = GenThing.TrueCenter(myPos, myRot, myDef.size, myDef.Altitude); IOrderedEnumerable <Thing> sortedCandidates = from x in candidates orderby Vector3.Distance(myTrueCenter, x.TrueCenter()), x.Position.x, x.Position.z select x; foreach (Thing th in sortedCandidates) { if (CompAffectedByFacilities.CanPotentiallyLinkTo_Static(th, myDef, myPos, myRot)) { CompProperties_Facility facilityProps = th.def.GetCompProperties <CompProperties_Facility>(); if (CompAffectedByFacilities.alreadyReturnedCount.ContainsKey(th.def)) { if (CompAffectedByFacilities.alreadyReturnedCount[th.def] >= facilityProps.maxSimultaneous) { continue; } } else { CompAffectedByFacilities.alreadyReturnedCount.Add(th.def, 0); } Dictionary <ThingDef, int> dictionary; ThingDef def; (dictionary = CompAffectedByFacilities.alreadyReturnedCount)[def = th.def] = dictionary[def] + 1; yield return(th); } } yield break; }
private void DrawResearchBenchFacilityRequirement(ThingDef requiredFacility, CompAffectedByFacilities bestMatchingBench, ResearchProjectDef project, ref Rect rect) { Thing thing = null; Thing thing2 = null; if (bestMatchingBench != null) { thing = bestMatchingBench.LinkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacility); thing2 = bestMatchingBench.LinkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacility && bestMatchingBench.IsFacilityActive(x)); } SetPrerequisiteStatusColor(thing2 != null, project); string text = requiredFacility.LabelCap; if (thing != null && thing2 == null) { text = text + " (" + "InactiveFacility".Translate() + ")"; } Widgets.LabelCacheHeight(ref rect, " " + text); }
private void DrawResearchBenchFacilityRequirement(ThingDef requiredFacility, CompAffectedByFacilities bestMatchingBench, ResearchProjectDef project, ref Rect rect) { Thing thing = null; Thing thing2 = null; if (bestMatchingBench != null) { thing = bestMatchingBench.LinkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacility); thing2 = bestMatchingBench.LinkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacility && bestMatchingBench.IsFacilityActive(x)); } SetPrerequisiteStatusColor(thing2 != null, project); string text = requiredFacility.LabelCap; if (thing != null && thing2 == null) { text += " (" + "InactiveFacility".Translate() + ")"; } rect.height = Text.CalcHeight(text, rect.width - 24f - 6f); Widgets.HyperlinkWithIcon(rect, new Dialog_InfoCard.Hyperlink(requiredFacility), text); }
private void LinkToNearbyBuildings() { UnlinkAll(); CompProperties_Facility props = Props; if (props.linkableBuildings != null) { for (int i = 0; i < props.linkableBuildings.Count; i++) { foreach (Thing item in parent.Map.listerThings.ThingsOfDef(props.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = item.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanLinkTo(parent)) { linkedBuildings.Add(item); compAffectedByFacilities.Notify_NewLink(parent); } } } } }
private void LinkToNearbyBuildings() { this.UnlinkAll(); CompProperties_Facility props = this.Props; if (props.linkableBuildings == null) { return; } for (int i = 0; i < props.linkableBuildings.Count; i++) { foreach (Thing current in this.parent.Map.listerThings.ThingsOfDef(props.linkableBuildings[i])) { CompAffectedByFacilities compAffectedByFacilities = current.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null && compAffectedByFacilities.CanLinkTo(this.parent)) { this.linkedBuildings.Add(current); compAffectedByFacilities.Notify_NewLink(this.parent); } } } }
private float GetResearchBenchRequirementsScore(Building_ResearchBench bench, List <ThingDef> requiredFacilities) { float num = 0f; for (int i = 0; i < requiredFacilities.Count; i++) { CompAffectedByFacilities benchComp = bench.GetComp <CompAffectedByFacilities>(); if (benchComp != null) { List <Thing> linkedFacilitiesListForReading = benchComp.LinkedFacilitiesListForReading; if (linkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacilities[i] && benchComp.IsFacilityActive(x)) != null) { num += 1f; } else if (linkedFacilitiesListForReading.Find((Thing x) => x.def == requiredFacilities[i]) != null) { num += 0.6f; } } } return(num); }
public virtual float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true) { if (!stat.supressDisabledError && Prefs.DevMode && IsDisabledFor(req.Thing)) { Log.ErrorOnce($"Attempted to calculate value for disabled stat {stat}; this is meant as a consistency check, either set the stat to neverDisabled or ensure this pawn cannot accidentally use this stat (thing={req.Thing.ToStringSafe()})", 75193282 + stat.index); } float num = GetBaseValueFor(req); Pawn pawn = req.Thing as Pawn; if (pawn != null) { if (pawn.skills != null) { if (stat.skillNeedOffsets != null) { for (int i = 0; i < stat.skillNeedOffsets.Count; i++) { num += stat.skillNeedOffsets[i].ValueFor(pawn); } } } else { num += stat.noSkillOffset; } if (stat.capacityOffsets != null) { for (int j = 0; j < stat.capacityOffsets.Count; j++) { PawnCapacityOffset pawnCapacityOffset = stat.capacityOffsets[j]; num += pawnCapacityOffset.GetOffset(pawn.health.capacities.GetLevel(pawnCapacityOffset.capacity)); } } if (pawn.story != null) { for (int k = 0; k < pawn.story.traits.allTraits.Count; k++) { num += pawn.story.traits.allTraits[k].OffsetOfStat(stat); } } List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int l = 0; l < hediffs.Count; l++) { HediffStage curStage = hediffs[l].CurStage; if (curStage != null) { float num2 = curStage.statOffsets.GetStatOffsetFromList(stat); if (num2 != 0f && curStage.statOffsetEffectMultiplier != null) { num2 *= pawn.GetStatValue(curStage.statOffsetEffectMultiplier); } num += num2; } } if (pawn.apparel != null) { for (int m = 0; m < pawn.apparel.WornApparel.Count; m++) { num += StatOffsetFromGear(pawn.apparel.WornApparel[m], stat); } } if (pawn.equipment != null && pawn.equipment.Primary != null) { num += StatOffsetFromGear(pawn.equipment.Primary, stat); } if (pawn.story != null) { for (int n = 0; n < pawn.story.traits.allTraits.Count; n++) { num *= pawn.story.traits.allTraits[n].MultiplierOfStat(stat); } } for (int num3 = 0; num3 < hediffs.Count; num3++) { HediffStage curStage2 = hediffs[num3].CurStage; if (curStage2 != null) { float num4 = curStage2.statFactors.GetStatFactorFromList(stat); if (Math.Abs(num4 - 1f) > float.Epsilon && curStage2.statFactorEffectMultiplier != null) { num4 = ScaleFactor(num4, pawn.GetStatValue(curStage2.statFactorEffectMultiplier)); } num *= num4; } } num *= pawn.ageTracker.CurLifeStage.statFactors.GetStatFactorFromList(stat); } if (req.StuffDef != null) { if (num > 0f || stat.applyFactorsIfNegative) { num *= req.StuffDef.stuffProps.statFactors.GetStatFactorFromList(stat); } num += req.StuffDef.stuffProps.statOffsets.GetStatOffsetFromList(stat); } if (req.ForAbility && stat.statFactors != null) { for (int num5 = 0; num5 < stat.statFactors.Count; num5++) { num *= req.AbilityDef.statBases.GetStatValueFromList(stat.statFactors[num5], 1f); } } if (req.HasThing) { CompAffectedByFacilities compAffectedByFacilities = req.Thing.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null) { num += compAffectedByFacilities.GetStatOffset(stat); } if (stat.statFactors != null) { for (int num6 = 0; num6 < stat.statFactors.Count; num6++) { num *= req.Thing.GetStatValue(stat.statFactors[num6]); } } if (pawn != null) { if (pawn.skills != null) { if (stat.skillNeedFactors != null) { for (int num7 = 0; num7 < stat.skillNeedFactors.Count; num7++) { num *= stat.skillNeedFactors[num7].ValueFor(pawn); } } } else { num *= stat.noSkillFactor; } if (stat.capacityFactors != null) { for (int num8 = 0; num8 < stat.capacityFactors.Count; num8++) { PawnCapacityFactor pawnCapacityFactor = stat.capacityFactors[num8]; float factor = pawnCapacityFactor.GetFactor(pawn.health.capacities.GetLevel(pawnCapacityFactor.capacity)); num = Mathf.Lerp(num, num * factor, pawnCapacityFactor.weight); } } if (pawn.Inspired) { num += pawn.InspirationDef.statOffsets.GetStatOffsetFromList(stat); num *= pawn.InspirationDef.statFactors.GetStatFactorFromList(stat); } } } return(num); }
private static bool IsPotentiallyValidFacilityForMe_Static(Thing facility, ThingDef myDef, IntVec3 myPos, Rot4 myRot) { return(CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility.def, facility.Position, facility.Rotation, myDef, myPos, myRot, facility.Map)); }
public virtual string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense) { StringBuilder stringBuilder = new StringBuilder(); float baseValueFor = this.GetBaseValueFor(req.Def); if (baseValueFor != 0f) { stringBuilder.AppendLine("StatsReport_BaseValue".Translate() + ": " + this.stat.ValueToString(baseValueFor, numberSense)); stringBuilder.AppendLine(); } Pawn pawn = req.Thing as Pawn; if (pawn != null) { if (pawn.skills != null) { if (this.stat.skillNeedOffsets != null) { stringBuilder.AppendLine("StatsReport_Skills".Translate()); for (int i = 0; i < this.stat.skillNeedOffsets.Count; i++) { SkillNeed skillNeed = this.stat.skillNeedOffsets[i]; int level = pawn.skills.GetSkill(skillNeed.skill).Level; float val = skillNeed.ValueFor(pawn); stringBuilder.AppendLine(string.Concat(new object[] { " ", skillNeed.skill.LabelCap, " (", level, "): ", val.ToStringSign(), this.ValueToString(val, false, ToStringNumberSense.Absolute) })); } stringBuilder.AppendLine(); } } else if (this.stat.noSkillOffset != 0f) { stringBuilder.AppendLine("StatsReport_Skills".Translate()); stringBuilder.AppendLine(string.Concat(new string[] { " ", "default".Translate().CapitalizeFirst(), " : ", this.stat.noSkillOffset.ToStringSign(), this.ValueToString(this.stat.noSkillOffset, false, ToStringNumberSense.Absolute) })); stringBuilder.AppendLine(); } if (this.stat.capacityOffsets != null) { stringBuilder.AppendLine((!"StatsReport_Health".CanTranslate()) ? "StatsReport_HealthFactors".Translate() : "StatsReport_Health".Translate()); foreach (PawnCapacityOffset current in from hfa in this.stat.capacityOffsets orderby hfa.capacity.listOrder select hfa) { string text = current.capacity.GetLabelFor(pawn).CapitalizeFirst(); float level2 = pawn.health.capacities.GetLevel(current.capacity); float offset = current.GetOffset(pawn.health.capacities.GetLevel(current.capacity)); string text2 = this.ValueToString(offset, false, ToStringNumberSense.Absolute); string text3 = Mathf.Min(level2, current.max).ToStringPercent() + ", " + "HealthOffsetScale".Translate(new object[] { current.scale.ToString() + "x" }); if (current.max < 999f) { text3 = text3 + ", " + "HealthFactorMaxImpact".Translate(new object[] { current.max.ToStringPercent() }); } stringBuilder.AppendLine(string.Concat(new string[] { " ", text, ": ", offset.ToStringSign(), text2, " (", text3, ")" })); } stringBuilder.AppendLine(); } if (pawn.RaceProps.intelligence >= Intelligence.ToolUser) { if (pawn.story != null && pawn.story.traits != null) { List <Trait> list = (from tr in pawn.story.traits.allTraits where tr.CurrentData.statOffsets != null && tr.CurrentData.statOffsets.Any((StatModifier se) => se.stat == this.stat) select tr).ToList <Trait>(); List <Trait> list2 = (from tr in pawn.story.traits.allTraits where tr.CurrentData.statFactors != null && tr.CurrentData.statFactors.Any((StatModifier se) => se.stat == this.stat) select tr).ToList <Trait>(); if (list.Count > 0 || list2.Count > 0) { stringBuilder.AppendLine("StatsReport_RelevantTraits".Translate()); for (int j = 0; j < list.Count; j++) { Trait trait = list[j]; string valueToStringAsOffset = trait.CurrentData.statOffsets.First((StatModifier se) => se.stat == this.stat).ValueToStringAsOffset; stringBuilder.AppendLine(" " + trait.LabelCap + ": " + valueToStringAsOffset); } for (int k = 0; k < list2.Count; k++) { Trait trait2 = list2[k]; string toStringAsFactor = trait2.CurrentData.statFactors.First((StatModifier se) => se.stat == this.stat).ToStringAsFactor; stringBuilder.AppendLine(" " + trait2.LabelCap + ": " + toStringAsFactor); } stringBuilder.AppendLine(); } } if (StatWorker.RelevantGear(pawn, this.stat).Any <Thing>()) { stringBuilder.AppendLine("StatsReport_RelevantGear".Translate()); if (pawn.apparel != null) { for (int l = 0; l < pawn.apparel.WornApparel.Count; l++) { Apparel gear = pawn.apparel.WornApparel[l]; stringBuilder.AppendLine(StatWorker.InfoTextLineFromGear(gear, this.stat)); } } if (pawn.equipment != null && pawn.equipment.Primary != null) { stringBuilder.AppendLine(StatWorker.InfoTextLineFromGear(pawn.equipment.Primary, this.stat)); } stringBuilder.AppendLine(); } } bool flag = false; List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int m = 0; m < hediffs.Count; m++) { HediffStage curStage = hediffs[m].CurStage; if (curStage != null) { float statOffsetFromList = curStage.statOffsets.GetStatOffsetFromList(this.stat); if (statOffsetFromList != 0f) { if (!flag) { stringBuilder.AppendLine("StatsReport_RelevantHediffs".Translate()); flag = true; } stringBuilder.AppendLine(" " + hediffs[m].LabelBase.CapitalizeFirst() + ": " + this.ValueToString(statOffsetFromList, false, ToStringNumberSense.Offset)); stringBuilder.AppendLine(); } } } float statFactorFromList = pawn.ageTracker.CurLifeStage.statFactors.GetStatFactorFromList(this.stat); if (statFactorFromList != 1f) { stringBuilder.AppendLine(string.Concat(new string[] { "StatsReport_LifeStage".Translate(), " (", pawn.ageTracker.CurLifeStage.label, "): ", statFactorFromList.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor) })); stringBuilder.AppendLine(); } } if (req.StuffDef != null) { if (baseValueFor > 0f || this.stat.applyFactorsIfNegative) { float statFactorFromList2 = req.StuffDef.stuffProps.statFactors.GetStatFactorFromList(this.stat); if (statFactorFromList2 != 1f) { stringBuilder.AppendLine(string.Concat(new string[] { "StatsReport_Material".Translate(), " (", req.StuffDef.LabelCap, "): ", statFactorFromList2.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor) })); stringBuilder.AppendLine(); } } float statOffsetFromList2 = req.StuffDef.stuffProps.statOffsets.GetStatOffsetFromList(this.stat); if (statOffsetFromList2 != 0f) { stringBuilder.AppendLine(string.Concat(new string[] { "StatsReport_Material".Translate(), " (", req.StuffDef.LabelCap, "): ", statOffsetFromList2.ToStringByStyle(this.stat.toStringStyle, ToStringNumberSense.Offset) })); stringBuilder.AppendLine(); } } CompAffectedByFacilities compAffectedByFacilities = req.Thing.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null) { compAffectedByFacilities.GetStatsExplanation(this.stat, stringBuilder); } if (this.stat.statFactors != null) { stringBuilder.AppendLine("StatsReport_OtherStats".Translate()); for (int n = 0; n < this.stat.statFactors.Count; n++) { StatDef statDef = this.stat.statFactors[n]; stringBuilder.AppendLine(" " + statDef.LabelCap + ": x" + statDef.Worker.GetValue(req, true).ToStringPercent()); } stringBuilder.AppendLine(); } if (pawn != null) { if (pawn.skills != null) { if (this.stat.skillNeedFactors != null) { stringBuilder.AppendLine("StatsReport_Skills".Translate()); for (int num = 0; num < this.stat.skillNeedFactors.Count; num++) { SkillNeed skillNeed2 = this.stat.skillNeedFactors[num]; int level3 = pawn.skills.GetSkill(skillNeed2.skill).Level; stringBuilder.AppendLine(string.Concat(new object[] { " ", skillNeed2.skill.LabelCap, " (", level3, "): x", skillNeed2.ValueFor(pawn).ToStringPercent() })); } stringBuilder.AppendLine(); } } else if (this.stat.noSkillFactor != 1f) { stringBuilder.AppendLine("StatsReport_Skills".Translate()); stringBuilder.AppendLine(" " + "default".Translate().CapitalizeFirst() + " : x" + this.stat.noSkillFactor.ToStringPercent()); stringBuilder.AppendLine(); } if (this.stat.capacityFactors != null) { stringBuilder.AppendLine((!"StatsReport_Health".CanTranslate()) ? "StatsReport_HealthFactors".Translate() : "StatsReport_Health".Translate()); if (this.stat.capacityFactors != null) { foreach (PawnCapacityFactor current2 in from hfa in this.stat.capacityFactors orderby hfa.capacity.listOrder select hfa) { string text4 = current2.capacity.GetLabelFor(pawn).CapitalizeFirst(); float factor = current2.GetFactor(pawn.health.capacities.GetLevel(current2.capacity)); string text5 = factor.ToStringPercent(); string text6 = "HealthFactorPercentImpact".Translate(new object[] { current2.weight.ToStringPercent() }); if (current2.max < 999f) { text6 = text6 + ", " + "HealthFactorMaxImpact".Translate(new object[] { current2.max.ToStringPercent() }); } if (current2.allowedDefect != 0f) { text6 = text6 + ", " + "HealthFactorAllowedDefect".Translate(new object[] { (1f - current2.allowedDefect).ToStringPercent() }); } stringBuilder.AppendLine(string.Concat(new string[] { " ", text4, ": x", text5, " (", text6, ")" })); } } stringBuilder.AppendLine(); } if (pawn.Inspired) { float statOffsetFromList3 = pawn.InspirationDef.statOffsets.GetStatOffsetFromList(this.stat); if (statOffsetFromList3 != 0f) { stringBuilder.AppendLine("StatsReport_Inspiration".Translate(new object[] { pawn.Inspiration.def.LabelCap }) + ": " + this.ValueToString(statOffsetFromList3, false, ToStringNumberSense.Offset)); stringBuilder.AppendLine(); } float statFactorFromList3 = pawn.InspirationDef.statFactors.GetStatFactorFromList(this.stat); if (statFactorFromList3 != 1f) { stringBuilder.AppendLine("StatsReport_Inspiration".Translate(new object[] { pawn.Inspiration.def.LabelCap }) + ": " + statFactorFromList3.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor)); stringBuilder.AppendLine(); } } } return(stringBuilder.ToString().TrimEndNewlines()); }
public virtual float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true) { if (Prefs.DevMode && this.IsDisabledFor(req.Thing)) { Log.ErrorOnce(string.Format("Attempted to calculate value for disabled stat {0}; this is meant as a consistency check, either set the stat to neverDisabled or ensure this pawn cannot accidentally use this stat (thing={1})", this.stat, req.Thing.ToStringSafe <Thing>()), 75193282 + (int)this.stat.index, false); } float num = this.GetBaseValueFor(req.Def); Pawn pawn = req.Thing as Pawn; if (pawn != null) { if (pawn.skills != null) { if (this.stat.skillNeedOffsets != null) { for (int i = 0; i < this.stat.skillNeedOffsets.Count; i++) { num += this.stat.skillNeedOffsets[i].ValueFor(pawn); } } } else { num += this.stat.noSkillOffset; } if (this.stat.capacityOffsets != null) { for (int j = 0; j < this.stat.capacityOffsets.Count; j++) { PawnCapacityOffset pawnCapacityOffset = this.stat.capacityOffsets[j]; num += pawnCapacityOffset.GetOffset(pawn.health.capacities.GetLevel(pawnCapacityOffset.capacity)); } } if (pawn.story != null) { for (int k = 0; k < pawn.story.traits.allTraits.Count; k++) { num += pawn.story.traits.allTraits[k].OffsetOfStat(this.stat); } } List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int l = 0; l < hediffs.Count; l++) { HediffStage curStage = hediffs[l].CurStage; if (curStage != null) { num += curStage.statOffsets.GetStatOffsetFromList(this.stat); } } if (pawn.apparel != null) { for (int m = 0; m < pawn.apparel.WornApparel.Count; m++) { num += StatWorker.StatOffsetFromGear(pawn.apparel.WornApparel[m], this.stat); } } if (pawn.equipment != null && pawn.equipment.Primary != null) { num += StatWorker.StatOffsetFromGear(pawn.equipment.Primary, this.stat); } if (pawn.story != null) { for (int n = 0; n < pawn.story.traits.allTraits.Count; n++) { num *= pawn.story.traits.allTraits[n].MultiplierOfStat(this.stat); } } num *= pawn.ageTracker.CurLifeStage.statFactors.GetStatFactorFromList(this.stat); } if (req.StuffDef != null) { if (num > 0f || this.stat.applyFactorsIfNegative) { num *= req.StuffDef.stuffProps.statFactors.GetStatFactorFromList(this.stat); } num += req.StuffDef.stuffProps.statOffsets.GetStatOffsetFromList(this.stat); } if (req.HasThing) { CompAffectedByFacilities compAffectedByFacilities = req.Thing.TryGetComp <CompAffectedByFacilities>(); if (compAffectedByFacilities != null) { num += compAffectedByFacilities.GetStatOffset(this.stat); } if (this.stat.statFactors != null) { for (int num2 = 0; num2 < this.stat.statFactors.Count; num2++) { num *= req.Thing.GetStatValue(this.stat.statFactors[num2], true); } } if (pawn != null) { if (pawn.skills != null) { if (this.stat.skillNeedFactors != null) { for (int num3 = 0; num3 < this.stat.skillNeedFactors.Count; num3++) { num *= this.stat.skillNeedFactors[num3].ValueFor(pawn); } } } else { num *= this.stat.noSkillFactor; } if (this.stat.capacityFactors != null) { for (int num4 = 0; num4 < this.stat.capacityFactors.Count; num4++) { PawnCapacityFactor pawnCapacityFactor = this.stat.capacityFactors[num4]; float factor = pawnCapacityFactor.GetFactor(pawn.health.capacities.GetLevel(pawnCapacityFactor.capacity)); num = Mathf.Lerp(num, num * factor, pawnCapacityFactor.weight); } } if (pawn.Inspired) { num += pawn.InspirationDef.statOffsets.GetStatOffsetFromList(this.stat); num *= pawn.InspirationDef.statFactors.GetStatFactorFromList(this.stat); } } } return(num); }
public static void NotifyFacilitiesAboutChangedLOSBlockers(List <Region> affectedRegions) { if (affectedRegions.Any()) { if (working) { Log.Warning("Tried to update facilities while already updating."); } else { working = true; try { visited.Clear(); processed.Clear(); int facilitiesToProcess = affectedRegions[0].Map.listerThings.ThingsInGroup(ThingRequestGroup.Facility).Count; int affectedByFacilitiesToProcess = affectedRegions[0].Map.listerThings.ThingsInGroup(ThingRequestGroup.AffectedByFacilities).Count; int facilitiesProcessed = 0; int affectedByFacilitiesProcessed = 0; if (facilitiesToProcess > 0 && affectedByFacilitiesToProcess > 0) { for (int i = 0; i < affectedRegions.Count; i++) { if (!visited.Contains(affectedRegions[i])) { RegionTraverser.BreadthFirstTraverse(affectedRegions[i], (Region from, Region r) => !visited.Contains(r), delegate(Region x) { visited.Add(x); List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial); for (int j = 0; j < list.Count; j++) { if (!processed.Contains(list[j])) { processed.Add(list[j]); CompFacility compFacility = list[j].TryGetComp <CompFacility>(); CompAffectedByFacilities compAffectedByFacilities = list[j].TryGetComp <CompAffectedByFacilities>(); if (compFacility != null) { compFacility.Notify_LOSBlockerSpawnedOrDespawned(); facilitiesProcessed++; } if (compAffectedByFacilities != null) { compAffectedByFacilities.Notify_LOSBlockerSpawnedOrDespawned(); affectedByFacilitiesProcessed++; } } } return(facilitiesProcessed >= facilitiesToProcess && affectedByFacilitiesProcessed >= affectedByFacilitiesToProcess); }, RegionsToSearch); if (facilitiesProcessed >= facilitiesToProcess && affectedByFacilitiesProcessed >= affectedByFacilitiesToProcess) { break; } } } } } finally { working = false; visited.Clear(); processed.Clear(); } } } }
public bool IsValidFacilityForMe(Thing facility) { return(CompAffectedByFacilities.IsPotentiallyValidFacilityForMe_Static(facility, this.parent.def, this.parent.Position, this.parent.Rotation)); }