コード例 #1
0
        public static List <Pair <Def, string> > GetUnlockDefsAndDescs(this ResearchProjectDef research)
        {
            if (_unlocksCache.ContainsKey(research.shortHash))
            {
                return(_unlocksCache [research.shortHash]);
            }

            List <Pair <Def, string> > unlocks = new List <Pair <Def, string> > ();

            // dumps recipes/plants unlocked, because of the peculiar way CCL helpdefs are done.
            List <ThingDef> dump = new List <ThingDef> ();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string> (d, "AllowsBuildingX".Translate(d.LabelCap))));
            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string> (d, "AllowsBuildingX".Translate(d.LabelCap))));
            unlocks.AddRange(research.GetRecipesUnlocked(ref dump)
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string> (d, "AllowsCraftingX".Translate(d.LabelCap))));
            string sowTags = string.Join(" and ", research.GetSowTagsUnlocked(ref dump).ToArray());

            unlocks.AddRange(dump.Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string> (d, "AllowsSowingXinY".Translate(d.LabelCap, sowTags))));

            _unlocksCache.Add(research.shortHash, unlocks);
            return(unlocks);
        }
コード例 #2
0
        public static List <Pair <Def, string> > GetDirectUnlocks(this ResearchProjectDef research, bool dedupe = false)
        {
            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetDirectRecipesUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsCraftingX(d.LabelCap))));

            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsPlantingX(d.LabelCap))));

            var descendants = research.Descendants();

            if (dedupe && descendants.Any())
            {
                var descendantUnlocks = descendants
                                        .SelectMany(c => c.GetUnlockDefsAndDescs(false).Select(u => u.First))
                                        .Distinct()
                                        .ToList();
                unlocks = unlocks.Where(u => !descendantUnlocks.Contains(u.First)).ToList();
            }

            return(unlocks);
        }
コード例 #3
0
        public static List <ThingDef> UnlockedWeapons(this ResearchProjectDef tech)
        {
            List <ThingDef> result = new List <ThingDef>();

            foreach (RecipeDef r in tech.GetRecipesUnlocked().Where(x => !x.products.NullOrEmpty()))
            {
                foreach (ThingDef weapon in r.products.Where(x => x.thingDef != null).Select(x => x.thingDef).Where(ShouldLockWeapon))
                {
                    result.Add(weapon);
                    if (!TechByWeapon.ContainsKey(weapon))
                    {
                        TechByWeapon.Add(weapon, tech);
                    }
                }
            }
            foreach (ThingDef weapon in tech.GetThingsUnlocked().Where(x => x.building != null && x.building.turretGunDef != null).Select(x => x.building.turretGunDef))
            {
                result.Add(weapon);
                if (!TechByWeapon.ContainsKey(weapon))
                {
                    TechByWeapon.Add(weapon, tech);
                }
            }
            if (!result.NullOrEmpty() && (!WeaponsByTech.ContainsKey(tech) || WeaponsByTech[tech].EnumerableNullOrEmpty()))
            {
                WeaponsByTech.Add(tech, result);
            }
            return(result);
        }
コード例 #4
0
        public static List <ThingDef> UnlockedWeapons(this ResearchProjectDef tech)
        {
            List <ThingDef> result = new List <ThingDef>();

            foreach (RecipeDef r in tech.GetRecipesUnlocked().Where(x => !x.products.NullOrEmpty()))
            {
                foreach (ThingDef weapon in r.products.Select(x => x.thingDef).Where(x => x.IsWeapon && (x.weaponTags.NullOrEmpty() || !x.weaponTags.Any(t => t.Contains("Basic"))) && !(x.defName.Contains("Tool") || x.defName.Contains("tool"))))
                {
                    result.Add(weapon);
                }
            }
            foreach (ThingDef weapon in tech.GetThingsUnlocked().Where(x => x.building != null && x.building.turretGunDef != null).Select(x => x.building.turretGunDef))
            {
                result.Add(weapon);
            }
            return(result);
        }
