コード例 #1
0
 public LevelPlanHolder()
 {
     for (int i = 0; i < LevelPlanData.Length; i++)
     {
         LevelPlanData[i] = new LevelPlanData(i + 1, new Kingmaker.UnitLogic.Class.LevelUp.Actions.ILevelUpAction[] { });
     }
 }
コード例 #2
0
 public void AddLevelPlan(LevelPlanData plan)
 {
     IsDirty   = true;
     IsApplied = false;
     LevelPlanData[plan.Level - 1] = plan;
     VerifyLevelPlan();
 }
コード例 #3
0
        static void ApplyDefaultBuild(TestLevelUpController controller)
        {
            var           defaultBuild = controller.State.SelectedClass.DefaultBuild;
            BlueprintRace race         = controller.Preview.Progression.Race;

            controller.Unit.Ensure <LevelUpPlanUnitHolder>();
            controller.Unit.Progression.DropLevelPlans();
            controller.Unit.AddFact(defaultBuild, null, null);
            LevelPlanData levelPlan = controller.Unit.Progression.GetLevelPlan(controller.State.NextLevel);
        }
コード例 #4
0
        /*
         * Create a level plan from BlueprintCharacterClass' defaultBuild
         * Refer AddClassLevels.LevelUp and LevelController.ApplyStatsDistributionPreset
         * LevelUpController.SelectDefaultClassBuild and CharacterBuildController.LoadDefaultProgression
         *
         * AddClassLevels and StatsDistributionPreset are both components of
         * BlueprintCharacterClass.DefaultBuild
         */
        public LevelPlanHolder(BlueprintCharacterClass defaultClass)
        {
            bool IsDefaultBuildPriority(LevelUpActionPriority priority)
            {
                return(priority != LevelUpActionPriority.Visual && priority != LevelUpActionPriority.Race && priority != LevelUpActionPriority.Class &&
                       priority != LevelUpActionPriority.ApplyClass && priority != LevelUpActionPriority.ApplySpellbook && priority != LevelUpActionPriority.ApplySkillPoints &&
                       priority != LevelUpActionPriority.Alignment);
            }

            using (new CodeTimer("Create default build"))
            {
                var defaultBuild   = defaultClass.DefaultBuild;
                var addClassLevels = defaultBuild.GetComponent <AddClassLevels>();
                var targetPoints   = Main.settings.DefaultPointBuy25 ? 25 : 20;
                var stats          = defaultBuild.GetComponents <StatsDistributionPreset>().FirstOrDefault(sd => sd.TargetPoints == targetPoints);
                //var race = Game.Instance.BlueprintRoot.Progression.CharacterRaces[0];
                var            race = ResourcesLibrary.TryGetBlueprint <BlueprintRace>("5c4e42124dc2b4647af6e36cf2590500");
                UnitEntityData unit = Main.settings.DefaultPointBuy25 ?
                                      Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.DefaultPlayerCharacter) :
                                      Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.CustomCompanion);
                var levelUpController = LevelUpController.Start(unit.Descriptor,
                                                                instantCommit: true,
                                                                mode: LevelUpState.CharBuildMode.CharGen);
                if (!levelUpController.SelectPortrait(Game.Instance.BlueprintRoot.CharGen.Portraits[0]))
                {
                    throw new Exception("Error selecting portrait");
                }
                if (!levelUpController.SelectGender(Gender.Male))
                {
                    throw new Exception("Error selecting gender");
                }
                if (!levelUpController.SelectRace(race))
                {
                    throw new Exception("Error selecting race");
                }
                //Default build must be aquired after selecting race but before selecting class
                levelUpController.Unit.Ensure <LevelUpPlanUnitHolder>();
                levelUpController.Unit.Progression.DropLevelPlans();
                levelUpController.Unit.AddFact(defaultBuild, null, null);
                LevelPlanData levelPlan = levelUpController.Unit.Progression.GetLevelPlan(levelUpController.State.NextLevel);
                if (!levelUpController.SelectClass(defaultClass))
                {
                    throw new Exception("Error selecting class");
                }
                levelUpController.LevelUpActions.RemoveAll((ILevelUpAction a) => IsDefaultBuildPriority(a.Priority));
                levelUpController.LevelUpActions.AddRange(from a in levelPlan.Actions
                                                          where IsDefaultBuildPriority(a.Priority)
                                                          select a);
                levelUpController.LevelUpActions = (from a in levelUpController.LevelUpActions
                                                    orderby a.Priority
                                                    select a).ToList();
                if (!levelUpController.SelectAlignment(Kingmaker.Enums.Alignment.TrueNeutral))
                {
                    throw new Exception("Error selecting alignment");
                }
                if (!levelUpController.SelectName($"Default {defaultClass.Name} Build"))
                {
                    throw new Exception("Error selecting name");
                }
                for (int i = 0; i < 20; i++)
                {
                    var plan = unit.Descriptor.Progression.GetLevelPlan(i + 1);
                    LevelPlanData[i] = plan;
                }
                LevelPlanData[0] = new LevelPlanData(1, levelUpController.LevelUpActions.ToArray());
            }
            using (new CodeTimer("Verify default build"))
            {
                VerifyLevelPlan();
            }
        }
