Example #1
0
        static bool Prefix(AbilityData __instance, ref SpellSource __result)
        {
            SpellTypeOverride component = __instance.Blueprint.GetComponent <SpellTypeOverride>();

            if ((bool)((UnityEngine.Object)component))
            {
                __result = component.Type;
                return(false);
            }
            if ((UnityEngine.Object)__instance.SourceItemUsableBlueprint != (UnityEngine.Object)null && __instance.SourceItemUsableBlueprint.Type != UsableItemType.Scroll || __instance.Blueprint.Type != AbilityType.Spell && __instance.Blueprint.Type != AbilityType.SpellLike)
            {
                __result = SpellSource.None;
                return(false);
            }
            if (__instance.Spellbook != null)
            {
                __result = __instance.Spellbook.Blueprint.IsArcane ? SpellSource.Arcane : SpellSource.Divine;
                return(false);
            }

            Kingmaker.UnitLogic.Feature feature = __instance.Caster.Progression.Features.Enumerable.FirstOrDefault <Kingmaker.UnitLogic.Feature>((Func <Kingmaker.UnitLogic.Feature, bool>)(f => f.Blueprint.GetComponents <AddFacts>().Any <AddFacts>((Func <AddFacts, bool>)(af => ((IEnumerable <BlueprintUnitFact>)af.Facts).Contains <BlueprintUnitFact>((BlueprintUnitFact)__instance.Blueprint)))));
            BlueprintCharacterClass     blueprintCharacterClass1;

            if (feature == null)
            {
                blueprintCharacterClass1 = (BlueprintCharacterClass)null;
            }
            else
            {
                BlueprintProgression sourceProgression = feature.SourceProgression;
                blueprintCharacterClass1 = sourceProgression != null ? ((IList <BlueprintCharacterClass>)sourceProgression.Classes).FirstOrDefault <BlueprintCharacterClass>() : (BlueprintCharacterClass)null;
            }
            BlueprintCharacterClass blueprintCharacterClass2 = blueprintCharacterClass1;

            if (!(bool)((UnityEngine.Object)blueprintCharacterClass2))
            {
                __result = SpellSource.Unknown;
                return(false);
            }
            var base_spellbook = __instance.Caster?.GetSpellbook(blueprintCharacterClass2);

            if (base_spellbook == null)
            {
                __result = blueprintCharacterClass2.IsDivineCaster ? SpellSource.Divine : (blueprintCharacterClass2.IsArcaneCaster ? SpellSource.Arcane : SpellSource.None);
                return(false);
            }
            __result = base_spellbook.Blueprint.IsArcane ? SpellSource.Arcane : (base_spellbook.Blueprint.IsAlchemist ? SpellSource.None : SpellSource.Divine);
            return(false);
        }
        static bool Prefix(SpellBookMetamagicMixer __instance, Kingmaker.UnitLogic.Feature feature, MetamagicBuilder ___m_MetamagicBuilder)
        {
            var unit = ___m_MetamagicBuilder?.Spellbook?.Owner;

            if (unit == null)
            {
                return(true);
            }

            var arcanist_part = unit.Get <SpellManipulationMechanics.UnitPartArcanistPreparedMetamagic>();

            if (arcanist_part == null)
            {
                return(true);
            }

            if (arcanist_part.spellbook != ___m_MetamagicBuilder.Spellbook.Blueprint)
            {
                return(true);
            }

            var current_metamagic_data = __instance.CurrentTemporarySpell?.MetamagicData;

            if (current_metamagic_data == null)
            {
                return(true);
            }

            var metamagic = feature.Get <AddMetamagicFeat>().Metamagic;
            var metamagic_after_removal = current_metamagic_data.MetamagicMask & ~metamagic;

            if (!arcanist_part.authorisedMetamagic(__instance.CurrentTemporarySpell.Blueprint, metamagic_after_removal))
            {
                return(false);
            }

            return(true);
        }
