コード例 #1
0
        public static void Learned(this ResearchProjectDef tech, float amount, float recipeCost, Pawn researcher, bool research = false)
        {
            float total = research ? tech.baseCost : recipeCost *tech.StuffCostFactor();

            amount *= research ? ResearchPointsPerWorkTick : StudyPointsPerWorkTick;
            Dictionary <ResearchProjectDef, float> expertise = researcher.TryGetComp <CompKnowledge>().expertise;

            foreach (ResearchProjectDef ancestor in expertise.Keys)
            {
                if (!tech.prerequisites.NullOrEmpty() && tech.prerequisites.Contains(ancestor))
                {
                    amount *= 2;
                    break;
                }
            }
            if (researcher != null && researcher.Faction != null)
            {
                amount /= tech.CostFactor(researcher.Faction.def.techLevel);
            }
            if (DebugSettings.fastResearch)
            {
                amount *= 500f;
            }
            if (researcher != null && research)
            {
                researcher.records.AddTo(RecordDefOf.ResearchPointsResearched, amount);
            }
            float num = tech.GetProgress(expertise);

            num += amount / total;
            //Log.Warning(tech + " research performed by " + researcher + ": " + amount + "/" + total);
            expertise[tech] = num;
        }
コード例 #2
0
        public void ResearchPerformed(float amount, Pawn researcher)
        {
            if (currentProj == null)
            {
                Log.Error("Researched without having an active project.");
                return;
            }
            amount *= ResearchPointsPerWorkTick;
            amount *= Find.Storyteller.difficulty.researchSpeedFactor;
            if (researcher != null && researcher.Faction != null)
            {
                amount /= currentProj.CostFactor(researcher.Faction.def.techLevel);
            }
            if (DebugSettings.fastResearch)
            {
                amount *= 500f;
            }
            researcher?.records.AddTo(RecordDefOf.ResearchPointsResearched, amount);
            float num = GetProgress(currentProj);

            num += amount;
            progress[currentProj] = num;
            if (currentProj.IsFinished)
            {
                FinishProject(currentProj, doCompletionDialog: true, researcher);
            }
        }
コード例 #3
0
 public float ResearchSpeedForGivenProject(ResearchProjectDef curProj, Pawn pawn)
 {
     if (ResearchInfo.Clean)
     {
         return(ListOfCurrentResearchers().
                Select(p => p.GetStatValue(StatDefOf.ResearchSpeed) * p.CurJob.targetA.Thing.GetStatValue(StatDefOf.ResearchSpeedFactor)).
                Sum());
     }
     if (ResearchInfo.ModHumanResources)
     {
         return(pawn.GetStatValue(StatDefOf.ResearchSpeed)
                * pawn.CurJob.targetA.Thing.GetStatValue(StatDefOf.ResearchSpeedFactor)
                * Aux_HR.HRPrerequisiteMultiplier(curProj, pawn)
                * pawn.GetStatValue(StatDefOf.GlobalLearningFactor)
                / curProj.CostFactor(Aux_HR.HRTechLevel(pawn)));
     }
     if (ResearchInfo.ModPawnsChooseResearch && !ResearchInfo.ModHumanResources)
     {
         return(ListOfCurrentResearchers().
                Where(p => Aux_PCR.PCRCurrentProject(p) == curProj).
                Select(p => p.GetStatValue(StatDefOf.ResearchSpeed) * p.CurJob.targetA.Thing.GetStatValue(StatDefOf.ResearchSpeedFactor)).
                Sum());
     }
     return(0f);
 }
