private static float GetStat(this BuildableDef entDef, ThingDef stuffDef, StatDef statDef) { if (stuffDef != null) { return(entDef.GetStatValueAbstract(statDef, stuffDef)); } else { return(entDef.GetStatValueAbstract(statDef)); } }
private static IEnumerable <StatDrawEntry> StatsToDraw(Def def, ThingDef stuff) { yield return(DescriptionEntry(def)); BuildableDef eDef = def as BuildableDef; if (eDef != null) { StatRequest statRequest = StatRequest.For(eDef, stuff); foreach (StatDef item in DefDatabase <StatDef> .AllDefs.Where((StatDef st) => st.Worker.ShouldShowFor(statRequest))) { yield return(new StatDrawEntry(item.category, item, eDef.GetStatValueAbstract(item, stuff), StatRequest.For(eDef, stuff))); } } ThingDef thingDef = def as ThingDef; if (thingDef == null || !thingDef.IsStuff) { yield break; } foreach (StatDrawEntry item2 in StuffStats(thingDef)) { yield return(item2); } }
private float WearFactor(Thing thing, BuildableDef def, ThingDef stuffDef) { if (thing == null) { return(def.GetStatValueAbstract(StatDefOf.ToolWearFactor, stuffDef)); } return(thing.GetStatValue(StatDefOf.ToolWearFactor)); }
//public static bool CanPlaceBlueprintOver(BuildableDef newDef, ThingDef oldDef) public static void Postfix(BuildableDef newDef, ThingDef oldDef, ref bool __result) { if (!OverMineable.PlaySettings_BlueprintOverRockToggle.enabled) { return; } if (newDef.GetStatValueAbstract(StatDefOf.WorkToBuild) > 0f) { __result |= oldDef.IsMineableRock(); } }
public static float CalculatedMarketValue(BuildableDef def, ThingDef stuffDef) { float num = 0f; RecipeDef recipeDef = StatWorker_MarketValue.CalculableRecipe(def); float num2; int num3; if (recipeDef != null) { num2 = recipeDef.workAmount; num3 = recipeDef.products[0].count; if (recipeDef.ingredients != null) { for (int i = 0; i < recipeDef.ingredients.Count; i++) { IngredientCount ingredientCount = recipeDef.ingredients[i]; int num4 = ingredientCount.CountRequiredOfFor(ingredientCount.FixedIngredient, recipeDef); num += (float)num4 * ingredientCount.FixedIngredient.BaseMarketValue; } } } else { num2 = Mathf.Max(def.GetStatValueAbstract(StatDefOf.WorkToMake, stuffDef), def.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef)); num3 = 1; if (def.costList != null) { for (int j = 0; j < def.costList.Count; j++) { ThingDefCountClass thingDefCountClass = def.costList[j]; num += (float)thingDefCountClass.count * thingDefCountClass.thingDef.BaseMarketValue; } } if (def.costStuffCount > 0) { if (stuffDef != null) { num += (float)def.costStuffCount / stuffDef.VolumePerUnit * stuffDef.GetStatValueAbstract(StatDefOf.MarketValue, null); } else { num += (float)def.costStuffCount * 2f; } } } if (num2 > 2f) { num += num2 * 0.0036f; } return(num / (float)num3); }
private float GetBaseEstimatedLifespan(Thing thing, BuildableDef def, ThingDef stuffDef, bool withWearFactor = true) { if (!((ThingDef)def).useHitPoints) { return(float.PositiveInfinity); } // For def if (thing == null) { return(GenDate.TicksToDays(Mathf.RoundToInt(BaseWearInterval * def.GetStatValueAbstract(RimWorld.StatDefOf.MaxHitPoints, stuffDef) / (withWearFactor ? WearFactor(null, def, stuffDef) : 1f)))); } // For thing return(GenDate.TicksToDays(Mathf.RoundToInt(BaseWearInterval * thing.MaxHitPoints / (withWearFactor ? WearFactor(thing, def, stuffDef) : 1f)))); }
private static IEnumerable <StatDrawEntry> StatsToDraw(Def def, ThingDef stuff) { yield return(StatsReportUtility.DescriptionEntry(def)); BuildableDef eDef = def as BuildableDef; if (eDef != null) { foreach (StatDef stat in from st in DefDatabase <StatDef> .AllDefs where st.Worker.ShouldShowFor(eDef) select st) { yield return(new StatDrawEntry(stat.category, stat, eDef.GetStatValueAbstract(stat, stuff), StatRequest.For(eDef, stuff, QualityCategory.Normal), ToStringNumberSense.Undefined)); } } }
public override void DesignateSingleCell(IntVec3 c) { if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(new EventPack(base.TutorTagDesignate, c))) { return; } if (DebugSettings.godMode || entDef.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef) == 0f) { if (entDef is TerrainDef) { base.Map.terrainGrid.SetTerrain(c, (TerrainDef)entDef); } else { Thing thing = ThingMaker.MakeThing((ThingDef)entDef, stuffDef); thing.SetFactionDirect(Faction.OfPlayer); GenSpawn.Spawn(thing, c, base.Map, placingRot); } } else { GenSpawn.WipeExistingThings(c, placingRot, entDef.blueprintDef, base.Map, DestroyMode.Deconstruct); GenConstruct.PlaceBlueprintForBuild(entDef, c, base.Map, placingRot, Faction.OfPlayer, stuffDef); } MoteMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(c, placingRot, entDef.Size), base.Map); ThingDef thingDef = entDef as ThingDef; if (thingDef != null && thingDef.IsOrbitalTradeBeacon) { PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BuildOrbitalTradeBeacon, KnowledgeAmount.Total); } if (TutorSystem.TutorialMode) { TutorSystem.Notify_Event(new EventPack(base.TutorTagDesignate, c)); } if (entDef.PlaceWorkers != null) { for (int i = 0; i < entDef.PlaceWorkers.Count; i++) { entDef.PlaceWorkers[i].PostPlace(base.Map, entDef, c, placingRot); } } }
private float GetBaseEstimatedLifespan(SurvivalTool tool, BuildableDef def) { SurvivalToolProperties props = def.GetModExtension <SurvivalToolProperties>() ?? SurvivalToolProperties.defaultValues; if (!((ThingDef)def).useHitPoints) { return(float.PositiveInfinity); } // For def if (tool == null) { return(GenDate.TicksToDays(Mathf.RoundToInt((BaseWearInterval * def.GetStatValueAbstract(StatDefOf.MaxHitPoints)) / props.toolWearFactor))); } // For thing StuffPropsTool stuffProps = tool.Stuff?.GetModExtension <StuffPropsTool>() ?? StuffPropsTool.defaultValues; float wearFactor = tool.def.GetModExtension <SurvivalToolProperties>().toolWearFactor *(stuffProps.wearFactorMultiplier); return(GenDate.TicksToDays(Mathf.RoundToInt((BaseWearInterval * tool.MaxHitPoints) / wearFactor))); }
//public override void DesignateSingleCell(IntVec3 c) public static bool Prefix(Designator_Build __instance, IntVec3 c, BuildableDef ___entDef, Rot4 ___placingRot) { //Replace the entire Designator_Build.DesignateSingleCell to behave differently if there is a replacable thing // Technically this is bypassing godmode, tutorial, PlayerKnowledgeDatabase, PlaceWorkers, but none of that should matter. ThingDef thingDef = ___entDef as ThingDef; if (thingDef == null) //Terrain? { return(true); } if (DebugSettings.godMode || ___entDef.GetStatValueAbstract(StatDefOf.WorkToBuild, __instance.StuffDef) == 0f) { return(true); } //Fix for door rotation so we find any rotation of doors if (typeof(Building_Door).IsAssignableFrom(thingDef.thingClass)) { ___placingRot = Building_Door.DoorRotationAt(c, __instance.Map); } List <Thing> replaceables = c.GetThingList(__instance.Map).FindAll( t => t.Position == c && t.Rotation == ___placingRot && Designator_ReplaceStuff.CanReplaceStuffFor(__instance.StuffDef, t, thingDef) ); if (replaceables.Count == 0) { return(true); } Designator_ReplaceStuff.ChooseReplace(replaceables, __instance.StuffDef); return(false); }