private static ThingDef RandomRequestedThingDef() { Func <ThingDef, bool> globalValidator = delegate(ThingDef td) { //if (td.BaseMarketValue / td.BaseMass < 5f) //{ // return false; //} if (!td.alwaysHaulable) { return(false); } CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>(); return((compProperties == null || compProperties.daysToRotStart >= 10f) && td != ThingDefOf.Silver && td.PlayerAcquirable); }; if (Rand.Value < 0.8f) { ThingDef result = null; bool flag = (from td in DefDatabase <ThingDef> .AllDefs where (td.IsWithinCategory(ThingCategoryDefOf.FoodMeals) || td.IsWithinCategory(ThingCategoryDefOf.PlantFoodRaw) || td.IsWithinCategory(ThingCategoryDefOf.PlantMatter) || td.IsWithinCategory(ThingCategoryDefOf.ResourcesRaw)) && td.BaseMarketValue < 4f && globalValidator(td) select td).TryRandomElement(out result); if (flag) { return(result); } } return((from td in DefDatabase <ThingDef> .AllDefs where (td.IsWithinCategory(ThingCategoryDefOf.Medicine) || td.IsWithinCategory(ThingCategoryDefOf.Drugs) || td.IsWithinCategory(ThingCategoryDefOf.Weapons) || td.IsWithinCategory(ThingCategoryDefOf.Apparel) || td.IsWithinCategory(ThingCategoryDefOf.ResourcesRaw)) && td.BaseMarketValue >= 4f && globalValidator(td) select td).RandomElementWithFallback(null)); }
static IEnumerable <ThingDef> Postfix(IEnumerable <ThingDef> meatThings) { Log.Message("running patch"); foreach (var thingDef in meatThings) { if (thingDef.defName == "Meat_ZTB_CorruptSlime") { thingDef.graphicData.texPath = "ZTBiomes/Item/Gel/Gel"; thingDef.graphicData.graphicClass = typeof(Graphic_Single); thingDef.SetStatBaseValue(StatDefOf.Nutrition, 0.03f); thingDef.SetStatBaseValue(StatDefOf.Flammability, 2.0f); thingDef.description = "ZTB_GelDesc".Translate(); thingDef.comps.Clear(); thingDef.comps.Add(new CompProperties_Forbiddable()); CompProperties_Rottable compProperties_Rottable = new CompProperties_Rottable(); compProperties_Rottable.daysToRotStart = 8f; compProperties_Rottable.rotDestroys = true; thingDef.comps.Add(compProperties_Rottable); } yield return(thingDef); } }
private static bool TryFindRandomRequestedThingDef_NewTmp(Map map, out ThingDef thingDef, out int count, List <ThingDef> dontRequest) { requestCountDict.Clear(); Func <ThingDef, bool> globalValidator = delegate(ThingDef td) { if (td.BaseMarketValue / td.BaseMass < 5f) { return(false); } if (!td.alwaysHaulable) { return(false); } CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>(); if (compProperties != null && compProperties.daysToRotStart < 10f) { return(false); } if (td.ingestible != null && td.ingestible.HumanEdible) { return(false); } if (td == ThingDefOf.Silver) { return(false); } if (!td.PlayerAcquirable) { return(false); } int num = RandomRequestCount(td, map); requestCountDict.Add(td, num); if (!PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map)) { return(false); } if (!PlayerItemAccessibilityUtility.PlayerCanMake(td, map)) { return(false); } if (td.thingSetMakerTags != null && td.thingSetMakerTags.Contains("RewardStandardHighFreq")) { return(false); } return((dontRequest.NullOrEmpty() || !dontRequest.Contains(td)) ? true : false); }; if (ThingSetMakerUtility.allGeneratableItems.Where((ThingDef td) => globalValidator(td)).TryRandomElement(out thingDef)) { count = requestCountDict[thingDef]; return(true); } count = 0; return(false); }
public static bool IsNonPerishable(ThingDef def) { var ing = def.ingestible; if (ing != null) { FoodTypeFlags types = FoodTypeFlags.Meal | FoodTypeFlags.Processed; if ((ing.foodType & types) != FoodTypeFlags.None) { CompProperties_Rottable rot = def.GetCompProperties <CompProperties_Rottable>(); if (rot == null || rot.daysToRotStart > 25) { return(true); } } } return(false); }
public static void AddSaltedMeats() { HashSet <ThingDef> defsToAdd = new HashSet <ThingDef>(); foreach (ThingDef td in DefDatabase <ThingDef> .AllDefs.Where(t => t.IsMeat)) { ThingDef d = new ThingDef { resourceReadoutPriority = td.resourceReadoutPriority, //ResourceCountPriority.Middle; category = td.category, // ThingCategory.Item; thingClass = td.thingClass, // typeof(ThingWithComps); graphicData = new GraphicData() }; d.graphicData.graphicClass = td.graphicData.graphicClass; // typeof(Graphic_Single); d.useHitPoints = td.useHitPoints; // true; d.selectable = td.selectable; // true; //d.SetStatBaseValue(StatDefOf.MaxHitPoints, 115f); d.SetStatBaseValue(StatDefOf.MaxHitPoints, td.GetStatValueAbstract(StatDefOf.MaxHitPoints) * 1.15f); d.altitudeLayer = td.altitudeLayer; // AltitudeLayer.Item; d.stackLimit = td.stackLimit; // 75; d.comps.Add(new CompProperties_Forbiddable()); CompProperties_Rottable rotProps = new CompProperties_Rottable { daysToRotStart = td.GetCompProperties <CompProperties_Rottable>().daysToRotStart, // 2f; rotDestroys = td.GetCompProperties <CompProperties_Rottable>().rotDestroys // true; }; d.comps.Add(rotProps); d.tickerType = td.tickerType; // TickerType.Rare; d.SetStatBaseValue(StatDefOf.Beauty, td.GetStatValueAbstract(StatDefOf.Beauty)); // -20f d.alwaysHaulable = td.alwaysHaulable; // true; d.rotatable = td.rotatable; // false; d.pathCost = td.pathCost; // 15; d.drawGUIOverlay = td.drawGUIOverlay; // true; d.socialPropernessMatters = td.socialPropernessMatters; // true; d.modContentPack = td.modContentPack; // + d.category = td.category; // ThingCategory.Item; d.description = td.description; d.useHitPoints = td.useHitPoints; // true; d.SetStatBaseValue(StatDefOf.MaxHitPoints, td.GetStatValueAbstract(StatDefOf.MaxHitPoints) * 1.15f); // 65f d.SetStatBaseValue(StatDefOf.DeteriorationRate, td.GetStatValueAbstract(StatDefOf.DeteriorationRate) * 0.5f); // 3f d.SetStatBaseValue(StatDefOf.Mass, td.GetStatValueAbstract(StatDefOf.Mass)); // 0.025f d.SetStatBaseValue(StatDefOf.Flammability, td.GetStatValueAbstract(StatDefOf.Flammability)); // 0.5f d.SetStatBaseValue(StatDefOf.Nutrition, td.GetStatValueAbstract(StatDefOf.Nutrition) * 1.6f); //d.ingestible.nutrition = td.ingestible.nutrition + 0.03f; d.SetStatBaseValue(StatDefOf.FoodPoisonChanceFixedHuman, 0.02f); //d.comps.Add(new CompProperties_FoodPoisonable()); d.BaseMarketValue = td.BaseMarketValue; if (d.thingCategories == null) { d.thingCategories = new List <ThingCategoryDef>(); } DirectXmlCrossRefLoader.RegisterListWantsCrossRef <ThingCategoryDef>(d.thingCategories, "LotR_MeatRawSalted", d); d.ingestible = new IngestibleProperties { parent = d }; d.ingestible.foodType = td.ingestible.foodType; // FoodTypeFlags.Meat; d.ingestible.preferability = td.ingestible.preferability; // FoodPreferability.RawBad; DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(d.ingestible, "tasteThought", ThoughtDefOf.AteRawFood.defName); d.ingestible.ingestEffect = td.ingestible.ingestEffect; d.ingestible.ingestSound = td.ingestible.ingestSound; d.ingestible.specialThoughtDirect = td.ingestible.specialThoughtDirect; d.ingestible.specialThoughtAsIngredient = td.ingestible.specialThoughtAsIngredient; d.graphicData.texPath = td.graphicData.texPath; d.graphicData.color = td.graphicData.color; //d.thingCategories.Add(TTADefOf.LotR_MeatRawSalted); d.defName = td.defName + "Salted"; d.label = "TTA_SaltedLabel".Translate(td.label); d.ingestible.sourceDef = td.ingestible.sourceDef; defsToAdd.Add(d); } TTADefOf.LotR_MeatRawSalted.parent = ThingCategoryDefOf.MeatRaw; while (defsToAdd?.Count > 0) { var thingDef = defsToAdd.FirstOrDefault(); if (thingDef != null) { if (!DefDatabase <ThingDef> .AllDefs.Contains(thingDef)) { thingDef.PostLoad(); DefDatabase <ThingDef> .Add(thingDef); if (!TTADefOf.LotR_MeatRawSalted.childThingDefs.Contains(thingDef)) { TTADefOf.LotR_MeatRawSalted.childThingDefs.Add(thingDef); } } defsToAdd.Remove(thingDef); } else { break; } } DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); }
public override bool CanEverMatch(ThingDef def) { CompProperties_Rottable compProperties = def.GetCompProperties <CompProperties_Rottable>(); return(compProperties != null && !compProperties.rotDestroys); }