示例#1
0
        public static bool Matches(this ResearchProjectDef tech, string query)
        {
            var culture = CultureInfo.CurrentUICulture;

            query = query.ToLower(culture);

            return
                (tech.LabelCap.RawText.ToLower(culture).Contains(query) ||
                 ResearchTree_Patches.GetUnlockDefsAndDescs(tech).Any(unlock => unlock.First.LabelCap.RawText.ToLower(culture).Contains(query)) ||
                 tech.description.ToLower(culture).Contains(query));
        }
示例#2
0
        static HarmonyPatches()
        {
            //Harmony.DEBUG = true;
            Instance.PatchAll();

            //ResearchTree/ResearchPal integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "fluffy.researchtree"))
            {
                Log.Message("[HumanResources] Deriving from ResearchTree.");
                ResearchTree_Patches.Execute(Instance, "FluffyResearchTree");
            }
            else if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "notfood.ResearchPal"))
            {
                Log.Message("[HumanResources] Deriving from ResearchPal.");
                ResearchTree_Patches.Execute(Instance, "ResearchPal");
                ResearchPal = true;
            }
            else
            {
                Log.Error("[HumanResources] Could not find ResearchTree nor ResearchPal. Human Resources will not work!");
            }

            //Go Explore! integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "Albion.GoExplore"))
            {
                Log.Message("[HumanResources] Go Explore detected! Integrating...");
                GoExplore_Patches.Execute(Instance);
            }

            //Material Filter patch
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "KamiKatze.MaterialFilter"))
            {
                Log.Message("[HumanResources] Material Filter detected! Patching...");
                MaterialFilter_Patch.Execute(Instance);
            }

            //Recipe icons patch
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "automatic.recipeicons"))
            {
                Log.Message("[HumanResources] Recipe Icons detected! Patching...");
                RecipeIcons_Patch.Execute(Instance);
            }

            //Simple Sidearms integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "PeteTimesSix.SimpleSidearms"))
            {
                Log.Message("[HumanResources] Simple Sidearms detected! Integrating...");
                SimpleSidearms_Patches.Execute(Instance);
            }
        }
