Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions ToyBox/classes/Infrastructure/CasterHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void HandleAddAllSpellsOnPartyEditor(UnitDescriptor unit) {
selectedSpellbook.RemoveSpellsOfLevel(level);
}

#if true // TODO: the else case if a patch that fixes the level for spontaneous spell casters learning scrolls
#if false // TODO: the else case if a patch that fixes the level for spontaneous spell casters learning scrolls
public static int GetActualSpellsLearnedForClass(UnitDescriptor unit, Spellbook spellbook, int level) {
Mod.Trace($"GetActualSpellsLearnedForClass - unit: {unit?.CharacterName} spellbook: {spellbook?.Blueprint.DisplayName} level:{level}");
// Get all +spells known facts for this spellbook's class so we can ignore them when getting spell counts
Expand Down Expand Up @@ -193,17 +193,16 @@ public static int GetActualSpellsLearned(Spellbook spellbook, int level, List<Bl
return known.Count;
}
#else
public static int GetActualSpellsLearnedForClass(UnitDescriptor unit, Spellbook spellbook, int level) {
public static int GetActualSpellsLearnedForClass(UnitDescriptor unit, Spellbook spellbook, int level, UnitDescriptor baseUnit = null) {
Mod.Trace($"GetActualSpellsLearnedForClass - unit: {unit?.CharacterName} spellbook: {spellbook?.Blueprint.DisplayName} level:{level}");
// Get all +spells known facts for this spellbook's class so we can ignore them when getting spell counts
var spellsToIgnore = unit.Facts.List.SelectMany(x =>
x.BlueprintComponents.Where(y => y is AddKnownSpell)).Select(z => z as AddKnownSpell)
.Where(x => x.CharacterClass == spellbook.Blueprint.CharacterClass && (x.Archetype == null || unit.Progression.IsArchetype(x.Archetype))).Select(y => y.Spell)
.ToList();
Spellbook spellbookOfNormalUnit = null;
if (unit.TryGetPartyMemberForLevelUpVersion(out var ch)) { // get the real units spellbook, the levelup version does not contain flags like CopiedFromScroll
if (ch?.Spellbooks?.Count() > 0)
spellbookOfNormalUnit = ch.Spellbooks.First(s => s.Blueprint == spellbook.Blueprint);
if (baseUnit != null) { // get the real units spellbook, the levelup version does not contain flags like CopiedFromScroll
spellbookOfNormalUnit = baseUnit.Spellbooks?.FirstOrDefault(s => s.Blueprint == spellbook.Blueprint);
}
return GetActualSpellsLearned(spellbook, level, spellsToIgnore, spellbookOfNormalUnit);
}
Expand All @@ -224,18 +223,20 @@ public static int GetActualSpellsLearned(Spellbook spellbook, int level, List<Bl
Func<AbilityData, bool> normalSpellbookCondition = x => true;
if (spellbookOfNormalUnit != null) {
var normalSpellsOfLevel = spellbookOfNormalUnit.SureKnownSpells(level);
normalSpellbookCondition = x => {
var sp = normalSpellsOfLevel.First(a => a.Blueprint == x.Blueprint);
if (sp == null)
return true;
return !sp.IsTemporary
&& !sp.CopiedFromScroll
&& !sp.IsFromMythicSpellList
&& sp.SourceItem == null
&& sp.SourceItemEquipmentBlueprint == null
&& sp.SourceItemUsableBlueprint == null
&& !sp.IsMysticTheurgeCombinedSpell;
};
if (normalSpellsOfLevel != null) {
normalSpellbookCondition = x => {
var sp = normalSpellsOfLevel.FirstOrDefault(a => a.Blueprint == x.Blueprint);
if (sp == null)
return true;
return !sp.IsTemporary
&& !sp.CopiedFromScroll
&& !sp.IsFromMythicSpellList
&& sp.SourceItem == null
&& sp.SourceItemEquipmentBlueprint == null
&& sp.SourceItemUsableBlueprint == null
&& !sp.IsMysticTheurgeCombinedSpell;
};
}
}
var known = spellbook.SureKnownSpells(level)
.Where(x => !x.IsTemporary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static bool Apply(LevelUpState state, UnitDescriptor unit) {
for (var index = 0; index <= 10; ++index) {
var spellsKnown = spellbook1.Blueprint.SpellsKnown;
var expectedCount = spellsKnown.GetCount(casterLevelAfter, index);
var actual = CasterHelpers.GetActualSpellsLearnedForClass(unit, spellbook1, index);
var actual = CasterHelpers.GetActualSpellsLearnedForClass(unit, spellbook1, index, Game.Instance.LevelUpController.m_BaseUnit);
int learnabl = spellbook1.GetSpellsLearnableOfLevel(index).Count();
int spelladd = Math.Max(0, Math.Min(expectedCount - actual, learnabl));
#if DEBUG
Expand Down