Exemplo n.º 1
0
        public static IntRange GetTrainingProgress(Pawn pawn, TrainableDef trainable)
        {
            var cur = Traverse.Create(pawn.training).Method("GetSteps", trainable).GetValue <int>();
            var max = trainable.steps;

            return(new IntRange(cur, max));
        }
Exemplo n.º 2
0
        public TipSignal?GetAnimalTooltip(TrainableDef def = null)
        {
            var builder = new StringBuilder();

            builder.AppendLine(Lang.Get("Model.Bio.Trainability", Base.RaceProps.trainability.LabelCap));
            builder.AppendLine(Lang.Get("Model.Bio.Wildness", Base.RaceProps.wildness.ToStringPercent()));

            builder.AppendLine($"{"TrainingDecayInterval".Translate()}: {TrainableUtility.DegradationPeriodTicks(Base.def).ToStringTicksToDays()}");
            if (!TrainableUtility.TamenessCanDecay(Base.def))
            {
                builder.AppendLine("TamenessWillNotDecay".Translate());
            }

            builder.AppendLine(Lang.Get("Model.Bio.Petness", Base.RaceProps.petness.ToStringPercent()));
            builder.AppendLine(Lang.Get("Model.Bio.Diet", Base.RaceProps.ResolvedDietCategory.ToStringHuman()));

            var master = Base.playerSettings?.Master?.LabelShort;

            if (!master.NullOrEmpty())
            {
                builder.AppendLine();
                builder.AppendLine(Lang.Get("Model.Bio.Master", master));
            }

            if (def != null)
            {
                builder.AppendLine();
                builder.AppendLine(def.description);
            }

            var text = builder.ToStringTrimmed().Size(Theme.RegularTextStyle.ActualSize);

            return(new TipSignal(() => text, GUIPlus.TooltipId));
        }
            private void SetWantedRecursive(TrainableDef td, bool wanted)
            {
                // cop out if nothing changed
                if (TrainingTargets[td] == wanted)
                {
                    return;
                }

                // make changes
                TrainingTargets[td] = wanted;
                if (wanted)
                {
                    SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                    if (td.prerequisites != null)
                    {
                        foreach (TrainableDef trainable in td.prerequisites)
                        {
                            SetWantedRecursive(trainable, true);
                        }
                    }
                }
                else
                {
                    SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                    IEnumerable <TrainableDef> enumerable = from t in DefDatabase <TrainableDef> .AllDefsListForReading
                                                            where
                                                            t.prerequisites != null && t.prerequisites.Contains(td)
                                                            select t;
                    foreach (TrainableDef current in enumerable)
                    {
                        SetWantedRecursive(current, false);
                    }
                }
            }
Exemplo n.º 4
0
        public static void DrawTrainingButton(Rect rect, Pawn pawn, TrainableDef td, AcceptanceReport ar)
        {
            if (ar.Accepted)
            {
                if (pawn.training.IsCompleted(td))
                {
                    GUI.DrawTexture(rect, CheckWhite);
                }
                else if (pawn.training.GetWanted(td))
                {
                    GUI.DrawTexture(rect, Widgets.CheckboxOnTex);

                    // Get method named "GetSteps", which is internal(non-public) and not static(instance)
                    var getSteps = typeof(Pawn_TrainingTracker).GetMethod("GetSteps",
                                                                          BindingFlags.NonPublic |
                                                                          BindingFlags.Instance);
                    if (getSteps == null)
                    {
#if DEBUG
                        Log.Error("GetSteps is null!");
#endif
                        return;
                    }

                    // Call "GetSteps" from instance pawn.training, parameter is td.
                    var curSteps = getSteps.Invoke(pawn.training, new object[] { td });
                    int steps    = td.steps;
                    // Return value of Invoke(...) is Object; thus casting into int type.
                    float barHeight = (rect.height / steps) * (int)curSteps;
                    Rect  bar       = new Rect(rect.xMax - 5f, rect.yMax - barHeight, 3f, barHeight);
                    GUI.DrawTexture(bar, BarBg);
                }
            }
        }
Exemplo n.º 5
0
        public static void ToggleAllTraining(TrainableDef td, List <Pawn> pawns)
        {
            bool[]             visible   = new bool[pawns.Count];
            AcceptanceReport[] canAssign = new AcceptanceReport[pawns.Count];
            bool[]             assigned  = pawns.Select(p => p.training.GetWanted(td)).ToArray();
            bool[]             trained   = pawns.Select(p => p.training.IsCompleted(td)).ToArray();
            bool all = true;

            for (int i = 0; i < pawns.Count; i++)
            {
                canAssign[i] = pawns[i].training.CanAssignToTrain(td, out visible[i]);
                if (!assigned[i] && !trained[i] && canAssign[i].Accepted)
                {
                    all = false;
                }
            }

            for (int i = 0; i < pawns.Count; i++)
            {
                if (all && assigned[i])
                {
                    SetWantedRecursive(td, pawns[i], false);
                }
                else if (!assigned[i] && canAssign[i].Accepted && !trained[i])
                {
                    SetWantedRecursive(td, pawns[i], true);
                }
            }
        }
