/*
         * Uses the CharacterBuildController to edit level plans
         * Refer MainMenu.StartChargen which sets up the state and then calls CharacterBuildController.HandleLevelUpStart
         *
         */
        public static void EditLevelPlan(LevelPlanHolder levelPlanHolder, int level)
        {
            var unit = levelPlanHolder.CreateUnit(level);

            if (Main.settings.ShowDollRoom)
            {
                ShowDollRoom(unit);
            }
            CharacterBuildController characterBuildController = Game.Instance.UI.CharacterBuildController;
            var mode = level == 1 ? LevelUpState.CharBuildMode.CharGen : LevelUpState.CharBuildMode.LevelUp;

            CurrentLevelUpController = LevelUpController.Start(
                unit: unit.Descriptor,
                instantCommit: false,
                unitJson: null,
                onSuccess: null,
                mode: mode);
            CurrentLevelUpController.SelectPortrait(Game.Instance.BlueprintRoot.CharGen.Portraits[0]);
            CurrentLevelUpController.SelectGender(Gender.Male);
            CurrentLevelUpController.SelectRace(Game.Instance.BlueprintRoot.Progression.CharacterRaces[0]);
            CurrentLevelUpController.SelectAlignment(Kingmaker.Enums.Alignment.TrueNeutral);
            CurrentLevelUpController.SelectVoice(Game.Instance.BlueprintRoot.CharGen.MaleVoices[0]);
            CurrentLevelUpController.SelectName("LevelPlan");
            Traverse.Create(characterBuildController).Property <LevelUpController>("LevelUpController").Value = CurrentLevelUpController;
            Traverse.Create(characterBuildController).Field("Mode").SetValue(CurrentLevelUpController.State.Mode);
            Traverse.Create(characterBuildController).Field("Unit").SetValue(unit.Descriptor);
            characterBuildController.Show(true);
        }
Ejemplo n.º 2
0
        public static LevelPlanHolder LoadLevelingPlan(string filepath)
        {
            var JsonSettings = new JsonSerializerSettings
            {
                TypeNameAssemblyFormat     = FormatterAssemblyStyle.Simple,
                Formatting                 = Formatting.Indented,
                Converters                 = DefaultJsonSettings.CommonConverters.ToList <JsonConverter>(),
                ContractResolver           = new OptInContractResolver(),
                TypeNameHandling           = TypeNameHandling.Auto,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                DefaultValueHandling       = DefaultValueHandling.Include,
                ReferenceLoopHandling      = ReferenceLoopHandling.Serialize
            };
            var serializer = JsonSerializer.Create(JsonSettings);

            using (StreamReader sr = new StreamReader(filepath))
                using (JsonTextReader reader = new JsonTextReader(sr))
                {
                    LevelPlanData[] data            = serializer.Deserialize <LevelPlanData[]>(reader);
                    var             levelPlanHolder = new LevelPlanHolder
                    {
                        LevelPlanData = data,
                        Name          = Path.GetFileNameWithoutExtension(filepath)
                    };
                    return(levelPlanHolder);
                }
        }
Ejemplo n.º 3
0
        internal static void TestDefaultLevelPlan2()
        {
            var            defaultClass   = ResourcesLibrary.TryGetBlueprint <BlueprintCharacterClass>("0937bec61c0dabc468428f496580c721"); //Alchemist
            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);
            UnitEntityData unitData       = Main.settings.DefaultPointBuy25 ?
                                            Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.DefaultPlayerCharacter) :
                                            Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.CustomCompanion);
            var unit = unitData.Descriptor;

            LogUnit("BlankUnit.txt", unit);
            var  levelUpController = TestLevelUpController.Start(unit: unit, instantCommit: true, unitJson: null, onSuccess: null, mode: LevelUpState.CharBuildMode.CharGen);
            bool success           = true;

            success = levelUpController.SelectPortrait(ResourcesLibrary.GetBlueprints <BlueprintPortrait>().First());
            if (!success)
            {
                Main.Log("Error selecting portrait");
            }
            success = levelUpController.SelectGender(Gender.Male);
            if (!success)
            {
                Main.Log("Error selecting gender");
            }
            var race = ResourcesLibrary.TryGetBlueprint <BlueprintRace>("0a5d473ead98b0646b94495af250fdc4"); //Human

            race    = ResourcesLibrary.TryGetBlueprint <BlueprintRace>("5c4e42124dc2b4647af6e36cf2590500");  //Tiefling
            success = levelUpController.SelectRace(race);
            if (!success)
            {
                Main.Log("Error selecting race");
            }
            levelUpController.State.SelectedClass = ResourcesLibrary.TryGetBlueprint <BlueprintCharacterClass>("0937bec61c0dabc468428f496580c721");
            ApplyDefaultBuild(levelUpController);
            //success = levelUpController.SelectClass(ResourcesLibrary.TryGetBlueprint<BlueprintCharacterClass>("0937bec61c0dabc468428f496580c721"));
            //if (!success) Main.Log("Error selecting class");
            //levelUpController.ApplyClassMechanics();
            //levelUpController.ApplySpellbook();
            //levelUpController.SelectDefaultClassBuild();

            var levelPlanHolder = new LevelPlanHolder();

            for (int i = 0; i < 20; i++)
            {
                var plan = unit.Progression.GetLevelPlan(i + 1);
                levelPlanHolder.LevelPlanData[i] = plan;
            }
            LevelPlanManager.CurrentLevelPlan = levelPlanHolder;

            var token = UnitSerialization.Serialize(unit);

            File.WriteAllText("TestDefaultAlch.json", token.ToString());
            LogUnit("TestDefaultAlch.txt", unit);
        }
