Skip to content

Commit

Permalink
Added Rule Creators to fix logging issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Vek17 committed Dec 24, 2024
1 parent 61d41cb commit 621c6fb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 0.7.12
* Fixed issue with missing log creators creating stutters and bloated logs.

# Version 0.7.11
* Fix for broken type issue in some game versions.

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-Core",
"Version": "0.7.11"
"Version": "0.7.12"
}
]
}
2 changes: 1 addition & 1 deletion TabletopTweaks-Core/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"Repository": "https://raw.githubusercontent.com/Vek17/TabletopTweaks-Core/master/Repository.json",
"Requirements": [],
"LoadAfter": [ "MewsiferConsole.Mod" ],
"Version": "0.7.11"
"Version": "0.7.12"
}
14 changes: 14 additions & 0 deletions TabletopTweaks-Core/NewRules/RuleAttackWithWeaponPrecision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
namespace TabletopTweaks.Core.NewRules {
class RuleAttackWithWeaponPrecision : RuleAttackWithWeapon {

[PostPatchInitialize]
static void AddGameLogEventCreator() {
if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleAttackWithWeaponPrecision))) {
Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[]
{
typeof(RuleAttackWithWeaponPrecision)
});
GameLogEventsFactory.Creators.Add(typeof(RuleAttackWithWeaponPrecision), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[]
{
rule
}));
}
}

public bool ForceSneakAttack { get; set; }
public RuleAttackWithWeaponPrecision([NotNull] UnitEntityData attacker, [NotNull] UnitEntityData target, [NotNull] ItemEntityWeapon weapon, int attackBonusPenalty) : base(attacker, target, weapon, attackBonusPenalty) {
}
Expand Down
28 changes: 23 additions & 5 deletions TabletopTweaks-Core/NewRules/RuleCalculateArmorAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Kingmaker.Items;
using Kingmaker.RuleSystem;
using Kingmaker.UI.Common;
using Kingmaker.UI.Models.Log;
using Kingmaker.UI.Models.Log.Events;
using Kingmaker.UI.MVVM._VM.Tooltip.Bricks;
using Kingmaker.UI.MVVM._VM.Tooltip.Templates;
using Kingmaker.UI.Tooltip;
Expand All @@ -21,11 +23,26 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using TabletopTweaks.Core.Utilities;
using UnityEngine;

namespace TabletopTweaks.Core.NewRules {
public class RuleCalculateArmorAC : RulebookEvent {

[PostPatchInitialize]
static void AddGameLogEventCreator() {
if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleCalculateArmorAC))) {
Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[]
{
typeof(RuleCalculateArmorAC)
});
GameLogEventsFactory.Creators.Add(typeof(RuleCalculateArmorAC), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[]
{
rule
}));
}
}

public int ArmorBonus => ArmorBaseBonus + ArmorEnhancementBonus + ArmorModifier + MythicMediumArmorEnduranceBonus + ArmoredMightBonus;
public int ArmoredMightBonus {
get {
Expand Down Expand Up @@ -79,7 +96,7 @@ static class ItemEntityArmor_RecalculateStats_RuleCalculateArmorAC_Patch {
static readonly MethodInfo ItemEntityArmor_AddModifier = AccessTools.Method(
typeof(ItemEntityArmor),
nameof(ItemEntityArmor.AddModifier),
new Type[] {
new Type[] {
typeof(ModifiableValue),
typeof(int),
typeof(ModifierDescriptor),
Expand Down Expand Up @@ -117,9 +134,10 @@ private static TargetInfo FindInsertionTarget(List<CodeInstruction> codes) {
var firstModifier = false;
for (int i = info.Index; i < codes.Count; i++) {
if (codes[i].opcode == OpCodes.Call && codes[i].Calls(ItemEntityArmor_AddModifier)) {
if (!firstModifier) {
firstModifier = true;
continue; }
if (!firstModifier) {
firstModifier = true;
continue;
}
info.End = i;
break;
}
Expand Down Expand Up @@ -207,6 +225,6 @@ static private void AddModifiers(TooltipTemplateItem __instance, RuleCalculateAr
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions TabletopTweaks-Core/NewRules/RuleFortificationCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
namespace TabletopTweaks.Core.NewRules {
public class RuleFortificationCheck : RulebookTargetEvent {

[PostPatchInitialize]
static void AddGameLogEventCreator() {
if (!GameLogEventsFactory.Creators.ContainsKey(typeof(RuleFortificationCheck))) {
Type gameLogEventType = typeof(GameLogRuleEvent<>).MakeGenericType(new Type[]
{
typeof(RuleFortificationCheck)
});
GameLogEventsFactory.Creators.Add(typeof(RuleFortificationCheck), (RulebookEvent rule) => (GameLogEvent)Activator.CreateInstance(gameLogEventType, new object[]
{
rule
}));
}
}

public RuleFortificationCheck([NotNull] RuleAttackRoll evt) : base(evt.Initiator, evt.Target) {
this.Roll = new RuleRollD100(Initiator);
this.ForCritical = evt.IsCriticalConfirmed;
Expand Down

0 comments on commit 621c6fb

Please sign in to comment.