Skip to content

Commit

Permalink
fixed issue with minagho fight
Browse files Browse the repository at this point in the history
  • Loading branch information
Lynn Pye committed Nov 6, 2022
1 parent 8babe8e commit 4e9f770
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 266 deletions.
2 changes: 2 additions & 0 deletions ChampionFeats/ChampionFeats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@
<Compile Include="Components\AddACFromArmor.cs" />
<Compile Include="Components\AddScalingAttackBonus.cs" />
<Compile Include="Components\AddScalingDamageBonus.cs" />
<Compile Include="Components\AddScalingDamageResistance.cs" />
<Compile Include="Components\AddScalingSavingThrows.cs" />
<Compile Include="Components\AddScalingSpellDamage.cs" />
<Compile Include="Components\AddScalingSpellDC.cs" />
<Compile Include="Components\AddScalingSpellPenetration.cs" />
<Compile Include="Components\ContextValuePatcher.cs" />
<Compile Include="Config\Blueprints.cs" />
<Compile Include="Config\IUpdatableSettings.cs" />
<Compile Include="Config\ModSettings.cs" />
Expand Down
255 changes: 24 additions & 231 deletions ChampionFeats/ChampionFeatsPatcher.cs

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions ChampionFeats/Components/AddACFromArmor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Kingmaker.UnitLogic.Buffs;
using System;
using Kingmaker.Blueprints.Items.Armors;
using ChampionFeats.Config;

namespace ChampionFeats.Components
{

Expand All @@ -19,11 +21,13 @@ class AddACFromArmor : UnitFactComponentDelegate,
IUnitEquipmentHandler,
IUnitBuffHandler
{
public const string BLUEPRINTNAME = "RMChampionFeatDefenceAC";

public override void OnTurnOn()
{
base.OnTurnOn();
UpdateModifier();
//UpdateModifier();
ActivateModifier();
}

public override void OnTurnOff()
Expand All @@ -38,19 +42,23 @@ public void HandleEquipmentSlotUpdated(ItemSlot slot, ItemEntity previousItem)
{
return;
}
UpdateModifier();
OnRecalculate();
//UpdateModifier();
}

public void HandleUnitChangeActiveEquipmentSet(UnitDescriptor unit)
{
UpdateModifier();
OnRecalculate();
//UpdateModifier();
}

/*
private void UpdateModifier()
{
DeactivateModifier();
ActivateModifier();
}
*/

private void ActivateModifier()
{
Expand Down Expand Up @@ -87,19 +95,25 @@ private int CalculateModifier()
break;
}

if (Blueprints.HasNPCImmortalityBuff(Fact.Owner))
{
return 0;
}
itemBonus *= StepLevel == 1 ? Fact.Owner.Progression.CharacterLevel : Math.Max(1 + (Fact.Owner.Progression.CharacterLevel / StepLevel), 1);

return itemBonus;
}

public void HandleBuffDidAdded(Buff buff)
{
UpdateModifier();
//UpdateModifier();
OnRecalculate();
}

public void HandleBuffDidRemoved(Buff buff)
{
UpdateModifier();
//UpdateModifier();
OnRecalculate();
}