Example #3
0
 public bool CheckFeature(Kingmaker.UnitLogic.Feature feature)
 {
     return(feature.Owner.Progression.Features.Enumerable.Where(p => p.Blueprint == this.dependent_feature).Any(f => f.Param == feature.Param));
 }
Example #4
0
            public static bool Prefix([NotNull] LevelUpState state, [NotNull] UnitDescriptor unit, [NotNull] IList <BlueprintFeatureBase> features, [CanBeNull] FeatureSource source, int level)
            {
                if (!Main.IsInGame)
                {
                    return(false);
                }
#if true
                //Logger.Log($"feature count = {features.ToArray().Count()} ");
                var description = source.Blueprint.GetDescription() ?? "nil";
                //Logger.Log($"source: {source.Blueprint.name} - {description}");
                foreach (BlueprintFeature blueprintFeature in features.OfType <BlueprintFeature>())
                {
                    if (blueprintFeature.MeetsPrerequisites((FeatureSelectionState)null, unit, state, true))
                    {
                        //Logger.Log($"    name: {blueprintFeature.Name} : {blueprintFeature.GetType()}");
                        if (blueprintFeature is IFeatureSelection selection)
                        {
                            // Bug Fix - due to issues in the implementation of FeatureSelectionState.CanSelectAnything we can get level up blocked so this is an attempt to work around for that
                            var numToAdd = settings.featsMultiplier;
                            if (selection is BlueprintFeatureSelection bpFS)
                            {
                                var bpFeatures = bpFS;
                                var items      = bpFS.ExtractSelectionItems(unit, null);
                                //Logger.Log($"        items: {items.Count()}");
                                var availableCount = 0;
                                foreach (var item in items)
                                {
#if false
                                    if (bpFS.is BlueprintParametrizedFeature bppF)
                                    {
                                        Logger.Log($"checking parameterized feature {bppF.Name}");
                                        if (selection.CanSelect(unit, state, null, item))
                                        {
                                            Logger.Log($"        {item.Feature.name}  is avaiable");
                                            availableCount++;
                                        }
                                    }
                                    else
#endif
                                    if (!unit.Progression.Features.HasFact(item.Feature))
                                    {
                                        availableCount++;
                                        //                                        Logger.Log($"        {item.Feature.name}  is avaiable");
                                    }
#if false
                                    if (selection.CanSelect(unit, state, null, item))
                                    {
                                        Logger.Log($"        {item.Feature.name}  is avaiable");
                                        availableCount++;
                                    }
                                    else
                                    {
                                        Logger.Log($"        {item.Feature.name}  is NOT avaiable");
                                    }
                                    if (!unit.Progression.Features.HasFact(item.Feature))
                                    {
                                        if (item.Feature.MeetsPrerequisites(null, unit, state, true))
                                        {
                                            Logger.Log($"        {item.Feature.name}  is avaiable");
                                            availableCount++;
                                        }
                                    }
                                    else
                                    {
                                        Logger.Log($"        has Fact {item.Feature.Name}");
                                    }
#endif
                                }
                                if (numToAdd > availableCount)
                                {
                                    Logger.Log($"reduced numToAdd: {numToAdd} -> {availableCount}");
                                    numToAdd = availableCount;
                                }
                            }
                            //Logger.Log($"        IFeatureSelection: {selection} adding: {numToAdd}");
                            for (int i = 0; i < numToAdd; ++i)
                            {
                                state.AddSelection((FeatureSelectionState)null, source, selection, level);
                            }
                        }
                        Kingmaker.UnitLogic.Feature feature     = (Kingmaker.UnitLogic.Feature)unit.AddFact((BlueprintUnitFact)blueprintFeature);
                        BlueprintProgression        progression = blueprintFeature as BlueprintProgression;
                        if ((UnityEngine.Object)progression != (UnityEngine.Object)null)
                        {
                            //Logger.Log($"        BlueprintProgression: {progression}");
                            LevelUpHelper.UpdateProgression(state, unit, progression);
                        }
                        FeatureSource source1 = source;
                        int           level1  = level;
                        feature.SetSource(source1, level1);
                    }