Esempio n. 1
0
            static void Postfix(ref bool __result, RuleSavingThrow __instance)
            {
                if (settings.toggleNoFriendlyFireForAOE)
                {
                    if (__instance.Reason != null)
                    {
                        if (__instance.Reason.Ability != null)
                        {
                            if (__instance.Reason.Caster != null && __instance.Reason.Caster.IsPlayerFaction && __instance.Initiator.IsPlayerFaction && __instance.Reason.Ability.Blueprint != null && ((__instance.Reason.Ability.Blueprint.EffectOnAlly == AbilityEffectOnUnit.Harmful) || (__instance.Reason.Ability.Blueprint.EffectOnEnemy == AbilityEffectOnUnit.Harmful)))
                            {
                                __result = true;
                            }
                        }
                    }
                }
#if false
                if (StringUtils.ToToggleBool(settings.togglePassSavingThrowIndividual))
                {
                    for (int i = 0; i < settings.togglePassSavingThrowIndividualArray.Count(); i++)
                    {
                        if (StringUtils.ToToggleBool(settings.togglePassSavingThrowIndividualArray[i]) && Storage.statsSavesDict[Storage.individualSavesArray[i]] == __instance.StatType)
                        {
                            if (UnitEntityDataUtils.CheckUnitEntityData(__instance.Initiator, (UnitSelectType)settings.indexPassSavingThrowIndividuall))
                            {
                                __result = true;
                            }
                        }
                    }
                }
#endif
            }
Esempio n. 2
0
        public bool canBeAttackedBy(UnitEntityData unit)
        {
            if (can_attack.Contains(unit))
            {
                return(true);
            }
            if (can_not_attack.Contains(unit))
            {
                return(false);
            }
            var spell_descriptor = this.Buff.Blueprint.GetComponent <SpellDescriptorComponent>();

            if (spell_descriptor != null &&
                (UnitDescriptionHelper.GetDescription(unit.Blueprint).Immunities.SpellDescriptorImmunity.Value & spell_descriptor.Descriptor.Value) != 0)
            {
                Common.AddBattleLogMessage($"{unit.CharacterName} is immune to {this.Fact.Name} of {Owner.CharacterName}");
                can_not_attack.Add(unit);
                return(false);
            }
            RuleSavingThrow ruleSavingThrow = this.Context.TriggerRule <RuleSavingThrow>(new RuleSavingThrow(unit, save_type, this.Context.Params.DC));

            if (ruleSavingThrow.IsPassed)
            {
                can_attack.Add(unit);
                Common.AddBattleLogMessage($"{unit.CharacterName} successfuly overcomes {this.Fact.Name} of {Owner.CharacterName}");
                return(true);
            }
            else
            {
                Common.AddBattleLogMessage($"{unit.CharacterName} fails to overcome {this.Fact.Name} of {Owner.CharacterName}");
                can_not_attack.Add(unit);
                return(false);
            }
        }
Esempio n. 3
0
 public void OnEventAboutToTrigger(RuleSavingThrow evt)
 {
     if (HasPanache(Owner) && evt.StatType == StatType.SaveReflex)
     {
         evt.Evasion = true;
     }
 }
        public override void runActions(MechanicsContext context, UnitEntityData target, int dc, int check_result)
        {
            if (check_result <= dc + dc_bypass)
            {
                return;
            }
            var intimidate_value = context.MaybeCaster.Stats.GetStat <ModifiableValueSkill>(StatType.SkillPersuasion).BaseValue;

            if (intimidate_value < min_value)
            {
                return;
            }

            RuleSavingThrow saving_throw = new RuleSavingThrow(target, SavingThrowType.Will, 10 + intimidate_value);

            context.TriggerRule(saving_throw);
            if (saving_throw.IsPassed)
            {
                return;
            }

            int duration = intimidate_value < upgrade_value ? 1 : RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D4));

            target.Descriptor.AddBuff(frightened_buff, context, new TimeSpan?(duration.Rounds().Seconds));
        }
