Skip to content

Commit

Permalink
adde support for Spiritual Wepaon-like spells
Browse files Browse the repository at this point in the history
  • Loading branch information
Holic75 committed Dec 27, 2020
1 parent 355d456 commit 1b340df
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
19 changes: 18 additions & 1 deletion ProperFlanking20/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Kingmaker.Enums;
using Kingmaker.RuleSystem;
using Kingmaker.UnitLogic.Buffs.Blueprints;
using Kingmaker.UnitLogic.FactLogic;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,7 +22,23 @@ static internal void load()
{
fixArrowSongMinstrel();
fixSharpenedAccuracy();
createTraits();
fixSpiritualWeapons();
createTraits();
}


static void fixSpiritualWeapons()
{
// twilight dagger should alwasy flank if possible
var twilight_dagger_feature = CallOfTheWild.SpiritualWeapons.twilight_knife_unit.AddFacts[0];
twilight_dagger_feature.AddComponent(CallOfTheWild.Helpers.Create<FlankingSpecial.AlwaysFlanking>());

//spiritual weapon and spiritual ally should ignore reach dead zone
var spiritual_weapon_feature = CallOfTheWild.SpiritualWeapons.spiritual_weapon_unit.AddFacts[0];
spiritual_weapon_feature.AddComponent(CallOfTheWild.Helpers.Create<ReachWeapons.IgnoreReachDeadZone>());
var spiritual_ally_feature = CallOfTheWild.SpiritualWeapons.spiritual_ally_unit.AddFacts[0];
spiritual_ally_feature.AddComponent(CallOfTheWild.Helpers.Create<ReachWeapons.IgnoreReachDeadZone>());

}


Expand Down
15 changes: 15 additions & 0 deletions ProperFlanking20/FlankingSpecial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,19 @@ public override bool isFlankingTogether(UnitEntityData target, UnitEntityData pa
return isFlanking(target) && ((partner == this.Owner.Unit.Descriptor.Pet) || (partner == this.Owner.Unit.Descriptor.Master.Value));
}
}


//always flanks independently of position if there is at least one other attacker
class AlwaysFlanking : Flanking.SpecialFlanking
{
public override bool isFlanking(UnitEntityData target)
{
return target.CombatState.EngagedBy.Count > 1 && target.CombatState.EngagedBy.Contains(this.Owner.Unit);
}

public override bool isFlankingTogether(UnitEntityData target, UnitEntityData partner)
{
return isFlanking(target) && target.CombatState.EngagedBy.Contains(partner);
}
}
}
1 change: 0 additions & 1 deletion ProperFlanking20/ProperFlanking2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
</Compile>
<Compile Include="FlankingSpecial.cs" />
<Compile Include="QuickDraw.cs" />
<Compile Include="ReachWeaponFix.cs" />
<Compile Include="ReachWeapons.cs" />
<Compile Include="RogueTalents.cs" />
<Compile Include="UnloadCTT.cs" />
Expand Down
12 changes: 0 additions & 12 deletions ProperFlanking20/ReachWeaponFix.cs

This file was deleted.

36 changes: 33 additions & 3 deletions ProperFlanking20/ReachWeapons.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Kingmaker.Controllers.Combat;
using Kingmaker.Blueprints;
using Kingmaker.Controllers.Combat;
using Kingmaker.EntitySystem.Entities;
using Kingmaker.Enums;
using Kingmaker.Items;
using Kingmaker.Items.Slots;
using Kingmaker.UnitLogic;
using Kingmaker.UnitLogic.Commands;
using Kingmaker.UnitLogic.Commands.Base;
using Kingmaker.Utility;
Expand All @@ -15,6 +17,28 @@

namespace ProperFlanking20.ReachWeapons
{
public class UnitPartIgnoreReachDeadZone : CallOfTheWild.AdditiveUnitPart
{
public bool active()
{
return !buffs.Empty();
}
}


public class IgnoreReachDeadZone : OwnedGameLogicComponent<UnitDescriptor>
{
public override void OnTurnOn()
{
this.Owner.Ensure<UnitPartIgnoreReachDeadZone>().addBuff(this.Fact);
}

public override void OnTurnOff()
{
this.Owner.Ensure<UnitPartIgnoreReachDeadZone>().removeBuff(this.Fact);
}
}

[Harmony12.HarmonyPatch(typeof(UnitEngagementExtension))]
[Harmony12.HarmonyPatch("IsReach", Harmony12.MethodType.Normal)]
class Patch_UnitEngagementExtension__IsReach__Patch
Expand All @@ -28,6 +52,7 @@ static void Postfix(UnitEntityData unit, UnitEntityData enemy, WeaponSlot hand,
}

bool is_reach = weapon.Blueprint.IsMelee && weapon.Blueprint.Type.AttackRange > GameConsts.MinWeaponRange;
is_reach = is_reach && !(unit?.Get<UnitPartIgnoreReachDeadZone>()?.active()).GetValueOrDefault();

if (__result == true && is_reach)
{ //we are going to use half of treat range in this case for dead zone
Expand Down Expand Up @@ -66,21 +91,26 @@ class Patch_UnitCommand__GetTargetPoint__Patch
{
static void Postfix(UnitCommand __instance, ref Vector3 __result)
{


var attack_command = __instance as UnitAttack;
if (attack_command == null || attack_command.PlannedAttack == null)
{
return;
}

var enemy = __instance.Target.Unit;
var unit = __instance.Executor;

bool is_reach = attack_command.PlannedAttack.Weapon.Blueprint.IsMelee && attack_command.PlannedAttack.Weapon.Blueprint.Type.AttackRange > GameConsts.MinWeaponRange;
is_reach = is_reach && !(unit?.Get<UnitPartIgnoreReachDeadZone>()?.active()).GetValueOrDefault();

if (!is_reach)
{
return;
}

var enemy = __instance.Target.Unit;
var unit = __instance.Executor;

if (enemy == null || unit == null)
{
return;
Expand Down
2 changes: 1 addition & 1 deletion ProperFlanking20/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "ProperFlanking2",
"DisplayName": "Proper Flanking 2",
"Author": "Holic75",
"Version": "1.2.0c",
"Version": "1.2.0d",
"ManagerVersion": "0.13.0",
"Requirements": [ "CallOfTheWild" ],
"AssemblyName": "ProperFlanking20.dll",
Expand Down

0 comments on commit 1b340df

Please sign in to comment.