Exemplo n.º 6
0
        public static void Initialize()
        {
            Method_RimWorld_HealthCardUtility_VisibleHediffGroupsInOrder = MethodInvoker.GetHandler(AccessTools.Method(typeof(HealthCardUtility), "VisibleHediffGroupsInOrder", new[] { typeof(Pawn), typeof(bool) }));
            Method_RimWorld_HealthCardUtility_VisibleHediffs             = MethodInvoker.GetHandler(AccessTools.Method(typeof(HealthCardUtility), "VisibleHediffs", new[] { typeof(Pawn), typeof(bool) }));
            Method_RimWorld_InspectPaneUtility_InterfaceToggleTab        = MethodInvoker.GetHandler(AccessTools.Method(typeof(InspectPaneUtility), "InterfaceToggleTab", new[] { typeof(InspectTabBase), typeof(IInspectPane) }));
            Method_RimWorld_InspectPaneUtility_ToggleTab  = MethodInvoker.GetHandler(AccessTools.Method(typeof(InspectPaneUtility), "ToggleTab", new[] { typeof(InspectTabBase), typeof(IInspectPane) }));
            Method_RimWorld_Pawn_TrainingTracker_GetSteps = MethodInvoker.GetHandler(AccessTools.Method(typeof(Pawn_TrainingTracker), "GetSteps", new[] { typeof(TrainableDef) }));
            Method_RimWorld_SkillUI_GetSkillDescription   = MethodInvoker.GetHandler(AccessTools.Method(typeof(SkillUI), "GetSkillDescription", new[] { typeof(SkillRecord) }));

            Field_RimWorld_AlertsReadout_ActiveAlerts = AccessTools.Field(typeof(AlertsReadout), "activeAlerts");
            Field_RimWorld_InspectPaneUtility_InspectTabButtonFillTex = AccessTools.Field(typeof(InspectPaneUtility), "InspectTabButtonFillTex");
            Field_Verse_LetterStack_LastTopYInt = AccessTools.Field(typeof(LetterStack), "lastTopYInt");
            Field_Verse_LetterStack_Letters     = AccessTools.Field(typeof(LetterStack), "letters");

            MainButtonDefOfRestrict = DefDatabase <MainButtonDef> .GetNamed("Schedule");

            MainButtonDefOfWork = DefDatabase <MainButtonDef> .GetNamed("Work");

            NeedDefOfMood = DefDatabase <NeedDef> .GetNamed("Mood");

            NeedDefOfBeauty = DefDatabase <NeedDef> .GetNamed("Beauty");

            NeedDefOfComfort = DefDatabase <NeedDef> .GetNamed("Comfort");

            NeedDefOfOutdoors = DefDatabase <NeedDef> .GetNamed("Outdoors");

            NeedDefOfRoomSize = DefDatabase <NeedDef> .GetNamed("RoomSize");

            TrainableDefOfHaul = DefDatabase <TrainableDef> .GetNamed("Haul");

            TrainableDefOfRescue = DefDatabase <TrainableDef> .GetNamed("Rescue");
        }
Exemplo n.º 7
0
 private static void SetWantedRecursive(TrainableDef td, Pawn pawn, bool checkOn)
 {
     pawn.training.SetWanted(td, checkOn);
     if (checkOn)
     {
         SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
         if (td.prerequisites != null)
         {
             foreach (TrainableDef trainable in td.prerequisites)
             {
                 SetWantedRecursive(trainable, pawn, true);
             }
         }
     }
     else
     {
         SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
         IEnumerable <TrainableDef> enumerable = from t in DefDatabase <TrainableDef> .AllDefsListForReading
                                                 where t.prerequisites != null && t.prerequisites.Contains(td)
                                                 select t;
         foreach (TrainableDef current in enumerable)
         {
             SetWantedRecursive(current, pawn, false);
         }
     }
 }
Exemplo n.º 8
0
        public static void DrawTrainingProgress(Rect rect, Pawn pawn, TrainableDef trainable, Color color)
        {
            var steps        = GetTrainingProgress(pawn, trainable);
            var progressRect = new Rect(rect.xMin, rect.yMax - rect.height / 5f,
                                        rect.width / steps.max * steps.min, rect.height / 5f);

            Widgets.DrawBoxSolid(progressRect, color);
        }