Esempio n. 5
0
 public void OnNewRound()
 {
     if (this.m_Ticks > this.m_TicksPassed && this.m_SuccesfullSaves > this.m_SavesSucceeded)
     {
         if (this.SaveType != SavingThrowType.Unknown)
         {
             RuleSavingThrow ruleSavingThrow = new RuleSavingThrow(this.Owner.Unit, this.SaveType, this.Context.Params.DC + this.m_BonusDC);
             ruleSavingThrow.Reason = (RuleReason)this.Fact;
             RuleSavingThrow evt = ruleSavingThrow;
             Game.Instance.Rulebook.TriggerEvent <RuleSavingThrow>(evt);
             if (!evt.IsPassed)
             {
                 triggerEffect();
             }
             if (evt.IsPassed)
             {
                 (this.Buff as IFactContextOwner).RunActionInContext(on_successful_save_action, this.Owner.Unit);
                 ++this.m_SavesSucceeded;
                 if (this.m_SavesSucceeded >= this.m_SuccesfullSaves)
                 {
                     this.Buff.Remove();
                 }
             }
         }
         ++this.m_TicksPassed;
     }
     else
     {
         this.Buff.Remove();
     }
 }
            public void ruleSavingThrowTriggered(RuleSavingThrow evt)
            {
                var context = evt.Reason?.Context;

                if (context == null)
                {
                    return;
                }

                var caster = context.MaybeCaster;

                if (caster == null)
                {
                    return;
                }

                if (caster != this.Owner.Unit)
                {
                    return;
                }

                if (context.SpellSchool == school &&
                    (save_type == SavingThrowType.Unknown || evt.Type == save_type))
                {
                    var cl_check = RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D20)) + evt.Reason.Context.Params.CasterLevel;
                    if (cl_check > evt.DifficultyClass)
                    {
                        Common.AddBattleLogMessage("Changing spell DC for " + evt.Initiator.CharacterName + $" form {evt.DifficultyClass} to {cl_check} due to {this.Fact.Name}");
                        Helpers.SetField(evt, "DifficultyClass", cl_check);
                    }
                }
            }
Esempio n. 7
0
 public void OnEventAboutToTrigger(RuleSavingThrow evt)
 {
     if (evt.Initiator != Owner.Unit)
     {
         return;
     }
     evt.AutoPass = true;
 }
Esempio n. 8
0
        private int DealHitPointsDamage(ContextActionDealDamage2.DamageInfo info)
        {
            if (this.Context.MaybeCaster == null)
            {
                UberDebug.LogError(this, (object)"Caster is missing", (object[])Array.Empty <object>());
                return(0);
            }
            BaseDamage damage1 = this.DamageType.GetDamageDescriptor(info.Dices, info.Bonus).CreateDamage();

            damage1.EmpowerBonus = !info.Empower ? damage1.EmpowerBonus : 1.5f;
            damage1.Maximized    = info.Maximize || damage1.Maximized;
            BaseDamage baseDamage = damage1;
            DamageCriticalModifierType?criticalModifier = info.CriticalModifier;
            int?critModifier = criticalModifier.HasValue ? new int?(criticalModifier.GetValueOrDefault().IntValue()) : new int?();

            baseDamage.CriticalModifier = critModifier;
            damage1.Half           = this.Half;
            damage1.AlreadyHalved  = info.PreRolledValue.HasValue && this.Half && this.AlreadyHalved;
            damage1.PreRolledValue = info.PreRolledValue;
            if (this.IsAoE && !info.PreRolledValue.HasValue)
            {
                int?nullable2 = this.Context.AoEDamage.Get <ContextActionDealDamage, int?>(this, new int?());
                if (nullable2.HasValue)
                {
                    damage1.PreRolledValue = nullable2;
                }
            }
            ContextAttackData data    = ElementsContext.GetData <ContextAttackData>();
            DamageBundle      damage2 = (DamageBundle)damage1;

            damage2.Weapon = data?.AttackRoll?.Weapon;
            RuleDealDamage rule = new RuleDealDamage(this.Context.MaybeCaster, this.Target.Unit, damage2)
            {
                Projectile             = data?.Projectile,
                AttackRoll             = data?.AttackRoll,
                HalfBecauseSavingThrow = info.HalfBecauseSavingThrow,
                MinHPAfterDamage       = !this.UseMinHPAfterDamage ? new int?() : new int?(this.MinHPAfterDamage),
                SourceAbility          = this.Context.SourceAbility,
                SourceArea             = this.Context.AssociatedBlueprint as BlueprintAbilityAreaEffect
            };

            if (this.IsShadowEvocation)
            {
                RuleSavingThrow ruleSavingThrow = this.Context.TriggerRule(new RuleSavingThrow(this.Target.Unit, SavingThrowType.Will, this.Context.Params.DC));
                rule.ReducedBecauseOfShadowEvocation = ruleSavingThrow.IsPassed;
            }
            if (this.IsShadowEvocationGreater)
            {
                RuleSavingThrow ruleSavingThrow = this.Context.TriggerRule(new RuleSavingThrow(this.Target.Unit, SavingThrowType.Will, this.Context.Params.DC));
                rule.ReducedBecauseOfShadowEvocationGreater = ruleSavingThrow.IsPassed;
            }
            this.Context.TriggerRule <RuleDealDamage>(rule);
            if (this.IsAoE && !this.Context.AoEDamage.Get <ContextActionDealDamage, int?>(this, new int?()).HasValue)
            {
                this.Context.AoEDamage[this] = new int?(rule.Calculate.CalculatedDamage.FirstItem <DamageValue>().RolledValue);
            }
            return(rule.Damage);
        }