コード例 #5
0
        public static List <Pair <Def, string> > GetUnlockDefsAndDescs(this ResearchProjectDef research)
        {
            if (_unlocksCache.ContainsKey(research))
            {
                return(_unlocksCache[research]);
            }

            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(
                                 d =>
                                 new Pair <Def, string>(d,
                                                        "Fluffy.ResearchTree.AllowsBuildingX".Translate(
                                                            d
                                                            .LabelCap))));
            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(
                                 d =>
                                 new Pair <Def, string>(d,
                                                        "Fluffy.ResearchTree.AllowsBuildingX".Translate(
                                                            d
                                                            .LabelCap))));
            unlocks.AddRange(research.GetRecipesUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(
                                 d =>
                                 new Pair <Def, string>(d,
                                                        "Fluffy.ResearchTree.AllowsCraftingX".Translate(
                                                            d
                                                            .LabelCap))));
            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(
                                 d =>
                                 new Pair <Def, string>(d,
                                                        "Fluffy.ResearchTree.AllowsPlantingX".Translate(
                                                            d
                                                            .LabelCap))));

            _unlocksCache.Add(research, unlocks);
            return(unlocks);
        }
コード例 #6
0
        public static List <Pair <Def, string> > GetUnlockDefsAndDescs(this ResearchProjectDef research, bool dedupe = true)
        {
            if (_unlocksCache.ContainsKey(research))
            {
                return(_unlocksCache[research]);
            }

            var unlocks = new List <Pair <Def, string> >();

            unlocks.AddRange(research.GetThingsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetTerrainUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsBuildingX(d.LabelCap))));

            unlocks.AddRange(research.GetRecipesUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsCraftingX(d.LabelCap))));

            unlocks.AddRange(research.GetPlantsUnlocked()
                             .Where(d => d.IconTexture() != null)
                             .Select(d => new Pair <Def, string>(d, ResourceBank.String.AllowsPlantingX(d.LabelCap))));



            // get unlocks for all descendant research, and remove duplicates.
            var descendants = research.Descendants();

            if (dedupe && descendants.Any())
            {
                var descendantUnlocks = descendants
                                        .SelectMany(c => c.GetUnlockDefsAndDescs(false).Select(u => u.First))
                                        .Distinct()
                                        .ToList();
                unlocks = unlocks.Where(u => !descendantUnlocks.Contains(u.First)).ToList();
            }

            _unlocksCache.Add(research, unlocks);
            return(unlocks);
        }
コード例 #7
0
        static HelpDef HelpForResearch( ResearchProjectDef researchProjectDef, HelpCategoryDef category )
        {
            var helpDef = new HelpDef();
            helpDef.defName = researchProjectDef.defName + "_ResearchProjectDef_Help";
            helpDef.keyDef = researchProjectDef.defName;
            helpDef.label = researchProjectDef.label;
            helpDef.category = category;

            var s = new StringBuilder();

            s.AppendLine( researchProjectDef.description );
            s.AppendLine();

            #region Base Stats

            s.AppendLine( "AutoHelpTotalCost".Translate( researchProjectDef.totalCost.ToString() ) );
            s.AppendLine();

            #endregion

            #region Research, Buildings, Recipes and SowTags

            // Add research required
            var researchDefs = researchProjectDef.GetResearchRequirements();
            BuildDefDescription( s, "AutoHelpListResearchRequired".Translate(), researchDefs.ConvertAll<Def>( def =>(Def)def ) );

            // Add buildings it unlocks
            var thingDefs = researchProjectDef.GetThingsUnlocked();
            BuildDefDescription( s, "AutoHelpListThingsUnlocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) );

            // Add recipes it unlocks
            var recipeDefs = researchProjectDef.GetRecipesUnlocked( ref thingDefs );
            BuildDefWithDefDescription( s, "AutoHelpListRecipesUnlocked".Translate(), "AutoHelpListRecipesOnThingsUnlocked".Translate(), recipeDefs.ConvertAll<Def>( def =>(Def)def ), thingDefs.ConvertAll<Def>( def =>(Def)def ) );

            // Look in advanced research to add plants and sow tags it unlocks
            var sowTags = researchProjectDef.GetSowTagsUnlocked( ref thingDefs );
            BuildDefWithStringDescription( s, "AutoHelpListPlantsUnlocked".Translate(), "AutoHelpListPlantsIn".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ), sowTags );

            #endregion

            #region Lockouts

            // Get advanced research which locks
            researchDefs = researchProjectDef.GetResearchedLockedBy();
            BuildDefDescription( s, "AutoHelpListResearchLockout".Translate(), researchDefs.ConvertAll<Def>( def =>(Def)def ) );

            #endregion

            helpDef.description = s.ToString();
            return helpDef;
        }
