Exemple #1
0
        private static IEnumerable <RecipeDef> ImpliedRecipeDefs()
        {
            foreach (ThingDef def in from d in DefDatabase <ThingDef> .AllDefs
                     where d.HasComp(typeof(CompMountable))
                     select d)
            {
                RecipeDef r = new RecipeDef();
                r.defName                 = "WTH_Mount_" + def.defName;
                r.label                   = "WTH_Mount".Translate(new object[] { def.label });
                r.jobString               = "WTH_Mount_Jobstring".Translate(new object[] { def.label });
                r.workerClass             = typeof(Recipe_MountTurret);
                r.appliedOnFixedBodyParts = new List <BodyPartDef>()
                {
                    WTH_DefOf.Reactor
                };
                r.anesthetize   = false;
                r.effectWorking = DefDatabase <EffecterDef> .AllDefs.FirstOrDefault((EffecterDef ed) => ed.defName == "Repair");

                r.surgerySuccessChanceFactor = 99999f;
                r.modContentPack             = def.modContentPack;
                r.workAmount = 2000f;
                r.addsHediff = WTH_DefOf.WTH_MountedTurret;
                IngredientCount ic = new IngredientCount();
                ic.SetBaseCount(1f);
                ic.filter.SetAllow(def, true);
                r.ingredients.Add(ic);
                r.fixedIngredientFilter.SetAllow(def, true);
                r.recipeUsers   = new List <ThingDef>();
                r.modExtensions = new List <DefModExtension>()
                {
                    new DefModExtension_Recipe()
                    {
                        requireBed     = true,
                        requiredHediff = WTH_DefOf.WTH_TurretModule
                    }
                };
                foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.category == ThingCategory.Pawn && d.race.IsMechanoid))
                {
                    r.recipeUsers.Add(current);
                }
                r.ResolveReferences();
                yield return(r);
            }
        }
Exemple #2
0
        static MyStaticConstructor()
        {
            IEnumerable <ThingDef> workTables = DefDatabase <ThingDef> .AllDefs.Where(t => t.IsWorkTable);

            FieldInfo thingDefs        = typeof(ThingFilter).GetField("thingDefs", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo allRecipesCached = typeof(ThingDef).GetField("allRecipesCached", BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (ThingDef workTable in workTables)
            {
                IEnumerable <RecipeDef> tableRecipes = workTable.AllRecipes.Where(r => r.ProducedThingDef?.HasSmeltProducts() ?? false);
                // If the table has no relevant recipes, no point doing anything else for it.
                if (!tableRecipes.Any())
                {
                    continue;
                }

                ThingFilter newFilter = new ThingFilter();
                thingDefs.SetValue(newFilter, tableRecipes.Select(r => r.ProducedThingDef).ToList());

                IngredientCount newCount = new IngredientCount();
                newCount.SetBaseCount(1);
                newCount.filter = newFilter;

                RecipeDef generatedRecipe = new RecipeDef
                {
                    defName         = "LuluScrapAnything_DisassembleAt" + workTable.defName,
                    label           = "LuluScrapAnything_BillLabel".Translate(),
                    description     = "LuluScrapAnything_BillDesc".Translate(),
                    jobString       = "LuluScrapAnything_BillJob".Translate(workTable.label),
                    workAmount      = 1600,
                    workSpeedStat   = MyDefOf.SmeltingSpeed,
                    effectWorking   = tableRecipes.GroupBy(r => r.effectWorking).OrderByDescending(g => g.Count()).Select(o => o.Key).First(),
                    soundWorking    = tableRecipes.GroupBy(r => r.soundWorking).OrderByDescending(g => g.Count()).Select(o => o.Key).First(),
                    specialProducts = new List <SpecialProductType> {
                        SpecialProductType.Smelted
                    },
                    recipeUsers = new List <ThingDef> {
                        workTable
                    },
                    ingredients = new List <IngredientCount> {
                        newCount
                    },
                    fixedIngredientFilter     = newFilter,
                    forceHiddenSpecialFilters = new List <SpecialThingFilterDef>
                    {
                        MyDefOf.AllowBurnableApparel,
                        MyDefOf.AllowBurnableWeapons,
                        MyDefOf.AllowNonBurnableApparel,
                        MyDefOf.AllowNonBurnableWeapons,
                        MyDefOf.AllowNonSmeltableApparel,
                        MyDefOf.AllowNonSmeltableWeapons,
                        MyDefOf.AllowSmeltable,
                        MyDefOf.AllowSmeltableApparel,
                    }
                };
                generatedRecipe.ResolveReferences();
                DefDatabase <RecipeDef> .Add(generatedRecipe);

                // Clear the recipe cache because we've added a new recipe.
                allRecipesCached.SetValue(workTable, null);
            }
        }