コード例 #4
0
        public static void Learned(this ResearchProjectDef tech, float amount, float recipeCost, Pawn researcher, bool research = false)
        {
            float total = research ? tech.baseCost : recipeCost *tech.StuffCostFactor();

            amount *= research ? ResearchPointsPerWorkTick : StudyPointsPerWorkTick;
            amount *= researcher.GetStatValue(StatDefOf.GlobalLearningFactor, true); //Because, why not?
            CompKnowledge techComp = researcher.TryGetComp <CompKnowledge>();
            Dictionary <ResearchProjectDef, float> expertise = techComp.expertise;

            foreach (ResearchProjectDef sucessor in expertise.Keys.Where(x => x.IsKnownBy(researcher)))
            {
                if (!sucessor.prerequisites.NullOrEmpty() && sucessor.prerequisites.Contains(tech))
                {
                    amount *= 2;
                    break;
                }
            }
            if (researcher != null && researcher.Faction != null)
            {
                amount /= tech.CostFactor(techComp.techLevel);
            }
            if (DebugSettings.fastResearch)
            {
                amount *= 500f;
            }
            if (researcher != null && research)
            {
                researcher.records.AddTo(RecordDefOf.ResearchPointsResearched, amount);
            }
            float num = tech.GetProgress(expertise);

            num            += amount / total;
            expertise[tech] = num;
        }
コード例 #5
0
ファイル: StartUp.cs プロジェクト: Juanfrank/SRTS-Expanded
 public static bool ResearchCostApparent(ResearchProjectDef __instance, ref float __result)
 {
   if (SRTSHelper.srtsDefProjects.Any(x => x.Value == __instance))
   {
     __result = SRTSHelper.GetResearchStat(__instance) * __instance.CostFactor(Faction.OfPlayer.def.techLevel);
     return false;
   }
   return true;
 }
コード例 #6
0
        public string ToolTipResearchSpeedDetails(ResearchProjectDef project, Pawn pawn)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append($"\n{(pawn.GetStatValue(StatDefOf.ResearchSpeed).ToStringPercent("F0") + " - " + "RqRI_ToolTipDetails_Researcher".Translate()).Truncate(260f)}");
            if (ResearchInfo.ModHumanResources)
            {
                sb.Append(pawn.GetStatValue(StatDefOf.GlobalLearningFactor) != 1f ? $"\n{(pawn.GetStatValue(StatDefOf.GlobalLearningFactor).ToStringPercent("F0") + " - " + StatDefOf.GlobalLearningFactor.LabelCap).Truncate(260f)}" : "");
                sb.Append(Aux_HR.HRPrerequisiteMultiplier(project, pawn) != 1f ? $"\n{(Aux_HR.HRPrerequisiteMultiplier(project, pawn).ToStringPercent("F0") + " - " + "RqRI_ToolTipDetails_PrerequisiteMultiplier".Translate()).Truncate(260f)}" : "");
                sb.Append(project.CostFactor(Aux_HR.HRTechLevel(pawn)) != 1f ? $"\n{((1 / project.CostFactor(Aux_HR.HRTechLevel(pawn))).ToStringPercent("F0") + " - " + "RqRI_ToolTipDetails_TechLevelMultiplier".Translate()).Truncate(260f)}" : "");
            }
            sb.Append($"\n{(pawn.CurJob.targetA.Thing.GetStatValue(StatDefOf.ResearchSpeedFactor).ToStringPercent("F0") + " - " + "RqRI_ToolTipDetails_ResearchBench".Translate()).Truncate(260f)}");
            return(sb.ToString());
        }
コード例 #7
0
        /// <summary>
        /// Creates text version of research description and additional unlocks/prereqs/etc sections.
        /// </summary>
        /// <returns>string description</returns>
        private string GetResearchTooltipString()
        {
            // start with the descripton
            var text = new StringBuilder();

            text.AppendLine(Research.description);
            text.AppendLine();

            var PlayerTechLevel = Faction.OfPlayer.def.techLevel;

            if (Research.techLevel > PlayerTechLevel)
            {
                text.AppendLine(ResourceBank.String.ResearchLevels(Research.techLevel, PlayerTechLevel) + " " +
                                ResourceBank.String.ResearchPenalty(Research.CostFactor(PlayerTechLevel)));
                text.AppendLine();
            }

            if (Research.requiredResearchBuilding != null)
            {
                text.AppendLine(ResourceBank.String.RequireBenchLabel + " " + Research.requiredResearchBuilding.label);
            }
            if (Research.requiredResearchFacilities != null)
            {
                foreach (ThingDef rrf in Research.requiredResearchFacilities)
                {
                    text.AppendLine(ResourceBank.String.RequireFacilityLabel + " " + rrf.label);
                }
            }
            if (Queue.IsQueued(this))
            {
                text.AppendLine(ResourceBank.String.LClickRemoveFromQueue);
            }
            else
            {
                text.AppendLine(ResourceBank.String.LClickReplaceQueue);
                text.AppendLine(ResourceBank.String.SLClickAddToQueue);
            }

            //To Help System
            if (ResearchPalMod.HasHelpTreeLoaded)
            {
                text.AppendLine(ResourceBank.String.RClickForDetails);
            }

            return(text.ToString());
        }