Ejemplo n.º 4
0
        public static void SaveLevelingPlan(LevelPlanHolder levelPlan)
        {
            string invalid = new string(Path.GetInvalidFileNameChars());

            foreach (char c in invalid)
            {
                levelPlan.Name = levelPlan.Name.Replace(c.ToString(), "");
            }
            if (string.IsNullOrEmpty(levelPlan.Name))
            {
                levelPlan.Name = "LevelPlan";
            }
            Dump(levelPlan.LevelPlanData, $"Mods/CharacterBuilder/LevelPlans/{levelPlan.Name}.json");
        }
Ejemplo n.º 5
0
        internal static void TestDefaultLevelPlan3()
        {
            var defaultClass = ResourcesLibrary.TryGetBlueprint <BlueprintCharacterClass>("0937bec61c0dabc468428f496580c721"); //Alchemist
            var defaultBuild = defaultClass.DefaultBuild;
            //Note: DefaultPlayerCharacter is StartGame_Player_Unit 4391e8b9afbb0cf43aeba700c089f56d
            //CustomCompanion is CustomCompanion baaff53a675a84f4983f1e2113b24552
            UnitEntityData unitData = Main.settings.DefaultPointBuy25 ?
                                      Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.DefaultPlayerCharacter) :
                                      Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.CustomCompanion);
            var unit = unitData.Descriptor;
            var race = ResourcesLibrary.TryGetBlueprint <BlueprintRace>("0a5d473ead98b0646b94495af250fdc4"); //Human

            race = ResourcesLibrary.TryGetBlueprint <BlueprintRace>("5c4e42124dc2b4647af6e36cf2590500");     //Tiefling
            unit.Progression.SetRace(race);
            //DefaultBuildData sets a global variable DefaultBuildData that is used by AddClassLevels to determine the race to use
            //If race is not set, it defaults to  unit.Progression.Race;
            using (new DefaultBuildData(race))
            {
                DefaultBuildData data = ElementsContext.GetData <DefaultBuildData>();
                Main.Log($"Default Build Data {data.Race.name}");
                unit.Ensure <LevelUpPlanUnitHolder>();
                unit.Progression.DropLevelPlans();
                unit.AddFact(defaultBuild, null, null);
                var levelPlanHolder = new LevelPlanHolder();
                for (int i = 0; i < 20; i++)
                {
                    var plan = unit.Progression.GetLevelPlan(i + 1);
                    levelPlanHolder.LevelPlanData[i] = plan;
                }
                var levelPlan = unit.Progression.GetLevelPlan(1);
                var stats     = levelPlan.Actions.Select(action =>
                {
                    if (action is AddStatPoint add)
                    {
                        return(1);
                    }
                    if (action is RemoveStatPoint)
                    {
                        return(-1);
                    }
                    return(0);
                }).Sum();
                Main.Log($"Added {stats} points");
                LevelPlanManager.CurrentLevelPlan = levelPlanHolder;
            }
        }
Ejemplo n.º 6
0
/*
 * Test creating a levelplan from a class's DefaultBuild. Refer AddClassLevels.LevelUp and LevelUpController.SelectDefaultClassBuild
 */
        internal static void TestDefaultLevelPlan()
        {
            var            defaultClass   = ResourcesLibrary.TryGetBlueprint <BlueprintCharacterClass>("0937bec61c0dabc468428f496580c721"); //Alchemist
            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);
            UnitEntityData unitData       = Main.settings.DefaultPointBuy25 ?
                                            Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.DefaultPlayerCharacter) :
                                            Game.Instance.CreateUnitVacuum(BlueprintRoot.Instance.CustomCompanion);
            var unit = unitData.Descriptor;

            new TestAddClassLevels(addClassLevels).LevelUp(unit, 5);
            Main.Log($"unit level {unit.Progression.CharacterLevel}");
            var levelPlanHolder = new LevelPlanHolder();

            for (int i = 0; i < 20; i++)
            {
                var plan = unit.Progression.GetLevelPlan(i);
                levelPlanHolder.LevelPlanData[i] = plan;
            }
            LevelPlanManager.CurrentLevelPlan = levelPlanHolder;
        }