public override void RunAction() { if (this.Context.MaybeCaster == null) { UberDebug.LogError((object)"Caster unit is missing", (object[])Array.Empty <object>()); } else { int num = bonus.Calculate(this.Context); var rule_skill_check = new RuleSkillCheck(this.Context.MaybeCaster, this.Stat, this.UseCustomDC ? this.CustomDC.Calculate(this.Context) : ((this.Target.Unit?.Descriptor?.Progression.CharacterLevel).GetValueOrDefault() + 10)); rule_skill_check.ShowAnyway = true; if (num != 0) { rule_skill_check.Bonus.AddModifier(num, null, Kingmaker.Enums.ModifierDescriptor.UntypedStackable); } if (this.Context.TriggerRule <RuleSkillCheck>(rule_skill_check).IsPassed) { this.Success.Run(); } else { this.Failure.Run(); } } }
public override void RunAction() { var target = this.Target.Unit; var initiator = this.Context.MaybeCaster; if (!InspectUnitsHelper.IsInspectAllow(target)) { return; } BlueprintUnit blueprintForInspection = target.Descriptor.BlueprintForInspection; InspectUnitsManager.UnitInfo info = Game.Instance.Player.InspectUnitsManager.GetInfo(blueprintForInspection); StatType statType = !(bool)((UnityEngine.Object)info.Blueprint.Type) ? StatType.SkillLoreNature : info.Blueprint.Type.KnowledgeStat; if (info == null) { return; } ModifiableValueSkill stat = initiator.Stats.GetStat <ModifiableValueSkill>(statType); int?nullable1; int?nullable2; if (stat == null) { nullable1 = new int?(); nullable2 = nullable1; } else { nullable2 = new int?(stat.BaseValue); } nullable1 = nullable2; int dc = info.DC; int bonus = value.Calculate(this.Context); if ((!nullable1.HasValue ? 0 : nullable1.Value) > 0 || (bool)initiator.Descriptor.State.Features.MakeKnowledgeCheckUntrained) { var skill_check = new RuleSkillCheck(initiator, statType, dc); skill_check.AddTemporaryModifier(initiator.Stats.GetStat(statType).AddModifier(bonus, null, descriptor)); skill_check.IgnoreDifficultyBonusToDC = true; int rollResult = Rulebook.Trigger <RuleSkillCheck>(skill_check).RollResult; Common.AddBattleLogMessage($"{initiator.CharacterName} DC {dc} monster lore check: {rollResult}"); if (dc <= rollResult && action_on_success != null) { action_on_success.Run(); } if (info.KnownPartsCount < 4) { info.SetCheck(rollResult, initiator); EventBus.RaiseEvent <IKnowledgeHandler>((Action <IKnowledgeHandler>)(h => h.HandleKnowledgeUpdated(info))); } } }
static bool Prefix(RulePartySkillCheck __instance, bool isTrigger, ref int ___m_D20, ref int ___m_StatValue, StatType ___m_StatType, int ___m_DifficultyClass) { ___m_StatValue = int.MinValue; var tr = Harmony12.Traverse.Create(__instance); tr.Property("Roller").SetValue(null); RuleSkillCheck selected_evt = null; foreach (UnitEntityData unitEntityData in Game.Instance.Player.Party) { if (unitEntityData.Descriptor.State.CanAct) { ModifiableValue stat = unitEntityData.Stats.GetStat(___m_StatType); ModifiableValueAttributeStat valueAttributeStat = stat as ModifiableValueAttributeStat; int num = valueAttributeStat != null ? valueAttributeStat.Bonus : stat.ModifiedValue; RuleSkillCheck evt = new RuleSkillCheck(unitEntityData, ___m_StatType, ___m_DifficultyClass) { Voice = __instance.Voice, EnsureSuccess = __instance.EnsureSuccess }; if (isTrigger) { evt.Silent = true;; Rulebook.Trigger <RuleSkillCheck>(evt); num += (int)evt.Bonus; } if (___m_StatValue < num) { ___m_StatValue = num; tr.Property("Roller").SetValue(unitEntityData); selected_evt = evt; } } } if (__instance.Roller == null) { UberDebug.Log("Roller is null, in the party skillcheck", (object[])Array.Empty <object>()); } else { if (!isTrigger) { selected_evt.Calculate(); } else { selected_evt.Silent = false; EventBus.RaiseEvent <IRollSkillCheckHandler>((Action <IRollSkillCheckHandler>)(h => h.HandleOnRuleSkillCheck(selected_evt))); //Game.Instance?.UI?.BattleLogManager?.HandleUnitSkillCheckRolled(selected_evt); } ___m_D20 = selected_evt.D20; } return(false); }
public void OnEventAboutToTrigger(RuleSkillCheck evt) { // If this was triggered from a party rule, remove the temporary bonuses before rolling. if (Modifiers == null) { return; } Modifiers.ForEach(m => m.Remove()); Modifiers = null; }
static private int getD20Value(RuleSkillCheck evt) { if (evt.IsTriggererd) { return(evt.D20 + evt.Bonus); } else { return(evt.D20); } }
private static void Postfix(ref bool __result, RuleSkillCheck __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; } } } } }
private static bool tryBreakFree(UnitEntityData target, UnitEntityData grappler, MechanicsContext context) { int dc = 0; if (context != null) { dc = context.Params.DC; } RuleCalculateCMB rule_calcualte_cmb1 = new RuleCalculateCMB(target, grappler, CombatManeuver.Grapple); RuleCalculateCMB rule_calcualte_cmb2 = context?.TriggerRule <RuleCalculateCMB>(rule_calcualte_cmb1) ?? Rulebook.Trigger <RuleCalculateCMB>(rule_calcualte_cmb1); if (Math.Max((int)(target.Stats.SkillMobility), (int)(target.Stats.SkillAthletics)) < rule_calcualte_cmb2.Result) { RuleSkillCheck rule_skill_check = new RuleSkillCheck(target, StatType.AdditionalCMB, dc); rule_skill_check.Bonus.AddModifier(rule_calcualte_cmb2.Result - target.Stats.AdditionalCMB.ModifiedValue, null, ModifierDescriptor.UntypedStackable); return((context?.TriggerRule <RuleSkillCheck>(rule_skill_check) ?? Rulebook.Trigger <RuleSkillCheck>(rule_skill_check)).IsPassed); } else { StatType stat = (int)(target.Stats.SkillMobility) > (int)(target.Stats.SkillAthletics) ? StatType.SkillMobility : StatType.SkillAthletics; RuleSkillCheck rule_skill_check = new RuleSkillCheck(target, stat, dc); return((context?.TriggerRule <RuleSkillCheck>(rule_skill_check) ?? Rulebook.Trigger <RuleSkillCheck>(rule_skill_check)).IsPassed); } }
public void OnEventDidTrigger(RuleSkillCheck evt) { }
public void OnEventAboutToTrigger(RuleSkillCheck evt) => IncreaseLuckBonus(evt, evt.StatType);
static bool Prefix(Demoralize __instance) { var tr = Harmony12.Traverse.Create(__instance); var target = tr.Property("Target").GetValue <TargetWrapper>(); MechanicsContext.Data data = ElementsContext.GetData <MechanicsContext.Data>(); MechanicsContext mechanicsContext = (data != null) ? data.Context : null; UnitEntityData unitEntityData = (mechanicsContext != null) ? mechanicsContext.MaybeCaster : null; if (unitEntityData == null || !target.IsUnit) { UberDebug.LogError(__instance, "Unable to apply buff: no context found", Array.Empty <object>()); return(false); } int num = 10 + target.Unit.Descriptor.Progression.CharacterLevel + target.Unit.Stats.Wisdom.Bonus; ModifiableValue.Modifier modifier = null; try { if (__instance.DazzlingDisplay && unitEntityData.Descriptor.State.Features.SwordlordWeaponProwess) { int num2 = 0; foreach (var feature in unitEntityData.Descriptor.Progression.Features) { var param = feature.Param; bool flag; if (param == null) { flag = false; } else { WeaponCategory?weaponCategory = param.WeaponCategory; WeaponCategory weaponCategory2 = WeaponCategory.DuelingSword; flag = (weaponCategory.GetValueOrDefault() == weaponCategory2 & weaponCategory != null); } if (flag) { num2++; } } modifier = unitEntityData.Stats.CheckIntimidate.AddModifier(num2, null, ModifierDescriptor.None); } var ruleSkillCheck = new RuleSkillCheck(unitEntityData, StatType.CheckIntimidate, num); var demoralize_bonus_part = mechanicsContext.MaybeCaster.Get <UnitPartDemoralizeBonus>(); if (demoralize_bonus_part != null) { ruleSkillCheck.Bonus.AddModifier(demoralize_bonus_part.getBonus(), null, ModifierDescriptor.UntypedStackable); } ruleSkillCheck = mechanicsContext.TriggerRule <RuleSkillCheck>(ruleSkillCheck); if (ruleSkillCheck.IsPassed) { int num3 = 1 + (ruleSkillCheck.RollResult - num) / 5 + (unitEntityData.Descriptor.State.Features.FrighteningThug ? 1 : 0); if (unitEntityData.Descriptor.State.Features.FrighteningThug && num3 >= 4) { target.Unit.Descriptor.AddBuff(__instance.GreaterBuff, mechanicsContext, new TimeSpan?(1.Rounds().Seconds)); } Buff buff = target.Unit.Descriptor.AddBuff(__instance.Buff, mechanicsContext, new TimeSpan?(num3.Rounds().Seconds)); if (unitEntityData.Descriptor.HasFact(__instance.ShatterConfidenceFeature) && buff != null) { Buff fact = target.Unit.Descriptor.AddBuff(__instance.ShatterConfidenceBuff, mechanicsContext, new TimeSpan?(num3.Rounds().Seconds)); buff.StoreFact(fact); } unitEntityData.Get <UnitPartActionOnDemoralize>()?.runActions(mechanicsContext, target.Unit, num, ruleSkillCheck.RollResult); var scoped_actions = (mechanicsContext?.SourceAbility?.GetComponents <ScopedDemoralizeActions>()).EmptyIfNull(); foreach (var s in scoped_actions) { s.actions.Run(); } } } finally { if (modifier != null) { modifier.Remove(); } } return(false); }