コード例 #8
0
        public string TimeToCompleteResearch(ResearchProjectDef curProj, Pawn pawn = null)
        {
            if (ResearchSpeedForGivenProject(curProj, pawn) <= 0)
            {
                return("-");
            }
            float hoursToComplete;

            if (ResearchInfo.ModHumanResources)
            {
                hoursToComplete = ((1 - Aux_HR.HRExpertise(pawn)[curProj]) * curProj.CostApparent /
                                   (ResearchSpeedForGivenProject(curProj, pawn) * curProj.CostFactor(pawn.Faction.def.techLevel) * Aux_HR.HRResearchPointsPerWorkTick * 2500f * (DebugSettings.fastResearch ? 500f : 1f)));
            }
            else
            {
                hoursToComplete = (curProj.CostApparent - curProj.ProgressApparent) /
                                  (ResearchSpeedForGivenProject(curProj, pawn) * 0.00825f * 2500f * Find.Storyteller.difficulty.researchSpeedFactor * (DebugSettings.fastResearch ? 500f : 1f));
            }
            TimeSpan time = TimeSpan.FromHours(hoursToComplete);

            return((time.Days > 0 ? $"{time.Days.ToString() + "LetterDay".Translate()} " : "") +
                   (time.Hours > 0 ? $"{time.Hours.ToString() + "LetterHour".Translate()} " : "") +
                   ($"{time.Minutes.ToString() + "LetterMinute".Translate()}"));
        }
コード例 #9
0
        /// <summary>
        /// Creates text version of research description and additional unlocks/prereqs/etc sections.
        /// </summary>
        /// <returns>string description</returns>
        private string GetResearchTooltipString()
        {
            // start with the description
            var text = new StringBuilder();

            text.AppendLine(Research.description);
            text.AppendLine();

            text.AppendLine(StringExtensions.TitleCase(Research.techLevel.ToStringHuman()));
            text.AppendLine();

            var PlayerTechLevel = Faction.OfPlayer.def.techLevel;

            if (Research.techLevel > PlayerTechLevel)
            {
                text.AppendLine(ResourceBank.String.ResearchLevels(Research.techLevel, PlayerTechLevel) + " " +
                                ResourceBank.String.ResearchPenalty(Research.CostFactor(PlayerTechLevel)));
                text.AppendLine();
            }

            if (Research.requiredResearchBuilding != null)
            {
                text.AppendLine(ResourceBank.String.RequireBenchLabel + " " + Research.requiredResearchBuilding.label);
            }
            if (Research.requiredResearchFacilities != null)
            {
                foreach (ThingDef rrf in Research.requiredResearchFacilities)
                {
                    text.AppendLine(ResourceBank.String.RequireFacilityLabel + " " + rrf.label);
                }
            }

            text.AppendLine();

            if (Queue.IsQueued(this))
            {
                text.AppendLine(ResourceBank.String.LClickRemoveFromQueue);
            }
            else
            {
                text.AppendLine(ResourceBank.String.LClickReplaceQueue);
                text.AppendLine(ResourceBank.String.SLClickAddToQueue);
            }

            if (Settings.debugResearch && Prefs.DevMode)
            {
                text.AppendLine(ResourceBank.String.CLClickDebugInstant);
            }

            //To Help System
            if (ResearchPalMod.HasHelpTreeLoaded)
            {
                text.AppendLine(ResourceBank.String.RClickForDetails);
            }

            if (Prefs.DevMode)
            {
                text.AppendLine();
                text.Append("Depth:" + Depth + " Genus:" + Genus + " Family:" + Family);
                text.Append("Position: " + this.Pos.ToString());
                text.Append("Rect: " + this.Rect.ToString());
            }

            return(text.ToString());
        }