Esempio n. 9
0
            static public bool Prefix(RuleDealDamage __instance, RulebookEventContext context)
            {
                if (__instance.Target == null)
                {
                    return(true);
                }

                var context2 = __instance.Reason.Context;

                if (context2?.AssociatedBlueprint != null && context2.AssociatedBlueprint is BlueprintBuff)
                {//do not apply shadow twice
                    return(true);
                }
                var summoned_context = ShadowSpells.getShadowBuff(__instance.Initiator.Descriptor)?.MaybeContext;

                if (context2 == null && summoned_context == null)
                {
                    return(true);
                }

                var shadow_descriptor2 = (context2?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;
                var shadow_summon      = (summoned_context?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;

                if (shadow_summon == SpellDescriptor.None && shadow_descriptor2 == SpellDescriptor.None)
                {
                    return(true);
                }

                if (shadow_summon > shadow_descriptor2)
                {
                    context2 = summoned_context;
                }

                if (!__instance.Target.Ensure <UnitPartDisbelief>().disbelief_contexts.ContainsKey(context2))
                {
                    RuleSavingThrow ruleSavingThrow = context2.TriggerRule <RuleSavingThrow>(new RuleSavingThrow(__instance.Target, SavingThrowType.Will, context2.Params.DC));
                    __instance.Target.Ensure <UnitPartDisbelief>().disbelief_contexts[context2] = ruleSavingThrow.IsPassed;
                }

                if (__instance.Target.Ensure <UnitPartDisbelief>().disbelief_contexts[context2])
                {
                    if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow20)
                    {
                        __instance.ReducedBecauseOfShadowEvocation = true;
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow60)
                    {
                        __instance.ReducedBecauseOfShadowEvocationGreater = true;
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow80)
                    {
                        __instance.Modifier = new float?((__instance.Modifier.HasValue ? __instance.Modifier.GetValueOrDefault() : 1f) * 0.8f);
                    }
                }
                return(true);
            }
Esempio n. 10
0
        static public bool makeDisbeliefSave(MechanicsContext context, UnitEntityData target)
        {
            disbelief_save_in_progress = true;
            Common.AddBattleLogMessage(target.CharacterName + " attempts a disbelief saving throw");
            RuleSavingThrow ruleSavingThrow = context.TriggerRule <RuleSavingThrow>(new RuleSavingThrow(target, SavingThrowType.Will, context.Params.DC));
            bool            res             = ruleSavingThrow.IsPassed;

            disbelief_save_in_progress = false;
            return(res);
        }
        static public void Postfix(ContextActionBreathOfLife __instance)
        {
            var tr      = Harmony12.Traverse.Create(__instance);
            var context = tr.Property("Context").GetValue <MechanicsContext>();
            var target  = tr.Property("Target").GetValue <TargetWrapper>().Unit;

            bool was_dead = false;

            if (target.HPLeft <= -(int)((ModifiableValue)target.Stats.Constitution))
            {
                was_dead = true;
            }

            int dice_count = __instance.Value.DiceCountValue.Calculate(context);
            int bonus_hp   = target.Descriptor.Ensure <UnitPartReceiveBonusHpPerDie>().getAmount(context.SourceAbility) * dice_count;

            if (target.Descriptor.Ensure <UnitPartReceiveBonusCasterLevelHealing>().active() && context.SourceAbility != null && __instance.Value != null)
            {
                var dice = __instance.Value.DiceType;
                if (dice_count == 0 || dice == DiceType.Zero || context.Params == null)
                {
                    return;
                }
                bonus_hp += context.Params.CasterLevel;
            }

            if ((target.Get <HarmlessSaves.UnitPartSaveAgainstHarmlessSpells>()?.active()).GetValueOrDefault() &&
                context.SourceAbility?.GetComponent <HarmlessSaves.HarmlessHealSpell>() != null &&
                context.SourceAbility.IsSpell &&
                target.IsAlly(context.MaybeCaster) &&
                target != context.MaybeCaster)
            {
                RuleSavingThrow ruleSavingThrow = new RuleSavingThrow(target, context.AssociatedBlueprint.GetComponent <HarmlessSaves.HarmlessHealSpell>().save_type, context.Params.DC);
                ruleSavingThrow.Reason = (RuleReason)((MechanicsContext)context);
                if (context.TriggerRule <RuleSavingThrow>(ruleSavingThrow).IsPassed)
                {
                    bonus_hp /= 2;
                }
            }

            if (bonus_hp > 0)
            {
                context.TriggerRule <RuleHealDamage>(new RuleHealDamage(target, target, DiceFormula.Zero, bonus_hp));
            }


            if (target.HPLeft > -(int)((ModifiableValue)target.Stats.Constitution) && was_dead)
            {
                target.Descriptor.Resurrect(0.0f, false);
            }
        }
Esempio n. 12
0
        public override void runActions(MechanicsContext context, UnitEntityData target, int dc, int check_result)
        {
            if (check_result <= dc + dc_bypass)
            {
                return;
            }
            var intimidate_value = context.MaybeCaster.Stats.GetStat <ModifiableValueSkill>(StatType.SkillPersuasion).BaseValue;

            if (intimidate_value < min_value)
            {
                return;
            }

            var spell_descriptors_to_add = new SpellDescriptor[]
            {
                SpellDescriptor.MindAffecting,
                SpellDescriptor.Fear
            };

            for (int i = 0; i < spell_descriptors_to_add.Length; i++)
            {
                if ((context.SpellDescriptor & spell_descriptors_to_add[i]) > 0)
                {
                    spell_descriptors_to_add[i] = SpellDescriptor.None;
                }
                else
                {
                    context.AddSpellDescriptor(spell_descriptors_to_add[i]);
                }
            }

            RuleSavingThrow saving_throw = new RuleSavingThrow(target, SavingThrowType.Will, 10 + intimidate_value);

            context.TriggerRule(saving_throw);

            foreach (var sd in spell_descriptors_to_add)
            {
                if (sd != SpellDescriptor.None)
                {
                    context.RemoveSpellDescriptor(sd);
                }
            }
            if (saving_throw.IsPassed)
            {
                return;
            }

            int duration = intimidate_value < upgrade_value ? 1 : RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D4));

            target.Descriptor.AddBuff(frightened_buff, context, new TimeSpan?(duration.Rounds().Seconds));
        }