Exemplo n.º 9
0
        public static void ToggleTraining(TrainableDef td, Pawn pawn, AcceptanceReport ar)
        {
            bool train = !pawn.training.GetWanted(td);

            if (ar.Accepted)
            {
                SetWantedRecursive(td, pawn, train);
            }
        }
Exemplo n.º 10
0
        public AcceptanceReport CanBeTrained(PawnKindDef pawnKind, TrainableDef td, out bool visible)
        {
            if (pawnKind.RaceProps.untrainableTags != null)
            {
                for (var index = 0; index < pawnKind.RaceProps.untrainableTags.Count; ++index)
                {
                    if (td.MatchesTag(pawnKind.RaceProps.untrainableTags[index]))
                    {
                        visible = false;
                        return(false);
                    }
                }
            }

            if (pawnKind.RaceProps.trainableTags != null)
            {
                for (var index = 0; index < pawnKind.RaceProps.trainableTags.Count; ++index)
                {
                    if (td.MatchesTag(pawnKind.RaceProps.trainableTags[index]))
                    {
                        if (pawnKind.RaceProps.baseBodySize < (double)td.minBodySize)
                        {
                            visible = true;
                            return(new AcceptanceReport(
                                       "CannotTrainTooSmall".Translate((object)pawnKind.LabelCap)));
                        }

                        visible = true;
                        return(true);
                    }
                }
            }

            if (!td.defaultTrainable)
            {
                visible = false;
                return(false);
            }

            if (pawnKind.RaceProps.baseBodySize < (double)td.minBodySize)
            {
                visible = true;
                return(new AcceptanceReport(
                           "FM.Livestock.CannotTrainTooSmall".Translate((object)pawnKind.GetLabelPlural())));
            }

            if (pawnKind.RaceProps.trainability.intelligenceOrder < td.requiredTrainability.intelligenceOrder)
            {
                visible = true;
                return
                    (new AcceptanceReport("CannotTrainNotSmartEnough".Translate((object)td.requiredTrainability)));
            }

            visible = true;
            return(true);
        }
Exemplo n.º 11
0
        public TrainingModel(PawnModel model, TrainableDef def)
        {
            try
            {
                Model = model;

                bool canTrainNow;
                try { canTrainNow = model.Base.RaceProps?.trainability != null && model.Base.training != null && model.Base.training.CanAssignToTrain(def, out var visible).Accepted&& visible; }
                catch (Exception exception)
                {
                    Mod.HandleWarning(exception);
                    canTrainNow = false;
                }

                if (!canTrainNow)
                {
                    Hidden = true;
                    return;
                }

                Label = def.LabelCap;

                var disabled   = !model.Base.training.GetWanted(def);
                var hasLearned = model.Base.training.HasLearned(def);

                var steps = GetSteps(model.Base, def);
                var value = steps + " / " + def.steps;
                Value = hasLearned ? value.Bold() : value;

                Tooltip = model.GetAnimalTooltip(def);

                if (disabled)
                {
                    Color = Theme.DisabledColor.Value;
                }
                else if (hasLearned)
                {
                    Color = Theme.SkillMinorPassionColor.Value;
                }
                else
                {
                    Color = Theme.MainTextColor.Value;
                }

                OnClick = InspectPanePlus.ToggleTrainingTab;
            }
            catch (Exception exception)
            {
                Mod.HandleWarning(exception);
                Hidden = true;
            }
        }
