Exemplo n.º 1
0
        private LevelUpController AddLevel(UnitDescriptor unit, Dictionary <SelectionEntry, HashSet <int> > selectionsHistory, HashSet <int> spellHistory)
        {
            LevelUpController levelUpController = LevelUpController.Start(unit, true, null, null, LevelUpState.CharBuildMode.LevelUp);

            if (levelUpController.State.CanSelectRace)
            {
                BlueprintRace    race = unit.Progression.Race;
                DefaultBuildData data = ElementsContext.GetData <DefaultBuildData>();
                if (data != null)
                {
                    race = data.Race;
                }
                if (race != null)
                {
                    levelUpController.SelectRace(race);
                }
            }
            if (levelUpController.State.CanSelectRaceStat)
            {
                levelUpController.SelectRaceStat(instance.RaceStat);
            }
            this.ApplyStatsDistributionPreset(levelUpController);
            if (unit.Progression.GetClassLevel(instance.CharacterClass) <= 0)
            {
                foreach (BlueprintArchetype archetype in instance.Archetypes)
                {
                    levelUpController.AddArchetype(instance.CharacterClass, archetype);
                }
            }
            levelUpController.SelectClass(instance.CharacterClass, false);
            levelUpController.ApplyClassMechanics();
            this.PerformSelections(levelUpController, selectionsHistory, new LevelUpActionPriority?(LevelUpActionPriority.ReplaceSpellbook));
            levelUpController.ApplySpellbook();
            while (levelUpController.State.AttributePoints > 0 && instance.LevelsStat.IsAttribute())
            {
                levelUpController.SpendAttributePoint(instance.LevelsStat);
            }
            this.PerformSelections(levelUpController, selectionsHistory, new LevelUpActionPriority?(LevelUpActionPriority.ApplySkillPoints));
            levelUpController.ApplySkillPoints();
            while (levelUpController.State.SkillPointsRemaining > 0)
            {
                int skillPointsRemaining = levelUpController.State.SkillPointsRemaining;
                foreach (StatType skill in instance.Skills)
                {
                    if (levelUpController.State.SkillPointsRemaining <= 0)
                    {
                        break;
                    }
                    levelUpController.SpendSkillPoint(skill);
                }
                if (skillPointsRemaining == levelUpController.State.SkillPointsRemaining)
                {
                    break;
                }
            }
            this.PerformSelections(levelUpController, selectionsHistory, null);
            this.PerformSpellSelections(levelUpController, spellHistory);
            return(levelUpController);
        }
Exemplo n.º 2
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;
            }
        }