示例#1
0
        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);
            }
        }
示例#2
0
 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));
 }
示例#3
0
        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);
            }
        }
示例#4
0
 public static bool CanAddSpellAsAbility(this UnitEntityData ch, BlueprintAbility ability) => ability.IsSpell && !ch.Descriptor.HasFact(ability) && !PartyEditor.IsOnPartyEditor();