public override void Apply(AbilityExecutionContext context, TargetWrapper target) { UnitDescriptor unit = context.MaybeOwner.Descriptor; AbilityData spell = context.Ability.ParamSpellSlot.Spell; Spellbook spellbook = context.Ability.ParamSpellbook; int spellLevel = context.Ability.ParamSpellLevel.Value; if (spellLevel < 1 || spellLevel > spellbook.MaxSpellLevel) { return; } foreach (var slot in spellbook.GetMemorizedSpells(spellLevel)) { if (slot.Spell == spell) { spellbook.ForgetMemorized(slot); } } unit.AddBuff(flagBuff, unit.Unit); UnityModManager.Logger.Log("Rua1?"); FastStudy.RefreshSubAbls(spellbook, spellLevel); UnityModManager.Logger.Log("Rua1?>"); FastStudy.AddMasterAbls(unit); }
static void OnGui(UnityModManager.ModEntry modEntry) { if (!modEnabled) { GUILayout.BeginHorizontal(); GUILayout.Label("The mod is disabled. Loading saved games with custom items will cause them to revert to regular versions."); GUILayout.EndHorizontal(); return; } UnitEntityData mainCharacterValue = Game.Instance?.Player?.MainCharacter.Value; if (mainCharacterValue == null || !mainCharacterValue.IsViewActive || ( Game.Instance.CurrentMode != GameModeType.Default && Game.Instance.CurrentMode != GameModeType.GlobalMap && Game.Instance.CurrentMode != GameModeType.FullScreenUi && Game.Instance.CurrentMode != GameModeType.Pause && Game.Instance.CurrentMode != GameModeType.EscMode && Game.Instance.CurrentMode != GameModeType.Rest && Game.Instance.CurrentMode != GameModeType.Kingdom )) { GUILayout.BeginHorizontal(); GUILayout.Label("Item crafting is not available in this game state."); GUILayout.EndHorizontal(); return; } GUILayout.BeginHorizontal(); GUILayout.Label($"Number of custom Craft Magic Items blueprints loaded: {customBlueprintGUIDs.Count}"); GUILayout.EndHorizontal(); RenderSelection(ref selectedItemTypeIndex, "Item Type: ", itemTypeNames, 3); ItemTypeData selectedType = itemTypeData[selectedItemTypeIndex]; // Only allow remote companions if in Oleg's (in Act I) or your capital (in Act II+) bool remote = Game.Instance.CurrentlyLoadedArea.IsCapital; List <UnitEntityData> partySpellCasters = (from entity in UIUtility.GetGroup(remote) where entity.IsPlayerFaction && !entity.Descriptor.IsPet && entity.Descriptor.Spellbooks != null && entity.Descriptor.Spellbooks.Any() && !entity.Descriptor.State.IsFinallyDead select entity).ToList <UnitEntityData>(); if (partySpellCasters.Count == 0) { GUILayout.BeginHorizontal(); GUILayout.Label("No characters with spells available."); GUILayout.EndHorizontal(); return; } GUILayout.BeginVertical(); string[] partyNames = (from entity in partySpellCasters select entity.CharacterName).ToArray <string>(); RenderSelection(ref selectedSpellcasterIndex, "Caster: ", partyNames, 8); UnitEntityData caster = partySpellCasters[selectedSpellcasterIndex]; List <Spellbook> spellbooks = (from book in caster.Descriptor.Spellbooks where book.CasterLevel > 0 select book).ToList <Spellbook>(); if (spellbooks.Count == 0) { GUILayout.BeginHorizontal(); GUILayout.Label($"{caster.CharacterName} is not yet able to cast spells."); GUILayout.EndHorizontal(); } else if (spellbooks.Count == 1) { selectedSpellbookIndex = 0; } else { string[] spellbookNames = (from book in spellbooks select book.Blueprint.Name.ToString()).ToArray <string>(); RenderSelection(ref selectedSpellbookIndex, "Class: ", spellbookNames, 10); } if (selectedSpellbookIndex < spellbooks.Count) { Spellbook spellbook = spellbooks[selectedSpellbookIndex]; int maxLevel = Math.Min(spellbook.MaxSpellLevel, selectedType.MaxSpellLevel); string[] spellLevelNames = (from index in Enumerable.Range(0, maxLevel) select $"Level {index}").ToArray <string>(); RenderSelection(ref selectedSpellLevelIndex, "Select spell level: ", spellLevelNames, 10); int spellLevel = selectedSpellLevelIndex; IEnumerable <AbilityData> spellOptions = null; if (spellLevel == 0) { // Cantrips/Orisons are special. spellOptions = spellbook.GetKnownSpells(spellLevel); } else if (spellbook.Blueprint.Spontaneous) { // Spontaneous spellcaster if (spellbook.GetSpontaneousSlots(spellLevel) > 0) { GUILayout.BeginHorizontal(); GUILayout.Label($"{caster.CharacterName} can cast {spellbook.GetSpontaneousSlots(spellLevel)} more level {spellLevel} spells today."); GUILayout.EndHorizontal(); spellOptions = spellbook.GetKnownSpells(spellLevel); } } else { // Prepared spellcaster spellOptions = (from slot in spellbook.GetMemorizedSpells(spellLevel) where slot.Spell != null && slot.Available select slot.Spell); } if (spellOptions == null || !spellOptions.Any()) { GUILayout.BeginHorizontal(); GUILayout.Label($"{caster.CharacterName} cannot currently cast any level {spellLevel} spells."); GUILayout.EndHorizontal(); } else { int minCasterLevel = Math.Max(1, 2 * spellLevel - 1); if (minCasterLevel < spellbook.CasterLevel) { selectedCasterLevel = Mathf.RoundToInt(Mathf.Clamp(selectedCasterLevel, minCasterLevel, spellbook.CasterLevel)); GUILayout.BeginHorizontal(); GUILayout.Label("Caster level: ", GUILayout.ExpandWidth(false)); selectedCasterLevel = Mathf.RoundToInt(GUILayout.HorizontalSlider(selectedCasterLevel, minCasterLevel, spellbook.CasterLevel, GUILayout.Width(300))); GUILayout.Label($"{selectedCasterLevel}", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } else { selectedCasterLevel = minCasterLevel; GUILayout.BeginHorizontal(); GUILayout.Label($"Caster level: {selectedCasterLevel}", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } foreach (AbilityData spell in spellOptions.OrderBy(spell => spell.Name).Distinct()) { if (spell.MetamagicData != null && spell.MetamagicData.NotEmpty) { GUILayout.Label($"Cannot craft {itemTypeNames[selectedItemTypeIndex]} of {spell.Name} with metamagic applied."); } else if (spell.Blueprint.HasVariants) { // Spells with choices (e.g. Protection from Alignment, which can be Protection from Evil, Good, Chaos or Law) foreach (BlueprintAbility variant in spell.Blueprint.Variants) { RenderCraftItemControl(spellbook, spell, variant, spellLevel, selectedCasterLevel); } } else { RenderCraftItemControl(spellbook, spell, spell.Blueprint, spellLevel, selectedCasterLevel); } } } GUILayout.BeginHorizontal(); GUILayout.Label($"Current Money: {Game.Instance.Player.Money}"); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }