Exemplo n.º 1
0
        private static IEnumerable <RecipeDef> DefsFromRecipeMakers()
        {
            using (IEnumerator <ThingDef> enumerator = (from d in DefDatabase <ThingDef> .AllDefs
                                                        where d.recipeMaker != null
                                                        select d).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    ThingDef def             = enumerator.Current;
                    RecipeMakerProperties rm = def.recipeMaker;
                    RecipeDef             r  = new RecipeDef
                    {
                        defName        = "Make_" + def.defName,
                        label          = "RecipeMake".Translate(def.label),
                        jobString      = "RecipeMakeJobString".Translate(def.label),
                        modContentPack = def.modContentPack,
                        workAmount     = (float)rm.workAmount,
                        workSpeedStat  = rm.workSpeedStat,
                        efficiencyStat = rm.efficiencyStat
                    };
                    if (def.MadeFromStuff)
                    {
                        IngredientCount ingredientCount = new IngredientCount();
                        ingredientCount.SetBaseCount((float)def.costStuffCount);
                        ingredientCount.filter.SetAllowAllWhoCanMake(def);
                        r.ingredients.Add(ingredientCount);
                        r.fixedIngredientFilter.SetAllowAllWhoCanMake(def);
                        r.productHasIngredientStuff = true;
                    }
                    if (def.costList != null)
                    {
                        foreach (ThingDefCountClass cost in def.costList)
                        {
                            IngredientCount ingredientCount2 = new IngredientCount();
                            ingredientCount2.SetBaseCount((float)cost.count);
                            ingredientCount2.filter.SetAllow(cost.thingDef, allow: true);
                            r.ingredients.Add(ingredientCount2);
                        }
                    }
                    r.defaultIngredientFilter = rm.defaultIngredientFilter;
                    r.products.Add(new ThingDefCountClass(def, rm.productCount));
                    r.targetCountAdjustment   = rm.targetCountAdjustment;
                    r.skillRequirements       = rm.skillRequirements.ListFullCopyOrNull();
                    r.workSkill               = rm.workSkill;
                    r.workSkillLearnFactor    = rm.workSkillLearnPerTick;
                    r.unfinishedThingDef      = rm.unfinishedThingDef;
                    r.recipeUsers             = rm.recipeUsers.ListFullCopyOrNull();
                    r.effectWorking           = rm.effectWorking;
                    r.soundWorking            = rm.soundWorking;
                    r.researchPrerequisite    = rm.researchPrerequisite;
                    r.factionPrerequisiteTags = rm.factionPrerequisiteTags;
                    yield return(r);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_03ca:
            /*Error near IL_03cb: Unexpected return in MoveNext()*/;
        }
Exemplo n.º 2
0
 private static IEnumerable <RecipeDef> DefsFromRecipeMakers()
 {
     foreach (ThingDef def in from d in DefDatabase <ThingDef> .AllDefs
              where d.recipeMaker != null
              select d)
     {
         RecipeMakerProperties rm = def.recipeMaker;
         RecipeDef             r  = new RecipeDef();
         r.defName = "Make_" + def.defName;
         r.label   = "RecipeMake".Translate(new object[]
         {
             def.label
         });
         r.jobString = "RecipeMakeJobString".Translate(new object[]
         {
             def.label
         });
         r.modContentPack = def.modContentPack;
         r.workAmount     = (float)rm.workAmount;
         r.workSpeedStat  = rm.workSpeedStat;
         r.efficiencyStat = rm.efficiencyStat;
         if (def.MadeFromStuff)
         {
             IngredientCount ingredientCount = new IngredientCount();
             ingredientCount.SetBaseCount((float)def.costStuffCount);
             ingredientCount.filter.SetAllowAllWhoCanMake(def);
             r.ingredients.Add(ingredientCount);
             r.fixedIngredientFilter.SetAllowAllWhoCanMake(def);
             r.productHasIngredientStuff = true;
         }
         if (def.costList != null)
         {
             foreach (ThingDefCountClass thingDefCountClass in def.costList)
             {
                 IngredientCount ingredientCount2 = new IngredientCount();
                 ingredientCount2.SetBaseCount((float)thingDefCountClass.count);
                 ingredientCount2.filter.SetAllow(thingDefCountClass.thingDef, true);
                 r.ingredients.Add(ingredientCount2);
             }
         }
         r.defaultIngredientFilter = rm.defaultIngredientFilter;
         r.products.Add(new ThingDefCountClass(def, rm.productCount));
         r.targetCountAdjustment   = rm.targetCountAdjustment;
         r.skillRequirements       = rm.skillRequirements.ListFullCopyOrNull <SkillRequirement>();
         r.workSkill               = rm.workSkill;
         r.workSkillLearnFactor    = rm.workSkillLearnPerTick;
         r.unfinishedThingDef      = rm.unfinishedThingDef;
         r.recipeUsers             = rm.recipeUsers.ListFullCopyOrNull <ThingDef>();
         r.effectWorking           = rm.effectWorking;
         r.soundWorking            = rm.soundWorking;
         r.researchPrerequisite    = rm.researchPrerequisite;
         r.factionPrerequisiteTags = rm.factionPrerequisiteTags;
         yield return(r);
     }
     yield break;
 }
        private static RecipeDef CreateRecipeDefFromMaker(ThingDef def, int adjustedCount = 1)
        {
            RecipeMakerProperties recipeMaker = def.recipeMaker;
            RecipeDef             recipeDef   = new RecipeDef();

            recipeDef.defName = "Make_" + def.defName;
            if (adjustedCount != 1)
            {
                recipeDef.defName += "Bulk";
            }
            string text = def.label;

            if (adjustedCount != 1)
            {
                text = text + " x" + adjustedCount;
            }
            recipeDef.label          = "RecipeMake".Translate(text);
            recipeDef.jobString      = "RecipeMakeJobString".Translate(text);
            recipeDef.modContentPack = def.modContentPack;
            recipeDef.workAmount     = recipeMaker.workAmount * adjustedCount;
            recipeDef.workSpeedStat  = recipeMaker.workSpeedStat;
            recipeDef.efficiencyStat = recipeMaker.efficiencyStat;
            if (def.MadeFromStuff)
            {
                IngredientCount ingredientCount = new IngredientCount();
                ingredientCount.SetBaseCount(def.costStuffCount * adjustedCount);
                ingredientCount.filter.SetAllowAllWhoCanMake(def);
                recipeDef.ingredients.Add(ingredientCount);
                recipeDef.fixedIngredientFilter.SetAllowAllWhoCanMake(def);
                recipeDef.productHasIngredientStuff = true;
            }
            recipeDef.useIngredientsForColor = recipeMaker.useIngredientsForColor;
            if (def.costList != null)
            {
                foreach (ThingDefCountClass cost in def.costList)
                {
                    IngredientCount ingredientCount2 = new IngredientCount();
                    ingredientCount2.SetBaseCount(cost.count * adjustedCount);
                    ingredientCount2.filter.SetAllow(cost.thingDef, allow: true);
                    recipeDef.ingredients.Add(ingredientCount2);
                }
            }
            recipeDef.defaultIngredientFilter = recipeMaker.defaultIngredientFilter;
            recipeDef.products.Add(new ThingDefCountClass(def, recipeMaker.productCount * adjustedCount));
            recipeDef.targetCountAdjustment   = recipeMaker.targetCountAdjustment * adjustedCount;
            recipeDef.skillRequirements       = recipeMaker.skillRequirements.ListFullCopyOrNull();
            recipeDef.workSkill               = recipeMaker.workSkill;
            recipeDef.workSkillLearnFactor    = recipeMaker.workSkillLearnPerTick;
            recipeDef.requiredGiverWorkType   = recipeMaker.requiredGiverWorkType;
            recipeDef.unfinishedThingDef      = recipeMaker.unfinishedThingDef;
            recipeDef.recipeUsers             = recipeMaker.recipeUsers.ListFullCopyOrNull();
            recipeDef.effectWorking           = recipeMaker.effectWorking;
            recipeDef.soundWorking            = recipeMaker.soundWorking;
            recipeDef.researchPrerequisite    = recipeMaker.researchPrerequisite;
            recipeDef.researchPrerequisites   = recipeMaker.researchPrerequisites;
            recipeDef.factionPrerequisiteTags = recipeMaker.factionPrerequisiteTags;
            string[] items = recipeDef.products.Select((ThingDefCountClass p) => (p.count != 1) ? p.Label : Find.ActiveLanguageWorker.WithIndefiniteArticle(p.thingDef.label)).ToArray();
            recipeDef.description           = "RecipeMakeDescription".Translate(items.ToCommaList(useAnd: true));
            recipeDef.descriptionHyperlinks = recipeDef.products.Select((ThingDefCountClass p) => new DefHyperlink(p.thingDef)).ToList();
            if (adjustedCount != 1 && recipeDef.workAmount < 0f)
            {
                recipeDef.workAmount = recipeDef.WorkAmountTotal(null) * (float)adjustedCount;
            }
            return(recipeDef);
        }