示例#1
0
        public void OnEventAboutToTrigger(RuleCalculateDamage evt)
        {
            MechanicsContext context = evt.Reason.Context;

            if (context?.SourceAbility == null || !context.SpellDescriptor.HasAnyFlag((Kingmaker.Blueprints.Classes.Spells.SpellDescriptor) this.SpellDescriptor) || !context.SourceAbility.IsSpell)
            {
                return;
            }


            if (!Helpers.checkSpellbook(spellbook, specific_class, context.SourceAbilityContext?.Ability?.Spellbook, context.MaybeCaster.Descriptor))
            {
                return;
            }

            if (!context.HasMetamagic((Metamagic)MetamagicFeats.MetamagicExtender.ForceFocus))
            {
                return;
            }

            foreach (BaseDamage baseDamage in evt.DamageBundle)
            {
                var dice_formula = baseDamage.Dice;
                if (dice_formula.Dice == DiceType.Zero || dice_formula.Rolls <= 0)
                {
                    continue;
                }

                var dice = dice_formula.Dice;
                switch (dice)
                {
                case DiceType.D4:
                {
                    dice = DiceType.D6;
                    break;
                }

                case DiceType.D6:
                {
                    dice = DiceType.D8;
                    break;
                }

                case DiceType.D8:
                {
                    dice = DiceType.D10;
                    break;
                }

                case DiceType.D10:
                {
                    dice = DiceType.D12;
                    break;
                }
                }

                baseDamage.ReplaceDice(new DiceFormula(dice_formula.Rolls, dice));
            }
        }
示例#2
0
        static bool Prefix(ContextRankConfig __instance, MechanicsContext context, ref int __result, bool ___m_UseMax, int ___m_Max, BlueprintCharacterClass[] ___m_Class)
        {
            try
            {
                var self      = __instance;
                var baseValue = GetBaseValue(self, context);

                if (self.IsBasedOnClassLevel && ___m_Class.Contains(Helpers.sorcererClass))
                {
                    var part = context.MaybeCaster.Get <UnitPartBloodline>();
                    Log.Write($"ContextRankConfig based on class level {self}, part {part}, blueprint {context.AssociatedBlueprint.name}, {context.AssociatedBlueprint.GetType().Name}");

                    var level = part?.CalcLevel(context.AssociatedBlueprint);
                    if (level.HasValue)
                    {
                        Log.Write($"ContextRankConfig: modify level of {context.AssociatedBlueprint.name}: {level}");
                        baseValue = context.Params.RankBonus + level.Value;
                    }
                }

                var value = (int)ApplyProgression(self, baseValue);

                // TODO: this may allow intensifying something that isn't damage dice.
                // We'd need to scan for ContextActionDealDamage, and then see if its ContextValue matches.
                var spell = context.SourceAbility;
                if (spell != null && ___m_UseMax)
                {
                    if (context.HasMetamagic((Metamagic)ModMetamagic.Intensified))
                    {
                        // Intensified spell: increase the maximum damage dice by 5 levels.
                        int max = ___m_Max;
                        // Figure out what base value results in the max.
                        int maxBaseValue = 1;
                        for (; (int)ApplyProgression(self, maxBaseValue) < max && maxBaseValue <= 20; maxBaseValue++)
                        {
                            ;
                        }
                        int newMax = (int)ApplyProgression(self, maxBaseValue + 5);
                        __result = Math.Min(value, newMax);
                        Log.Write($"Intensified spell: result {__result}, value {value}, max {max} (reached at level {maxBaseValue}), adjusted max {newMax}");
                        return(false);
                    }
                    if ((spell.SpellDescriptor & SpellDescriptor.Cure) != 0 && OracleClass.cureSpells.Value.Contains(spell))
                    {
                        var progressionData = context.MaybeCaster?.Descriptor.Progression;
                        if (progressionData?.Features.HasFact(LifeMystery.enhancedCures) == true)
                        {
                            __result = Math.Min(value, progressionData.GetClassLevel(OracleClass.oracle));
                            Log.Write($"Enhanced cures: result {__result}, value {value}, spell {spell.name}, caster {context.MaybeCaster}");
                            return(false);
                        }
                    }
                }
                __result = (int)ApplyMinMax(self, value);
                return(false);
            }
            catch (Exception e)
            {
                Log.Error($"caught error in ApplyMinMax {e}");
            }
            return(true);
        }