Пример #1
0
 private static void Postfix(LevelUpController __instance)
 {
     Mod.Debug("Clearing Cache because LevelUpController.Commit called");
     CasterHelpers.ClearCachedSpellsLearned(__instance.Unit);
     CasterHelpers.CacheSpellsLearned(__instance.Unit);
 }
Пример #2
0
            public static bool Prefix(LevelUpState state, UnitDescriptor unit)
            {
                if (!settings.toggleMulticlass)
                {
                    return(true);
                }

                if (state.SelectedClass == null)
                {
                    return(false);
                }

                var component1 = state.SelectedClass.GetComponent <SkipLevelsForSpellProgression>();

                if (component1 != null && component1.Levels.Contains(state.NextClassLevel))
                {
                    return(false);
                }

                var classData = unit.Progression.GetClassData(state.SelectedClass);

                if (classData?.Spellbook == null)
                {
                    return(false);
                }

                var spellbook1 = unit.DemandSpellbook(classData.Spellbook);

                if (state.SelectedClass.Spellbook && state.SelectedClass.Spellbook != classData.Spellbook)
                {
                    var spellbook2 = unit.Spellbooks.FirstOrDefault(s => s.Blueprint == state.SelectedClass.Spellbook);
                    if (spellbook2 != null)
                    {
                        foreach (var allKnownSpell in spellbook2.GetAllKnownSpells())
                        {
                            spellbook1.AddKnown(allKnownSpell.SpellLevel, allKnownSpell.Blueprint);
                        }

                        unit.DeleteSpellbook(state.SelectedClass.Spellbook);
                    }
                }
                var casterLevelAfter = CasterHelpers.GetRealCasterLevel(unit, spellbook1.Blueprint);     // Calculates based on progression which includes class selected in level up screen

                spellbook1.AddLevelFromClass(classData.CharacterClass);                                  // This only adds one class at a time and will only ever increase by 1 or 2
                var casterLevelBefore  = casterLevelAfter - (classData.CharacterClass.IsMythic ? 2 : 1); // Technically only needed to see if this is our first level of a casting class
                var spellSelectionData = state.DemandSpellSelection(spellbook1.Blueprint, spellbook1.Blueprint.SpellList);

                if (spellbook1.Blueprint.SpellsKnown != null)
                {
                    for (var index = 0; index <= 10; ++index)
                    {
                        var spellsKnown   = spellbook1.Blueprint.SpellsKnown;
                        var expectedCount = spellsKnown.GetCount(casterLevelAfter, index);
                        var actual        = CasterHelpers.GetCachedSpellsKnown(unit, spellbook1, index);
#if DEBUG
                        //Mod.Trace($"Spellbook {spellbook1.Blueprint.Name}: Granting {expectedCount-actual} spells of spell level:{index} based on expected={expectedCount} and actual={actual}");
#endif
                        spellSelectionData.SetLevelSpells(index, Math.Max(0, expectedCount - actual));
                    }
                }
                var maxSpellLevel = spellbook1.MaxSpellLevel;
                if (spellbook1.Blueprint.SpellsPerLevel > 0)
                {
                    if (casterLevelBefore == 0)
                    {
                        spellSelectionData.SetExtraSpells(0, maxSpellLevel);
                        spellSelectionData.ExtraByStat = true;
                        spellSelectionData.UpdateMaxLevelSpells(unit);
                    }
                    else
                    {
                        spellSelectionData.SetExtraSpells(spellbook1.Blueprint.SpellsPerLevel, maxSpellLevel);
                    }
                }
                foreach (var component2 in spellbook1.Blueprint.GetComponents <AddCustomSpells>())
                {
                    ApplySpellbook.TryApplyCustomSpells(spellbook1, component2, state, unit);
                }

                return(false);
            }
Пример #3
0
 private static void Postfix(UnitEntityData entity) => CasterHelpers.CacheSpellsLearned(entity);