示例#3
0
        public static void InferSkillBias(this ResearchProjectDef tech)
        {
            //Log.Warning("InferSkillBias Starting for "+tech.LabelCap);
            //1. check what it unlocks
            List <Pair <Def, string> > unlocks   = ResearchTree_Patches.GetUnlockDefsAndDescs(tech);
            IEnumerable <Def>          defs      = unlocks.Select(x => x.First).AsEnumerable();
            IEnumerable <ThingDef>     thingDefs = from d in defs
                                                   where d is ThingDef
                                                   select d as ThingDef;
            IEnumerable <RecipeDef> recipeDefs = from d in defs
                                                 where d is RecipeDef
                                                 select d as RecipeDef;
            IEnumerable <TerrainDef> terrainDefs = from d in defs
                                                   where d is TerrainDef
                                                   select d as TerrainDef;

            //2. look for skills based on unlocked stuff

            //a. checking by query on the research tree
            //int matches = 0;
            if (tech.Matches("scanner") > 0 | tech.Matches("terraform") > 0)
            {
                miningTag = true;                                                                /*matches++;*/
            }
            ;

            if (tech.Matches("sterile") > 0 | tech.Matches("medical") > 0 | tech.Matches("medicine") > 0 | tech.Matches("cryptosleep") > 0 | tech.Matches("prostheses") > 0 | tech.Matches("implant") > 0 | tech.Matches("organs") > 0 | tech.Matches("surgery") > 0)
            {
                medicineTag = true;                                                                                                                                                                                                                                                         /*matches++;*/
            }
            ;

            if (tech.Matches("irrigation") > 0 | tech.Matches("soil") > 0 | tech.Matches("hydroponic") > 0)
            {
                plantsTag = true;                                                                                               /*matches++;*/
            }
            ;

            if (tech.Matches("tool") > 0)
            {
                craftingTag = true;
            }

            if (tech.Matches("manage") > 0)
            {
                intellectualTag = true;
            }

            //b. checking by unlocked things
            if (thingDefs.Count() > 0)
            {
                foreach (ThingDef t in thingDefs)
                {
                    if (t != null)
                    {
                        InvestigateThingDef(t);
                    }
                }
            }

            //c. checking by unlocked recipes
            if (recipeDefs.Count() > 0)
            {
                foreach (RecipeDef r in recipeDefs)
                {
                    //Log.Message("trying recipe " + r.label);
                    foreach (ThingDef t in r.products.Select(x => x.thingDef))
                    {
                        InvestigateThingDef(t);
                    }
                    if (r.workSkill != null)
                    {
                        AccessTools.Field(typeof(Extension_Research), r.workSkill.defName.ToLower() + "Tag").SetValue(tech, true);
                    }
                }
            }

            //d. checking by unlocked terrainDefs
            if (terrainDefs.Count() > 0)
            {
                foreach (TerrainDef t in terrainDefs)
                {
                    if (!constructionTag && t.designationCategory != null && t.designationCategory.label.Contains("floor"))
                    {
                        constructionTag = true;
                    }
                    else if (!miningTag)
                    {
                        miningTag = true;
                    }
                }
            }

            //e. special cases
            if (HarmonyPatches.RunSpecialCases)
            {
                if (tech.defName.StartsWith("ResearchProject_RotR"))
                {
                    miningTag       = true;
                    constructionTag = true;
                }
                if (tech.defName.StartsWith("BackupPower") || tech.defName.StartsWith("FluffyBreakdowns"))
                {
                    constructionTag = true;
                }
            }

            //3. Figure out Bias.
            //int ThingDefCount = thingDefs.Count();
            //int RecipeDefCount = recipeDefs.Count();
            //int TerrainDefCount = terrainDefs.Count();

            List <SkillDef> relevantSkills = new List <SkillDef>();

            if (shootingTag)
            {
                relevantSkills.Add(SkillDefOf.Shooting);
                shootingTag = false;
            }
            if (meleeTag)
            {
                relevantSkills.Add(SkillDefOf.Melee);
                meleeTag = false;
            }
            if (constructionTag)
            {
                relevantSkills.Add(SkillDefOf.Construction);
                constructionTag = false;
            }
            if (miningTag)
            {
                relevantSkills.Add(SkillDefOf.Mining);
                miningTag = false;
            }
            if (cookingTag)
            {
                relevantSkills.Add(SkillDefOf.Cooking);
                cookingTag = false;
            }
            if (plantsTag)
            {
                relevantSkills.Add(SkillDefOf.Plants);
                plantsTag = false;
            }
            if (animalsTag)
            {
                relevantSkills.Add(SkillDefOf.Animals);
                animalsTag = false;
            }
            if (craftingTag)
            {
                relevantSkills.Add(SkillDefOf.Crafting);
                craftingTag = false;
            }
            if (artisticTag)
            {
                relevantSkills.Add(SkillDefOf.Artistic);
                artisticTag = false;
            }
            if (medicineTag)
            {
                relevantSkills.Add(SkillDefOf.Medicine);
                medicineTag = false;
            }
            if (socialTag)
            {
                relevantSkills.Add(SkillDefOf.Social);
                socialTag = false;
            }
            if (intellectualTag)
            {
                relevantSkills.Add(SkillDefOf.Intellectual);
                intellectualTag = false;
            }

            if (!relevantSkills.NullOrEmpty())
            {
                SkillsByTech.Add(tech, relevantSkills);
                foreach (SkillDef skill in relevantSkills)
                {
                    if (!TechsBySkill.ContainsKey(skill))
                    {
                        TechsBySkill.Add(skill, new List <ResearchProjectDef>()
                        {
                            tech
                        });
                    }
                    else
                    {
                        TechsBySkill[skill].Add(tech);
                    }
                }
            }
            else
            {
                Log.Warning("[HumanResources] No relevant skills could be calculated for " + tech + ". It won't be known by anyone.");
            }
        }