コード例 #10
0
        private void DrawLeftRect(Rect leftOutRect)
        {
            Rect position = leftOutRect;

            GUI.BeginGroup(position);
            if (selectedProject != null)
            {
                Rect outRect  = new Rect(0f, 0f, position.width, 500f);
                Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, leftScrollViewHeight);
                Widgets.BeginScrollView(outRect, ref leftScrollPosition, viewRect);
                float num = 0f;
                Text.Font = GameFont.Medium;
                GenUI.SetLabelAlign(TextAnchor.MiddleLeft);
                Rect rect = new Rect(0f, num, viewRect.width, 50f);
                Widgets.LabelCacheHeight(ref rect, selectedProject.LabelCap);
                GenUI.ResetLabelAlign();
                Text.Font = GameFont.Small;
                num      += rect.height;
                Rect rect2 = new Rect(0f, num, viewRect.width, 0f);
                Widgets.LabelCacheHeight(ref rect2, selectedProject.description);
                num += rect2.height + 10f;
                string text = "ProjectTechLevel".Translate().CapitalizeFirst() + ": " + selectedProject.techLevel.ToStringHuman().CapitalizeFirst() + "\n" + "YourTechLevel".Translate().CapitalizeFirst() + ": " + Faction.OfPlayer.def.techLevel.ToStringHuman().CapitalizeFirst();
                float  num2 = selectedProject.CostFactor(Faction.OfPlayer.def.techLevel);
                if (num2 != 1f)
                {
                    string text2 = text;
                    text = text2 + "\n\n" + "ResearchCostMultiplier".Translate().CapitalizeFirst() + ": " + num2.ToStringPercent() + "\n" + "ResearchCostComparison".Translate(selectedProject.baseCost.ToString("F0"), selectedProject.CostApparent.ToString("F0"));
                }
                Rect rect3 = new Rect(0f, num, viewRect.width, 0f);
                Widgets.LabelCacheHeight(ref rect3, text);
                num = rect3.yMax + 10f;
                float num3 = DrawResearchPrereqs(rect: new Rect(0f, num, viewRect.width, 500f), project: selectedProject);
                if (num3 > 0f)
                {
                    num += num3 + 15f;
                }
                num += DrawResearchBenchRequirements(rect: new Rect(0f, num, viewRect.width, 500f), project: selectedProject);
                num  = (leftScrollViewHeight = num + 3f);
                Widgets.EndScrollView();
                bool flag  = Prefs.DevMode && selectedProject != Find.ResearchManager.currentProj && !selectedProject.IsFinished;
                Rect rect6 = new Rect(0f, 0f, 90f, 50f);
                if (flag)
                {
                    rect6.x = (outRect.width - (rect6.width * 2f + 20f)) / 2f;
                }
                else
                {
                    rect6.x = (outRect.width - rect6.width) / 2f;
                }
                rect6.y = outRect.y + outRect.height + 20f;
                if (selectedProject.IsFinished)
                {
                    Widgets.DrawMenuSection(rect6);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect6, "Finished".Translate());
                    Text.Anchor = TextAnchor.UpperLeft;
                }
                else if (selectedProject == Find.ResearchManager.currentProj)
                {
                    Widgets.DrawMenuSection(rect6);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect6, "InProgress".Translate());
                    Text.Anchor = TextAnchor.UpperLeft;
                }
                else if (!selectedProject.CanStartNow)
                {
                    Widgets.DrawMenuSection(rect6);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect6, "Locked".Translate());
                    Text.Anchor = TextAnchor.UpperLeft;
                }
                else if (Widgets.ButtonText(rect6, "Research".Translate()))
                {
                    SoundDefOf.ResearchStart.PlayOneShotOnCamera();
                    Find.ResearchManager.currentProj = selectedProject;
                    TutorSystem.Notify_Event("StartResearchProject");
                }
                if (flag)
                {
                    Rect rect7 = rect6;
                    rect7.x += rect7.width + 20f;
                    if (Widgets.ButtonText(rect7, "Debug Insta-finish"))
                    {
                        Find.ResearchManager.currentProj = selectedProject;
                        Find.ResearchManager.FinishProject(selectedProject);
                    }
                }
                Rect rect8 = new Rect(15f, rect6.y + rect6.height + 20f, position.width - 30f, 35f);
                Widgets.FillableBar(rect8, selectedProject.ProgressPercent, ResearchBarFillTex, ResearchBarBGTex, doBorder: true);
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect8, selectedProject.ProgressApparent.ToString("F0") + " / " + selectedProject.CostApparent.ToString("F0"));
                Text.Anchor = TextAnchor.UpperLeft;
            }
            GUI.EndGroup();
        }
