public static void RemoveAbility(this UnitEntityData ch, BlueprintAbility ability) { if (ability.IsSpell) { if (PartyEditor.IsOnPartyEditor() && PartyEditor.SelectedSpellbook.TryGetValue(ch.HashKey(), out var selectedSpellbook)) { if (UIUtilityUnit.SpellbookHasSpell(selectedSpellbook, ability)) { selectedSpellbook.RemoveSpell(ability); return; } } foreach (var spellbook in ch.Spellbooks) { if (UIUtilityUnit.SpellbookHasSpell(spellbook, ability)) { spellbook.RemoveSpell(ability); } } } var abilities = ch.Descriptor.Abilities; if (abilities.HasFact(ability)) { abilities.RemoveFact(ability); } }
public static bool HasAbility(this UnitEntityData ch, BlueprintAbility ability) { if (ability.IsSpell) { if (PartyEditor.IsOnPartyEditor() && PartyEditor.SelectedSpellbook.TryGetValue(ch.HashKey(), out var selectedSpellbook)) { return(UIUtilityUnit.SpellbookHasSpell(selectedSpellbook, ability)); } } return(ch.Spellbooks.Any(spellbook => spellbook.IsKnown(ability)) || ch.Descriptor.Abilities.HasFact(ability)); }
public static void AddAbility(this UnitEntityData ch, BlueprintAbility ability) { if (ability.IsSpell) { if (CanAddAbility(ch, ability)) { if (PartyEditor.IsOnPartyEditor() && PartyEditor.SelectedSpellbook.TryGetValue(ch.HashKey(), out var selectedSpellbook)) { selectedSpellbook.AddKnown(PartyEditor.selectedSpellbookLevel, ability); return; } } Mod.Trace($"adding spell: {ability.Name}"); foreach (var spellbook in ch.Spellbooks) { var spellbookBP = spellbook.Blueprint; var maxLevel = spellbookBP.MaxSpellLevel; Mod.Trace($"checking {spellbook.Blueprint.Name} maxLevel: {maxLevel}"); for (var level = 0; level <= maxLevel; level++) { var learnable = spellbookBP.SpellList.GetSpells(level); var allowsSpell = learnable.Contains(ability); var allowText = allowsSpell ? "FOUND" : "did not find"; Mod.Trace($"{allowText} spell {ability.Name} in {learnable.Count()} level {level} spells"); if (allowsSpell) { Mod.Trace($"spell level = {level}"); spellbook.AddKnown(level, ability); } } } } else { ch.Descriptor.AddFact(ability); } }
public static bool CanAddSpellAsAbility(this UnitEntityData ch, BlueprintAbility ability) => ability.IsSpell && !ch.Descriptor.HasFact(ability) && !PartyEditor.IsOnPartyEditor();