Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Extra ammo perks cleanup and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzr authored and Skau committed Apr 16, 2020
1 parent 909ce74 commit 9af1c8b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 54 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@ This is going to be a mod that just fixes up some things in Mount & Blade 2:

* Perks
* Athletics
* Extra Arrows
* Extra Throwing Weapon
* Peak Form
* Leadership
* Disciplinarian <sub><sup>Fixed in e1.0.6</sup></sub>
* Scouting
* Healthy Scout
* Riding
* Spare Arrows
* Spare Throwing Weapon
* Bow Expert
* Conroi
* Crossbow Expert
* Squires
* Bow
* Mounted Archer
* Large Quiver
* Battle Equipped
* Crossbow
* Crossbow Cavalry
* Throwing
* Fully Armed
* Battle Ready
* Steward
* Agrarian
* Assessor
Expand Down
50 changes: 1 addition & 49 deletions src/CommunityPatch/Patches/ExtraAmmoPerksPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IEnumerable<MethodBase> GetMethodsChecked() {
yield return TargetMethodInfo;
}

public override bool IsApplicable(Game game) {
public override bool? IsApplicable(Game game) {
var patchInfo = Harmony.GetPatchInfo(TargetMethodInfo);
if (AlreadyPatchedByOthers(patchInfo))
return false;
Expand All @@ -47,54 +47,6 @@ protected static bool HasMount(Agent agent) {
return item != null && item.HasHorseComponent;
}

static short ApplyArrowPerks(Hero hero, bool hasMount) {
short extraAmmo = 0;

if (hero.GetPerkValue(DefaultPerks.Bow.LargeQuiver)) {
extraAmmo += 3;
}

if (hero.GetPerkValue(DefaultPerks.Bow.BattleEquipped)) {
extraAmmo += 6;
}

if (hasMount) {
if (hero.GetPerkValue(DefaultPerks.Riding.SpareArrows)) {
extraAmmo += 3;
}
}
else {
if (hero.GetPerkValue(DefaultPerks.Athletics.ExtraArrows)) {
extraAmmo += 2;
}
}
return extraAmmo;
}

static short ApplyThrowingAmmoPerks(Hero hero, bool hasMount) {
short extraAmmo = 0;

if (hero.GetPerkValue(DefaultPerks.Throwing.FullyArmed)) {
extraAmmo += 1;
}

if (hero.GetPerkValue(DefaultPerks.Throwing.BattleReady)) {
extraAmmo += 2;
}

if (hasMount) {
if (hero.GetPerkValue(DefaultPerks.Riding.SpareThrowingWeapon)) {
extraAmmo += 1;
}
}
else {
if (hero.GetPerkValue(DefaultPerks.Athletics.ExtraThrowingWeapons)) {
extraAmmo += 1;
}
}
return extraAmmo;
}

protected static void ApplyPerk(Agent agent, int ammoAmount, Func<Hero, WeaponComponentData, bool> canApplyPerk) {
if (agent.IsHero && agent.Character is CharacterObject charObj) {
var hero = charObj.HeroObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -22,6 +22,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Arrows &&
hero.GetPerkValue(DefaultPerks.Bow.BattleEquipped);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) => ApplyPerk(__instance, 6, CanApplyPerk);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -21,6 +22,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Arrows &&
hero.GetPerkValue(DefaultPerks.Bow.LargeQuiver);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) => ApplyPerk(__instance, 3, CanApplyPerk);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -21,6 +22,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Thrown &&
hero.GetPerkValue(DefaultPerks.Throwing.BattleReady);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) => ApplyPerk(__instance, 2, CanApplyPerk);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -18,10 +19,11 @@ public override void Apply(Game game) {
Applied = true;
}

static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData)
=> WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Thrown &&
hero.GetPerkValue(DefaultPerks.Throwing.FullyArmed);
static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Thrown &&
hero.GetPerkValue(DefaultPerks.Throwing.FullyArmed);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) => ApplyPerk(__instance, 1, CanApplyPerk);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -22,6 +23,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Arrows &&
hero.GetPerkValue(DefaultPerks.Athletics.ExtraArrows);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) {
if (!HasMount(__instance)) {
ApplyPerk(__instance, 2, CanApplyPerk);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -22,6 +23,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Thrown &&
hero.GetPerkValue(DefaultPerks.Athletics.ExtraThrowingWeapons);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) {
if (!HasMount(__instance)) {
ApplyPerk(__instance, 1, CanApplyPerk);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -22,6 +23,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Arrows &&
hero.GetPerkValue(DefaultPerks.Riding.SpareArrows);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) {
if (HasMount(__instance)) {
ApplyPerk(__instance, 3, CanApplyPerk);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
Expand All @@ -21,6 +22,7 @@ static bool CanApplyPerk(Hero hero, WeaponComponentData weaponComponentData) =>
WeaponComponentData.GetItemTypeFromWeaponClass(weaponComponentData.WeaponClass) == ItemObject.ItemTypeEnum.Thrown &&
hero.GetPerkValue(DefaultPerks.Riding.SpareThrowingWeapon);

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Postfix(Agent __instance) {
if (HasMount(__instance)) {
ApplyPerk(__instance, 1, CanApplyPerk);
Expand Down

0 comments on commit 9af1c8b

Please sign in to comment.