コード例 #11
0
        private void DrawLeftRect(Rect leftOutRect)
        {
            Rect position = leftOutRect;

            GUI.BeginGroup(position);
            if (selectedProject != null)
            {
                Rect outRect  = new Rect(0f, 0f, position.width, 520f);
                Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, leftScrollViewHeight);
                Widgets.BeginScrollView(outRect, ref leftScrollPosition, viewRect);
                float num = 0f;
                Text.Font = GameFont.Medium;
                GenUI.SetLabelAlign(TextAnchor.MiddleLeft);
                Rect rect = new Rect(0f, num, viewRect.width - 0f, 50f);
                Widgets.LabelCacheHeight(ref rect, selectedProject.LabelCap);
                GenUI.ResetLabelAlign();
                Text.Font = GameFont.Small;
                num      += rect.height;
                Rect rect2 = new Rect(0f, num, viewRect.width, 0f);
                Widgets.LabelCacheHeight(ref rect2, selectedProject.description);
                num += rect2.height;
                Rect rect3 = new Rect(0f, num, viewRect.width, 500f);
                num += DrawTechprintInfo(rect3, selectedProject);
                if ((int)selectedProject.techLevel > (int)Faction.OfPlayer.def.techLevel)
                {
                    float  num2  = selectedProject.CostFactor(Faction.OfPlayer.def.techLevel);
                    Rect   rect4 = new Rect(0f, num, viewRect.width, 0f);
                    string text  = "TechLevelTooLow".Translate(Faction.OfPlayer.def.techLevel.ToStringHuman(), selectedProject.techLevel.ToStringHuman(), num2.ToStringPercent());
                    if (num2 != 1f)
                    {
                        text += " " + "ResearchCostComparison".Translate(selectedProject.baseCost.ToString("F0"), selectedProject.CostApparent.ToString("F0"));
                    }
                    Widgets.LabelCacheHeight(ref rect4, text);
                    num += rect4.height;
                }
                if (!ColonistsHaveResearchBench)
                {
                    GUI.color = ColoredText.RedReadable;
                    Rect rect5 = new Rect(0f, num, viewRect.width, 0f);
                    Widgets.LabelCacheHeight(ref rect5, "CannotResearchNoBench".Translate());
                    num      += rect5.height;
                    GUI.color = Color.white;
                }
                num += DrawResearchPrereqs(rect: new Rect(0f, num, viewRect.width, 500f), project: selectedProject);
                num += DrawResearchBenchRequirements(rect: new Rect(0f, num, viewRect.width, 500f), project: selectedProject);
                Rect rect8 = new Rect(0f, num, viewRect.width, 500f);
                num += DrawUnlockableHyperlinks(rect8, selectedProject);
                num  = (leftScrollViewHeight = num + 3f);
                Widgets.EndScrollView();
                Rect rect9 = new Rect(0f, outRect.yMax + 10f, position.width, 68f);
                if (selectedProject.CanStartNow && selectedProject != Find.ResearchManager.currentProj)
                {
                    if (Widgets.ButtonText(rect9, "Research".Translate()))
                    {
                        SoundDefOf.ResearchStart.PlayOneShotOnCamera();
                        Find.ResearchManager.currentProj = selectedProject;
                        TutorSystem.Notify_Event("StartResearchProject");
                        if (!ColonistsHaveResearchBench)
                        {
                            Messages.Message("MessageResearchMenuWithoutBench".Translate(), MessageTypeDefOf.CautionInput);
                        }
                    }
                }
                else
                {
                    string text2 = "";
                    if (selectedProject.IsFinished)
                    {
                        text2       = "Finished".Translate();
                        Text.Anchor = TextAnchor.MiddleCenter;
                    }
                    else if (selectedProject == Find.ResearchManager.currentProj)
                    {
                        text2       = "InProgress".Translate();
                        Text.Anchor = TextAnchor.MiddleCenter;
                    }
                    else
                    {
                        text2 = "Locked".Translate() + ":";
                        if (!selectedProject.PrerequisitesCompleted)
                        {
                            text2 += "\n  " + "PrerequisitesNotCompleted".Translate();
                        }
                        if (!selectedProject.TechprintRequirementMet)
                        {
                            text2 += "\n  " + "InsufficientTechprintsApplied".Translate(selectedProject.TechprintsApplied, selectedProject.techprintCount);
                        }
                    }
                    Widgets.DrawHighlight(rect9);
                    Widgets.Label(rect9.ContractedBy(5f), text2);
                    Text.Anchor = TextAnchor.UpperLeft;
                }
                Rect rect10 = new Rect(0f, rect9.yMax + 10f, position.width, 35f);
                Widgets.FillableBar(rect10, selectedProject.ProgressPercent, ResearchBarFillTex, ResearchBarBGTex, doBorder: true);
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect10, selectedProject.ProgressApparent.ToString("F0") + " / " + selectedProject.CostApparent.ToString("F0"));
                Text.Anchor = TextAnchor.UpperLeft;
                if (Prefs.DevMode && selectedProject != Find.ResearchManager.currentProj && !selectedProject.IsFinished && Widgets.ButtonText(new Rect(rect9.x, rect9.y - 30f, 120f, 30f), "Debug: Finish now"))
                {
                    Find.ResearchManager.currentProj = selectedProject;
                    Find.ResearchManager.FinishProject(selectedProject);
                }
                if (Prefs.DevMode && !selectedProject.TechprintRequirementMet && Widgets.ButtonText(new Rect(rect9.x + 120f, rect9.y - 30f, 120f, 30f), "Debug: Apply techprint"))
                {
                    Find.ResearchManager.ApplyTechprint(selectedProject, null);
                    SoundDefOf.TechprintApplied.PlayOneShotOnCamera();
                }
            }
            GUI.EndGroup();
        }