Exemplo n.º 12
0
        public static void DoTrainableTooltip(Rect rect, Pawn pawn, TrainableDef td, AcceptanceReport canTrain,
                                              bool wanted, bool completed, IntRange steps)
        {
            // copy pasta from TrainingCardUtility.DoTrainableTooltip
            TooltipHandler.TipRegion(rect, () =>
            {
                string text = td.LabelCap + "\n\n" + td.description;
                if (!canTrain.Accepted)
                {
                    text = text + "\n\n" + canTrain.Reason;
                }
                else if (!td.prerequisites.NullOrEmpty <TrainableDef>())
                {
                    text += "\n";
                    for (int i = 0; i < td.prerequisites.Count; i++)
                    {
                        if (!pawn.training.HasLearned(td.prerequisites[i]))
                        {
                            text = text + "\n" + "TrainingNeedsPrerequisite".Translate(td.prerequisites[i].LabelCap);
                        }
                    }
                }
                if (completed && steps.min == steps.max)
                {
                    text += "\n" + "Fluffy.AnimalTab.XHasMasteredY".Translate(pawn.Name.ToStringShort, td.LabelCap);
                }
                if (wanted && !completed)
                {
                    text += "\n" + "Fluffy.AnimalTab.XHasLearnedYOutOfZ".Translate(pawn.Name.ToStringShort, steps.min,
                                                                                   steps.max);
                }
                if (completed && steps.min < steps.max)
                {
                    text += "\n" + "Fluffy.AnimalTab.XHasForgottenYOutOfZ".Translate(pawn.Name.ToStringShort,
                                                                                     steps.max - steps.min, steps.max);
                }
                if (wanted)
                {
                    text += "\n" + "Fluffy.AnimalTab.XIsDesignatedTrainY".Translate(pawn.Name.ToStringShort,
                                                                                    td.LabelCap);
                }
                else if (completed || steps.min > 0)
                {
                    text += "\n" + "Fluffy.AnimalTab.XIsNotDesignatedTrainY".Translate(pawn.Name.ToStringShort,
                                                                                       td.LabelCap);
                }

                return(text);
            }, (int)(rect.y * 612 + rect.x));
        }
        private bool TrainingCompleted(Pawn meeseeks, Pawn targetPawn, SavedTargetInfo jobTarget)
        {
            TrainableDef desiredTrainable = jobTarget.trainable;

            if (targetPawn.training.HasLearned(desiredTrainable))
            {
                return(true);
            }
            else if (!targetPawn.training.GetWanted(desiredTrainable))
            {
                targetPawn.training.SetWantedRecursive(desiredTrainable, true);
            }

            return(false);
        }
Exemplo n.º 14
0
 private static void WriteItemToConsole(TrainableDef item)
 {
     CONS.WriteLine($"  {nameof(TrainableDef)}");
     CONS.WriteLine($"    defName: {item.DefName.ToStringOrDefault()}");
     CONS.WriteLine($"    label: {item.Label.ToStringOrDefault()}");
     CONS.WriteLine($"    description: {item.Description.ToStringOrDefault()}");
     CONS.WriteLine($"    icon: {item.Icon.ToStringOrDefault()}");
     if (item.Priority.HasValue)
     {
         CONS.WriteLine($"    listPriority: {item.Priority.Value}");
     }
     if (item.Difficulty.HasValue)
     {
         CONS.WriteLine($"    difficulty: {item.Difficulty.Value}");
     }
     if (item.MinBodySize.HasValue)
     {
         CONS.WriteLine($"    minBodySize: {item.MinBodySize.Value}");
     }
     if (item.RequiredTrainableIntelligence != null)
     {
         CONS.WriteLine($"    requiredTrainableIntelligence: {item.RequiredTrainableIntelligence}");
     }
     if (item.Steps.HasValue)
     {
         CONS.WriteLine($"    steps: {item.Steps.Value}");
     }
     if (item.DefaultTrainable.HasValue)
     {
         CONS.WriteLine($"    defaultTrainable: {item.DefaultTrainable.Value}");
     }
     if ((item.Prerequisites?.Any()).GetValueOrDefault())
     {
         CONS.WriteLine($"    prerequisites");
         foreach (var li in item.Prerequisites)
         {
             CONS.WriteLine($"      li: {li.ToStringOrDefault()}");
         }
     }
     if ((item.Tags?.Any()).GetValueOrDefault())
     {
         CONS.WriteLine($"    tags");
         foreach (var li in item.Tags)
         {
             CONS.WriteLine($"      li: {li.ToStringOrDefault()}");
         }
     }
 }
Exemplo n.º 15
0
        public static float computeTrainPriority(Pawn worker, Pawn target)
        {
            Pawn_TrainingTracker train     = target.training;
            TrainableDef         nextTrain = train.NextTrainableToTrain();
            MethodInfo           dynMethod = train.GetType().GetMethod("GetSteps", BindingFlags.Instance | BindingFlags.NonPublic);
            int   steps    = (int)dynMethod.Invoke(train, new object[] { nextTrain });
            float priority = trainmap[nextTrain.defName];

            if (nextTrain.defName == "Tameness")
            {
                priority += (10 - steps);
            }
            else
            {
                priority += steps;
            }
            //Log.Message("Hello from computeTrainPriority with pawn: " + target.Name.ToStringShort + ", " + nextTrain.defName + ", Steps:" + steps + ", Priority" + priority);
            return(priority);
        }
