public static bool TriggerAttackReplacementCombatManeuver(this UnitEntityData initiator, UnitEntityData target, ItemEntityWeapon weapon, int attackBonusPenalty, CombatManeuver combatManeuver) { var combatManeuverRule = new RuleCombatManeuver(initiator, target, combatManeuver); combatManeuverRule.ReplaceAttackBonus = new int?(initiator.Stats.BaseAttackBonus + attackBonusPenalty); BlueprintAbility combatManeuverAbility = Main.Library.Get <BlueprintAbility>(CombatManeuverData.combatManeuverActionIds[combatManeuver]); var abilityData = new Kingmaker.UnitLogic.Abilities.AbilityData(combatManeuverAbility, initiator.Descriptor); var context = abilityData.CreateExecutionContext(target); Game.Instance.UI.BattleLogManager.HandleUseAbility(abilityData, null); var combatTextManager = initiator.GetCombatTextManager(); if (combatTextManager != null) { /*MethodInfo settingsForbidsMethod = combatTextManager.GetType().GetMethod("SettingForbids", BindingFlags.NonPublic | BindingFlags.Instance); * bool forbids = (bool)settingsForbidsMethod.Invoke(combatTextManager, new object[] { SettingsRoot.Instance.ShowSpellNameInCombatText }); * if (!forbids) * combatTextManager.AddCombatText(combatManeuverAbility.Name, combatTextManager.DefaultColor, true, combatManeuverAbility.Icon);*/ var mockSpellRule = new RuleCastSpell(abilityData, target); combatTextManager.OnEventDidTrigger(mockSpellRule); } return(context.TriggerRule(combatManeuverRule).Success); }
public override void RunAction() { try { //Log.Append($"{GetType().Name}.RunAction()"); var context = Buff.Context.SourceAbilityContext; var ability = context.Ability; //Log.Append($" ability {ability} caster {context.Caster.CharacterName} fact {ability.Fact}"); //Log.Append($" spellbook {ability.Spellbook?.Blueprint} main target {context.MainTarget}"); //Log.Flush(); var spellData = new AbilityData(Spell, context.Caster.Descriptor, ability.Fact, ability.Spellbook?.Blueprint); spellData.OverrideSpellLevel = Context.Params.SpellLevel; var castSpell = new RuleCastSpell(spellData, context.MainTarget); // Disable spell failure: we already cast the spell. castSpell.IsCutscene = true; castSpell = Rulebook.Trigger(castSpell); if (IsInstant) { castSpell.ExecutionProcess.InstantDeliver(); } } catch (Exception e) { Log.Error(e); } }
public void OnEventAboutToTrigger(RuleCastSpell evt) { if (!evt.Spell.Blueprint.IsSpell || evt.Spell.Spellbook == null || (evt.Spell.StickyTouch != null)) { return; } if (ignore_psychic && evt.Spell.Spellbook.Blueprint.GetComponent <SpellbookMechanics.PsychicSpellbook>() != null) { return; } int threshold = this.chance.Calculate(this.Fact.MaybeContext); int d100 = RulebookEvent.Dice.D100; //Main.logger.Log($"Failure: {d100}/{threshold}"); if (d100 > threshold) { return; } evt.SpellFailureChance = 200; if (do_not_spend_slot_if_failed) { evt.Spell.Caster.Ensure <SpellbookMechanics.UnitPartDoNotSpendNextSpell>().active = true; } }
public void OnEventAboutToTrigger(RuleCastSpell evt) { if (!evt.Spell.Blueprint.IsSpell || (evt.Spell.StickyTouch != null)) { return; } evt.SpellFailureChance = Math.Max(evt.SpellFailureChance, this.chance); }
public void OnEventAboutToTrigger(RuleCastSpell evt) { //Main.logger.Log("Checking " + evt.Spell.Name); if ((evt.Spell?.SourceItemUsableBlueprint == null) || (evt.Spell.StickyTouch != null)) { return; } evt.SpellFailureChance = Math.Max(evt.SpellFailureChance, this.chance); //Main.logger.Log("Ok " + evt.SpellFailureChance.ToString()); }
public void OnEventDidTrigger(RuleCastSpell evt) { if (DoNotRemove || spell == null || evt.Spell != spell) { return; } // Our spell was cast, time to remove the buff. Buff.Remove(); }
private void applySpell(SpellSlot spell_slot, AbilityExecutionContext context, TargetWrapper target) { var spell = getSpellOrVariant(spell_slot.Spell); spendSpellSlot(spell_slot); spell.SpendMaterialComponent(); var rule_cast_spell = new RuleCastSpell(spell, target); rule_cast_spell.Context.AttackRoll = Rulebook.CurrentContext.AllEvents.LastOfType <RuleAttackWithWeapon>()?.AttackRoll; Rulebook.Trigger <RuleCastSpell>(rule_cast_spell); }
public void OnEventDidTrigger(RuleCastSpell evt) { AbilityExecutionContext context = evt.Context; context.RemoveSpellDescriptor(SpellDescriptor.Fire); context.RemoveSpellDescriptor(SpellDescriptor.Cold); context.RemoveSpellDescriptor(SpellDescriptor.Acid); context.RemoveSpellDescriptor(SpellDescriptor.Electricity); context.AddSpellDescriptor(ChangeSpellElementalDamage.ElementToSpellDescriptor(this.Element)); //context.Recalculate(); }
static void Postfix(RuleCastSpell __instance, ref bool __result) { if ((__instance.Spell.Caster?.Unit?.IsPlayerFaction ?? false) && (StringUtils.ToToggleBool(settings.toggleArcaneSpellFailureRoll))) { if (!StringUtils.ToToggleBool(settings.toggleArcaneSpellFailureRollOutOfCombatOnly)) { __result = false; } else if (StringUtils.ToToggleBool(settings.toggleArcaneSpellFailureRollOutOfCombatOnly) && !__instance.Initiator.IsInCombat) { __result = false; } } }
public void releaseSpellOnTarget(TargetWrapper target) { if (spell != null && (spell.CanTarget(target) || ignore_target_checkers)) { var rule_cast_spell = new RuleCastSpell(spell, target); rule_cast_spell.Context.AttackRoll = Rulebook.CurrentContext.AllEvents.LastOfType <RuleAttackWithWeapon>()?.AttackRoll; if (always_hit) { rule_cast_spell.Context.ForceAlwaysHit = true; } Rulebook.Trigger <RuleCastSpell>(rule_cast_spell); Common.AddBattleLogMessage($"{this.Owner.CharacterName} released {spell.Blueprint.Name} from {this.Fact.Name}."); spell = null; } }
public void OnEventAboutToTrigger(RuleCastSpell evt) { if (evt.Spell?.Spellbook?.Blueprint != spellbook) { return; } foreach (var b in evt.Initiator.Buffs) { if (!b.IsSuppressed && (b.Context.SpellDescriptor & (SpellDescriptor.NegativeEmotion | SpellDescriptor.Fear | SpellDescriptor.Shaken)) != 0) { evt.SpellFailureChance = Math.Max(evt.SpellFailureChance, 100); break; } } }
public void OnEventAboutToTrigger(RuleCastSpell evt) { if (!evt.Spell.Blueprint.IsSpell || evt.Spell.Spellbook == null || (evt.Spell.StickyTouch != null)) { return; } if (RulebookEvent.Dice.D100 > this.chance) { return; } evt.SpellFailureChance = 200; if (do_not_spend_slot_if_failed) { evt.Spell.Caster.Ensure <SpellbookMechanics.UnitPartDoNotSpendNextSpell>().active = true; } }
public void OnEventDidTrigger(RuleCastSpell evt) { try { var context = evt.Context; if (context.AbilityBlueprint.Type == AbilityType.Spell && (context.Params.Metamagic & (Metamagic)ModMetamagic.Elemental) != 0) { Log.Write($"{GetType().Name}: apply {EnergyType} energy type to spell {context.AbilityBlueprint.name}"); context.RemoveSpellDescriptor(SpellDescriptor.Fire); context.RemoveSpellDescriptor(SpellDescriptor.Cold); context.RemoveSpellDescriptor(SpellDescriptor.Acid); context.RemoveSpellDescriptor(SpellDescriptor.Electricity); context.AddSpellDescriptor(ElementToSpellDescriptor(EnergyType)); } } catch (Exception e) { Log.Error(e); } }
static public void Prefix(RuleCastSpell __instance) { Main.logger.Log($"rule cast spell"); }
public void OnEventAboutToTrigger(RuleCastSpell evt) { }
static public void Postfix(RuleCastSpell __instance) { Main.logger.Log($"rule cast return success is {__instance.Success}"); }
public void OnEventDidTrigger(RuleCastSpell evt) { }