コード例 #12
0
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);

            // Get Tech Level & appropriate techs
            TechLevel techLevel = parent.GetComp <CompBlueprint>().techLevel;
            List <ResearchProjectDef> techList = DefDatabase <ResearchProjectDef> .AllDefsListForReading.FindAll((ResearchProjectDef x) => ((x.techLevel == techLevel) && (!x.IsFinished) && (x.CanStartNow)));

            ResearchProjectDef chosenResearchProject = techList.RandomElement <ResearchProjectDef>(); // TODO: weigh the selection

            if (chosenResearchProject == null)
            {
                // RESEARCH IS NULL! Do nothing.
                Log.Error("No research has been selected because none fit the conditions.");
                return;
            }

            if (Faction.OfPlayer.def.techLevel >= techLevel)
            {
                researchPercentage = 1f; //100% of base cost
                endMessage         = "The " + techLevel.ToStringHuman() + " technology blueprint revealed everything about " + chosenResearchProject.label.ToString() + ".";
            }
            else
            {
                researchPercentage = 0.34f; //34% of base cost
                endMessage         = "The " + techLevel.ToStringHuman() + " technology blueprint is complicated, but it helped understand " + chosenResearchProject.label.ToString() + ".";
            }

            // Change current project just the time to add research points then restore it
            ResearchProjectDef storedResearchProject = Find.ResearchManager.currentProj;

            Find.ResearchManager.currentProj = chosenResearchProject;

            ResearchGainAmount = chosenResearchProject.CostApparent * researchPercentage / 0.007f / chosenResearchProject.CostFactor(usedBy.Faction.def.techLevel);

            Find.ResearchManager.ResearchPerformed(ResearchGainAmount, null);

            Find.ResearchManager.currentProj = storedResearchProject;

            // Feedback top left
            Messages.Message(endMessage, MessageTypeDefOf.PositiveEvent); // Adds a message top left
        }