Exemplo n.º 16
0
        public static string GetTrainingTip(Pawn pawn, TrainableDef td, AcceptanceReport ar)
        {
            var label = new StringBuilder();

            label.AppendLine(td.LabelCap);
            if (!ar.Accepted)
            {
                label.AppendLine(ar.Reason);
            }
            else
            {
                if (pawn.training.IsCompleted(td))
                {
                    label.Append("Fluffy.TrainingCompleted".Translate());
                }
                else
                {
                    label.AppendLine(!pawn.training.GetWanted(td)
                        ? "Fluffy.NotTraining".Translate()
                        : "Fluffy.CurrentlyTraining".Translate());

                    var getSteps = typeof(Pawn_TrainingTracker).GetMethod("GetSteps",
                                                                          BindingFlags.NonPublic |
                                                                          BindingFlags.Instance);
                    if (getSteps == null)
                    {
#if DEBUG
                        Log.Error("GetSteps is null!");
#endif
                        return(label.ToString());
                    }

                    var curSteps = getSteps.Invoke(pawn.training, new object[] { td });
                    int steps    = td.steps;
                    label.Append("Fluffy.StepsCompleted".Translate(curSteps, steps));
                }
            }
            return(label.ToString());
        }
Exemplo n.º 17
0
        public TrainingModel(PawnModel model, TrainableDef def) : base(model)
        {
            var trainable   = (model.Base.RaceProps?.trainability != null) && (model.Base.training != null);
            var visible     = false;
            var canTrainNow = model.Base.training?.CanAssignToTrain(def, out visible).Accepted ?? false;

            if (!trainable || !visible || !canTrainNow)
            {
                Hidden = true;
                return;
            }

            Label = def.LabelCap;

            var disabled   = !model.Base.training.GetWanted(def);
            var hasLearned = model.Base.training.HasLearned(def);

            var steps = GetSteps(model.Base, def);
            var value = steps + " / " + def.steps;

            Value = hasLearned ? value.Bold() : value;

            Tooltip = model.GetAnimalTooltip(def);

            if (disabled)
            {
                Color = Theme.DisabledColor.Value;
            }
            else if (hasLearned)
            {
                Color = Theme.SkillMinorPassionColor.Value;
            }
            else
            {
                Color = Theme.MainTextColor.Value;
            }
        }
 private static void SetWantedRecursive(TrainableDef td, Pawn pawn, bool checkOn)
 {
     pawn.training.SetWanted(td, checkOn);
     if (checkOn)
     {
         if (td.prerequisites != null)
         {
             for (int i = 0; i < td.prerequisites.Count; i++)
             {
                 TrainingCardUtility.SetWantedRecursive(td.prerequisites[i], pawn, true);
             }
         }
     }
     else
     {
         IEnumerable <TrainableDef> enumerable = from t in DefDatabase <TrainableDef> .AllDefsListForReading
                                                 where t.prerequisites != null && t.prerequisites.Contains(td)
                                                 select t;
         foreach (TrainableDef current in enumerable)
         {
             TrainingCardUtility.SetWantedRecursive(current, pawn, false);
         }
     }
 }
        private static bool TryDrawTrainableRow(Rect rect, Pawn pawn, TrainableDef td)
        {
            bool             flag = pawn.training.IsCompleted(td);
            bool             flag2;
            AcceptanceReport canTrain = pawn.training.CanAssignToTrain(td, out flag2);

            if (!flag2)
            {
                return(false);
            }
            Widgets.DrawHighlightIfMouseover(rect);
            Rect rect2 = rect;

            rect2.width -= 50f;
            rect2.xMin  += (float)td.indent * 15f;
            Rect rect3 = rect;

            rect3.xMin = rect3.xMax - 50f + 17f;
            if (!flag)
            {
                bool wanted = pawn.training.GetWanted(td);
                bool flag3  = wanted;
                Widgets.LabelCheckbox(rect2, td.LabelCap, ref wanted, !canTrain.Accepted);
                if (wanted != flag3)
                {
                    ConceptDatabase.KnowledgeDemonstrated(ConceptDefOf.AnimalTraining, KnowledgeAmount.Total);
                    TrainingCardUtility.SetWantedRecursive(td, pawn, wanted);
                }
            }
            else
            {
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect2, td.LabelCap);
                Text.Anchor = TextAnchor.UpperLeft;
            }
            if (flag)
            {
                GUI.color = Color.green;
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(rect3, TrainingCardUtility.GetSteps(pawn.training, td) + " / " + td.steps);
            Text.Anchor = TextAnchor.UpperLeft;
            if (Game.GodMode && !pawn.training.IsCompleted(td))
            {
                Rect rect4 = rect3;
                rect4.yMin = rect4.yMax - 10f;
                rect4.xMin = rect4.xMax - 10f;
                if (Widgets.TextButton(rect4, "+", true, false))
                {
                    pawn.training.Train(td, Find.ListerPawns.FreeColonistsSpawned.RandomElement <Pawn>());
                }
            }
            TooltipHandler.TipRegion(rect, delegate
            {
                string text = td.LabelCap + "\n\n" + td.description;
                if (!canTrain.Accepted)
                {
                    text = text + "\n\n" + canTrain.Reason;
                }
                else if (!td.prerequisites.NullOrEmpty <TrainableDef>())
                {
                    text += "\n";
                    for (int i = 0; i < td.prerequisites.Count; i++)
                    {
                        if (!pawn.training.IsCompleted(td.prerequisites[i]))
                        {
                            text = text + "\n" + "TrainingNeedsPrerequisite".Translate(new object[]
                            {
                                td.prerequisites[i].LabelCap
                            });
                        }
                    }
                }
                return(text);
            }, (int)(rect.y * 612f));
            GUI.color = Color.white;
            return(true);
        }
