From 61c7834b354cbde39424849e1d662fc756e1fc4c Mon Sep 17 00:00:00 2001 From: Sean Petrie Date: Tue, 28 Sep 2021 02:05:43 -0500 Subject: [PATCH] Issues with arrow consumption and melee vital --- CHANGELOG.md | 11 +++- Repository.json | 2 +- TabletopTweaks/Bugfixes/Features/Feats.cs | 29 +++++++-- .../Bugfixes/General/WeaponProperties.cs | 3 +- TabletopTweaks/Info.json | 2 +- .../ActivatableAbilitySpendLogic.cs | 61 +++++++++++-------- .../NewComponents/AdditionalSpellSelection.cs | 8 +-- 7 files changed, 75 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 808230cb..61d17f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,13 @@ +## Version 1.3.4a +* fixed issue where weapon materials didn't apply correctly +* fixed issues where activiatable abilities with resources spent incorrecty +* fixed issue where vital force was not properly applied to melee attacks + ## Version 1.3.4 -* added precision critical +* added precision critical mythic ability * rowdy's vital force now deals precision damage -* profane ascention now works corectly for dex and strength based characters -* sword saint's perfect criticaly now correctl costs 2 points of pool instead of 1 +* profane ascension now works correctly for dexterity and strength based characters +* sword saint's perfect critical now correctly costs 2 points of pool instead of 1 ## Version 1.3.3 * fixed mounted maniac not triggering diff --git a/Repository.json b/Repository.json index 8d673610..34300fae 100644 --- a/Repository.json +++ b/Repository.json @@ -2,7 +2,7 @@ "Releases": [ { "Id": "TabletopTweaks", - "Version": "1.3.4" + "Version": "1.3.4a" } ] } \ No newline at end of file diff --git a/TabletopTweaks/Bugfixes/Features/Feats.cs b/TabletopTweaks/Bugfixes/Features/Feats.cs index 308bb97e..6a8290b7 100644 --- a/TabletopTweaks/Bugfixes/Features/Feats.cs +++ b/TabletopTweaks/Bugfixes/Features/Feats.cs @@ -342,6 +342,8 @@ private static int FindInsertionTarget(List codes) { private class VitalStrikeEventHandler : IInitiatorRulebookHandler, IRulebookHandler, + IInitiatorRulebookHandler, + IRulebookHandler, IInitiatorRulebookHandler, IRulebookHandler, ISubscriber, IInitiatorRulebookSubscriber { @@ -361,7 +363,6 @@ public void OnEventAboutToTrigger(RuleCalculateWeaponStats evt) { } public void OnEventDidTrigger(RuleCalculateWeaponStats evt) { - Main.Log("RuleCalculateWeaponStats::OnEventDidTrigger"); DamageDescription damageDescription = evt.DamageDescription.FirstItem(); if (damageDescription != null && damageDescription.TypeDescription.Type == DamageType.Physical) { var vitalDamage = new DamageDescription() { @@ -377,7 +378,10 @@ public void OnEventDidTrigger(RuleCalculateWeaponStats evt) { evt.DamageDescription.Insert(1, vitalDamage); } } + public void OnEventAboutToTrigger(RuleAttackWithWeapon evt) { + } + //For Ranged - Handling of damage calcs does not occur the same due to projectiles public void OnEventDidTrigger(RuleAttackWithWeapon evt) { if (!m_Rowdy) { return; } RuleAttackRoll ruleAttackRoll = evt.AttackRoll; @@ -397,15 +401,30 @@ public void OnEventDidTrigger(RuleAttackWithWeapon evt) { } } - public void OnEventAboutToTrigger(RuleAttackWithWeapon evt) { + //For Melee + public void OnEventAboutToTrigger(RulePrepareDamage evt) { + if (!m_Rowdy) { return; } + RuleAttackRoll ruleAttackRoll = evt.ParentRule.AttackRoll; + if (ruleAttackRoll == null) { return; } + if (evt.Initiator.Stats.SneakAttack < 1) { return; } + if (!ruleAttackRoll.TargetUseFortification || ruleAttackRoll.FortificationOvercomed) { + DamageTypeDescription damageTypeDescription = evt.DamageBundle + .First() + .CreateTypeDescription(); + int rowdyDice = evt.Initiator.Stats.SneakAttack * 2; + DiceFormula dice = new DiceFormula(rowdyDice, DiceType.D6); + BaseDamage baseDamage = damageTypeDescription.GetDamageDescriptor(dice, 0).CreateDamage(); + baseDamage.Precision = true; + evt.Add(baseDamage); + } } - private readonly UnitEntityData m_Unit; + public void OnEventDidTrigger(RulePrepareDamage evt) { + } + private readonly UnitEntityData m_Unit; private int m_DamageMod; - private bool m_Mythic; - private bool m_Rowdy; } } diff --git a/TabletopTweaks/Bugfixes/General/WeaponProperties.cs b/TabletopTweaks/Bugfixes/General/WeaponProperties.cs index 7d605829..0bb68adf 100644 --- a/TabletopTweaks/Bugfixes/General/WeaponProperties.cs +++ b/TabletopTweaks/Bugfixes/General/WeaponProperties.cs @@ -3,6 +3,7 @@ using Kingmaker.EntitySystem.Entities; using Kingmaker.RuleSystem.Rules.Damage; using System; +using System.Linq; namespace TabletopTweaks.Bugfixes.General { static class WeaponProperties { @@ -23,7 +24,7 @@ static void Postfix(WeaponReality __instance, RulePrepareDamage evt) { class WeaponMaterial_OnEventAboutToTrigger_Patch { static void Postfix(WeaponMaterial __instance, RulePrepareDamage evt) { if (evt.DamageBundle.Weapon == __instance.Owner && evt.DamageBundle.WeaponDamage != null) { - foreach (PhysicalDamage damage in evt.DamageBundle) { + foreach (PhysicalDamage damage in evt.DamageBundle.OfType()) { damage.AddMaterial(__instance.Material); } } diff --git a/TabletopTweaks/Info.json b/TabletopTweaks/Info.json index 8f70d0f8..41552d2d 100644 --- a/TabletopTweaks/Info.json +++ b/TabletopTweaks/Info.json @@ -9,5 +9,5 @@ "ManagerVersion": "0.23.0", "Repository": "https://raw.githubusercontent.com/Vek17/WrathMods-TabletopTweaks/master/Repository.json", "Requirements": [], - "Version": "1.3.4" + "Version": "1.3.4a" } \ No newline at end of file diff --git a/TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs b/TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs index 11a8116e..0f5f9415 100644 --- a/TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs +++ b/TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs @@ -15,19 +15,34 @@ namespace TabletopTweaks.MechanicsChanges { static class ActivatableAbilitySpendLogic { public enum CustomSpendType : int { - Crit = 100 + Crit = 0b00000000_00000001_00000000_00000000 } - public static ResourceSpendType Amount(this CustomSpendType type, int value) { - return (ResourceSpendType)((int)type + value); + public static ResourceSpendType Amount(this CustomSpendType type, byte value) { + return (ResourceSpendType)((int)type | value); + } + + private static int Amount(this CustomSpendType type) { + return ((int)type & 0b00000000_00000000_00000000_11111111); + } + + private static int CustomValue(this ResourceSpendType type) { + return ((int)type & 0b00000000_00000000_00000000_11111111); + } + + private static bool IsCustomSpendType(this ResourceSpendType type) { + return ((int)type & 0b11111111_11111111_00000000_00000000) > 0; + } + + private static bool IsType(this ResourceSpendType flag, CustomSpendType type) { + return (flag & (ResourceSpendType)type) > 0; } [HarmonyPatch(typeof(ActivatableAbilityResourceLogic), "Kingmaker.UnitLogic.ActivatableAbilities.IActivatableAbilitySpendResourceLogic.OnCrit")] class ActivatableAbilityResourceLogic_OnCrit_PerfectCritical_Patch { static void Postfix(ActivatableAbilityResourceLogic __instance) { - var spendAmount = (int)__instance.SpendType - (int)CustomSpendType.Crit; - if (spendAmount < 100 && spendAmount > 0) { + if (__instance.SpendType.IsType(CustomSpendType.Crit)) { __instance.SpendResource(true); } } @@ -37,9 +52,8 @@ static void Postfix(ActivatableAbilityResourceLogic __instance) { class ActivatableAbilityResourceLogic_IsAvailable_PerfectCritical_Patch { static void Postfix(ActivatableAbilityResourceLogic __instance, ref bool __result, EntityFactComponent runtime) { using (runtime.RequestEventContext()) { - var spendAmount = (int)__instance.SpendType - (int)CustomSpendType.Crit; - if (spendAmount < 100 && spendAmount > 0) { - __result = __instance.Owner.Resources.HasEnoughResource(__instance.RequiredResource, spendAmount); + if (__instance.SpendType.IsType(CustomSpendType.Crit)) { + __result = __instance.Owner.Resources.HasEnoughResource(__instance.RequiredResource, __instance.SpendType.CustomValue()); } } } @@ -48,25 +62,22 @@ static void Postfix(ActivatableAbilityResourceLogic __instance, ref bool __resul [HarmonyPatch(typeof(ActivatableAbilityResourceLogic), "SpendResource", new Type[] { typeof(bool) })] class ActivatableAbilityResourceLogic_SpendResource_PerfectCritical_Patch { static bool Prefix(ActivatableAbilityResourceLogic __instance) { - var spendAmount = (int)__instance.SpendType - (int)CustomSpendType.Crit; - if (spendAmount < 100 && spendAmount > 0) { - if (__instance.Owner.HasFact(__instance.FreeBlueprint)) { - return false; - } - if (!__instance.RequiredResource) { - if (__instance.Fact.SourceItem != null && !__instance.Fact.SourceItem.SpendCharges()) { - __instance.Fact.TurnOffImmediately(); - } - return false; - } - if (__instance.Owner.Resources.HasEnoughResource(__instance.RequiredResource, spendAmount)) { - __instance.Owner.Resources.Spend(__instance.RequiredResource, spendAmount); - return false; + if (!__instance.SpendType.IsCustomSpendType()) { return true; } + if (__instance.Owner.HasFact(__instance.FreeBlueprint)) { + return false; + } + if (!__instance.RequiredResource) { + if (__instance.Fact.SourceItem != null && !__instance.Fact.SourceItem.SpendCharges()) { + __instance.Fact.TurnOffImmediately(); } - - __instance.Fact.TurnOffImmediately(); + return false; + } + if (__instance.Owner.Resources.HasEnoughResource(__instance.RequiredResource, __instance.SpendType.CustomValue())) { + __instance.Owner.Resources.Spend(__instance.RequiredResource, __instance.SpendType.CustomValue()); + return false; } - return false; + __instance.Fact.TurnOffImmediately(); + return true; } } diff --git a/TabletopTweaks/NewComponents/AdditionalSpellSelection.cs b/TabletopTweaks/NewComponents/AdditionalSpellSelection.cs index fde25671..78afbed9 100644 --- a/TabletopTweaks/NewComponents/AdditionalSpellSelection.cs +++ b/TabletopTweaks/NewComponents/AdditionalSpellSelection.cs @@ -35,7 +35,6 @@ public override void OnActivate() { .OfType() .Where(c => c.spellbook.Blueprint.AssetGuid.Equals(spellbook.Blueprint.AssetGuid)) .Where(c => c.SpellList.Guid.Equals(SpellList.Guid)) - .Where(c => c.AdjustedMaxLevel == this.AdjustedMaxLevel) //Experemental "Fix" .Aggregate(0, (acc, x) => acc + x.Count) ?? 0; spellSelection = controller.State.DemandSpellSelection(spellbook.Blueprint, SpellList); spellSelection.SetExtraSpells(spellCount, AdjustedMaxLevel); @@ -71,10 +70,9 @@ static void Postfix(SpellSelectionData __instance, ref bool __result, UnitDescri if (!__instance.Spellbook.AllSpellsKnown) { return; } if (__instance.ExtraSelected != null && __instance.ExtraSelected.Length != 0) { if (__instance.ExtraSelected.HasItem((BlueprintAbility i) => i == null) && !__instance.ExtraByStat) { - for (int k = 0; k <= __instance.ExtraMaxLevel; k++) { - int ii = k; - if (__instance.SpellList.SpellsByLevel[k].SpellsFiltered.HasItem((BlueprintAbility sb) => !sb.IsCantrip - && !__instance.SpellbookContainsSpell(spellbook, ii, sb) && !__instance.ExtraSelected.Contains(sb))) { + for (int level = 0; level <= __instance.ExtraMaxLevel; level++) { + if (__instance.SpellList.SpellsByLevel[level].SpellsFiltered.HasItem((BlueprintAbility sb) => !sb.IsCantrip + && !__instance.SpellbookContainsSpell(spellbook, level, sb) && !__instance.ExtraSelected.Contains(sb))) { __result = true; } }