private static void RegainWeapon(Pawn pawn) { if (pawn.equipment.Primary == null) { PawnWeaponGenerator.TryGenerateWeaponFor(pawn); } }
public static bool Prefix(ref Thing newThing) { if (newThing.def.HasModExtension <RelicExtension>()) { Log.Message("Trying to spawn Relic: " + newThing.def.LabelCap); if (Find.World.GetComponent <RelicTracker>() is RelicTracker relicTracker) { if (relicTracker.CanSpawn(newThing, out RelicTracked data)) { data.SpawnedRelic(); // relicTracker.spawnedRelics.SetOrAdd(newThing.def, true); Log.Message("Recording new Relic: " + newThing.def.LabelCap); PawnWeaponGenerator.Reset(); if (newThing.TryGetCompFast <CompQuality>() is CompQuality quality) { quality.SetQuality(QualityCategory.Legendary, ArtGenerationContext.Outsider); } } else { ThingDef relicDef = newThing.def; /* * float silver = newThing.MarketValue * 0.75f; * newThing = ThingMaker.MakeThing(ThingDefOf.Silver); * newThing.stackCount = (int)silver; */ Log.Warning("Tried to spawn Relic: " + relicDef.LabelCap + " But one already exists in this World.");// Spawning "+ silver+" instead."); return(false); } } } return(true); }
private static void RegainWeapon(Pawn pawn) { if (pawn.equipment.Primary == null) { PawnWeaponGenerator.TryGenerateWeaponFor(pawn, new PawnGenerationRequest(pawn.kindDef)); } }
public static void PawnKindsWeaponUsage() { List <TableDataGetter <PawnKindDef> > list = new List <TableDataGetter <PawnKindDef> >(); list.Add(new TableDataGetter <PawnKindDef>("defName", (PawnKindDef x) => x.defName)); list.Add(new TableDataGetter <PawnKindDef>("avg $", (PawnKindDef x) => x.weaponMoney.Average.ToString())); list.Add(new TableDataGetter <PawnKindDef>("min $", (PawnKindDef x) => x.weaponMoney.min.ToString())); list.Add(new TableDataGetter <PawnKindDef>("max $", (PawnKindDef x) => x.weaponMoney.max.ToString())); list.Add(new TableDataGetter <PawnKindDef>("points", (PawnKindDef x) => x.combatPower.ToString())); list.AddRange(from w in DefDatabase <ThingDef> .AllDefs where w.IsWeapon && !w.weaponTags.NullOrEmpty() orderby w.IsMeleeWeapon descending, w.techLevel, w.BaseMarketValue select new TableDataGetter <PawnKindDef>(w.label.Shorten() + "\n$" + w.BaseMarketValue.ToString("F0"), delegate(PawnKindDef k) { if (k.weaponTags != null && w.weaponTags.Any((string z) => k.weaponTags.Contains(z))) { float num = PawnWeaponGenerator.CheapestNonDerpPriceFor(w); if (k.weaponMoney.max < num) { return("-"); } if (k.weaponMoney.min > num) { return("✓"); } return((1f - (num - k.weaponMoney.min) / (k.weaponMoney.max - k.weaponMoney.min)).ToStringPercent("F0")); } return(string.Empty); })); DebugTables.MakeTablesDialog(from x in DefDatabase <PawnKindDef> .AllDefs where (int)x.RaceProps.intelligence >= 1 orderby(x.defaultFactionType == null) ? 2147483647 : ((int)x.defaultFactionType.techLevel), x.combatPower select x, list.ToArray()); }
private static void TryGenerateWeaponFor_Coping(Pawn pawn, Pawn sourcePawn, bool forceWeapon) { if ((sourcePawn != null) && ((forceWeapon) || (sourcePawn.RaceProps.Humanlike && pawn.RaceProps.Humanlike) || (sourcePawn.def == pawn.def))) { // TODO: Verificar pela arma que foi derrubada if (sourcePawn.equipment == null) { return; } while (sourcePawn.equipment.AllEquipment.Any()) { ThingWithComps equipment; sourcePawn.equipment.TryDropEquipment(sourcePawn.equipment.AllEquipment.First(), out equipment, sourcePawn.Position, true); pawn.equipment.AddEquipment(equipment); } } else { PawnWeaponGenerator.TryGenerateWeaponFor(pawn); } }
public override void TryExecute() { ThingDef itemDef = ThingDef.Named("DropPodIncoming"); Thing itemThing = new Thing(); ThingDef stuff = null; ThingDef itemThingDef = ThingDef.Named(item.defname); if (itemThingDef.race != null) { TryExecuteAnimal(itemThingDef, quantity); return; } if (itemThingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(itemThingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(itemThingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff)) { stuff = GenStuff.RandomStuffByCommonalityFor(itemThingDef, TechLevel.Undefined); } } itemThing = ThingMaker.MakeThing(itemThingDef, (stuff != null) ? stuff : null); QualityCategory q = new QualityCategory(); if (itemThing.TryGetQuality(out q)) { ItemHelper.setItemQualityRandom(itemThing); } Map map = Helper.AnyPlayerMap; IntVec3 vec = DropCellFinder.TradeDropSpot(map); if (itemThingDef.Minifiable) { itemThingDef = itemThingDef.minifiedDef; MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null); minifiedThing.InnerThing = itemThing; minifiedThing.stackCount = quantity; TradeUtility.SpawnDropPod(vec, map, minifiedThing); } else { itemThing.stackCount = quantity; TradeUtility.SpawnDropPod(vec, map, itemThing); } string letter = Helper.ReplacePlaceholder("TwitchStoriesDescription80".Translate(), from: Viewer.username, amount: quantity.ToString(), item: item.abr.CapitalizeFirst()); LetterDef letterDef = ItemHelper.GetLetterFromValue(price); Find.LetterStack.ReceiveLetter(item.abr.Truncate(15, true).CapitalizeFirst(), letter, letterDef, new TargetInfo(vec, map, false)); EndCarePackage(); }
public override void TryExecute() { ThingDef itemDef = ThingDef.Named("DropPodIncoming"); Thing itemThing = new Thing(); ThingDef stuff = null; ThingDef itemThingDef = ThingDef.Named(item.defname); if (itemThingDef.race != null) { TryExecuteAnimal(itemThingDef, quantity); return; } if (itemThingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(itemThingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(itemThingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff)) { stuff = GenStuff.RandomStuffByCommonalityFor(itemThingDef, TechLevel.Undefined); } } itemThing = ThingMaker.MakeThing(itemThingDef, (stuff != null) ? stuff : null); QualityCategory q = new QualityCategory(); if (itemThing.TryGetQuality(out q)) { ItemHelper.setItemQualityRandom(itemThing); } IntVec3 vec; if (itemThingDef.Minifiable) { itemThingDef = itemThingDef.minifiedDef; MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null); minifiedThing.InnerThing = itemThing; minifiedThing.stackCount = quantity; vec = Helper.Rain(itemDef, minifiedThing); } else { itemThing.stackCount = quantity; vec = Helper.Rain(itemDef, itemThing); } string letter = Helper.ReplacePlaceholder("TwitchStoriesDescription80".Translate(), from: viewer.username, amount: quantity.ToString(), item: item.abr.CapitalizeFirst()); Helper.CarePackage(letter, LetterDefOf.PositiveEvent, vec); EndCarePackage(); }
private static ThingDef CheapestNonDerpStuff(RecipeDef d) { ThingDef productDef = d.products[0].thingDef; if (!productDef.MadeFromStuff) { return(null); } return((from td in d.ingredients.First().filter.AllowedThingDefs where !productDef.IsWeapon || !PawnWeaponGenerator.IsDerpWeapon(productDef, td) select td).MinBy((ThingDef td) => td.BaseMarketValue / td.VolumePerUnit)); }
public void Hatch() { PawnGenerationRequest request = new PawnGenerationRequest(this.Props.hatcherPawn, this.hatcheeFaction, PawnGenerationContext.NonPlayer, -1, false, true, false, false, true, false, 1f, false, true, true, false, false, false, false, false, 0, null, 1, null, null, null, null, null); Pawn hatchling = PawnGenerator.GeneratePawn(request); hatchling.SetFactionDirect(Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Horrors"))); PawnUtility.TrySpawnHatchedOrBornPawn(hatchling, this.parent); PawnInventoryGenerator.GenerateInventoryFor(hatchling, request); PawnWeaponGenerator.TryGenerateWeaponFor(hatchling, request); Lord lord = CreateNewLord(); lord.AddPawn(hatchling); this.parent.Destroy(DestroyMode.Vanish); }
private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request) { ProfilerThreadCheck.BeginSample("GenerateGearFor"); ProfilerThreadCheck.BeginSample("GenerateStartingApparelFor"); PawnApparelGenerator.GenerateStartingApparelFor(pawn, request); ProfilerThreadCheck.EndSample(); ProfilerThreadCheck.BeginSample("TryGenerateWeaponFor"); PawnWeaponGenerator.TryGenerateWeaponFor(pawn); ProfilerThreadCheck.EndSample(); ProfilerThreadCheck.BeginSample("GenerateInventoryFor"); PawnInventoryGenerator.GenerateInventoryFor(pawn, request); ProfilerThreadCheck.EndSample(); ProfilerThreadCheck.EndSample(); }
public void Hatch() { var request = new PawnGenerationRequest(Props.hatcherPawn, hatcheeFaction, PawnGenerationContext.NonPlayer, -1, false, true, false, false, true, false, 1f, false, true, true, false); var hatchling = PawnGenerator.GeneratePawn(request); hatchling.SetFactionDirect(Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Horrors"))); PawnUtility.TrySpawnHatchedOrBornPawn(hatchling, parent); PawnInventoryGenerator.GenerateInventoryFor(hatchling, request); PawnWeaponGenerator.TryGenerateWeaponFor(hatchling, request); var lord = CreateNewLord(); lord.AddPawn(hatchling); parent.Destroy(); }
public void PutItemInCargoPod(string quote, int amount, string username) { var itemDef = ThingDef.Named("DropPodIncoming"); var itemThing = new Thing(); // Lets see if a new item needs to be made from stuff ThingDef stuff = null; ThingDef itemThingDef = ThingDef.Named(this.defname); if (itemThingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(itemThingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(itemThingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff)) { stuff = GenStuff.RandomStuffByCommonalityFor(itemThingDef, TechLevel.Undefined); } } itemThing = ThingMaker.MakeThing(itemThingDef, (stuff != null) ? stuff : null); QualityCategory q = new QualityCategory(); if (itemThing.TryGetQuality(out q)) { setItemQualityRandom(itemThing); } IntVec3 vec; if (itemThingDef.Minifiable) { itemThingDef = itemThingDef.minifiedDef; MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null); minifiedThing.InnerThing = itemThing; minifiedThing.stackCount = amount; vec = Helper.Rain(itemDef, minifiedThing); } else { itemThing.stackCount = amount; vec = Helper.Rain(itemDef, itemThing); } quote = Helper.ReplacePlaceholder(quote, from: username, amount: amount.ToString(), item: this.abr); Helper.CarePackage(quote, LetterDefOf.PositiveEvent, vec); }
protected override void Generate(ThingSetMakerParams parms, List <Thing> outThings) { foreach (ThingDef thingDef in AllGeneratableThingsDebugSub(parms)) { ThingDef stuff = null; if (thingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(thingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff)) { stuff = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined); } } Thing thing = ThingMaker.MakeThing(thingDef, stuff); outThings.Add(thing); } }
public static List <Thing> GenerateApperalReward(int apperalCount) { List <Thing> returnList = new List <Thing>(); IEnumerable <ThingDef> apperalList = (from x in DefDatabase <ThingDef> .AllDefs where x.IsApparel == true && x.apparel.tags != null && (x.apparel.tags.Contains("SpacerMilitary") || x.apparel.tags.Contains("IndustrialAdvanced") || x.apparel.tags.Contains("BeltDefense") || x.apparel.tags.Contains("BeltDefensePop")) select x); for (int i = 0; i < apperalCount; i++) { ThingDef thingDef; ThingDef stuffDef = null; if (apperalList == null) { Log.Error("Potential apperal list count is 0"); break; } apperalList.TryRandomElement(out thingDef); if (thingDef == null) { Log.Error("Could not resolve thingdef to spawn apperal"); continue; } if (thingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(thingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuffDef)) { stuffDef = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined); } } Thing apperal = ThingMaker.MakeThing(thingDef, stuffDef); CompQuality compQuality = apperal.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.GenerateQualityTraderItem(), ArtGenerationContext.Outsider); } returnList.Add(apperal); } return(returnList); }
public override IEnumerable <string> ConfigErrors() { foreach (string item in base.ConfigErrors()) { yield return(item); } if (backstoryFilters != null && backstoryFiltersOverride != null) { yield return("both backstoryCategories and backstoryCategoriesOverride are defined"); } if (race == null) { yield return("no race"); } if (baseRecruitDifficulty > 1.0001f) { yield return(defName + " recruitDifficulty is greater than 1. 1 means impossible to recruit."); } if (combatPower < 0f) { yield return(defName + " has no combatPower."); } if (weaponMoney != FloatRange.Zero) { float num = 999999f; int j; for (j = 0; j < weaponTags.Count; j++) { IEnumerable <ThingDef> source = DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.weaponTags != null && d.weaponTags.Contains(weaponTags[j])); if (source.Any()) { num = Mathf.Min(num, source.Min((ThingDef d) => PawnWeaponGenerator.CheapestNonDerpPriceFor(d))); } } if (num < 999999f && num > weaponMoney.min) { yield return("Cheapest weapon with one of my weaponTags costs " + num + " but weaponMoney min is " + weaponMoney.min + ", so could end up weaponless."); } } if (!RaceProps.Humanlike && lifeStages.Count != RaceProps.lifeStageAges.Count) { yield return("PawnKindDef defines " + lifeStages.Count + " lifeStages while race def defines " + RaceProps.lifeStageAges.Count); } if (apparelRequired != null) { for (int i = 0; i < apparelRequired.Count; i++) { for (int k = i + 1; k < apparelRequired.Count; k++) { if (!ApparelUtility.CanWearTogether(apparelRequired[i], apparelRequired[k], race.race.body)) { yield return(string.Concat("required apparel can't be worn together (", apparelRequired[i], ", ", apparelRequired[k], ")")); } } } } if (alternateGraphics == null) { yield break; } foreach (AlternateGraphic alternateGraphic in alternateGraphics) { if (alternateGraphic.Weight < 0f) { yield return("alternate graphic has negative weight."); } } }
private static void GenerateGearFor(Pawn pawn, PawnGenerationRequest request) { PawnApparelGenerator.GenerateStartingApparelFor(pawn, request); PawnWeaponGenerator.TryGenerateWeaponFor(pawn); PawnInventoryGenerator.GenerateInventoryFor(pawn, request); }
static RemoveSpacerStuff() { DebugString.AppendLine("RemoveSpacerStuff - Start Removal Log"); DebugString.AppendLine("Tech Max Level = " + MAX_TECHLEVEL); removedDefs = 0; IEnumerable <ResearchProjectDef> projects = new List <ResearchProjectDef>(); if (ModStuff.Settings.LimitResearch) { projects = DefDatabase <ResearchProjectDef> .AllDefs.Where(rpd => rpd.techLevel > MAX_TECHLEVEL); } if (ModStuff.Settings.LimitItems) { things = new HashSet <ThingDef>(DefDatabase <ThingDef> .AllDefs.Where(td => td.techLevel > MAX_TECHLEVEL || (td.researchPrerequisites?.Any(rpd => projects.Contains(rpd)) ?? false))); } DebugString.AppendLine("RecipeDef Removal List"); foreach (var thing in from thing in things where thing.tradeTags != null select thing) { var tags = thing.tradeTags.ToArray(); foreach (var tag in tags) { if (tag.StartsWith("CE_AutoEnableCrafting")) { thing.tradeTags.Remove(tag); } } } //var recipeDefsToRemove = DefDatabase<RecipeDef>.AllDefs.Where(rd => // rd.products.Any(tcc => things.Contains(tcc.thingDef)) || // rd.AllRecipeUsers.All(td => things.Contains(td)) || // projects.Contains(rd.researchPrerequisite)).Cast<Def>().ToList(); //recipeDefsToRemove?.RemoveAll(x => // x.defName == "ExtractMetalFromSlag" || // x.defName == "SmeltWeapon" || // x.defName == "DestroyWeapon" || // x.defName == "OfferingOfPlants_Meagre" || // x.defName == "OfferingOfPlants_Decent" || // x.defName == "OfferingOfPlants_Sizable" || // x.defName == "OfferingOfPlants_Worthy" || // x.defName == "OfferingOfPlants_Impressive" || // x.defName == "OfferingOfMeat_Meagre" || // x.defName == "OfferingOfMeat_Decent" || // x.defName == "OfferingOfMeat_Sizable" || // x.defName == "OfferingOfMeat_Worthy" || // x.defName == "OfferingOfMeat_Impressive" || // x.defName == "OfferingOfMeals_Meagre" || // x.defName == "OfferingOfMeals_Decent" || // x.defName == "OfferingOfMeals_Sizable" || // x.defName == "OfferingOfMeals_Worthy" || // x.defName == "OfferingOfMeals_Impressive" || // x.defName == "ROMV_ExtractBloodVial" || // x.defName == "ROMV_ExtractBloodPack" // ); //RemoveStuffFromDatabase(typeof(DefDatabase<RecipeDef>), recipeDefsToRemove); DebugString.AppendLine("ResearchProjectDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ResearchProjectDef>), projects); DebugString.AppendLine("Scenario Part Removal List"); var getThingInfo = typeof(ScenPart_ThingCount).GetField("thingDef", BindingFlags.NonPublic | BindingFlags.Instance); foreach (var def in DefDatabase <ScenarioDef> .AllDefs) { foreach (var sp in def.scenario.AllParts) { if (!(sp is ScenPart_ThingCount) || !things.Contains((ThingDef)getThingInfo?.GetValue(sp))) { continue; } def.scenario.RemovePart(sp); DebugString.AppendLine("- " + sp.Label + " " + ((ThingDef)getThingInfo?.GetValue(sp))?.label + " from " + def.label); } } foreach (var thingCategoryDef in DefDatabase <ThingCategoryDef> .AllDefs) { thingCategoryDef.childThingDefs.RemoveAll(things.Contains); } DebugString.AppendLine("Stock Generator Part Cleanup"); foreach (var tkd in DefDatabase <TraderKindDef> .AllDefs) { for (var i = tkd.stockGenerators.Count - 1; i >= 0; i--) { var stockGenerator = tkd.stockGenerators[i]; switch (stockGenerator) { case StockGenerator_SingleDef sd when things.Contains(Traverse.Create(sd).Field("thingDef") .GetValue <ThingDef>()): var def = Traverse.Create(sd).Field("thingDef") .GetValue <ThingDef>(); tkd.stockGenerators.Remove(stockGenerator); DebugString.AppendLine("- " + def.label + " from " + tkd.label + "'s StockGenerator_SingleDef"); break; case StockGenerator_MultiDef md: var thingListTraverse = Traverse.Create(md).Field("thingDefs"); var thingList = thingListTraverse.GetValue <List <ThingDef> >(); var removeList = thingList.FindAll(things.Contains); removeList.ForEach(x => DebugString.AppendLine("- " + x.label + " from " + tkd.label + "'s StockGenerator_MultiDef")); thingList.RemoveAll(things.Contains); if (thingList.NullOrEmpty()) { tkd.stockGenerators.Remove(stockGenerator); } else { thingListTraverse.SetValue(thingList); } break; } } } //DebugString.AppendLine("IncidentDef Removal List"); //var removedDefNames = new List<string> //{ // "Disease_FibrousMechanites", // "Disease_SensoryMechanites", // "ResourcePodCrash", // "PsychicSoothe", // "RefugeePodCrash", // "RansomDemand", // "MeteoriteImpact", // "PsychicDrone", // "ShortCircuit", // "ShipChunkDrop", // "OrbitalTraderArrival", // "StrangerInBlackJoin", // "DefoliatorShipPartCrash", // "PsychicEmanatorShipPartCrash", // "MechCluster", // "AnimalInsanityMass" //}; //IEnumerable<IncidentDef> incidents = from IncidentDef incident in DefDatabase<IncidentDef>.AllDefs // where removedDefNames.Contains(incident.defName) // select incident; //foreach (IncidentDef incident in incidents) //{ // incident.targetTags?.Clear(); // incident.baseChance = 0f; // incident.allowedBiomes?.Clear(); // incident.earliestDay = int.MaxValue; //} //RemoveStuffFromDatabase(typeof(DefDatabase<IncidentDef>), incidents.Cast<Def>()); //DebugString.AppendLine("Replaced Ancient Asphalt Road / Ancient Asphalt Highway with Stone Road"); //RoadDef[] targetRoads = { RoadDefOf.AncientAsphaltRoad, RoadDefOf.AncientAsphaltHighway }; //RoadDef originalRoad = DefDatabase<RoadDef>.GetNamed("StoneRoad"); //List<string> fieldNames = AccessTools.GetFieldNames(typeof(RoadDef)); //fieldNames.Remove("defName"); //foreach (FieldInfo fi in fieldNames.Select(name => AccessTools.Field(typeof(RoadDef), name))) //{ // object fieldValue = fi.GetValue(originalRoad); // foreach (RoadDef targetRoad in targetRoads) fi.SetValue(targetRoad, fieldValue); //} //DebugString.AppendLine("Special Hediff Removal List"); //RemoveStuffFromDatabase(typeof(DefDatabase<HediffDef>), (hediffs = new[] { HediffDefOf.Gunshot }).Cast<Def>()); //DebugString.AppendLine("RaidStrategyDef Removal List"); //RemoveStuffFromDatabase(typeof(DefDatabase<RaidStrategyDef>), // DefDatabase<RaidStrategyDef>.AllDefs // .Where(rs => typeof(ScenPart_ThingCount).IsAssignableFrom(rs.workerClass)).Cast<Def>()); //// ItemCollectionGeneratorUtility.allGeneratableItems.RemoveAll(match: things.Contains); //// //// foreach (Type type in typeof(ItemCollectionGenerator_Standard).AllSubclassesNonAbstract()) //// type.GetMethod(name: "Reset")?.Invoke(obj: null, parameters: null); DebugString.AppendLine("ThingDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ThingDef>), things.ToArray()); DebugString.AppendLine("ThingSetMaker Reset"); ThingSetMakerUtility.Reset(); //DebugString.AppendLine("TraitDef Removal List"); //RemoveStuffFromDatabase(typeof(DefDatabase<TraitDef>), // // { nameof(TraitDefOf.Prosthophobe), "Prosthophile" } ? // DefDatabase<TraitDef>.AllDefs // .Where(td => new[] { nameof(TraitDefOf.BodyPurist), "Transhumanist" }.Contains(td.defName)) // .Cast<Def>()); DebugString.AppendLine("Designators Resolved Again"); var resolveDesignatorsAgain = typeof(DesignationCategoryDef).GetMethod("ResolveDesignators", BindingFlags.NonPublic | BindingFlags.Instance); foreach (var dcd in DefDatabase <DesignationCategoryDef> .AllDefs) { resolveDesignatorsAgain?.Invoke(dcd, null); } if (ModStuff.Settings.LimitPawns) { DebugString.AppendLine("PawnKindDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <PawnKindDef>), DefDatabase <PawnKindDef> .AllDefs .Where(pkd => (!pkd.defaultFactionType?.isPlayer ?? false) && (pkd.race.techLevel > MAX_TECHLEVEL || pkd.defaultFactionType?.techLevel > MAX_TECHLEVEL))); } if (ModStuff.Settings.LimitFactions) { DebugString.AppendLine("FactionDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <FactionDef>), DefDatabase <FactionDef> .AllDefs.Where(fd => !fd.isPlayer && fd.techLevel > MAX_TECHLEVEL)); if (ModLister.RoyaltyInstalled) { var incident = DefDatabase <IncidentDef> .GetNamedSilentFail("CaravanArrivalTributeCollector"); if (incident != null) { RemoveStuffFromDatabase(typeof(DefDatabase <IncidentDef>), new List <Def> { incident }); } } } if (ModStuff.Settings.LogRemovals) { Log.Message(DebugString.ToString()); } else { Log.Message("Removed " + removedDefs + " spacer defs"); } PawnWeaponGenerator.Reset(); PawnApparelGenerator.Reset(); Debug.Log(DebugString.ToString()); DebugString = new StringBuilder(); }
private static void DoPlayLoad() { DeepProfiler.Start("GraphicDatabase.Clear()"); try { GraphicDatabase.Clear(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.InitAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: true); } finally { DeepProfiler.End(); } DeepProfiler.Start("TKeySystem.BuildMappings()"); try { TKeySystem.BuildMappings(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Inject selected language data into game data (early pass)."); try { LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DirectXmlCrossRefLoader.Clear(); DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve)."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); Pawn.ResetStaticData(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); BaseGen.Reset(); ResourceCounter.ResetDefs(); ApparelProperties.ResetStaticData(); WildPlantSpawner.ResetStaticData(); PawnGenerator.Reset(); TunnelHiveSpawner.ResetStaticData(); Hive.ResetStaticData(); ExpectationsUtility.Reset(); WealthWatcher.ResetStaticData(); SkillUI.Reset(); QuestNode_GetThingPlayerCanProduce.ResetStaticData(); Pawn_PsychicEntropyTracker.ResetStaticData(); ColoredText.ResetStaticData(); QuestNode_GetRandomNegativeGameCondition.ResetStaticData(); RoyalTitleUtility.ResetStaticData(); RewardsGenerator.ResetStaticData(); WorkGiver_FillFermentingBarrel.ResetStaticData(); WorkGiver_DoBill.ResetStaticData(); WorkGiver_InteractAnimal.ResetStaticData(); WorkGiver_Warden_DoExecution.ResetStaticData(); WorkGiver_GrowerSow.ResetStaticData(); WorkGiver_Miner.ResetStaticData(); WorkGiver_FixBrokenDownBuilding.ResetStaticData(); WorkGiver_ConstructDeliverResources.ResetStaticData(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { DeepProfiler.Start("ThingCategoryDef resolver"); try { DefDatabase <ThingCategoryDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } DeepProfiler.Start("RecipeDef resolver"); try { DeepProfiler.enabled = false; DefDatabase <RecipeDef> .ResolveAllReferences(onlyExactlyMyType : true, parallel : true); DeepProfiler.enabled = true; } finally { DeepProfiler.End(); } DeepProfiler.Start("Static resolver calls"); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (!(item2 == typeof(ThingDef)) && !(item2 == typeof(ThingCategoryDef)) && !(item2 == typeof(RecipeDef))) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true, false); } } } finally { DeepProfiler.End(); } DeepProfiler.Start("ThingDef resolver"); try { DefDatabase <ThingDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve)."); try { PawnWeaponGenerator.Reset(); BuildingProperties.FinalizeInit(); ThingSetMakerUtility.Reset(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Static constructor calls"); try { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Garbage Collection"); try { AbstractFilesystem.ClearAllCache(); GC.Collect(int.MaxValue, GCCollectionMode.Forced); } finally { DeepProfiler.End(); } }); }
private static void DoPlayLoad() { GraphicDatabase.Clear(); DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.LoadAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); PawnWeaponGenerator.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); WorkGiver_FillFermentingBarrel.Reset(); WorkGiver_DoBill.Reset(); Pawn.Reset(); WorkGiver_InteractAnimal.Reset(); WorkGiver_Warden_DoExecution.Reset(); WorkGiver_GrowerSow.Reset(); WorkGiver_Miner.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); WorkGiver_FixBrokenDownBuilding.CacheTranslations(); ItemCollectionGeneratorUtility.Reset(); BaseGen.Reset(); HealthUtility.Reset(); ResourceCounter.ResetDefs(); WildSpawner.Reset(); ApparelProperties.Reset(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (item2 != typeof(ThingDef)) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true); } } DefDatabase <ThingDef> .ResolveAllReferences(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } }); }
static RemoveModernStuff() { DebugString.AppendLine("Lord of the Rings - The Third Age - Start Removal Log"); DebugString.AppendLine("Tech Limiter Active: Max Level = " + MAX_TECHLEVEL.ToString()); giveApproppriateTechLevels(); removedDefs = 0; IEnumerable <ResearchProjectDef> projects = DefDatabase <ResearchProjectDef> .AllDefs.Where(rpd => rpd.techLevel > MAX_TECHLEVEL); things = new HashSet <ThingDef>(DefDatabase <ThingDef> .AllDefs.Where(td => td.techLevel > MAX_TECHLEVEL || (td.researchPrerequisites?.Any(rpd => projects.Contains(rpd)) ?? false) || new[] { "Gun_Revolver", "VanometricPowerCell", "PsychicEmanator", "InfiniteChemreactor", "Joywire", "Painstopper" }.Contains(td.defName))); DebugString.AppendLine("RecipeDef Removal List"); var recipeDefsToRemove = DefDatabase <RecipeDef> .AllDefs.Where(rd => rd.products.Any(tcc => things.Contains(tcc.thingDef)) || rd.AllRecipeUsers.All(td => things.Contains(td)) || projects.Contains(rd.researchPrerequisite)).Cast <Def>().ToList(); recipeDefsToRemove?.RemoveAll(x => x.defName == "ExtractMetalFromSlag" || x.defName == "SmeltWeapon" || x.defName == "DestroyWeapon" || x.defName == "OfferingOfPlants_Meagre" || x.defName == "OfferingOfPlants_Decent" || x.defName == "OfferingOfPlants_Sizable" || x.defName == "OfferingOfPlants_Worthy" || x.defName == "OfferingOfPlants_Impressive" || x.defName == "OfferingOfMeat_Meagre" || x.defName == "OfferingOfMeat_Decent" || x.defName == "OfferingOfMeat_Sizable" || x.defName == "OfferingOfMeat_Worthy" || x.defName == "OfferingOfMeat_Impressive" || x.defName == "OfferingOfMeals_Meagre" || x.defName == "OfferingOfMeals_Decent" || x.defName == "OfferingOfMeals_Sizable" || x.defName == "OfferingOfMeals_Worthy" || x.defName == "OfferingOfMeals_Impressive" || x.defName == "ROMV_ExtractBloodVial" || x.defName == "ROMV_ExtractBloodPack" ); RemoveStuffFromDatabase(typeof(DefDatabase <RecipeDef>), recipeDefsToRemove); DebugString.AppendLine("ResearchProjectDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ResearchProjectDef>), projects.Cast <Def>()); DebugString.AppendLine("Scenario Part Removal List"); FieldInfo getThingInfo = typeof(ScenPart_ThingCount).GetField("thingDef", BindingFlags.NonPublic | BindingFlags.Instance); foreach (ScenarioDef def in DefDatabase <ScenarioDef> .AllDefs) { foreach (ScenPart sp in def.scenario.AllParts) { if (sp is ScenPart_ThingCount && things.Contains((ThingDef)getThingInfo?.GetValue(sp))) { def.scenario.RemovePart(sp); DebugString.AppendLine("- " + sp.Label + " " + ((ThingDef)getThingInfo?.GetValue(sp)).label + " from " + def.label); } } } foreach (ThingCategoryDef thingCategoryDef in DefDatabase <ThingCategoryDef> .AllDefs) { thingCategoryDef.childThingDefs.RemoveAll(things.Contains); } DebugString.AppendLine("Stock Generator Part Cleanup"); foreach (TraderKindDef tkd in DefDatabase <TraderKindDef> .AllDefs) { for (int i = tkd.stockGenerators.Count - 1; i >= 0; i--) { StockGenerator stockGenerator = tkd.stockGenerators[i]; switch (stockGenerator) { case StockGenerator_SingleDef sd when things.Contains(Traverse.Create(sd).Field("thingDef") .GetValue <ThingDef>()): ThingDef def = Traverse.Create(sd).Field("thingDef") .GetValue <ThingDef>(); tkd.stockGenerators.Remove(stockGenerator); DebugString.AppendLine("- " + def.label + " from " + tkd.label + "'s StockGenerator_SingleDef"); break; case StockGenerator_MultiDef md: Traverse thingListTraverse = Traverse.Create(md).Field("thingDefs"); List <ThingDef> thingList = thingListTraverse.GetValue <List <ThingDef> >(); var removeList = thingList.FindAll(things.Contains); removeList?.ForEach(x => DebugString.AppendLine("- " + x.label + " from " + tkd.label + "'s StockGenerator_MultiDef")); thingList.RemoveAll(things.Contains); if (thingList.NullOrEmpty()) { tkd.stockGenerators.Remove(stockGenerator); } else { thingListTraverse.SetValue(thingList); } break; } } } DebugString.AppendLine("IncidentDef Removal List"); IEnumerable <IncidentDef> incidents = DefDatabase <IncidentDef> .AllDefs .Where(id => new[] { typeof (IncidentWorker_ShipChunkDrop ), AccessTools .TypeByName( "IncidentWorker_ShipPartCrash"), typeof (IncidentWorker_QuestJourneyOffer ), typeof (IncidentWorker_ResourcePodCrash ), //typeof(IncidentWorker_RefugeePodCrash), typeof(IncidentWorker_TransportPodCrash), typeof (IncidentWorker_PsychicDrone ), typeof (IncidentWorker_RansomDemand ), typeof (IncidentWorker_ShortCircuit ), typeof (IncidentWorker_OrbitalTraderArrival ), typeof (IncidentWorker_PsychicSoothe ) }.SelectMany( it => it .AllSubclassesNonAbstract() .Concat( it)) .ToArray() .Contains( id .workerClass) || new[] { "Disease_FibrousMechanites", "Disease_SensoryMechanites", "RaidEnemyEscapeShip", "StrangerInBlackJoin" }.Contains( id .defName)).ToList(); foreach (IncidentDef incident in incidents) { incident.targetTags?.Clear(); incident.baseChance = 0f; incident.allowedBiomes?.Clear(); incident.earliestDay = int.MaxValue; } RemoveStuffFromDatabase(typeof(DefDatabase <IncidentDef>), incidents.Cast <Def>()); DebugString.AppendLine("Replaced Ancient Asphalt Road / Ancient Asphalt Highway with Stone Road"); RoadDef[] targetRoads = { RoadDefOf.AncientAsphaltRoad, RoadDefOf.AncientAsphaltHighway }; RoadDef originalRoad = DefDatabase <RoadDef> .GetNamed("StoneRoad"); List <string> fieldNames = AccessTools.GetFieldNames(typeof(RoadDef)); fieldNames.Remove("defName"); foreach (FieldInfo fi in fieldNames.Select(name => AccessTools.Field(typeof(RoadDef), name))) { object fieldValue = fi.GetValue(originalRoad); foreach (RoadDef targetRoad in targetRoads) { fi.SetValue(targetRoad, fieldValue); } } DebugString.AppendLine("Special Hediff Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <HediffDef>), (hediffs = new[] { HediffDefOf.Gunshot }).Cast <Def>()); DebugString.AppendLine("RaidStrategyDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <RaidStrategyDef>), DefDatabase <RaidStrategyDef> .AllDefs .Where(rs => typeof(ScenPart_ThingCount).IsAssignableFrom(rs.workerClass)).Cast <Def>()); // ItemCollectionGeneratorUtility.allGeneratableItems.RemoveAll(match: things.Contains); // // foreach (Type type in typeof(ItemCollectionGenerator_Standard).AllSubclassesNonAbstract()) // type.GetMethod(name: "Reset")?.Invoke(obj: null, parameters: null); DebugString.AppendLine("ThingDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ThingDef>), things.ToArray()); DebugString.AppendLine("ThingSetMaker Reset"); ThingSetMakerUtility.Reset(); DebugString.AppendLine("TraitDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <TraitDef>), // { nameof(TraitDefOf.Prosthophobe), "Prosthophile" } ? DefDatabase <TraitDef> .AllDefs .Where(td => new[] { nameof(TraitDefOf.BodyPurist), "Transhumanist" }.Contains(td.defName)) .Cast <Def>()); DebugString.AppendLine("Designators Resolved Again"); MethodInfo resolveDesignatorsAgain = typeof(DesignationCategoryDef).GetMethod("ResolveDesignators", BindingFlags.NonPublic | BindingFlags.Instance); foreach (DesignationCategoryDef dcd in DefDatabase <DesignationCategoryDef> .AllDefs) { resolveDesignatorsAgain?.Invoke(dcd, null); } DebugString.AppendLine("PawnKindDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <PawnKindDef>), DefDatabase <PawnKindDef> .AllDefs .Where(pkd => (!pkd.defaultFactionType?.isPlayer ?? false) && (pkd.race.techLevel > MAX_TECHLEVEL || pkd.defaultFactionType?.techLevel > MAX_TECHLEVEL) && !pkd.defName.EqualsIgnoreCase("Villager") && !pkd.defName.EqualsIgnoreCase("SpaceRefugee")) .Cast <Def>()); DebugString.AppendLine("FactionDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <FactionDef>), DefDatabase <FactionDef> .AllDefs.Where(fd => !fd.isPlayer && fd.techLevel > MAX_TECHLEVEL).Cast <Def>()); DebugString.AppendLine("BackstoryDef Removal List"); BackstoryHandler.RemoveIncompatibleBackstories(DebugString); DebugString.AppendLine("MapGeneratorDef Removal List"); DebugString.AppendLine("- GenStep_SleepingMechanoids"); DebugString.AppendLine("- GenStep_Turrets"); DebugString.AppendLine("- GenStep_Power"); foreach (MapGeneratorDef mgd in DefDatabase <MapGeneratorDef> .AllDefs) { mgd.genSteps.RemoveAll(gs => gs.genStep is GenStep_SleepingMechanoids || gs.genStep is GenStep_Turrets || gs.genStep is GenStep_Power); } DebugString.AppendLine("RuleDef Removal List"); DebugString.AppendLine("- SymbolResolver_AncientCryptosleepCasket"); DebugString.AppendLine("- SymbolResolver_ChargeBatteries"); DebugString.AppendLine("- SymbolResolver_EdgeMannedMortor"); DebugString.AppendLine("- SymbolResolver_FirefoamPopper"); DebugString.AppendLine("- SymbolResolver_MannedMortar"); DebugString.AppendLine("- SymbolResolver_"); foreach (RuleDef rd in DefDatabase <RuleDef> .AllDefs) { rd.resolvers.RemoveAll(sr => sr is SymbolResolver_AncientCryptosleepCasket || sr is SymbolResolver_ChargeBatteries || sr is SymbolResolver_EdgeMannedMortar || sr is SymbolResolver_FirefoamPopper || sr is SymbolResolver_MannedMortar || sr is SymbolResolver_OutdoorLighting); if (rd.resolvers.Count == 0) { rd.resolvers.Add(new SymbolResolver_AddWortToFermentingBarrels()); } } Log.Message("Removed " + removedDefs + " modern defs"); PawnWeaponGenerator.Reset(); PawnApparelGenerator.Reset(); Debug.Log(DebugString.ToString()); DebugString = new StringBuilder(); }
static RemoveMedievalStuff() { DebugString.AppendLine("RemoveMedievalStuff - Start Removal Log"); DebugString.AppendLine("Tech Max Level = " + MAX_TECHLEVEL); removedDefs = 0; IEnumerable <ResearchProjectDef> projects = new List <ResearchProjectDef>(); if (ModStuff.Settings.LimitResearch) { projects = DefDatabase <ResearchProjectDef> .AllDefs.Where(rpd => rpd.techLevel > MAX_TECHLEVEL); } if (ModStuff.Settings.LimitItems) { things = new HashSet <ThingDef>(DefDatabase <ThingDef> .AllDefs.Where(td => td.techLevel > MAX_TECHLEVEL || (td.researchPrerequisites?.Any(rpd => projects.Contains(rpd)) ?? false))); } DebugString.AppendLine("RecipeDef Removal List"); foreach (var thing in from thing in things where thing.tradeTags != null select thing) { var tags = thing.tradeTags.ToArray(); foreach (var tag in tags) { if (tag.StartsWith("CE_AutoEnableCrafting")) { thing.tradeTags.Remove(tag); } } } DebugString.AppendLine("ResearchProjectDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ResearchProjectDef>), projects); DebugString.AppendLine("Scenario Part Removal List"); var getThingInfo = typeof(ScenPart_ThingCount).GetField("thingDef", BindingFlags.NonPublic | BindingFlags.Instance); foreach (var def in DefDatabase <ScenarioDef> .AllDefs) { foreach (var sp in def.scenario.AllParts) { if (!(sp is ScenPart_ThingCount) || !things.Contains((ThingDef)getThingInfo?.GetValue(sp))) { continue; } def.scenario.RemovePart(sp); DebugString.AppendLine("- " + sp.Label + " " + ((ThingDef)getThingInfo?.GetValue(sp))?.label + " from " + def.label); } } foreach (var thingCategoryDef in DefDatabase <ThingCategoryDef> .AllDefs) { thingCategoryDef.childThingDefs.RemoveAll(things.Contains); } DebugString.AppendLine("Stock Generator Part Cleanup"); foreach (var tkd in DefDatabase <TraderKindDef> .AllDefs) { for (var i = tkd.stockGenerators.Count - 1; i >= 0; i--) { var stockGenerator = tkd.stockGenerators[i]; switch (stockGenerator) { case StockGenerator_SingleDef sd when things.Contains(Traverse.Create(sd).Field("thingDef").GetValue <ThingDef>()): var def = Traverse.Create(sd).Field("thingDef").GetValue <ThingDef>(); tkd.stockGenerators.Remove(stockGenerator); DebugString.AppendLine("- " + def.label + " from " + tkd.label + "'s StockGenerator_SingleDef"); break; case StockGenerator_MultiDef md: var thingListTraverse = Traverse.Create(md).Field("thingDefs"); var thingList = thingListTraverse.GetValue <List <ThingDef> >(); var removeList = thingList.FindAll(things.Contains); removeList.ForEach(x => DebugString.AppendLine("- " + x.label + " from " + tkd.label + "'s StockGenerator_MultiDef")); thingList.RemoveAll(things.Contains); if (thingList.NullOrEmpty()) { tkd.stockGenerators.Remove(stockGenerator); } else { thingListTraverse.SetValue(thingList); } break; } } } DebugString.AppendLine("ThingDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <ThingDef>), things.ToArray()); DebugString.AppendLine("ThingSetMaker Reset"); ThingSetMakerUtility.Reset(); DebugString.AppendLine("Designators Resolved Again"); var resolveDesignatorsAgain = typeof(DesignationCategoryDef).GetMethod("ResolveDesignators", BindingFlags.NonPublic | BindingFlags.Instance); foreach (var dcd in DefDatabase <DesignationCategoryDef> .AllDefs) { resolveDesignatorsAgain?.Invoke(dcd, null); } if (ModStuff.Settings.LimitPawns) { DebugString.AppendLine("PawnKindDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <PawnKindDef>), DefDatabase <PawnKindDef> .AllDefs.Where(pkd => (!pkd.defaultFactionType?.isPlayer ?? false) && pkd.race.techLevel > MAX_TECHLEVEL)); } if (ModStuff.Settings.LimitFactions) { DebugString.AppendLine("FactionDef Removal List"); RemoveStuffFromDatabase(typeof(DefDatabase <FactionDef>), DefDatabase <FactionDef> .AllDefs.Where(fd => !fd.isPlayer && fd.techLevel > MAX_TECHLEVEL)); if (ModLister.RoyaltyInstalled) { var incident = DefDatabase <IncidentDef> .GetNamedSilentFail("CaravanArrivalTributeCollector"); if (incident != null) { RemoveStuffFromDatabase(typeof(DefDatabase <IncidentDef>), new List <Def> { incident }); } } // foreach (var factionDef in DefDatabase<FactionDef>.AllDefs.Where(fd => !fd.isPlayer && fd.techLevel > MAX_TECHLEVEL)) // { // factionDef.hidden = true; // factionDef.canMakeRandomly = false; // factionDef.maxCountAtGameStart = 0; // } } if (ModStuff.Settings.LogRemovals) { Log.Message(DebugString.ToString()); } else { Log.Message("Removed " + removedDefs + " industrial defs"); } PawnWeaponGenerator.Reset(); PawnApparelGenerator.Reset(); Debug.Log(DebugString.ToString()); DebugString = new StringBuilder(); }
public override IEnumerable <string> ConfigErrors() { foreach (string err in this.< ConfigErrors > __BaseCallProxy0()) { yield return(err); } if (this.race == null) { yield return("no race"); } else if (this.RaceProps.Humanlike && this.backstoryCategory.NullOrEmpty()) { yield return("Humanlike needs backstoryCategory."); } if (this.baseRecruitDifficulty > 1.0001f) { yield return(this.defName + " recruitDifficulty is greater than 1. 1 means impossible to recruit."); } if (this.combatPower < 0f) { yield return(this.defName + " has no combatPower."); } if (this.weaponMoney != FloatRange.Zero) { float minCost = 999999f; int i; for (i = 0; i < this.weaponTags.Count; i++) { IEnumerable <ThingDef> source = from d in DefDatabase <ThingDef> .AllDefs where d.weaponTags != null && d.weaponTags.Contains(this.weaponTags[i]) select d; if (source.Any <ThingDef>()) { minCost = Mathf.Min(minCost, source.Min((ThingDef d) => PawnWeaponGenerator.CheapestNonDerpPriceFor(d))); } } if (minCost > this.weaponMoney.min) { yield return(string.Concat(new object[] { "Cheapest weapon with one of my weaponTags costs ", minCost, " but weaponMoney min is ", this.weaponMoney.min, ", so could end up weaponless." })); } } if (!this.RaceProps.Humanlike && this.lifeStages.Count != this.RaceProps.lifeStageAges.Count) { yield return(string.Concat(new object[] { "PawnKindDef defines ", this.lifeStages.Count, " lifeStages while race def defines ", this.RaceProps.lifeStageAges.Count })); } if (this.apparelRequired != null) { for (int k = 0; k < this.apparelRequired.Count; k++) { for (int j = k + 1; j < this.apparelRequired.Count; j++) { if (!ApparelUtility.CanWearTogether(this.apparelRequired[k], this.apparelRequired[j], this.race.race.body)) { yield return(string.Concat(new object[] { "required apparel can't be worn together (", this.apparelRequired[k], ", ", this.apparelRequired[j], ")" })); } } } } yield break; }