Exemplo n.º 20
0
 public static void ToggleTraining(TrainableDef td, Pawn pawn, AcceptanceReport ar)
 {
     bool train = !pawn.training.GetWanted(td);
     if (ar.Accepted)
     {
         SetWantedRecursive(td, pawn, train);
     }
 }
Exemplo n.º 21
0
        public static void DrawTrainingButton(Rect rect, Pawn pawn, TrainableDef td, AcceptanceReport ar)
        {
            if (ar.Accepted)
            {
                if (pawn.training.IsCompleted(td))
                {
                    GUI.DrawTexture(rect, CheckWhite);
                }
                else if (pawn.training.GetWanted(td))
                {
                    GUI.DrawTexture(rect, Widgets.CheckboxOnTex);

                    // Get method named "GetSteps", which is internal(non-public) and not static(instance)
                    var getSteps = typeof(Pawn_TrainingTracker).GetMethod( "GetSteps",
                                                                           BindingFlags.NonPublic |
                                                                           BindingFlags.Instance );
                    if (getSteps == null)
                    {
#if DEBUG
                        Log.Error("GetSteps is null!");
#endif
                        return;
                    }

                    // Call "GetSteps" from instance pawn.training, parameter is td.
                    var curSteps = getSteps.Invoke( pawn.training, new object[] {td} );
                    int steps = td.steps;
                    // Return value of Invoke(...) is Object; thus casting into int type.
                    float barHeight = (rect.height/steps)*(int) curSteps;
                    Rect bar = new Rect( rect.xMax - 5f, rect.yMax - barHeight, 3f, barHeight );
                    GUI.DrawTexture( bar, BarBg );
                }
            }
        }
Exemplo n.º 22
0
 private static int GetSteps(Pawn pawn, TrainableDef def) => (int)Access.Method_RimWorld_Pawn_TrainingTracker_GetSteps.Invoke(pawn.training, def);
Exemplo n.º 23
0
        public static string GetTrainingTip(Pawn pawn, TrainableDef td, AcceptanceReport ar)
        {
            var label = new StringBuilder();
            label.AppendLine(td.LabelCap);
            if (!ar.Accepted)
            {
                label.AppendLine(ar.Reason);
            }
            else
            {
                if (pawn.training.IsCompleted(td))
                {
                    label.Append("Fluffy.TrainingCompleted".Translate());
                }
                else
                {
                    label.AppendLine(!pawn.training.GetWanted(td)
                        ? "Fluffy.NotTraining".Translate()
                        : "Fluffy.CurrentlyTraining".Translate());

                    var getSteps = typeof(Pawn_TrainingTracker).GetMethod("GetSteps",
                                                                           BindingFlags.NonPublic |
                                                                           BindingFlags.Instance);
                    if (getSteps == null)
                    {
#if DEBUG
                        Log.Error("GetSteps is null!");
#endif
                        return label.ToString();
                    }
                    
                    var curSteps = getSteps.Invoke(pawn.training, new object[] { td });
                    int steps = td.steps;
                    label.Append( "Fluffy.StepsCompleted".Translate( curSteps, steps ) );
                }
            }
            return label.ToString();
        }