コード例 #5
0
 public bool SelectDefaultClassBuild()
 {
     if (!this.HasNextLevelPlan)
     {
         return(false);
     }
     if (!this.State.IsFirstLevel)
     {
         this.RemoveAction <SelectClass>(null);
         bool flag = this.ApplyLevelUpPlan(true);
         if (flag)
         {
             this.m_PlanChanged = false;
             this.UpdateDifficulty();
             return(true);
         }
         return(false);
     }
     else
     {
         if (this.State.SelectedClass == null)
         {
             return(false);
         }
         BlueprintUnitFact defaultBuild = this.State.SelectedClass.DefaultBuild;
         if (defaultBuild == null)
         {
             return(false);
         }
         BlueprintRace race = this.Preview.Progression.Race;
         if (race == null || this.State.CanSelectRace)
         {
             return(false);
         }
         bool result;
         try
         {
             using (new DefaultBuildData(race))
             {
                 this.Unit.Ensure <LevelUpPlanUnitHolder>();
                 this.Unit.Progression.DropLevelPlans();
                 this.Unit.AddFact(defaultBuild, null, null);
                 LevelPlanData levelPlan = this.Unit.Progression.GetLevelPlan(this.State.NextLevel);
                 if (levelPlan == null)
                 {
                     result = false;
                 }
                 else
                 {
                     this.m_RecalculatePreview = true;
                     this.LevelUpActions.RemoveAll((ILevelUpAction a) => TestLevelUpController.IsDefaultBuildPriority(a.Priority));
                     this.LevelUpActions.AddRange(from a in levelPlan.Actions
                                                  where TestLevelUpController.IsDefaultBuildPriority(a.Priority)
                                                  select a);
                     this.LevelUpActions = (from a in this.LevelUpActions
                                            orderby a.Priority
                                            select a).ToList <ILevelUpAction>();
                     this.UpdatePreview();
                     this.m_HasPlan     = true;
                     this.m_PlanChanged = false;
                     this.UpdateDifficulty();
                     result = true;
                 }
             }
         }
         finally
         {
             this.Unit.RemoveFact(defaultBuild);
             this.Unit.Remove <LevelUpPlanUnitHolder>();
         }
         return(result);
     }
 }
コード例 #6
0
        private bool ApplyLevelUpPlan(bool ignoreSettings = false)
        {
            this.m_HasPlan = false;
            bool flag2;

            if (this.State.Mode != LevelUpState.CharBuildMode.PreGen && !ignoreSettings)
            {
                var UnitPartImportableCompanionType = Type.GetType("Kingmaker.Dungeon.Units.UnitPartImportableCompanion, Assembly-CSharp");
                var unitPartImportableCompanion     = GetUnitPart(UnitPartImportableCompanionType, this.Unit);
                flag2 = unitPartImportableCompanion != null ?
                        (bool)AccessTools.Field(UnitPartImportableCompanionType, "IsOnImportedPlan").GetValue(unitPartImportableCompanion) :
                        false;
            }
            else
            {
                flag2 = true;
            }
            bool flag3 = flag2;

            if (!flag3)
            {
                switch (Game.Instance.Player.Difficulty.AutoLevelup)
                {
                case AutolevelupState.Off:
                    flag3 = false;
                    break;

                case AutolevelupState.Companions:
                    flag3 = (this.Unit.Unit != Game.Instance.Player.MainCharacter);
                    break;

                case AutolevelupState.AllPossible:
                    flag3 = true;
                    break;

                default:
                    flag3 = false;
                    break;
                }
            }
            if (!flag3)
            {
                return(false);
            }
            LevelPlanData levelPlan = this.Unit.Progression.GetLevelPlan(this.State.NextLevel);

            if (levelPlan == null)
            {
                return(false);
            }
            this.m_ApplyingPlan = true;
            try
            {
                foreach (ILevelUpAction action in levelPlan.Actions)
                {
                    this.m_HasPlan = true;
                    this.AddAction(action, true);
                }
            }
            finally
            {
                this.m_ApplyingPlan = false;
            }
            return(this.m_HasPlan);
        }