public int LightBonus;
Expand Down
15 changes: 8 additions & 7 deletions ChampionFeats/Components/AddScalingAttackBonus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ChampionFeats.Config;
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.Facts;
using Kingmaker.Blueprints.JsonSystem;
Expand All @@ -15,22 +16,22 @@ namespace ChampionFeats.Components
[TypeId("40059667d9b245fdae9d8524d669b125")]
class AddScalingAttackBonus : UnitFactComponentDelegate, IInitiatorRulebookHandler<RuleCalculateAttackBonusWithoutTarget>, IRulebookHandler<RuleCalculateAttackBonusWithoutTarget>, ISubscriber, IInitiatorRulebookSubscriber
{
public const string BLUEPRINTNAME = "RMChampionFeatOffenceAim";

// Token: 0x0600BD67 RID: 48487 RVA: 0x002F5FA0 File Offset: 0x002F41A0
public void OnEventAboutToTrigger(RuleCalculateAttackBonusWithoutTarget evt)
{
if (Blueprints.HasNPCImmortalityBuff(Fact.Owner))
{
return;
}
int bonus = (((this.Fact.Owner.Progression.CharacterLevel - 1) / Main.settings.ScalingABLevelsPerStep) + 1) * Main.settings.ScalingABBonusPerStep;
evt.AddModifier(bonus, Fact, Descriptor);

evt.AddModifier(bonus, Fact, ModifierDescriptor.UntypedStackable);
}

// Token: 0x0600BD68 RID: 48488 RVA: 0x00003B1E File Offset: 0x00001D1E
public void OnEventDidTrigger(RuleCalculateAttackBonusWithoutTarget evt)
{
}
public ModifierDescriptor Descriptor;
// Token: 0x04007BE2 RID: 31714
public ContextValue value;
// Token: 0x04007BE4 RID: 31716
public ContextValue Bonus;
}
}
12 changes: 7 additions & 5 deletions ChampionFeats/Components/AddScalingDamageBonus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ChampionFeats.Config;
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.Enums;
Expand All @@ -15,21 +16,22 @@ namespace ChampionFeats.Components
[TypeId("dd0309ebf4c847c4941fe4a2c9dcbb98")]
public class AddScalingDamageBonus : UnitFactComponentDelegate, IInitiatorRulebookHandler<RuleCalculateWeaponStats>, IRulebookHandler<RuleCalculateWeaponStats>, ISubscriber, IInitiatorRulebookSubscriber
{
public const string BLUEPRINTNAME = "RMChampionFeatOffenceDam";

// Token: 0x0600A58A RID: 42378 RVA: 0x0029FB50 File Offset: 0x0029DD50
public void OnEventAboutToTrigger(RuleCalculateWeaponStats evt)
{
if (Blueprints.HasNPCImmortalityBuff(Fact.Owner))
{
return;
}
int totalBonus = (((this.Fact.Owner.Progression.CharacterLevel - 1) / Main.settings.ScalingDamageLevelsPerStep) + 1) * Main.settings.ScalingDamageBonusPerStep;

evt.AddDamageModifier(totalBonus, Fact, ModifierDescriptor.UntypedStackable);
}

// Token: 0x0600A58B RID: 42379 RVA: 0x00003B1E File Offset: 0x00001D1E
public void OnEventDidTrigger(RuleCalculateWeaponStats evt)
{
}

// Token: 0x04006D06 RID: 27910
public ContextValue Bonus;
public ContextValue value;
}
}
40 changes: 40 additions & 0 deletions ChampionFeats/Components/AddScalingDamageResistance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Kingmaker.Blueprints.Facts;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.Blueprints;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingmaker.UnitLogic.FactLogic;
using System.Runtime.InteropServices;
using Kingmaker.RuleSystem.Rules.Damage;
using Kingmaker.Items;
using Kingmaker.Blueprints.Classes;
using Kingmaker.UnitLogic.Buffs.Blueprints;
using Kingmaker.UnitLogic;
using Kingmaker.PubSubSystem;
using ChampionFeats.Extensions;
using ChampionFeats.Utilities;
using Kingmaker.Enums;
using Kingmaker.UnitLogic.Mechanics.Components;
using Kingmaker.Enums.Damage;
using Kingmaker.UnitLogic.Mechanics;
using Kingmaker.EntitySystem.Entities;

namespace ChampionFeats.Components
{
[AllowedOn(typeof(BlueprintUnit), false)]
[AllowedOn(typeof(BlueprintUnitFact), false)]
[AllowedOn(typeof(BlueprintFeature))]
[AllowMultipleComponents]
[TypeId("5EEED74D80FF46ACA9FB2A15025B4727")]
/*
* See comments in ContextValuePatches for why this class is basically barren.
* Only exists to hold the blueprint name now.
*/
public class AddScalingDamageResistance : UnitFactComponentDelegate, ISubscriber
{
public const string BLUEPRINTNAME = "RMChampionFeatDefenceDR";
}
}
95 changes: 89 additions & 6 deletions ChampionFeats/Components/AddScalingSavingThrows.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,118 @@
using System;
using System.Runtime.InteropServices;
using ChampionFeats.Config;
using Kingmaker;
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.Classes;
using Kingmaker.Blueprints.Facts;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.EntitySystem;
using Kingmaker.EntitySystem.Entities;
using Kingmaker.EntitySystem.Stats;
using Kingmaker.Enums;
using Kingmaker.PubSubSystem;
using Kingmaker.RuleSystem.Rules;
using Kingmaker.UnitLogic;
using Kingmaker.UnitLogic.Buffs.Blueprints;
using Kingmaker.UnitLogic.FactLogic;
using Kingmaker.UnitLogic.Mechanics;
using static Kingmaker.Blueprints.Area.FactHolder;
using static Kingmaker.Kingdom.KingdomStats;
using static UnityModManagerNet.UnityModManager.Param;