Esempio n. 13
0
        public void ruleSavingThrowTriggered(RuleSavingThrow evt)
        {
            var context = evt.Reason?.Context;

            if (context == null)
            {
                return;
            }

            var caster = context.MaybeCaster;

            if (caster == null)
            {
                return;
            }

            if (caster != this.Owner.Unit)
            {
                return;
            }

            if (context?.SourceAbility.GetComponent <DisbeliefSpell>() == null)
            {
                context = ShadowSpells.extractMainContext(context, caster);
                if (context == null)
                {
                    return;
                }

                if (!ShadowSpells.is_making_disbelief_save)
                {
                    return;
                }
            }


            if (context.SpellSchool == school &&
                (save_type == SavingThrowType.Unknown || evt.Type == save_type) &&
                (context?.SourceAbility.GetComponent <DisbeliefSpell>() != null || !evt.Initiator.Ensure <UnitPartDisbelief>().attemptedDisbelief(context))
                )
            {
                var cl_check = RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D20)) + evt.Reason.Context.Params.CasterLevel;
                if (cl_check > evt.DifficultyClass)
                {
                    Common.AddBattleLogMessage("Changing spell DC for " + evt.Initiator.CharacterName + $" form {evt.DifficultyClass} to {cl_check} due to {this.Fact.Name}");
                    Helpers.SetField(evt, "DifficultyClass", cl_check);
                }
            }
        }