示例#4
0
        static HarmonyPatches()
        {
            //Harmony.DEBUG = true;
            Instance.PatchAll();

            //ResearchTree/ResearchPal integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("fluffy.researchtree")))
            {
                Log.Message("[HumanResources] Deriving from ResearchTree.");
                ResearchTree_Patches.Execute(Instance, "FluffyResearchTree");
            }
            else if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("notfood.ResearchPal")))
            {
                Log.Message("[HumanResources] Deriving from ResearchPal.");
                ResearchTree_Patches.Execute(Instance, "ResearchPal");
                ResearchPal = true;
            }
            else if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("VinaLx.ResearchPalForked")))
            {
                Log.Message("[HumanResources] Deriving from ResearchPal - Forked.");
                ResearchTree_Patches.Execute(Instance, "ResearchPal", true);
                ResearchPal = true;
            }
            else
            {
                Log.Error("[HumanResources] Could not find ResearchTree nor ResearchPal. Human Resources will not work!");
            }

            //Go Explore! integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("Albion.GoExplore")))
            {
                Log.Message("[HumanResources] Go Explore detected! Integrating...");
                GoExplore_Patches.Execute(Instance);
            }

            //Material Filter patch
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("KamiKatze.MaterialFilter")))
            {
                Log.Message("[HumanResources] Material Filter detected! Adapting...");
                MaterialFilter_Patch.Execute(Instance);
            }

            //Recipe icons patch
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("automatic.recipeicons")))
            {
                Log.Message("[HumanResources] Recipe Icons detected! Adapting...");
                RecipeIcons_Patch.Execute(Instance);
            }

            //Simple Sidearms integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("PeteTimesSix.SimpleSidearms")))
            {
                Log.Message("[HumanResources] Simple Sidearms detected! Integrating...");
                SimpleSidearms_Patches.Execute(Instance);
            }

            //Prison Labor integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("avius.prisonlabor")))
            {
                Log.Message("[HumanResources] Prison Labor detected! Integrating...");
                PrisonLabor = true;
            }

            //Children, School and Learning integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("Dylan.CSL")))
            {
                Log.Message("[HumanResources] Children, School and Learning detected! Integrating...");
                ChildrenSchoolLearning_Patch.Execute(Instance);
            }

            //Dual Wield integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("Roolo.DualWield")))
            {
                Log.Message("[HumanResources] Dual Wield detected! Integrating...");
                DualWield_Patch.Execute(Instance);
            }

            //Hospitality integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing.StartsWith("orion.hospitality")))
            {
                Log.Message("[HumanResources] Hospitality detected! Integrating...");
                Hospitality_Patches.Execute(Instance);
            }

            //Provisions for specific research projects
            if (LoadedModManager.RunningModsListForReading.Any(x =>
                                                               x.PackageIdPlayerFacing.StartsWith("loconeko.roadsoftherim") ||
                                                               x.PackageIdPlayerFacing.StartsWith("mlie.roadsoftherim") ||
                                                               x.PackageIdPlayerFacing.StartsWith("fluffy.backuppower") ||
                                                               x.PackageIdPlayerFacing.StartsWith("fluffy.fluffybreakdowns") ||
                                                               x.PackageIdPlayerFacing.StartsWith("Ogliss.AdMech.Armoury")))
            {
                RunSpecialCases = true;
            }
        }
        static HarmonyPatches()
        {
            //Harmony.DEBUG = true;
            Instance.PatchAll();

            //ResearchTree/ResearchPal integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "fluffy.researchtree"))
            {
                Log.Message("[HumanResources] Deriving from ResearchTree.");
                ResearchTree_Patches.Execute(Instance, "FluffyResearchTree");
            }
            else if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "notfood.ResearchPal"))
            {
                Log.Message("[HumanResources] Deriving from ResearchPal.");
                ResearchTree_Patches.Execute(Instance, "ResearchPal");
                ResearchPal = true;
            }
            else
            {
                Log.Error("[HumanResources] Could not find ResearchTree nor ResearchPal. Human Resources will not work!");
            }

            ////Royalty integration
            //if (ModLister.RoyaltyInstalled)
            //{
            //    Log.Message("[HumanResources] Royalty detected! Integrating...");
            //    Royalty_Patches.Execute(Instance);
            //}

            //Go Explore! integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "Albion.GoExplore"))
            {
                Log.Message("[HumanResources] Go Explore detected! Integrating...");
                GoExplore_Patches.Execute(Instance);
            }

            //Material Filter patch - OBSOLETE?
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "KamiKatze.MaterialFilter"))
            {
                Log.Message("[HumanResources] Material Filter detected! Adapting...");
                MaterialFilter_Patch.Execute(Instance);
            }

            //Recipe icons patch - OBSOLETE?
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "automatic.recipeicons"))
            {
                Log.Message("[HumanResources] Recipe Icons detected! Adapting...");
                RecipeIcons_Patch.Execute(Instance);
            }

            //Simple Sidearms integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "PeteTimesSix.SimpleSidearms"))
            {
                Log.Message("[HumanResources] Simple Sidearms detected! Integrating...");
                SimpleSidearms_Patches.Execute(Instance);
            }

            //Prison Labor integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "avius.prisonlabor"))
            {
                Log.Message("[HumanResources] Prison Labor detected! Integrating...");
                PrisonLabor = true;
            }

            //Children, School and Learning integration
            if (LoadedModManager.RunningModsListForReading.Any(x => x.PackageIdPlayerFacing == "Dylan.CSL"))
            {
                Log.Message("[HumanResources] Children, School and Learning detected! Integrating...");
                Type SchoolDefOfType = AccessTools.TypeByName("School.SchoolDefOf");
                TechDefOf.HR_Learn = (WorkTypeDef)AccessTools.Field(SchoolDefOfType, "Study").GetValue(new object());
            }

            //Provisions for specific research projects
            if (LoadedModManager.RunningModsListForReading.Any(x =>
                                                               x.PackageIdPlayerFacing == "loconeko.roadsoftherim" ||
                                                               x.PackageIdPlayerFacing == "fluffy.backuppower" ||
                                                               x.PackageIdPlayerFacing == "fluffy.fluffybreakdowns"))
            {
                RunSpecialCases = true;
            }
        }
