public static float CalculateBaseTendQuality(Pawn doctor, Pawn patient, ThingDef medicine) { float medicinePotency = medicine?.GetStatValueAbstract(StatDefOf.MedicalPotency) ?? 0.3f; float medicineQualityMax = medicine?.GetStatValueAbstract(StatDefOf.MedicalQualityMax) ?? 0.7f; return(CalculateBaseTendQuality(doctor, patient, medicinePotency, medicineQualityMax)); }
public static float?MeleeDpsBluntFactorOverall(this ThingDef d) { float damage = d.GetStatValueAbstract(StatDefOf.BluntDamageMultiplier); float?cooldown = d.GetStatFactorValue(StatDefOf.MeleeWeapon_CooldownMultiplier); if (cooldown == null) { return(null); } return((damage / cooldown).RoundTo2()); }
private static void SetTwoHandDefault(Dictionary <string, Record> dict, ThingDef td) { if (td.defName.Contains("Bow") || td.defName.Contains("Shotgun") || td.GetStatValueAbstract(StatDefOf.Mass) > 3f) { dict.Add(td.defName, new Record(true, td.label)); } else { dict.Add(td.defName, new Record(false, td.label)); } }
private static void SetDualWieldDefault(Dictionary <string, Record> dict, ThingDef td) { if (td.defName.Contains("Bow_") || td.defName.Contains("Blowgun") || td.GetStatValueAbstract(StatDefOf.Mass) > 3f || (td.IsMeleeWeapon && td.GetStatValueAbstract(StatDefOf.Mass) > 1.5f)) { dict.Add(td.defName, new Record(false, td.label)); } else { dict.Add(td.defName, new Record(true, td.label)); } }
public ThingStuffPair(ThingDef thing, ThingDef stuff, float commonalityMultiplier = 1f) { this.thing = thing; this.stuff = stuff; this.commonalityMultiplier = commonalityMultiplier; if (stuff != null && !thing.MadeFromStuff) { Log.Warning(string.Concat(new object[] { "Created ThingStuffPairWithQuality with stuff ", stuff, " but ", thing, " is not made from stuff." }), false); stuff = null; } this.cachedPrice = thing.GetStatValueAbstract(StatDefOf.MarketValue, stuff); this.cachedInsulationCold = thing.GetStatValueAbstract(StatDefOf.Insulation_Cold, stuff); this.cachedInsulationHeat = thing.GetStatValueAbstract(StatDefOf.Insulation_Heat, stuff); }
public static float GetNutrition(Thing foodSource, ThingDef foodDef) { if (foodSource == null || foodDef == null) { return(0f); } if (foodSource.def == foodDef) { return(foodSource.GetStatValue(StatDefOf.Nutrition)); } return(foodDef.GetStatValueAbstract(StatDefOf.Nutrition)); }
public static bool GetDynamicAllowsMedicine(MedicalCareCategory cat, ThingDef meds) { if ((int)cat < medList.Count) { //compare medical potencies return(meds.GetStatValueAbstract(StatDefOf.MedicalPotency, null) <= indexedMedList[(int)cat].potency); } else { throw new InvalidOperationException(); } }
public override bool HandlesThingDef(ThingDef td) { if (td == ThingDefOf.Apparel_ShieldBelt) { return(true); } if (td == ThingDefOf.Apparel_SmokepopBelt) { return(true); } return(base.HandlesThingDef(td) && td.IsApparel && (td.GetStatValueAbstract(StatDefOf.ArmorRating_Blunt) > 0.15f || td.GetStatValueAbstract(StatDefOf.ArmorRating_Sharp) > 0.15f)); }
public override bool HandlesThingDef(ThingDef td) { if (td == ThingDefOf.Apparel_ShieldBelt) { return(true); } if (td == ThingDefOf.Apparel_SmokepopBelt) { return(true); } ThingDef stuff = GenStuff.DefaultStuffFor(td); if (base.HandlesThingDef(td) && td.IsApparel) { if (!(td.GetStatValueAbstract(StatDefOf.ArmorRating_Blunt, stuff) > 0.15f)) { return(td.GetStatValueAbstract(StatDefOf.ArmorRating_Sharp, stuff) > 0.15f); } return(true); } return(false); }
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); }
public static bool PossibleToWeighNoMoreThan(ThingDef t, float maxMass, IEnumerable <ThingDef> allowedStuff) { if (maxMass == float.MaxValue || t.category == ThingCategory.Pawn) { return(true); } if (maxMass < 0f) { return(false); } if (t.MadeFromStuff) { foreach (ThingDef item in allowedStuff) { if (t.GetStatValueAbstract(StatDefOf.Mass, item) <= maxMass) { return(true); } } return(false); } return(t.GetStatValueAbstract(StatDefOf.Mass) <= maxMass); }
public static bool AllowsMedicine(this MedicalCareCategory cat, ThingDef meds) { switch (cat) { case MedicalCareCategory.NoCare: return(false); case MedicalCareCategory.NoMeds: return(false); case MedicalCareCategory.HerbalOrWorse: return(meds.GetStatValueAbstract(StatDefOf.MedicalPotency) <= ThingDefOf.MedicineHerbal.GetStatValueAbstract(StatDefOf.MedicalPotency)); case MedicalCareCategory.NormalOrWorse: return(meds.GetStatValueAbstract(StatDefOf.MedicalPotency) <= ThingDefOf.MedicineIndustrial.GetStatValueAbstract(StatDefOf.MedicalPotency)); case MedicalCareCategory.Best: return(true); default: throw new InvalidOperationException(); } }
// Token: 0x0600005D RID: 93 RVA: 0x00004604 File Offset: 0x00002804 public override float ValuePerUnitOf(ThingDef t) { if (t.IsNutritionGivingIngestible) { return(t.GetStatValueAbstract(StatDefOf.Nutrition)); } if (t.defName == "AYSalt" || t.defName == "WoodLog") { return(1f); } return(0f); }
// Token: 0x060034E6 RID: 13542 RVA: 0x00121E0C File Offset: 0x0012000C private static float CalculateMarketValue(ThingDef raceDef) { float num = 0f; if (raceDef.race.meatDef != null) { int num2 = Mathf.RoundToInt(raceDef.GetStatValueAbstract(StatDefOf.MeatAmount, null)); num += (float)num2 * raceDef.race.meatDef.GetStatValueAbstract(StatDefOf.MarketValue, null); } if (raceDef.race.leatherDef != null) { int num3 = Mathf.RoundToInt(raceDef.GetStatValueAbstract(StatDefOf.LeatherAmount, null)); num += (float)num3 * raceDef.race.leatherDef.GetStatValueAbstract(StatDefOf.MarketValue, null); } if (raceDef.butcherProducts != null) { for (int i = 0; i < raceDef.butcherProducts.Count; i++) { num += raceDef.butcherProducts[i].thingDef.BaseMarketValue * (float)raceDef.butcherProducts[i].count; } } return(num * 0.6f); }
public override void Randomize() { thingDef = PossibleThingDefs().RandomElement(); stuff = GenStuff.RandomStuffFor(thingDef); if (thingDef.statBases.StatListContains(StatDefOf.MarketValue)) { float num = Rand.Range(200, 2000); float statValueAbstract = thingDef.GetStatValueAbstract(StatDefOf.MarketValue, stuff); count = Mathf.CeilToInt(num / statValueAbstract); } else { count = Rand.RangeInclusive(1, 100); } }
private static void SetTwoHandDefault(Dictionary <string, Record> dict, ThingDef td) { if (td.GetModExtension <DefModextension_DefaultSettings>() is DefModextension_DefaultSettings modExt) { dict.Add(td.defName, new Record(modExt.twoHand, td.label)); } else if (td.defName.Contains("Bow") || td.defName.Contains("Shotgun") || td.GetStatValueAbstract(StatDefOf.Mass) > 3f) { dict.Add(td.defName, new Record(true, td.label)); } else { dict.Add(td.defName, new Record(false, td.label)); } }
//if found fogged: public static AcceptanceReport BlueprintExistsAcceptance(Map map, IntVec3 center, ThingDef entDef) { if (!OverMineable.PlaySettings_BlueprintOverRockToggle.blueprintOverRock) { return(new AcceptanceReport("CannotPlaceInUndiscovered".Translate())); } if (center.GetThingList(map).Any(t => t is Blueprint && t.def.entityDefToBuild == entDef)) { return(new AcceptanceReport("IdenticalBlueprintExists".Translate())); } if (entDef.GetStatValueAbstract(StatDefOf.WorkToBuild) == 0f) { return(new AcceptanceReport("CannotPlaceInUndiscovered".Translate())); } return(true); }
public static bool StoreXUntilStackFull(CompCachedDeepStorage comp, ThingDef def, int stackCount, Map map, IntVec3 cell, out List <Thing> storedThings) { bool result = false; storedThings = new List <Thing>(); stackCount = stackCount > def.stackLimit ? def.stackLimit : stackCount; float unitWeight = def.GetStatValueAbstract(StatDefOf.Mass); float maxWeight = comp.maxNumberStacks * def.stackLimit * unitWeight; // Used for query NonFullThings. Using temp, which is destroyed because TryAbsorbStack(), will return value not found. Thing temp2 = ThingMaker.MakeThing(def, GenStuff.DefaultStuffFor(def)); int maxCapacity = comp.CapacityToStoreThingAt(temp2, map, cell); int iteration = Mathf.CeilToInt((float)maxCapacity / stackCount); for (int i = 0; i < iteration; i++) { Thing temp = ThingMaker.MakeThing(def, GenStuff.DefaultStuffFor(def)); temp.stackCount = stackCount; if (GenPlace.TryPlaceThing(temp, cell, map, ThingPlaceMode.Direct)) { storedThings.Add(temp); } float rawWeight = unitWeight * (i + 1) * stackCount; float finalWeight = rawWeight > maxWeight ? maxWeight : rawWeight; float rawStack = (float)stackCount * (i + 1) / def.stackLimit; int finalStack = rawStack > comp.maxNumberStacks ? comp.maxNumberStacks : Mathf.CeilToInt(rawStack); int rawCapacity = maxCapacity - stackCount * (i + 1); int finalCapacity = rawCapacity < 0 ? 0 : rawCapacity; result = comp.CellStorages.TestCellStorageWeight(cell, finalWeight); result &= comp.CellStorages.TestCellStorageStack(cell, finalStack); result &= comp.CellStorages.TestSpareSpaceOnNonFull( temp2, cell, (def.stackLimit - stackCount * ((i + 1) % iteration) % def.stackLimit) % def.stackLimit); result &= comp.TestCellStorageCapacity(temp2, map, cell, finalCapacity); } return(result); }
public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null) { if (thing != null) { // while existing building is selected (thing as ThingWithComps)? .GetComp <CompWirelessDetonationGridNode>()? .DrawRadiusRing(true); } else { // preparing to build var radiusStat = def.GetStatValueAbstract(Resources.Stat.rxSignalRange); if (radiusStat > 0f) { GenDraw.DrawRadiusRing(center, radiusStat); } } }
// predict possible market value for spawned items public static float PredictBaseMarketValue(ThingDef thingDef, CompCraftedValue_Properties compProps) { var recipe = DefDatabase<RecipeDef>.GetNamed("Make" + thingDef.defName); var workValue = thingDef.GetStatValueAbstract(StatDefOf.WorkToMake) * compProps.valuePerWorkFactor; var randomIngredientsValue = recipe.ingredients.Sum(ingredient => ingredient.filter.AllowedThingDefs.RandomElement().BaseMarketValue * ingredient.GetBaseCount()); var minIngredientsValue = recipe.ingredients.Sum(ingredient => ingredient.filter.AllowedThingDefs.Min(def => def.BaseMarketValue) * ingredient.GetBaseCount()); var maxIngredientsValue = recipe.ingredients.Sum(ingredient => ingredient.filter.AllowedThingDefs.Max(def => def.BaseMarketValue) * ingredient.GetBaseCount()); var profitCoefficient = maxIngredientsValue != minIngredientsValue ? (float)Math.Pow(maxIngredientsValue - minIngredientsValue, 1 - compProps.profitFactor) : 0f; return profitCoefficient * (randomIngredientsValue - minIngredientsValue) + workValue + minIngredientsValue; }
private static Material MakeRow(ThingDef d) { var row = new Material { Label = d.LabelCap, Description = d.DescriptionDetailed, ItemsOnMap = d.CountOnMap() }; try { row.TexturePath = d.modContentPack.RootDir + @"\Textures\" + d.graphicData.texPath; } catch { } var fields = typeof(StatDefOf).GetFields(); foreach (var field in fields) { var rowProp = typeof(Material).GetProperty(field.Name); if (rowProp != null) { StatDef statDef = (StatDef)field.GetValue(null); IsStatFactor.TryGetValue(field.Name, out bool isStatFactor); float?value = isStatFactor ? d.GetStatFactorValue(statDef) : d.GetStatValueAbstract(statDef); rowProp.SetValue(row, value.Nullify().ByStyle(statDef.toStringStyle), null); } } row.HitPoints = d.GetStatFactorValue(StatDefOf.MaxHitPoints).Nullify().ToPercent(); // CombatExtended if (CE_MeleePenetrationFactor != null) { row.CE_MeleePenetrationFactor = d.GetStatFactorValue(CE_MeleePenetrationFactor); } row.Category = GetCategory(d); return(row); }
public static bool EverPlayerSellable(ThingDef def) { if (!def.tradeability.PlayerCanSell()) { return(false); } if (def.GetStatValueAbstract(StatDefOf.MarketValue) <= 0f) { return(false); } if (def.category != ThingCategory.Item && def.category != ThingCategory.Pawn && def.category != ThingCategory.Building) { return(false); } if (def.category == ThingCategory.Building && !def.Minifiable) { return(false); } return(true); }
public MarkData(ThingDef p) { if (DefDatabase <PawnKindDef> .AllDefs.Any(x => x.race == p)) { this.kindDef = DefDatabase <PawnKindDef> .AllDefs.Where(x => x.race == p).Any() ? DefDatabase <PawnKindDef> .AllDefs.Where(x => x.race == p).RandomElement() : null; } else { Log.Warning(string.Format("Warning, no pawnkinds found for {0} Race def: {1}", p.LabelCap, p.defName)); } this.raceDef = p; this.MarkScore = p.GetStatValueAbstract(StatDef.Named("HMS_MarkScore")); /* * this.Label = p.LabelCap; * this.Humanlike = p.race.Humanlike; * this.MarkDef = HMSUtility.GetMark(p); * this.MarkDefs = HMSUtility.GetMarks(p); */ }
public static void Postfix(Pawn p, ref FloatRange __result) { if (p.RaceProps.Humanlike && p.InBed()) { ThingDef raceDef = p.kindDef.race; Building_Bed bed = p.CurrentBed(); FloatRange altResult = new FloatRange(raceDef.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null), raceDef.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null)); altResult.min -= bed.GetStatValue(BedInsulationCold.Bed_Insulation_Cold, true); altResult.max += bed.GetStatValue(BedInsulationHeat.Bed_Insulation_Heat, true); if (__result.min > altResult.min) { __result.min = altResult.min; } if (__result.max < altResult.max) { __result.max = altResult.max; } //Log.Message("comfortable range modified for " + p + " by bed" + bed + ": " + __result.ToString()); } }
public static IEnumerable <CompWirelessDetonationGridNode> GetPotentialNeighborsFor(ThingDef def, IntVec3 pos, Map map) { var radius = def.GetStatValueAbstract(Resources.Stat.rxSignalRange); if (radius > 0f) { var endpoint = (def.GetCompProperties <CompProperties_WirelessDetonationGridNode>()?.endpoint).GetValueOrDefault(); var candidates = map.listerBuildings.allBuildingsColonist; for (var i = 0; i < candidates.Count; i++) { CompWirelessDetonationGridNode comp; if (candidates[i] is ThingWithComps building && (comp = building.GetComp <CompWirelessDetonationGridNode>()) != null && building.Position.DistanceTo(pos) <= Mathf.Min(radius, comp.Radius) && (endpoint == false || !comp.Props.endpoint)) { yield return(comp); } } } }
public IEnumerable <string> ConfigErrors() { if (preferability == FoodPreferability.Undefined) { yield return("undefined preferability"); /*Error: Unable to find new state assignment for yield return*/; } if (foodType == FoodTypeFlags.None) { yield return("no foodType"); /*Error: Unable to find new state assignment for yield return*/; } if (parent.GetStatValueAbstract(StatDefOf.Nutrition) == 0f && preferability != FoodPreferability.NeverForNutrition) { yield return("Nutrition == 0 but preferability is " + preferability + " instead of " + FoodPreferability.NeverForNutrition); /*Error: Unable to find new state assignment for yield return*/; } if (!parent.IsCorpse && (int)preferability > 3 && !parent.socialPropernessMatters && parent.EverHaulable) { yield return("ingestible preferability > DesperateOnlyForHumanlikes but socialPropernessMatters=false. This will cause bugs wherein wardens will look in prison cells for food to give to prisoners and so will repeatedly pick up and drop food inside the cell."); /*Error: Unable to find new state assignment for yield return*/; } if (joy > 0f && joyKind == null) { yield return("joy > 0 with no joy kind"); /*Error: Unable to find new state assignment for yield return*/; } if (joy == 0f && joyKind != null) { yield return("joy is 0 but joyKind is " + joyKind); /*Error: Unable to find new state assignment for yield return*/; } }
public static bool IsHotMeal(ThingDef def) { if (def.GetStatValueAbstract(StatDefOf.Nutrition) == 0) { return(false); } var ing = def.ingestible; if (ing != null) { if (ing.preferability == FoodPreferability.NeverForNutrition) { return(false); } var ft = ing.foodType; var compare = FoodTypeFlags.Meal; //| FoodTypeFlags.Meat | FoodTypeFlags.Corpse | FoodTypeFlags.VegetableOrFruit | FoodTypeFlags.AnimalProduct; if ((compare & ft) != FoodTypeFlags.None) { return(true); } } return(false); }
private static int GetDamageAmount(ThingDef weapon, ProjectileProperties pp) { var damageAmountBase = pp.damageAmountBase; float?wdm = weapon.GetStatValueAbstract(StatDefOf.RangedWeapon_DamageMultiplier); float weaponDamageMultiplier = wdm == null ? 1f : (float)wdm; int num; if (damageAmountBase != -1) { num = damageAmountBase; } else { if (pp.damageDef == null) { return(1); } num = pp.damageDef.defaultDamage; } return(Mathf.RoundToInt(num * weaponDamageMultiplier)); }
//Industrial Level Legendary Armor private bool HandlesArmorDefs(ThingDef td) { return(td == ThingDefOf.Apparel_ShieldBelt || (td.tradeability != Tradeability.None && td.techLevel <= TechLevel.Industrial && td.IsApparel && (td.GetStatValueAbstract(StatDefOf.ArmorRating_Blunt, null) > 0.15f || td.GetStatValueAbstract(StatDefOf.ArmorRating_Sharp, null) > 0.15f))); }
private static bool GeneratesLeather(ThingDef sourceDef) { return(sourceDef.category == ThingCategory.Pawn && sourceDef.GetStatValueAbstract(StatDefOf.LeatherAmount, null) > 0f); }
public bool OutdoorTemperatureAcceptableFor(int tile, ThingDef animalRace) { float outdoorTemp = this.GetOutdoorTemp(tile); return(outdoorTemp > animalRace.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null) && outdoorTemp < animalRace.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null)); }