Esempio n. 14
0
        public void ruleSavingThrowBeforeTrigger(RuleSavingThrow evt)
        {
            var context = evt.Reason?.Context;

            if (context == null)
            {
                return;
            }

            var caster = context.MaybeCaster;

            if (caster == null)
            {
                return;
            }

            if (caster != this.Owner.Unit)
            {
                return;
            }

            if (evt.Initiator == null)
            {
                return;
            }


            if (caster.Descriptor.Progression?.Race != evt.Initiator.Descriptor.Progression?.Race)
            {
                return;
            }

            if (spells.Contains(context.SourceAbility) || spells.Contains(context.SourceAbility?.Parent))
            {
                var bonus = -value.Calculate(this.Fact.MaybeContext);
                evt.AddTemporaryModifier(evt.Initiator.Stats.SaveWill.AddModifier(bonus, (GameLogicComponent)this, this.descriptor));
                evt.AddTemporaryModifier(evt.Initiator.Stats.SaveReflex.AddModifier(bonus, (GameLogicComponent)this, this.descriptor));
                evt.AddTemporaryModifier(evt.Initiator.Stats.SaveFortitude.AddModifier(bonus, (GameLogicComponent)this, this.descriptor));
            }
        }
        public override void OnEventDidTrigger(RuleDealDamage evt)
        {
            try
            {
                var context      = Helpers.GetMechanicsContext();
                var spellContext = context?.SourceAbilityContext;
                var target       = Helpers.GetTargetWrapper()?.Unit;
                if (spellContext == null || target == null)
                {
                    return;
                }

                var spellbook = spellContext.Ability.Spellbook;

                if (evt.Damage > 0 && context.HasMetamagic((Metamagic)ModMetamagic.Dazing))
                {
                    var savingThrow = context.SavingThrow;
                    if (savingThrow == null)
                    {
                        // Will save to negate the effect
                        savingThrow        = new RuleSavingThrow(target, SavingThrowType.Will, context.Params.DC);
                        savingThrow.Reason = context;
                        context.TriggerRule(savingThrow);
                        Log.Write($"Dazing spell -- will saving throw: {savingThrow.Reason} was {savingThrow.D20}");
                    }
                    if (!savingThrow.IsPassed)
                    {
                        var spellLevel = context.Params.SpellLevel;
                        Log.Write($"Dazing spell -- apply daze for {spellLevel} rounds.");
                        Helpers.CreateApplyBuff(DazeBuff, Helpers.CreateContextDuration(spellLevel), fromSpell: true).RunAction();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Esempio n. 16
0
        internal static bool Prefix(AbilityExecutionContext context, TargetWrapper target)
        {
            if (!target.IsUnit)
            {
                return(true);
            }
            if (context?.Params == null || context.MaybeCaster == null)
            {
                return(true);
            }

            if (!(target.Unit.Get <UnitPartSaveAgainstHarmlessSpells>()?.active()).GetValueOrDefault())
            {
                return(true);
            }

            if (target.Unit == context.MaybeCaster || !target.Unit.IsAlly(context.MaybeCaster))
            {
                return(true);
            }

            if (context.AbilityBlueprint?.GetComponent <HarmlessSpell>() == null || !context.AbilityBlueprint.IsSpell)
            {
                return(true);
            }

            RuleSavingThrow ruleSavingThrow = new RuleSavingThrow(target.Unit, context.AbilityBlueprint.GetComponent <HarmlessSpell>().save_type, context.Params.DC);

            ruleSavingThrow.Reason = (RuleReason)((MechanicsContext)context);
            if (context.TriggerRule <RuleSavingThrow>(ruleSavingThrow).IsPassed)
            {
                return(false);
            }

            return(true);
        }
 public void OnEventAboutToTrigger(RuleSavingThrow evt)
 {
     evt.AutoPass = true;
 }
Esempio n. 18
0
 public void ruleSavingThrowTriggered(RuleSavingThrow evt)
 {
 }
Esempio n. 19
0
            static public bool Prefix(RuleApplyBuff __instance, RulebookEventContext context)
            {
                if (ShadowSpells.isShadowBuff(__instance.Blueprint))
                {
                    return(true);
                }
                var context2 = __instance.Reason.Context;

                if (context2?.AssociatedBlueprint != null && context2.AssociatedBlueprint is BlueprintBuff)
                {//do not apply shadow twice
                    return(true);
                }
                var summoned_context = ShadowSpells.getShadowBuff(__instance.Initiator.Descriptor)?.MaybeContext;

                if (context2 == null && summoned_context == null)
                {
                    return(true);
                }


                var shadow_descriptor2 = (context2?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;
                var shadow_summon      = (summoned_context?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;

                if (shadow_summon == SpellDescriptor.None && shadow_descriptor2 == SpellDescriptor.None)
                {
                    return(true);
                }


                if (shadow_summon > shadow_descriptor2)
                {
                    context2 = summoned_context;
                }

                if (__instance.Initiator == null)
                {
                    return(true);
                }

                if (!__instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts.ContainsKey(context2))
                {
                    RuleSavingThrow ruleSavingThrow = context2.TriggerRule <RuleSavingThrow>(new RuleSavingThrow(__instance.Initiator, SavingThrowType.Will, context2.Params.DC));
                    __instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts[context2] = ruleSavingThrow.IsPassed;
                }

                if (__instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts[context2])
                {
                    if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow20)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 20)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow60)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 60)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow80)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 80)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                }

                return(true);
            }
