Skip to content

Commit

Permalink
Compatibility with attack / damage stat replacers
Browse files Browse the repository at this point in the history
  • Loading branch information
pheonix99 committed Jun 23, 2022
1 parent f9a502c commit 6a72483
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
25 changes: 22 additions & 3 deletions ToggleableThrowingWeapons/Component/ThrownOnlyStrToDamage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ class ThrownOnlyStatToDamage : WeaponEnchantmentLogic, IInitiatorRulebookHandler
// Token: 0x0600C1F7 RID: 49655 RVA: 0x00311EA0 File Offset: 0x003100A0
public void OnEventAboutToTrigger(RuleCalculateWeaponStats evt)
{
ModifiableValueAttributeStat modifiableValueAttributeStat = evt.Initiator.Descriptor.Stats.GetStat(this.Stat) as ModifiableValueAttributeStat;
if (evt.Weapon == base.Owner && modifiableValueAttributeStat != null && evt.Weapon.Blueprint.IsRanged)
if (evt.Weapon == null)
return;

ModifiableValueAttributeStat weaponmodifiableValueAttributeStat = evt.Initiator.Descriptor.Stats.GetStat(this.Stat) as ModifiableValueAttributeStat;
if (evt.Weapon != null && evt.Weapon == base.Owner && weaponmodifiableValueAttributeStat != null && evt.Weapon.Blueprint.IsRanged)
{
var dmgBonusStat = evt.DamageBonusStat;
if (dmgBonusStat != null)
{
ModifiableValueAttributeStat modifiableValueAttributeStat = Owner.Wielder.Stats.GetStat(dmgBonusStat.Value) as ModifiableValueAttributeStat;
if (modifiableValueAttributeStat.Bonus >= weaponmodifiableValueAttributeStat.Bonus)
{
return;
}

}



evt.OverrideDamageBonusStat(this.Stat);
evt.OverrideDamageBonusStatMultiplier(this.Multiplier);



}
}

Expand All @@ -29,6 +46,8 @@ public void OnEventDidTrigger(RuleCalculateWeaponStats evt)
{
}



// Token: 0x04007E90 RID: 32400
public StatType Stat;

Expand Down
2 changes: 1 addition & 1 deletion ToggleableThrowingWeapons/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "ToggleableThrowingWeapons",
"DisplayName": "Toggleable Throwing Weapons",
"Author": "pheonix99",
"Version": "1.2.0",
"Version": "1.2.1",
"ManagerVersion": "0.21.3",
"AssemblyName": "ToggleableThrowingWeapons.dll",
"EntryMethod": "ToggleableThrowingWeapons.Main.Load",
Expand Down
55 changes: 55 additions & 0 deletions ToggleableThrowingWeapons/Patch/PatchAttackStatReplacement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using HarmonyLib;
using Kingmaker.EntitySystem.Stats;
using Kingmaker.RuleSystem.Rules;
using Kingmaker.UnitLogic.FactLogic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToggleableThrowingWeapons.Component;

namespace ToggleableThrowingWeapons.Patch
{
class PatchAttackStatReplacement
{
[HarmonyPatch(typeof(AttackStatReplacement), "OnEventAboutToTrigger")]
static class FixAttackStatReplacer
{

[HarmonyPriority(Priority.Normal)]
public static void Postfix(AttackStatReplacement __instance, RuleCalculateAttackBonusWithoutTarget evt)
{
if (__instance.CheckWeaponTypes)
{


var crossref = evt.Weapon?.Blueprint.Type.Components.OfType<ThrownCrossrefTypeComponent>().FirstOrDefault();
if (crossref != null)
{
Main.TTWContext.Logger.Log($"Assessing Crossref for hackage: {crossref.m_OtherForm.NameSafe()}");
Main.TTWContext.Logger.Log($"First local weapon type is {__instance.WeaponTypes.FirstOrDefault().name}");
ModifiableValueAttributeStat modifiableValueAttributeStat = __instance.Owner.Stats.GetStat(evt.AttackBonusStat) as ModifiableValueAttributeStat;
ModifiableValueAttributeStat modifiableValueAttributeStat2 = __instance.Owner.Stats.GetStat(__instance.ReplacementStat) as ModifiableValueAttributeStat;
bool flag = modifiableValueAttributeStat2 != null && modifiableValueAttributeStat != null && modifiableValueAttributeStat2.Bonus >= modifiableValueAttributeStat.Bonus;

if (flag)
{


if (__instance.WeaponTypes.HasReference(crossref.m_OtherForm))
{

evt.AttackBonusStat = __instance.ReplacementStat;
Main.TTWContext.Logger.Log($"Patching Crossref");
}
}

}

}
}
}

}
}
2 changes: 1 addition & 1 deletion ToggleableThrowingWeapons/ToggleableThrowingWeapons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
<Compile Include="Content\BaseWeapons.cs" />
<Compile Include="Content\MatchHambeardWeapons.cs" />
<Compile Include="Content\ModeSwitching.cs" />
<Compile Include="Content\NewFeats.cs" />
<Compile Include="Content\PairCreation.cs" />
<Compile Include="Main.cs" />
<Compile Include="ModLogic\ModContextTTW.cs" />
<Compile Include="Patch\OverrideItemEntityBlueprintHook.cs" />
<Compile Include="Patch\PatchAttackStatReplacement.cs" />
<Compile Include="Patch\PatchWeaponCategoryExtension.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\AddToRoot.cs" />
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The item names don't change by mode. I'll get to this later.
Thanks to Truinto for the AddFactOnlyParty code.

#Changelog
1.2.1: Fixed interaction with Way Of The Shooting Star, should fix interaction with other attack /dmg stat replacers in general. Mod thrown weapon STR damage effect no longer force-sets stat dmg multiplier to 100%

1.2: Point Blank Master (and any other ranged-only paramaterized features added by mods) now apply to thrown daggers/starknives. Increased range to 30 feet.

1.1: Fixed dex to melee damage cutting out, fixed some graphical jank

0 comments on commit 6a72483

Please sign in to comment.