Exemplo n.º 24
0
        public static void ToggleAllTraining(TrainableDef td, List<Pawn> pawns)
        {
            bool[] visible = new bool[pawns.Count];
            AcceptanceReport[] canAssign = new AcceptanceReport[pawns.Count];
            bool[] assigned = pawns.Select(p => p.training.GetWanted(td)).ToArray();
            bool[] trained = pawns.Select(p => p.training.IsCompleted(td)).ToArray();
            bool all = true;

            for (int i = 0; i < pawns.Count; i++)
            {
                canAssign[i] = pawns[i].training.CanAssignToTrain(td, out visible[i]);
                if (!assigned[i] && !trained[i] && canAssign[i].Accepted) all = false;
            }

            for (int i = 0; i < pawns.Count; i++)
            {
                if (all && assigned[i])
                {
                    SetWantedRecursive(td, pawns[i], false);
                } else if (!assigned[i] && canAssign[i].Accepted && !trained[i])
                {
                    SetWantedRecursive(td, pawns[i], true);
                }
            }            
        }
Exemplo n.º 25
0
 public static void DoTrainableTooltip(Rect rect, Pawn pawn, TrainableDef td, AcceptanceReport canTrain)
 {
     Traverse.Create(typeof(TrainingCardUtility))
     .Method("DoTrainableTooltip", rect, pawn, td, canTrain)
     .GetValue();     // invoke
 }
Exemplo n.º 26
0
        private static void SetWantedRecursive(TrainableDef td, Pawn pawn, bool checkOn)
        {
            pawn.training.SetWanted(td, checkOn);
            if (checkOn)
            {

                SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                if (td.prerequisites != null)
                {
                    foreach (TrainableDef trainable in td.prerequisites)
                    {
                        SetWantedRecursive(trainable, pawn, true);
                    }
                }
            }
            else
            {
                SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                IEnumerable<TrainableDef> enumerable = from t in DefDatabase<TrainableDef>.AllDefsListForReading
                                                       where t.prerequisites != null && t.prerequisites.Contains(td)
                                                       select t;
                foreach (TrainableDef current in enumerable)
                {
                    SetWantedRecursive(current, pawn, false);
                }
            }
        }
Exemplo n.º 27
0
 public AcceptanceReport CanBeTrained( PawnKindDef pawnKind, TrainableDef td, out bool visible )
 {
     if ( pawnKind.RaceProps.untrainableTags != null )
     {
         for ( int index = 0; index < pawnKind.RaceProps.untrainableTags.Count; ++index )
         {
             if ( td.MatchesTag( pawnKind.RaceProps.untrainableTags[index] ) )
             {
                 visible = false;
                 return false;
             }
         }
     }
     if ( pawnKind.RaceProps.trainableTags != null )
     {
         for ( int index = 0; index < pawnKind.RaceProps.trainableTags.Count; ++index )
         {
             if ( td.MatchesTag( pawnKind.RaceProps.trainableTags[index] ) )
             {
                 if ( pawnKind.RaceProps.baseBodySize < (double)td.minBodySize )
                 {
                     visible = true;
                     return new AcceptanceReport( "CannotTrainTooSmall".Translate( (object)pawnKind.LabelCap ) );
                 }
                 visible = true;
                 return true;
             }
         }
     }
     if ( !td.defaultTrainable )
     {
         visible = false;
         return false;
     }
     if ( pawnKind.RaceProps.baseBodySize < (double)td.minBodySize )
     {
         visible = true;
         return new AcceptanceReport( "CannotTrainTooSmall".Translate( (object)pawnKind.LabelCap ) );
     }
     if ( pawnKind.RaceProps.trainableIntelligence < td.requiredTrainableIntelligence )
     {
         visible = true;
         return
             new AcceptanceReport(
                 "CannotTrainNotSmartEnough".Translate( (object)td.requiredTrainableIntelligence ) );
     }
     visible = true;
     return true;
 }