Esempio n. 20
0
        public override IEnumerator <AbilityDeliveryTarget> Deliver(AbilityExecutionContext context, TargetWrapper target)
        {
            UnitEntityData caster = context.MaybeCaster;
            bool           flag   = caster == null;

            if (flag)
            {
                UberDebug.LogError(this, "Caster is missing", Array.Empty <object>());
                yield break;
            }
            WeaponSlot threatHand = caster.GetThreatHand();
            bool       flag2      = threatHand == null;

            if (flag2)
            {
                UberDebug.LogError("Caster can't attack", Array.Empty <object>());
                yield break;
            }
            UnitEntityData targetUnit = target.Unit;
            bool           flag3      = targetUnit == null;

            if (flag3)
            {
                UberDebug.LogError("Can't be applied to point", Array.Empty <object>());
                yield break;
            }
            int attackPenalty = 0;

            AbilityEffectCoupDeGrace.EventHandlers handlers = new AbilityEffectCoupDeGrace.EventHandlers();
            handlers.Add(new AbilityEffectCoupDeGrace.Coup(caster));
            RuleAttackWithWeapon rule = new RuleAttackWithWeapon(caster, targetUnit, threatHand.Weapon, attackPenalty)
            {
                AutoHit = true,
                AutoCriticalConfirmation = true,
                AutoCriticalThreat       = true
            };

            using (handlers.Activate())
            {
                context.TriggerRule <RuleAttackWithWeapon>(rule);
            }
            AbilityEffectCoupDeGrace.EventHandlers eventHandlers = null;
            yield return(new AbilityDeliveryTarget(target));

            RuleSavingThrow rule3 = new RuleSavingThrow(targetUnit, SavingThrowType.Fortitude, AbilityEffectCoupDeGrace.m_coupDamage + 10);

            context.TriggerRule <RuleSavingThrow>(rule3);
            bool flag6 = !rule3.IsPassed;

            if (flag6)
            {
                targetUnit.Descriptor.State.MarkedForDeath = true;
            }
            using (context.GetDataScope(target))
            {
                this.Actions.Run();
            }
            ElementsContextData elementsContextData = null;

            rule3 = null;
            yield break;
        }
Esempio n. 21
0
 public void OnEventDidTrigger(RuleSavingThrow evt)
 {
 }
