Exemplo n.º 1
0
 private static IEnumerable <Pawn> SortedPawns(this ResearchProjectDef tech)
 {
     if (tech.IsFinished)
     {
         return(currentPawns.Where(x => !tech.IsKnownBy(x)).OrderBy(x => x.workSettings.WorkIsActive(TechDefOf.HR_Learn)).ThenByDescending(x => x.skills.GetSkill(SkillDefOf.Intellectual).Level));
     }
     else
     {
         return(currentPawns.OrderBy(x => tech.IsKnownBy(x)) /*.ThenBy(x => x.workSettings.WorkIsActive(WorkTypeDefOf.Research)).ThenByDescending(x => x.skills.GetSkill(SkillDefOf.Intellectual).Level)*/);
     }
 }
Exemplo n.º 2
0
        public static string GetTask(Pawn pawn, ResearchProjectDef tech)
        {
            bool known     = tech.IsKnownBy(pawn);
            bool completed = tech.IsFinished;

            return(known ? headerWrite : completed?headerRead : headerResearch);
        }
Exemplo n.º 3
0
        public static bool Prefix(ResearchManager __instance, ResearchProjectDef proj, Pawn applyingPawn)
        {
            var expertise = applyingPawn.TryGetComp <CompKnowledge>()?.expertise;

            if (ModLister.RoyaltyInstalled && !expertise.EnumerableNullOrEmpty())
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("LetterTechprintAppliedPartIntro".Translate(proj.Named("PROJECT")));
                stringBuilder.AppendLine();
                if (proj.techprintCount > __instance.GetTechprints(proj))
                {
                    __instance.AddTechprints(proj, 1);
                    if (proj.techprintCount == __instance.GetTechprints(proj))
                    {
                        stringBuilder.AppendLine("LetterTechprintAppliedPartJustUnlocked".Translate(proj.Named("PROJECT")));
                        stringBuilder.AppendLine();
                    }
                    else
                    {
                        stringBuilder.AppendLine("LetterTechprintAppliedPartNotUnlockedYet".Translate(__instance.GetTechprints(proj), proj.techprintCount.ToString(), proj.Named("PROJECT")));
                        stringBuilder.AppendLine();
                    }
                }
                //else if (expertise.ContainsKey(proj) && expertise[proj] >= 1f)
                else if (proj.IsKnownBy(applyingPawn))
                {
                    stringBuilder.AppendLine("LetterTechprintAppliedPartAlreadyResearched".Translate(proj.Named("PROJECT")));
                    stringBuilder.AppendLine();
                }
                else
                {
                    float num = 0f;
                    if (expertise.ContainsKey(proj))
                    {
                        num              = (1 - expertise[proj]) * 0.5f;
                        expertise[proj] += num;
                    }
                    else
                    {
                        expertise.Add(proj, 0.5f);
                        num = 0.5f;
                    }
                    stringBuilder.AppendLine("LetterTechprintAppliedPartAlreadyUnlocked".Translate(num * 100, proj.Named("PROJECT")));
                    stringBuilder.AppendLine();
                }
                if (applyingPawn != null)
                {
                    stringBuilder.AppendLine("LetterTechprintAppliedPartExpAwarded".Translate(2000.ToString(), SkillDefOf.Intellectual.label, applyingPawn.Named("PAWN")));
                    applyingPawn.skills.Learn(SkillDefOf.Intellectual, 2000f, false);
                }
                if (stringBuilder.Length > 0)
                {
                    Find.LetterStack.ReceiveLetter("LetterTechprintAppliedLabel".Translate(proj.Named("PROJECT")), stringBuilder.ToString().TrimEndNewlines(), LetterDefOf.PositiveEvent, null);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        private static IEnumerable <Widgets.DropdownMenuElement <Pawn> > GeneratePawnRestrictionOptions(this ResearchProjectDef tech, bool completed)
        {
            SkillDef skill = SkillDefOf.Intellectual;

            using (IEnumerator <Pawn> enumerator = tech.SortedPawns().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Pawn          pawn      = enumerator.Current;
                    CompKnowledge techComp  = pawn.TryGetComp <CompKnowledge>();
                    bool          known     = tech.IsKnownBy(pawn);
                    WorkTypeDef   workGiver = (completed || known) ? TechDefOf.HR_Learn : WorkTypeDefOf.Research;
                    string        header    = known ? TechStrings.headerWrite : completed ? TechStrings.headerRead : TechStrings.headerResearch;
                    if (techComp != null && (techComp.homework.NullOrEmpty() || !techComp.homework.Contains(tech)))
                    {
                        if (pawn.WorkTypeIsDisabled(workGiver))
                        {
                            yield return(new Widgets.DropdownMenuElement <Pawn>
                            {
                                option = new FloatMenuOption(string.Format("{0}: {1} ({2})", header, pawn.LabelShortCap, "WillNever".Translate(workGiver.verb)), null, MenuOptionPriority.DisabledOption, null, null, 0f, null, null),
                                payload = pawn
                            });
                        }
                        else if (!pawn.workSettings.WorkIsActive(workGiver))
                        {
                            yield return(new Widgets.DropdownMenuElement <Pawn>
                            {
                                option = new FloatMenuOption(string.Format("{0}: {1} ({2})", header, pawn.LabelShortCap, "NotAssigned".Translate()), delegate()
                                {
                                    techComp.AssignBranch(tech);
                                }, MenuOptionPriority.VeryLow, null, null, 0f, null, null),
                                payload = pawn
                            });
                        }
                        else
                        {
                            yield return(new Widgets.DropdownMenuElement <Pawn>
                            {
                                option = new FloatMenuOption(string.Format("{0}: {1} ({2} {3})", new object[]
                                {
                                    header,
                                    pawn.LabelShortCap,
                                    pawn.skills.GetSkill(skill).Level,
                                    skill.label
                                }),
                                                             delegate() { techComp.AssignBranch(tech); },
                                                             MenuOptionPriority.Default, null, null, 0f, null, null),
                                payload = pawn
                            });
                        }
                    }
                }
            }
            yield break;
        }
Exemplo n.º 5
0
        public static bool Prefix(Pawn p, RecipeDef ___recipe)
        {
            if (p.TechBound())
            {
                var expertise = p.TryGetComp <CompKnowledge>().expertise;
                if (expertise != null)
                {
                    //Look for a required ResearchProjectDef the pawn must know:
                    ResearchProjectDef requisite = null;

                    //If the recipe has it own prerequisite, then that's it:
                    if (___recipe.researchPrerequisite != null)
                    {
                        requisite = ___recipe.researchPrerequisite;
                    }

                    //If not, only for complex recipes, inspect its home buildings.
                    //In this case, it will only look for the first pre-requisite on a given building's list.
                    else if (!___recipe.recipeUsers.NullOrEmpty() && (___recipe.UsesUnfinishedThing || ___recipe.defName.StartsWith("Make_")))
                    {
                        ThingDef recipeHolder = null;
                        //If any building is free from prerequisites, then that's used.
                        var noPreReq = ___recipe.recipeUsers.Where(x => x.researchPrerequisites.NullOrEmpty());
                        if (noPreReq.Any())
                        {
                            recipeHolder = noPreReq.FirstOrDefault();
                        }
                        //Otherwise, check each one and choose the one with the cheapest prerequisite.
                        else if (___recipe.recipeUsers.Count() > 1)
                        {
                            recipeHolder = ___recipe.recipeUsers.Aggregate((l, r) => (l.researchPrerequisites.FirstOrDefault().baseCost < r.researchPrerequisites.FirstOrDefault().baseCost) ? l : r);
                        }
                        //Or, if its just one, pick that.
                        else
                        {
                            recipeHolder = ___recipe.recipeUsers.FirstOrDefault();
                        }
                        //At last, define what's the requisite for the selected building.
                        if (recipeHolder != null && !recipeHolder.researchPrerequisites.NullOrEmpty())
                        {
                            requisite = recipeHolder.researchPrerequisites.FirstOrDefault();
                        }
                    }
                    if (requisite != null && !requisite.IsKnownBy(p))
                    {
                        JobFailReason.Is("DoesntKnowHowToCraft".Translate(p, ___recipe.label, requisite.label));
                        return(false);
                    }
                }
            }
            return(true);
        }