Skip to content

Commit

Permalink
Issues with arrow consumption and melee vital
Browse files Browse the repository at this point in the history
  • Loading branch information
Vek17 committed Sep 28, 2021
1 parent de9692e commit 61c7834
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 41 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Releases": [
{
"Id": "TabletopTweaks",
"Version": "1.3.4"
"Version": "1.3.4a"
}
]
}
29 changes: 24 additions & 5 deletions TabletopTweaks/Bugfixes/Features/Feats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ private static int FindInsertionTarget(List<CodeInstruction> codes) {

private class VitalStrikeEventHandler : IInitiatorRulebookHandler<RuleCalculateWeaponStats>,
IRulebookHandler<RuleCalculateWeaponStats>,
IInitiatorRulebookHandler<RulePrepareDamage>,
IRulebookHandler<RulePrepareDamage>,
IInitiatorRulebookHandler<RuleAttackWithWeapon>,
IRulebookHandler<RuleAttackWithWeapon>,
ISubscriber, IInitiatorRulebookSubscriber {
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion TabletopTweaks/Bugfixes/General/WeaponProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<PhysicalDamage>()) {
damage.AddMaterial(__instance.Material);
}
}
Expand Down
2 changes: 1 addition & 1 deletion TabletopTweaks/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
61 changes: 36 additions & 25 deletions TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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());
}
}
}
Expand All @@ -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;
}
}

Expand Down
8 changes: 3 additions & 5 deletions TabletopTweaks/NewComponents/AdditionalSpellSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public override void OnActivate() {
.OfType<AdditionalSpellSelection>()
.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);
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 61c7834

Please sign in to comment.