public void OnEventAboutToTrigger(RuleDealDamage evt) { var weapon_attack = evt.AttackRoll?.RuleAttackWithWeapon; if (weapon_attack == null || !check(weapon_attack)) { return; } var bonus = value.Calculate(this.Fact.MaybeContext); evt.DamageBundle.WeaponDamage?.AddBonus(bonus); }
// ReSharper disable once UnusedMember.Local private static void Postfix(UnitUseAbility __instance) { var caster = __instance.Executor; var bondedComponent = Main.GetBondedItemComponentForCaster(caster.Descriptor); if (bondedComponent != null && bondedComponent.ownerItem != null && bondedComponent.ownerItem.Wielder != caster.Descriptor) { Main.AddBattleLogMessage( Main.L10NFormat(caster, "craftMagicItems-logMessage-not-wielding-bonded-item", bondedComponent.ownerItem.Name), new L10NString("craftMagicItems-bonded-item-glossary")); // Concentration checks have no way of overriding the DC, so contrive some fake damage to give a DC of 20 + spell level. var ruleDamage = new RuleDealDamage(caster, caster, null); Main.Accessors.SetRuleDealDamageDamage(ruleDamage, 20); __instance.MakeConcentrationCheck(ruleDamage); } }
public void OnEventDidTrigger(RuleAttackWithWeapon evt) { if (unit == null) { return; } var unit_attack_roll = Rulebook.Trigger <RuleAttackRoll>(new RuleAttackRoll(evt.Initiator, unit, evt.WeaponStats, evt.AttackBonusPenalty)); if (unit_attack_roll.IsHit) { var damage_base = evt.Weapon.Blueprint.DamageType.CreateDamage(DiceFormula.Zero, 0);//we write 0 damage here, since bonus damage is added in OnEventAboutToTrigger(RuleCalculateDamage evt) RuleDealDamage rule = new RuleDealDamage(this.Owner.Unit, unit, new DamageBundle(damage_base)); Rulebook.Trigger <RuleDealDamage>(rule); } unit = null; }
public static void Postfix(ref int __result, RuleDealDamage __instance, int damage) { if (settings.toggleNoFriendlyFireForAOE) { BlueprintScriptableObject blueprint = __instance.Reason.Context?.AssociatedBlueprint; if (!(blueprint is BlueprintBuff)) { BlueprintAbility blueprintAbility = __instance.Reason.Context?.SourceAbility; if (blueprintAbility != null && __instance.Initiator.IsPlayerFaction && __instance.Target.IsPlayerFaction && ((blueprintAbility.EffectOnAlly == AbilityEffectOnUnit.Harmful) || (blueprintAbility.EffectOnEnemy == AbilityEffectOnUnit.Harmful))) { __result = 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); } context2 = ShadowSpells.extractMainContext(context2, __instance.Initiator); if (context2 == null) { return(true); } if (!__instance.Target.Ensure <UnitPartDisbelief>().attemptedDisbelief(context2)) { if (__instance.Target.Descriptor.State.HasCondition(UnitCondition.TrueSeeing)) { __instance.Target.Ensure <UnitPartDisbelief>().register(context2, true); } else { __instance.Target.Ensure <UnitPartDisbelief>().register(context2, ShadowSpells.makeDisbeliefSave(context2, __instance.Target)); } } if (__instance.Target.Ensure <UnitPartDisbelief>().disbelieved(context2)) { int illusion_reality = ShadowSpells.getSpellReality(context2); if (illusion_reality > 0) { __instance.Modifier = new float?((__instance.Modifier.HasValue ? __instance.Modifier.GetValueOrDefault() : 1f) * 0.01f * illusion_reality); Common.AddBattleLogMessage(__instance.Target.CharacterName + " reduces damage from " + context2.SourceAbility.Name + " to " + illusion_reality.ToString() + "% due to disbelief"); } } return(true); }
public void OnNewRound() { if (!this.Owner.Ensure <UnitPartBleed>().isCurrentBleedBuff(this.Fact)) { return; } var dices = new DiceFormula(this.dice_value.DiceCountValue.Calculate(this.Context), this.dice_value.DiceType); var bonus = this.dice_value.BonusValue.Calculate(this.Context) + this.Owner.Ensure <UnitPartBleed>().bleed_bonus; var base_dmg = (BaseDamage) new DirectDamage(dices, bonus); base_dmg.IgnoreReduction = true; RuleDealDamage evt_dmg = new RuleDealDamage(this.Context.MaybeCaster, this.Owner.Unit, new DamageBundle(new BaseDamage[] { base_dmg })); evt_dmg.SourceAbility = Context?.SourceAbility; evt_dmg.Reason = this.Fact; Rulebook.Trigger <RuleDealDamage>(evt_dmg); }
private void triggerEffect() { int bonus = this.ContextValue.Calculate(this.Context); if (Stat != StatType.Unknown) { ModifiableValue stat = this.Owner.Stats.GetStat(this.Stat); RuleDealStatDamage rule = new RuleDealStatDamage(this.Owner.Unit, this.Owner.Unit, this.Stat, DiceFormula.Zero, bonus); rule.Reason = (RuleReason)this.Fact; this.Context.TriggerRule <RuleDealStatDamage>(rule); } else { var hp_damage = new DamageBundle(new BaseDamage[1] { (BaseDamage) new DirectDamage(new DiceFormula(0, DiceType.Zero), bonus) } ); RuleDealDamage rule = new RuleDealDamage(this.Owner.Unit, this.Owner.Unit, hp_damage); rule.Reason = (RuleReason)this.Fact; this.Context.TriggerRule <RuleDealDamage>(rule); } }
public void OnEventAboutToTrigger(RuleDealDamage evt) { }
public void OnEventDidTrigger(RuleDealDamage evt) { }
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(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)) { if (__instance.Target.Descriptor.State.HasCondition(UnitCondition.TrueSeeing)) { __instance.Target.Ensure <UnitPartDisbelief>().disbelief_contexts[context2] = true; } else { __instance.Target.Ensure <UnitPartDisbelief>().disbelief_contexts[context2] = ShadowSpells.makeDisbeliefSave(context2, __instance.Target); } } 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); }