namespace ChampionFeats.Components
{
[AllowedOn(typeof(BlueprintUnitFact), false)]
[AllowedOn(typeof(BlueprintBuff))]
[AllowedOn(typeof(BlueprintFeature))]
[AllowMultipleComponents]
[TypeId("D09E14DCC14748708E79AE101363676E")]
class AddScalingSavingThrows : UnitFactComponentDelegate, IInitiatorRulebookHandler<RuleSavingThrow>, IRulebookHandler<RuleSavingThrow>, ISubscriber, IInitiatorRulebookSubscriber
public class AddScalingSavingThrows : UnitFactComponentDelegate, ISubscriber
{
public void OnEventAboutToTrigger(RuleSavingThrow evt)
public const string BLUEPRINTNAME = "RMChampionFeatSavingThrow";

/*
* Used after settings are saved, to recalculate saving throw values in case the step/bonus
* values for Champion Saves was changed
*/
public static void OnSettingsSave()
{
UpdateSavingThrows();
}

private static void UpdateSavingThrows()
{
foreach (var unit in Game.Instance.State.Units)
{
Feature feature = unit.GetFeature(Resources.GetModBlueprint<BlueprintFeature>(BLUEPRINTNAME));
feature.TurnOff();
feature.TurnOn();
}
}

private static void RemoveModifier(UnitEntityData unit, StatType statType)
{
SaveModifier modToRemove = null;
foreach (var list in unit.Stats.GetStat(statType).ModifierList)
{
foreach (var mod in list.Value)
{
if (mod is SaveModifier)
{
modToRemove = (SaveModifier)mod;
}
if (modToRemove != null)
{
break;
}
}
if (modToRemove != null)
{
break;
}
}
if (modToRemove != null)
{
unit.Stats.GetStat(statType).RemoveModifier(modToRemove);
}
}

private static void RemoveModifiers(UnitEntityData unit, EntityFactComponent runtime)
{
int bonus = Main.settings.ScalingSaveBonusPerLevel;
evt.AddModifier(bonus, Fact, ModifierDescriptor.UntypedStackable);
RemoveModifier(unit, StatType.SaveFortitude);
RemoveModifier(unit, StatType.SaveReflex);
RemoveModifier(unit, StatType.SaveWill);
}

public void OnEventDidTrigger(RuleSavingThrow evt)
private static void AddModifiers(UnitEntityData unit, EntityFactComponent runtime)
{
unit.Stats.GetStat(StatType.SaveFortitude)?.AddModifier(GetNewModifier(unit, runtime));
unit.Stats.GetStat(StatType.SaveReflex)?.AddModifier(GetNewModifier(unit, runtime));
unit.Stats.GetStat(StatType.SaveWill)?.AddModifier(GetNewModifier(unit, runtime));
}

private static ModifiableValue.Modifier GetNewModifier(UnitEntityData unit, EntityFactComponent runtime)
{
return new SaveModifier()
{
ModDescriptor = ModifierDescriptor.UntypedStackable,
Source = runtime.Fact,
ModValue = Main.settings.ScalingSaveBonusPerLevel * unit.Progression.CharacterLevel
};
}

public override void OnTurnOff()
{
RemoveModifiers(base.Owner, base.Runtime);
}

public override void OnTurnOn()
{
base.OnTurnOn();
AddModifiers(base.Owner, base.Runtime);
}
}

public class SaveModifier : ModifiableValue.Modifier
{
}
}
11 changes: 7 additions & 4 deletions ChampionFeats/Components/AddScalingSpellDC.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ChampionFeats.Config;
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.Facts;
using Kingmaker.Blueprints.JsonSystem;
Expand All @@ -19,18 +20,22 @@ namespace ChampionFeats.Components
[TypeId("be0495e1ab3a4f0ab50cede89bd1b087")]
class AddScalingSpellDC : UnitFactComponentDelegate, IInitiatorRulebookHandler<RuleCalculateAbilityParams>, IRulebookHandler<RuleCalculateAbilityParams>, ISubscriber, IInitiatorRulebookSubscriber
{
public const string BLUEPRINTNAME = "RMChampionFeatOffenceSpellDC";

public void OnEventAboutToTrigger(RuleCalculateAbilityParams evt)
{

if(evt.Spell == null)
if (evt.Spell == null)
{
return; // not a spell at all
}
else if (!evt.Spell.IsSpell)
{
return; // not an ACTUAL spell (or spell-like, anyway)
}
if (Blueprints.HasNPCImmortalityBuff(Fact.Owner))
{
return;
}

//we're here, so we know we're a spell.

Expand All @@ -42,7 +47,5 @@ public void OnEventAboutToTrigger(RuleCalculateAbilityParams evt)
public void OnEventDidTrigger(RuleCalculateAbilityParams evt)
{
}

public ContextValue Value;
}
}
Loading

0 comments on commit 4e9f770

Please sign in to comment.