Exemplo n.º 28
0
 public bool this[TrainableDef index]
 {
     get { return TrainingTargets[index]; }
     set { SetWantedRecursive( index, value ); }
 }
 public bool this[TrainableDef index]
 {
     get { return(TrainingTargets[index]); }
     set { SetWantedRecursive(index, value); }
 }
        private void DrawColumnHeader_Training( ref float curX, Rect rect )
        {
            List<TrainableDef> trainables = TrainableUtility.TrainableDefsInListOrder;
            float width = rect.width / trainables.Count;
            var iconSize = 16f;
            float widthOffset = ( width - iconSize ) / 2;
            float heightOffset = ( rect.height - iconSize ) / 2;
            float x = rect.xMin;
            float y = rect.yMin;

            for ( var i = 0; i < trainables.Count; i++ )
            {
                var bg = new Rect( x, y, width, rect.height );
                var icon = new Rect( x + widthOffset, y + heightOffset, iconSize, iconSize );
                x += width;
                if ( Mouse.IsOver( bg ) )
                {
                    GUI.DrawTexture( bg, TexUI.HighlightTex );
#if DEBUG
                    Log.Message( trainables[i].label );
#endif
                }
                var tooltip = new StringBuilder();
                tooltip.AppendLine( "Fluffy.SortByTrainables".Translate( trainables[i].LabelCap ) );
                tooltip.AppendLine( "Fluffy.ShiftToTrainAll".Translate() ).AppendLine()
                       .Append( trainables[i].description );
                TooltipHandler.TipRegion( bg, tooltip.ToString() );
                GUI.DrawTexture( icon, TrainingTextures[i] );
                if ( Widgets.ButtonInvisible( bg ) )
                {
                    if ( !Event.current.shift )
                    {
                        if ( MainTabWindow_Animals.Order == MainTabWindow_Animals.Orders.Training &&
                             MainTabWindow_Animals.TrainingOrder == trainables[i] )
                        {
                            MainTabWindow_Animals.Asc = !MainTabWindow_Animals.Asc;
                        }
                        else
                        {
                            MainTabWindow_Animals.Order = MainTabWindow_Animals.Orders.Training;
                            MainTabWindow_Animals.Asc = false;
                            MainTabWindow_Animals.TrainingOrder = trainables[i];
                        }
                    }
                    else if ( Event.current.shift )
                    {
                        Widgets_Animals.ToggleAllTraining( trainables[i], Pawns );
                    }
                    SoundDefOf.AmountIncrement.PlayOneShotOnCamera();
                    MainTabWindow_Animals.IsDirty = true;
                }
            }

            curX += 90f;
        }
        public static int GetSteps(Pawn_TrainingTracker training, TrainableDef td)
        {
            DefMap <TrainableDef, int> defMap = (DefMap <TrainableDef, int>)TrainingCardUtility.stepsField.GetValue(training);

            return(defMap[td]);
        }
Exemplo n.º 32
0
 private TrainingModel GetTrainingModel(TrainableDef def) => new TrainingModel(this, def);
        private void InitWork()
        {
            // Caching stuff
            if (Obedience == null)
            {
                Obedience = DefDatabase <TrainableDef> .GetNamed("Obedience");
            }
            if (Release == null)
            {
                Release = DefDatabase <TrainableDef> .GetNamed("Release");
            }
            if (Haul == null)
            {
                Haul = DefDatabase <TrainableDef> .GetNamed("Haul");
            }

            if (BasicWorker == null)
            {
                BasicWorker = DefDatabase <WorkTypeDef> .GetNamed("BasicWorker");
            }
            if (Cleaning == null)
            {
                Cleaning = DefDatabase <WorkTypeDef> .GetNamed("Cleaning");
            }
            if (Hauling == null)
            {
                Hauling = DefDatabase <WorkTypeDef> .GetNamed("Hauling");
            }

            if (IsFormerHuman())
            {
                return;
            }

            if (skills == null)
            {
                skills = new Pawn_SkillTracker(this);
                foreach (SkillRecord skill in skills.skills) // to make skills neutral for price factor
                {
                    skill.Level = 6;
                }
            }

            if (story == null)
            {
                story = new Pawn_StoryTracker(this) // necessary for job giver to work properly, but adds a bunch of problems since only humanlikes are supposed to have it
                {
                    bodyType  = BodyTypeDefOf.Thin,
                    crownType = CrownType.Average,
                    //childhood = xxx,
                    //adulthood = xxx
                };
            }

            if (workSettings == null)
            {
                workSettings = new Pawn_WorkSettings(this);
                workSettings.EnableAndInitialize();
                workSettings.DisableAll();
            }
        }
Exemplo n.º 34
0
            private void SetWantedRecursive( TrainableDef td, bool wanted )
            {
                // cop out if nothing changed
                if ( TrainingTargets[td] == wanted )
                    return;

                // make changes
                TrainingTargets[td] = wanted;
                if ( wanted )
                {
                    SoundDefOf.CheckboxTurnedOn.PlayOneShotOnCamera();
                    if ( td.prerequisites != null )
                    {
                        foreach ( TrainableDef trainable in td.prerequisites )
                        {
                            SetWantedRecursive( trainable, true );
                        }
                    }
                }
                else
                {
                    SoundDefOf.CheckboxTurnedOff.PlayOneShotOnCamera();
                    IEnumerable<TrainableDef> enumerable = from t in DefDatabase<TrainableDef>.AllDefsListForReading
                                                           where
                                                               t.prerequisites != null && t.prerequisites.Contains( td )
                                                           select t;
                    foreach ( TrainableDef current in enumerable )
                    {
                        SetWantedRecursive( current, false );
                    }
                }
            }
Exemplo n.º 35
0
 public bool this[TrainableDef index]
 {
     get => TrainingTargets[index];