コード例 #8
0
        static HelpDef HelpForResearch( ResearchProjectDef researchProjectDef, HelpCategoryDef category )
        {
            var helpDef = new HelpDef();
            helpDef.defName = researchProjectDef.defName + "_ResearchProjectDef_Help";
            helpDef.keyDef = researchProjectDef;
            helpDef.label = researchProjectDef.label;
            helpDef.category = category;
            helpDef.description = researchProjectDef.description;

            #region Base Stats

            HelpDetailSection totalCost = new HelpDetailSection(null, new [] { "AutoHelpTotalCost".Translate(researchProjectDef.totalCost.ToString()) });
            helpDef.HelpDetailSections.Add( totalCost );

            #endregion

            #region Research, Buildings, Recipes and SowTags

            // Add research required
            var researchDefs = researchProjectDef.GetResearchRequirements();
            if( !researchDefs.NullOrEmpty() )
            {
                HelpDetailSection researchRequirements = new HelpDetailSection(
                    "AutoHelpListResearchRequired".Translate(),
                    researchDefs.ConvertAll<Def>(def => (Def)def));

                helpDef.HelpDetailSections.Add( researchRequirements );
            }

            // Add research unlocked
            //CCL_Log.Message(researchProjectDef.label, "getting unlocked research");
            researchDefs = researchProjectDef.GetResearchUnlocked();
            if( !researchDefs.NullOrEmpty() )
            {
                HelpDetailSection reseachUnlocked = new HelpDetailSection(
                    "AutoHelpListResearchLeadsTo".Translate(),
                    researchDefs.ConvertAll<Def>(def => (Def)def));

                helpDef.HelpDetailSections.Add( reseachUnlocked );
            }

            // Add buildings it unlocks
            var thingDefs = researchProjectDef.GetThingsUnlocked();
            if( !thingDefs.NullOrEmpty() )
            {
                HelpDetailSection thingsUnlocked = new HelpDetailSection(
                    "AutoHelpListThingsUnlocked".Translate(),
                    thingDefs.ConvertAll<Def>(def => (Def)def));

                helpDef.HelpDetailSections.Add( thingsUnlocked );
            }

            // Add recipes it unlocks
            var recipeDefs = researchProjectDef.GetRecipesUnlocked( ref thingDefs );
            if(
                (!recipeDefs.NullOrEmpty()) &&
                (!thingDefs.NullOrEmpty())
            )
            {
                HelpDetailSection recipesUnlocked = new HelpDetailSection(
                    "AutoHelpListRecipesUnlocked".Translate(),
                    recipeDefs.ConvertAll<Def>(def => (Def)def));

                helpDef.HelpDetailSections.Add( recipesUnlocked );

                HelpDetailSection recipesOnThingsUnlocked = new HelpDetailSection(
                    "AutoHelpListRecipesOnThingsUnlocked".Translate(),
                    thingDefs.ConvertAll<Def>(def => (Def)def));

                helpDef.HelpDetailSections.Add( recipesOnThingsUnlocked );
            }

            // Look in advanced research to add plants and sow tags it unlocks
            var sowTags = researchProjectDef.GetSowTagsUnlocked( ref thingDefs );
            if(
                (!sowTags.NullOrEmpty()) &&
                (!thingDefs.NullOrEmpty())
            )
            {
                HelpDetailSection plantsUnlocked = new HelpDetailSection(
                    "AutoHelpListPlantsUnlocked".Translate(),
                    thingDefs.ConvertAll<Def>( def =>(Def)def ));

                helpDef.HelpDetailSections.Add( plantsUnlocked );

                HelpDetailSection plantsIn = new HelpDetailSection(
                    "AutoHelpListPlantsIn".Translate(),
                    sowTags.ToArray());

                helpDef.HelpDetailSections.Add( plantsIn );
            }

            #endregion

            #region Lockouts

            // Get advanced research which locks
            researchDefs = researchProjectDef.GetResearchedLockedBy();
            if( !researchDefs.NullOrEmpty() )
            {
                HelpDetailSection researchLockout = new HelpDetailSection(
                    "AutoHelpListResearchLockout".Translate(),
                    researchDefs.ConvertAll<Def>( def =>(Def)def ) );

                helpDef.HelpDetailSections.Add( researchLockout );
            }

            #endregion

            return helpDef;
        }