示例#6
0
        public override void Draw(Rect visibleRect, bool forceDetailedMode = false)
        {
            if (!IsVisible(visibleRect))
            {
                Highlighted = false;
                return;
            }

            var detailedMode = forceDetailedMode; //|| MainTabWindow_ResearchTree.Instance.ZoomLevel < DetailedModeZoomLevelCutoff;
            var mouseOver    = Mouse.IsOver(Rect);

            if (Event.current.type == EventType.Repaint)
            {
                // researches that are completed or could be started immediately, and that have the required building(s) available
                GUI.color = mouseOver ? GenUI.MouseoverColor : Color;

                if (mouseOver || Highlighted)
                {
                    GUI.DrawTexture(Rect, ResearchTree_Assets.ButtonActive);
                }
                else
                {
                    GUI.DrawTexture(Rect, ResearchTree_Assets.Button);
                }

                // grey out center to create a progress bar effect, completely greying out research not started.
                //if (Available)
                //{
                var progressBarRect = Rect.ContractedBy(3f);
                //GUI.color = Assets.ColorAvailable[Research.techLevel];
                GUI.color = Widgets.WindowBGFillColor;
                if (techComp.expertise.ContainsKey(Research))
                {
                    progressBarRect.xMin += techComp.expertise[Research] * progressBarRect.width;
                }
                //else
                //{
                //    progressBarRect.xMin += Research.ProgressPercent * progressBarRect.width;
                //}
                GUI.DrawTexture(progressBarRect, BaseContent.WhiteTex);
                //}

                Highlighted = false;

                // draw the research label
                if (!Completed && !Available)
                {
                    GUI.color = Color.grey;
                }
                else
                {
                    GUI.color = Color.white;
                }

                if (detailedMode)
                {
                    Text.Anchor   = TextAnchor.UpperLeft;
                    Text.WordWrap = false;
                    Text.Font     = _largeLabel ? GameFont.Tiny : GameFont.Small;
                    Widgets.Label(LabelRect, Research.LabelCap);
                }
                else
                {
                    Text.Anchor   = TextAnchor.MiddleCenter;
                    Text.WordWrap = false;
                    Text.Font     = GameFont.Small;//GameFont.Medium;
                    Widgets.Label(Rect, Research.LabelCap);
                }

                // draw research cost and icon
                if (detailedMode)
                {
                    Text.Anchor = TextAnchor.UpperRight;
                    Text.Font   = Research.CostApparent > 1000000 ? GameFont.Tiny : GameFont.Small;
                    Widgets.Label(CostLabelRect, Research.CostApparent.ToStringByStyle(ToStringStyle.Integer));
                    GUI.DrawTexture(CostIconRect, !Completed && !Available ? ResearchTree_Assets.Lock : ResearchTree_Assets.ResearchIcon, ScaleMode.ScaleToFit);
                }

                Text.WordWrap = true;

                // attach description and further info to a tooltip
                TooltipHandler.TipRegion(Rect, GetResearchTooltipString, Research.GetHashCode());
                if (!BuildingPresent())
                {
                    string root        = HarmonyPatches.ResearchPal ? "ResearchPal" : "Fluffy.ResearchTree";
                    string languageKey = root + ".MissingFacilities";
                    TooltipHandler.TipRegion(Rect, languageKey.Translate(string.Join(", ", MissingFacilities().Select(td => td.LabelCap).ToArray())));
                }

                // draw unlock icons
                if (detailedMode)
                {
                    var unlocks = ResearchTree_Patches.GetUnlockDefsAndDescs(Research);
                    for (var i = 0; i < unlocks.Count; i++)
                    {
                        var iconRect = new Rect(
                            IconsRect.xMax - (i + 1) * (Constants.IconSize.x + 4f),
                            IconsRect.yMin + (IconsRect.height - Constants.IconSize.y) / 2f,
                            Constants.IconSize.x,
                            Constants.IconSize.y);

                        if (iconRect.xMin - Constants.IconSize.x < IconsRect.xMin &&
                            i + 1 < unlocks.Count)
                        {
                            // stop the loop if we're about to overflow and have 2 or more unlocks yet to print.
                            iconRect.x = IconsRect.x + 4f;
                            GUI.DrawTexture(iconRect, ResearchTree_Assets.MoreIcon, ScaleMode.ScaleToFit);
                            var tip = string.Join("\n", unlocks.GetRange(i, unlocks.Count - i).Select(p => p.Second).ToArray());
                            TooltipHandler.TipRegion(iconRect, tip);
                            // new TipSignal( tip, Settings.TipID, TooltipPriority.Pawn ) );
                            break;
                        }

                        // draw icon
                        unlocks[i].First.DrawColouredIcon(iconRect);

                        // tooltip
                        TooltipHandler.TipRegion(iconRect, unlocks[i].Second);
                    }
                }
            }

            if (Widgets.ButtonInvisible(Rect, true))
            {
                MainButtonDefOf.Research.Worker.InterfaceTryActivate();
                ResearchTree_Patches.subjectToShow = Research;
            }
        }
示例#7
0
 public bool BuildingPresent()
 {
     return(ResearchTree_Patches.BuildingPresent(Research));
 }
示例#8
0
 public List <ThingDef> MissingFacilities()
 {
     return(ResearchTree_Patches.MissingFacilities(Research));
 }