Esempio n. 22
0
 public void OnEventAboutToTrigger(RuleSavingThrow evt) => IncreaseLuckBonus(evt, evt.StatType);
        static public bool Prefix(ContextActionHealTarget __instance)
        {
            var tr      = Harmony12.Traverse.Create(__instance);
            var context = tr.Property("Context").GetValue <MechanicsContext>();
            var target  = tr.Property("Target").GetValue <TargetWrapper>().Unit;

            if (target == null)
            {
                UberDebug.LogError(__instance, (object)"Invalid target for effect '{0}'", __instance.GetType().Name);
            }
            else if (context.MaybeCaster == null)
            {
                UberDebug.LogError(__instance, (object)"Caster is missing", (object[])Array.Empty <object>());
            }
            else
            {
                int bonus         = __instance.Value.Calculate(context);
                var bonus_to_dice = __instance.Value.BonusValue.Calculate(context);

                var hp_bonus_to_caster_level = context.MaybeCaster.Get <UnitPartExtendHpBonusToCasterLevel>();

                if (hp_bonus_to_caster_level != null && hp_bonus_to_caster_level.active(context.SourceAbility) && context.Params != null)
                {
                    var additional_hp = context.Params.CasterLevel - bonus_to_dice;
                    //Main.logger.Log("Additional Hp: " + additional_hp.ToString());
                    if (additional_hp < 0)
                    {
                        additional_hp = 0;
                    }

                    if (context.HasMetamagic(Metamagic.Empower))
                    {
                        additional_hp += additional_hp / 2;
                    }

                    bonus_to_dice += additional_hp;
                    bonus         += additional_hp;
                }

                if (!context.HasMetamagic(Metamagic.Maximize) && context.MaybeCaster.Ensure <UnitPartHealingMetamagic>().hasMaximize(context.SourceAbility, context.MaybeCaster, target))
                {
                    bonus = (int)__instance.Value.DiceType * __instance.Value.DiceCountValue.Calculate(context) + bonus_to_dice;

                    if (context.HasMetamagic(Metamagic.Empower))
                    {
                        bonus = (int)(bonus * 1.5f);
                    }
                }

                if (!context.HasMetamagic(Metamagic.Empower) && context.MaybeCaster.Ensure <UnitPartHealingMetamagic>().hasEmpower(context.SourceAbility, context.MaybeCaster, target))
                {
                    bonus = (int)(bonus * 1.5f);
                }

                int dice_count = __instance.Value.DiceCountValue.Calculate(context);
                bonus += target.Descriptor.Ensure <UnitPartReceiveBonusHpPerDie>().getAmount(context.SourceAbility) * dice_count;
                var extra_bonus = (context.MaybeCaster?.Get <UnitPartBonusHealing>()?.getAmount(context.SourceAbility)).GetValueOrDefault();
                bonus += extra_bonus;

                if (target.Descriptor.Ensure <UnitPartReceiveBonusCasterLevelHealing>().active() && context.SourceAbility != null && __instance.Value != null)
                {
                    var dice = __instance.Value.DiceType;
                    if (dice_count != 0 && dice != DiceType.Zero && context.Params != null)
                    {
                        bonus += context.Params.CasterLevel;
                    }
                }


                if ((target.Get <HarmlessSaves.UnitPartSaveAgainstHarmlessSpells>()?.active()).GetValueOrDefault() &&
                    context.SourceAbility?.GetComponent <HarmlessSaves.HarmlessHealSpell>() != null &&
                    context.SourceAbility.IsSpell &&
                    target.IsAlly(context.MaybeCaster) &&
                    target != context.MaybeCaster)
                {
                    RuleSavingThrow ruleSavingThrow = new RuleSavingThrow(target, context.AssociatedBlueprint.GetComponent <HarmlessSaves.HarmlessHealSpell>().save_type, context.Params.DC);
                    ruleSavingThrow.Reason = (RuleReason)((MechanicsContext)context);
                    if (context.TriggerRule <RuleSavingThrow>(ruleSavingThrow).IsPassed)
                    {
                        bonus /= 2;
                    }
                }

                if (bonus > 0)
                {
                    context.TriggerRule <RuleHealDamage>(new RuleHealDamage(context.MaybeCaster, target, DiceFormula.Zero, bonus));
                }
            }

            return(false);
        }
        public static void runActionOnDamageDealt(RuleDealDamage evt, ActionList action, int min_dmg = 1, bool only_critical = false, SavingThrowType save_type = SavingThrowType.Unknown,
                                                  BlueprintBuff context_buff = null, DamageEnergyType energy_descriptor      = DamageEnergyType.Acid, bool use_damage_energy_type = false)
        {
            if (only_critical && (evt.AttackRoll == null || !evt.AttackRoll.IsCriticalConfirmed))
            {
                return;
            }


            var target = evt.Target;

            if (target == null)
            {
                return;
            }

            if (evt.Damage <= min_dmg)
            {
                return;
            }

            if (use_damage_energy_type)
            {
                bool damage_found = false;
                foreach (var dmg in evt.DamageBundle)
                {
                    var energy_damage = (dmg as EnergyDamage);

                    if (energy_damage != null && energy_damage.EnergyType == energy_descriptor)
                    {
                        damage_found = true;
                        break;
                    }
                }

                if (!damage_found)
                {
                    return;
                }
            }

            if (save_type != SavingThrowType.Unknown)
            {
                var context_params = evt.Initiator.Buffs?.GetBuff(context_buff)?.MaybeContext?.Params;
                if (context_params == null)
                {
                    return;
                }

                var dc = context_params.DC;
                var rule_saving_throw = new RuleSavingThrow(target, save_type, dc);
                Rulebook.Trigger(rule_saving_throw);

                if (rule_saving_throw.IsPassed)
                {
                    return;
                }
            }

            var context_fact = evt.Initiator.Buffs?.GetBuff(context_buff);

            (context_fact as IFactContextOwner)?.RunActionInContext(action, target);
        }
            static public bool Prefix(RuleApplyBuff __instance, RulebookEventContext context)
            {
                /*if (ShadowSpells.isShadowBuff(__instance.Blueprint))
                 * {
                 *  return true;
                 * }*/
                var rule_summon = Rulebook.CurrentContext.AllEvents.LastOfType <RuleSummonUnit>();

                if (rule_summon != null)
                {//do not interrupt summon buffs
                    return(true);
                }

                var context2 = __instance.Reason.Context;
                //there are also actions after summon that should not be affected
                //we need to check if we are still inside SpawnMonsterComponent
                var summon_context = __instance.Initiator.Buffs?.GetBuff(Game.Instance.BlueprintRoot.SystemMechanics.SummonedUnitBuff)?.MaybeContext?.ParentContext;

                if (summon_context == context2)
                {
                    return(true);
                }


                if (context2?.AssociatedBlueprint != null && context2.AssociatedBlueprint is BlueprintBuff)
                {//do not apply shadow twice
                    return(true);
                }
                var summoned_context = ShadowSpells.getShadowBuff(__instance.Initiator.Descriptor)?.MaybeContext;

                if (context2 == null && summoned_context == null)
                {
                    return(true);
                }


                var shadow_descriptor2 = (context2?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;
                var shadow_summon      = (summoned_context?.SpellDescriptor).GetValueOrDefault() & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow;

                if (shadow_summon == SpellDescriptor.None && shadow_descriptor2 == SpellDescriptor.None)
                {
                    return(true);
                }


                if (shadow_summon > shadow_descriptor2)
                {
                    context2 = summoned_context;
                }

                if (__instance.Initiator == null)
                {
                    return(true);
                }

                if (!__instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts.ContainsKey(context2))
                {
                    RuleSavingThrow ruleSavingThrow = context2.TriggerRule <RuleSavingThrow>(new RuleSavingThrow(__instance.Initiator, SavingThrowType.Will, context2.Params.DC));
                    __instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts[context2] = ruleSavingThrow.IsPassed;
                }

                if (__instance.Initiator.Ensure <UnitPartDisbelief>().disbelief_contexts[context2])
                {
                    if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow20)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 20)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow60)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 60)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                    else if ((context2.SpellDescriptor & (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow) == (SpellDescriptor)AdditionalSpellDescriptors.ExtraSpellDescriptor.Shadow80)
                    {
                        if (RulebookEvent.Dice.D(new DiceFormula(1, DiceType.D100)) > 80)
                        {
                            __instance.CanApply = false;
                            Common.AddBattleLogMessage(__instance.Initiator.CharacterName + " avoids " + context2.SourceAbility.Name + " effect due to disbelief");
                            return(false);
                        }
                    }
                }

                return(true);
            }
 public void ruleSavingThrowBeforeTrigger(RuleSavingThrow evt)
 {
 }