Skip to content

Commit

Permalink
Support for varriable cost usage abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Vek17 committed Sep 28, 2021
1 parent a88410f commit de9692e
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* added precision critical
* 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

## Version 1.3.3
* fixed mounted maniac not triggering
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ All fixes and added content are configurable and can be disabled by editing the
Coup De Grace now scales properly (Thanks @Perunq)
Class specific feat selections should now have the correct feats
The Holy Symbol of Iomedae no longer turns itself off
Profane ascention now works corectly for dexterity and strength based characters

Aeon
Allows bane uses to scale will all classes instead of just Inquisitor
Expand Down Expand Up @@ -182,6 +183,8 @@ All fixes and added content are configurable and can be disabled by editing the
Nature Mage
Magus
Spell combat now works with abilities that have variants
Sword Saint
Perfect Critical now correctly costs 2 points of pool instead of 1
Monk
Zen Archer
Perfect Strike now upgrades at level 10
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.3"
"Version": "1.3.4"
}
]
}
23 changes: 22 additions & 1 deletion TabletopTweaks/Bugfixes/Classes/Magus.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using HarmonyLib;
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.UnitLogic.Abilities;
using Kingmaker.UnitLogic.ActivatableAbilities;
using Kingmaker.UnitLogic.Parts;
using System;
using TabletopTweaks.Config;
using TabletopTweaks.Extensions;
using TabletopTweaks.MechanicsChanges;
using static TabletopTweaks.MechanicsChanges.ActivatableAbilitySpendLogic;

namespace TabletopTweaks.Bugfixes.Classes {
static class Magus {
Expand All @@ -17,11 +22,27 @@ static void Postfix() {
Main.LogHeader("Patching Magus Resources");

PatchBase();
PatchSwordSaint();
}
static void PatchBase() {
}
}
static void PatchSwordSaint() {
PatchPerfectCritical();

void PatchPerfectCritical() {
if (ModSettings.Fixes.Magus.Archetypes["SwordSaint"].IsDisabled("PerfectCritical")) { return; }

var SwordSaintPerfectStrikeCritAbility = Resources.GetBlueprint<BlueprintActivatableAbility>("c6559839738a7fc479aadc263ff9ffff");

SwordSaintPerfectStrikeCritAbility.SetDescription("At 4th level, when a sword saint confirms a critical hit, " +
"he can spend 2 points from his arcane pool to increase his weapon's critical multiplier by 1.");
SwordSaintPerfectStrikeCritAbility
.GetComponent<ActivatableAbilityResourceLogic>()
.SpendType = CustomSpendType.Crit.Amount(2);
Main.LogPatch("Patched", SwordSaintPerfectStrikeCritAbility);
}
}
}
[HarmonyPatch(typeof(UnitPartMagus), "IsSpellFromMagusSpellList", new Type[] { typeof(AbilityData) })]
class UnitPartMagus_IsSpellFromMagusSpellList_VarriantAbilities_Patch {
static void Postfix(UnitPartMagus __instance, ref bool __result, AbilityData spell) {
Expand Down
9 changes: 8 additions & 1 deletion TabletopTweaks/Config/Fixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@
"SpellCombatAbilityVariants": true
}
},
"Archetypes": {}
"Archetypes": {
"SwordSaint": {
"DisableAll": false,
"Enabled": {
"PerfectCritical": true
}
}
}
},
"Monk": {
"DisableAll": false,
Expand Down
99 changes: 99 additions & 0 deletions TabletopTweaks/MechanicsChanges/ActivatableAbilitySpendLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using HarmonyLib;
using Kingmaker.Blueprints;
using Kingmaker.EntitySystem;
using Kingmaker.UnitLogic;
using Kingmaker.UnitLogic.ActivatableAbilities;
using Kingmaker.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Kingmaker.UnitLogic.ActivatableAbilities.ActivatableAbilityResourceLogic;

namespace TabletopTweaks.MechanicsChanges {
static class ActivatableAbilitySpendLogic {

public enum CustomSpendType : int {
Crit = 100
}

public static ResourceSpendType Amount(this CustomSpendType type, int value) {
return (ResourceSpendType)((int)type + value);
}

[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) {
__instance.SpendResource(true);
}
}
}

[HarmonyPatch(typeof(ActivatableAbilityResourceLogic), "IsAvailable")]
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);
}
}
}
}

[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;
}

__instance.Fact.TurnOffImmediately();
}
return false;
}
}

[HarmonyPatch(typeof(ActivatableAbility), "ResourceCount", MethodType.Getter)]
class ActivatableAbility_ResourceCount_PerfectCritical_Patch {
static void Postfix(ActivatableAbility __instance, ref int? __result) {
__instance.m_CachedResourceLogic = __instance.m_CachedResourceLogic ??
__instance.SelectComponentsWithRuntime<ActivatableAbilityResourceLogic>()
.ToArray();
ActivatableAbilityResourceLogic component = __instance.m_CachedResourceLogic
.FirstItem()
.Component;
BlueprintAbilityResource blueprintAbilityResource =
(component != null && component.SpendType != ActivatableAbilityResourceLogic.ResourceSpendType.None)
? component.RequiredResource : null;
if (component == null) { return; }
if (blueprintAbilityResource == null) { return; }
if (component.FreeBlueprint != null && __instance.Owner.HasFact(component.FreeBlueprint)) {
return;
}
var spendAmount = (int)component.SpendType - (int)CustomSpendType.Crit;
if (spendAmount < 100 && spendAmount > 0) {
__result = __instance.Owner.Resources.GetResourceAmount(blueprintAbilityResource) / spendAmount;
}
}
}


}
}
5 changes: 5 additions & 0 deletions TabletopTweaks/Resources.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using JetBrains.Annotations;
using Kingmaker.Blueprints;
using System;
using System.Collections.Generic;
using TabletopTweaks.Config;

namespace TabletopTweaks {
static class Resources {
public static readonly Dictionary<BlueprintGuid, SimpleBlueprint> ModBlueprints = new Dictionary<BlueprintGuid, SimpleBlueprint>();

internal static object GetBlueprint<T>() {
throw new NotImplementedException();
}
#if false
public static IEnumerable<T> GetBlueprints<T>() where T : BlueprintScriptableObject {
if (blueprints == null) {
Expand Down
1 change: 1 addition & 0 deletions TabletopTweaks/TabletopTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<Compile Include="Config\IUpdatableSettings.cs" />
<Compile Include="Config\NestedSettingGroup.cs" />
<Compile Include="Config\SettingGroup.cs" />
<Compile Include="MechanicsChanges\ActivatableAbilitySpendLogic.cs" />
<Compile Include="MechanicsChanges\ArchetypePrerequisites .cs" />
<Compile Include="MechanicsChanges\CannyDefenseStacking.cs" />
<Compile Include="MechanicsChanges\ActivatableResourceFreeResourceLogic.cs" />
Expand Down

0 comments on commit de9692e

Please sign in to comment.