static void removeSpell(BlueprintAbility s, Spellbook sb) { var ability_datas = sb.GetAllKnownSpells().Where(a => a.Blueprint == s).ToArray(); sb.RemoveSpell(s); foreach (var a in ability_datas) { EventBus.RaiseEvent <ISpellBookCustomSpell>((Action <ISpellBookCustomSpell>)(h => h.RemoveSpellHandler(a))); } }
static void Postfix(Spellbook __instance) { if (!__instance.Blueprint.Spontaneous) { return; } var memorization_spellbook_blueprint = __instance.Blueprint.GetComponent <GetKnownSpellsFromMemorizationSpellbook>()?.spellbook; if (memorization_spellbook_blueprint == null || memorization_spellbook_blueprint.Spontaneous) { return; } var memorization_spellbook = __instance.Owner?.Spellbooks.Where(s => s.Blueprint == memorization_spellbook_blueprint).FirstOrDefault(); if (memorization_spellbook == null) { return; } foreach (var s in __instance.GetAllKnownSpells().ToArray()) { __instance.RemoveSpell(s.Blueprint); } __instance.Owner.Ensure <SpellManipulationMechanics.UnitPartArcanistPreparedMetamagic>().clear(); var m_known_spells = Helpers.GetField <List <AbilityData>[]>(__instance, "m_KnownSpells"); var m_known_SpellLevels = Helpers.GetField <Dictionary <BlueprintAbility, int> >(__instance, "m_KnownSpellLevels"); foreach (var slot in memorization_spellbook.GetAllMemorizedSpells()) { if (slot.Spell != null) { var new_ability = new AbilityData(slot.Spell.Blueprint, __instance); if (slot.Spell.MetamagicData != null) { new_ability.MetamagicData = slot.Spell.MetamagicData.Clone(); __instance.Owner.Ensure <SpellManipulationMechanics.UnitPartArcanistPreparedMetamagic>().add(new_ability.Blueprint, new_ability.MetamagicData.MetamagicMask); } else { __instance.Owner.Ensure <SpellManipulationMechanics.UnitPartArcanistPreparedMetamagic>().add(new_ability.Blueprint, (Metamagic)0); } var spell_level = memorization_spellbook.GetSpellLevel(slot.Spell.Blueprint); new_ability.DecorationBorderNumber = slot.Spell.DecorationBorderNumber; new_ability.DecorationColorNumber = slot.Spell.DecorationColorNumber; m_known_spells[slot.Spell.SpellLevel].Add(new_ability); m_known_SpellLevels[slot.Spell.Blueprint] = spell_level; EventBus.RaiseEvent <ISpellBookCustomSpell>((Action <ISpellBookCustomSpell>)(h => h.AddSpellHandler(new_ability))); } } }
public static bool Prefix(LevelUpState state, UnitDescriptor unit) { if (!settings.toggleMulticlass) { return(false); } if ((UnityEngine.Object)state.SelectedClass == (UnityEngine.Object)null) { return(true); } SkipLevelsForSpellProgression component1 = state.SelectedClass.GetComponent <SkipLevelsForSpellProgression>(); if ((UnityEngine.Object)component1 != (UnityEngine.Object)null && ((IEnumerable <int>)component1.Levels).Contains <int>(state.NextClassLevel)) { return(true); } ClassData classData = unit.Progression.GetClassData(state.SelectedClass); if (classData == null || !((UnityEngine.Object)classData.Spellbook != (UnityEngine.Object)null)) { return(true); } Spellbook spellbook1 = unit.DemandSpellbook(classData.Spellbook); if ((bool)(UnityEngine.Object)state.SelectedClass.Spellbook && (UnityEngine.Object)state.SelectedClass.Spellbook != (UnityEngine.Object)classData.Spellbook) { Spellbook spellbook2 = unit.Spellbooks.FirstOrDefault <Spellbook>((Func <Spellbook, bool>)(s => (UnityEngine.Object)s.Blueprint == (UnityEngine.Object)state.SelectedClass.Spellbook)); if (spellbook2 != null) { foreach (AbilityData allKnownSpell in spellbook2.GetAllKnownSpells()) { spellbook1.AddKnown(allKnownSpell.SpellLevel, allKnownSpell.Blueprint); } unit.DeleteSpellbook(state.SelectedClass.Spellbook); } } int casterLevelBefore = spellbook1.CasterLevel; spellbook1.AddLevelFromClass(classData.CharacterClass); int casterLevelAfter = spellbook1.CasterLevel; if (casterLevelBefore == casterLevelAfter) { return(true); // Mod line } SpellSelectionData spellSelectionData = state.DemandSpellSelection(spellbook1.Blueprint, spellbook1.Blueprint.SpellList); if ((UnityEngine.Object)spellbook1.Blueprint.SpellsKnown != (UnityEngine.Object)null) { for (int index = 0; index <= 10; ++index) { BlueprintSpellsTable spellsKnown = spellbook1.Blueprint.SpellsKnown; int?count = spellsKnown.GetCount(casterLevelBefore, index); int num1 = count ?? 0; count = spellsKnown.GetCount(casterLevelAfter, index); int num2 = count ?? 0; spellSelectionData.SetLevelSpells(index, Math.Max(0, num2 - num1)); } } int 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 (AddCustomSpells component2 in spellbook1.Blueprint.GetComponents <AddCustomSpells>()) { ApplySpellbook.TryApplyCustomSpells(spellbook1, component2, state, unit); } return(true); }
static public bool Prefix(ApplySpellbook __instance, LevelUpState state, UnitDescriptor unit) { if (state.SelectedClass != ArcanistClass.arcanist) { return(true); } if (state.SelectedClass == null) { return(false); } SkipLevelsForSpellProgression component = state.SelectedClass.GetComponent <SkipLevelsForSpellProgression>(); if (component != null && component.Levels.Contains(state.NextClassLevel)) { return(false); } ClassData classData = unit.Progression.GetClassData(state.SelectedClass); if (classData == null) { return(false); } if (classData.Spellbook != null) { Spellbook spellbook = unit.DemandSpellbook(classData.Spellbook); if (state.SelectedClass.Spellbook && state.SelectedClass.Spellbook != classData.Spellbook) { Spellbook spellbook2 = unit.Spellbooks.FirstOrDefault((Spellbook s) => s.Blueprint == state.SelectedClass.Spellbook); if (spellbook2 != null) { foreach (AbilityData abilityData in spellbook2.GetAllKnownSpells()) { spellbook.AddKnown(abilityData.SpellLevel, abilityData.Blueprint, false); } unit.DeleteSpellbook(state.SelectedClass.Spellbook); } } int casterLevel = spellbook.CasterLevel; spellbook.AddCasterLevel(); int casterLevel2 = spellbook.CasterLevel; SpellSelectionData spellSelectionData = state.DemandSpellSelection(spellbook.Blueprint, spellbook.Blueprint.SpellList); if (spellbook.Blueprint.SpellsKnown != null && 1 == 0) { // SelectedClass must be arcanist, arcanist requires wizard-like spell selection, // while its SpellsKnown is not null for (int i = 0; i <= 9; i++) { int?count = spellbook.Blueprint.SpellsKnown.GetCount(casterLevel, i); int num = (count == null) ? 0 : count.Value; int?count2 = spellbook.Blueprint.SpellsKnown.GetCount(casterLevel2, i); int num2 = (count2 == null) ? 0 : count2.Value; spellSelectionData.SetLevelSpells(i, num2 - num); } } int maxSpellLevel = spellbook.MaxSpellLevel; if (spellbook.Blueprint.SpellsPerLevel > 0) { if (casterLevel == 0) { spellSelectionData.SetExtraSpells(0, maxSpellLevel); spellSelectionData.ExtraByStat = true; spellSelectionData.UpdateMaxLevelSpells(unit); } else { spellSelectionData.SetExtraSpells(spellbook.Blueprint.SpellsPerLevel, maxSpellLevel); } } foreach (AddCustomSpells customSpells in spellbook.Blueprint.GetComponents <AddCustomSpells>()) { ApplySpellbook_TryApplyCustomSpells(__instance, spellbook, customSpells, state, unit); } } return(false); }