Skip to content

Commit 01677e7

Browse files
committed
1.6.0: Make compatible with game version 1.8.0
Mostly a simple rebuild. Take this opportunity to reformat the source files though to a more personally-preferred style.
1 parent 1b3c581 commit 01677e7

15 files changed

+223
-400
lines changed

src/ArmyArrowCounter/AacMissionBehavior.cs

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
using TaleWorlds.Library;
44
using TaleWorlds.MountAndBlade;
55

6-
namespace ArmyArrowCounter
7-
{
8-
class AacMissionBehavior : MissionBehavior
9-
{
6+
namespace ArmyArrowCounter {
7+
class AacMissionBehavior : MissionBehavior {
108
public event Action PlayerBuiltEvent;
119
public event Action<Agent> AllyAgentBuiltEvent;
1210
public event Action<Agent> AllyAgentRemovedEvent;
@@ -24,119 +22,93 @@ class AacMissionBehavior : MissionBehavior
2422
private ArrowRecountTriggerer ArrowRecountTriggerer;
2523
private AacUiApplier AacUiApplier;
2624

27-
public AacMissionBehavior()
28-
{
25+
public AacMissionBehavior() {
2926
ArrowCounter = new ArrowCounter(this);
3027
ArrowRecountTriggerer = new ArrowRecountTriggerer(this, ArrowCounter);
3128
AacUiApplier = new AacUiApplier(this, AacViewModelFactory.Create(ArrowCounter));
3229
}
3330

3431
public override MissionBehaviorType BehaviorType => MissionBehaviorType.Other;
3532

36-
public override void OnMissionModeChange(MissionMode oldMissionMode, bool atStart)
37-
{
33+
public override void OnMissionModeChange(MissionMode oldMissionMode, bool atStart) {
3834
base.OnMissionModeChange(oldMissionMode, atStart);
3935

40-
if (Utils.IsStartOfBattle(oldMissionMode, Mission.Mode))
41-
{
36+
if (Utils.IsStartOfBattle(oldMissionMode, Mission.Mode)) {
4237
BattleStartEvent?.Invoke();
4338
IsActivated = true;
44-
}
45-
else if (Utils.IsStartofSiege(oldMissionMode, Mission.Mode))
46-
{
39+
} else if (Utils.IsStartofSiege(oldMissionMode, Mission.Mode)) {
4740
PlayerAgent = Agent.Main;
4841
IsActivated = true;
4942
SiegeBattleStartEvent?.Invoke();
50-
}
51-
else if (Utils.IsStartofHideoutBattle(oldMissionMode, Mission.Mode))
52-
{
43+
} else if (Utils.IsStartofHideoutBattle(oldMissionMode, Mission.Mode)) {
5344
PlayerAgent = Agent.Main;
5445
IsActivated = true;
5546
HideoutBattleStartEvent?.Invoke();
56-
}
57-
else if (Utils.IsEndOfHideoutConversation(oldMissionMode, Mission.Mode))
58-
{
47+
} else if (Utils.IsEndOfHideoutConversation(oldMissionMode, Mission.Mode)) {
5948
IsActivated = true;
60-
}
61-
else
62-
{
49+
} else {
6350
IsActivated = false;
6451
}
6552
}
6653

67-
public override void OnAgentBuild(Agent agent, Banner banner)
68-
{
54+
public override void OnAgentBuild(Agent agent, Banner banner) {
6955
base.OnAgentBuild(agent, banner);
7056

71-
if (!IsActivated)
72-
{
57+
if (!IsActivated) {
7358
return;
7459
}
7560

76-
if (Agent.Main == null)
77-
{
61+
if (Agent.Main == null) {
7862
return;
7963
}
8064

81-
if (PlayerAgent == null)
82-
{
65+
if (PlayerAgent == null) {
8366
PlayerAgent = Agent.Main;
8467
PlayerBuiltEvent?.Invoke();
8568
return;
8669
}
8770

88-
if (Utils.IsPlayerAlly(agent, PlayerAgent))
89-
{
71+
if (Utils.IsPlayerAlly(agent, PlayerAgent)) {
9072
AllyAgentBuiltEvent?.Invoke(agent);
9173
}
9274
}
9375

94-
public override void OnAgentRemoved(Agent affectedAgent, Agent affectorAgent, AgentState agentState, KillingBlow blow)
95-
{
76+
public override void OnAgentRemoved(Agent affectedAgent, Agent affectorAgent, AgentState agentState, KillingBlow blow) {
9677
base.OnAgentRemoved(affectedAgent, affectorAgent, agentState, blow);
9778

98-
if (!IsActivated)
99-
{
79+
if (!IsActivated) {
10080
return;
10181
}
10282

103-
if (PlayerAgent != null && Utils.IsPlayerAlly(affectedAgent, PlayerAgent))
104-
{
83+
if (PlayerAgent != null && Utils.IsPlayerAlly(affectedAgent, PlayerAgent)) {
10584
AllyAgentRemovedEvent?.Invoke(affectedAgent);
10685
}
10786
}
10887

109-
public override void OnAgentShootMissile(Agent shooterAgent, EquipmentIndex weaponIndex, Vec3 position, Vec3 velocity, Mat3 orientation, bool hasRigidBody, int forcedMissileIndex)
110-
{
88+
public override void OnAgentShootMissile(Agent shooterAgent, EquipmentIndex weaponIndex, Vec3 position, Vec3 velocity, Mat3 orientation, bool hasRigidBody, int forcedMissileIndex) {
11189
base.OnAgentShootMissile(shooterAgent, weaponIndex, position, velocity, orientation, hasRigidBody, forcedMissileIndex);
11290

113-
if (!IsActivated)
114-
{
91+
if (!IsActivated) {
11592
return;
11693
}
11794

118-
if (PlayerAgent != null && Utils.IsPlayerAlly(shooterAgent, PlayerAgent))
119-
{
95+
if (PlayerAgent != null && Utils.IsPlayerAlly(shooterAgent, PlayerAgent)) {
12096
AllyFiredMissileEvent?.Invoke(shooterAgent);
12197
}
12298
}
12399

124-
public override void OnItemPickup(Agent agent, SpawnedItemEntity item)
125-
{
100+
public override void OnItemPickup(Agent agent, SpawnedItemEntity item) {
126101
base.OnItemPickup(agent, item);
127102

128-
if (!IsActivated)
129-
{
103+
if (!IsActivated) {
130104
return;
131105
}
132106

133-
if (!Utils.IsAmmo(item))
134-
{
107+
if (!Utils.IsAmmo(item)) {
135108
return;
136109
}
137110

138-
if (PlayerAgent != null && Utils.IsPlayerAlly(agent, PlayerAgent))
139-
{
111+
if (PlayerAgent != null && Utils.IsPlayerAlly(agent, PlayerAgent)) {
140112
OnAllyPickedUpAmmoEvent?.Invoke(agent, item);
141113
}
142114
}

src/ArmyArrowCounter/AacUiApplier.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
using TaleWorlds.Engine.GauntletUI;
2-
using TaleWorlds.Engine.Screens;
32
using TaleWorlds.Library;
43
using TaleWorlds.ScreenSystem;
54

6-
namespace ArmyArrowCounter
7-
{
8-
class AacUiApplier
9-
{
5+
namespace ArmyArrowCounter {
6+
class AacUiApplier {
107
private ViewModel ViewModel;
118
private GauntletLayer GauntletLayer;
129

13-
public AacUiApplier(AacMissionBehavior aacMissionBehavior, ViewModel viewModel)
14-
{
10+
public AacUiApplier(AacMissionBehavior aacMissionBehavior, ViewModel viewModel) {
1511
ViewModel = viewModel;
1612
aacMissionBehavior.BattleStartEvent += OnBattleStart;
1713
GauntletLayer = new GauntletLayer(100);
1814
GauntletLayer.LoadMovie("ArmyArrowCounter", ViewModel);
1915
}
2016

21-
private void OnBattleStart()
22-
{
17+
private void OnBattleStart() {
2318
ScreenManager.TopScreen.AddLayer(GauntletLayer);
2419
}
2520
}

src/ArmyArrowCounter/ArrowCounter.cs

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
using TaleWorlds.Core;
44
using TaleWorlds.MountAndBlade;
55

6-
namespace ArmyArrowCounter
7-
{
8-
class ArrowCounter
9-
{
6+
namespace ArmyArrowCounter {
7+
class ArrowCounter {
108
public event Action<int> RemainingArrowsUpdateEvent;
119
public event Action<int> MaxArrowsUpdateEvent;
1210
public int RemainingArrows { get; private set; }
@@ -15,8 +13,7 @@ class ArrowCounter
1513
private readonly AacMissionBehavior AacMissionBehavior;
1614
private readonly Dictionary<int, short> AgentHashCodeToCurrentArrows = new Dictionary<int, short>();
1715

18-
public ArrowCounter(AacMissionBehavior aacMissionBehavior)
19-
{
16+
public ArrowCounter(AacMissionBehavior aacMissionBehavior) {
2017
AacMissionBehavior = aacMissionBehavior;
2118
aacMissionBehavior.SiegeBattleStartEvent += OnSiegeBattleStart;
2219
aacMissionBehavior.HideoutBattleStartEvent += OnHideoutBattleStart;
@@ -27,125 +24,102 @@ public ArrowCounter(AacMissionBehavior aacMissionBehavior)
2724
aacMissionBehavior.OnAllyPickedUpAmmoEvent += OnAllyPickedUpAmmo;
2825
}
2926

30-
private void OnSiegeBattleStart()
31-
{
27+
private void OnSiegeBattleStart() {
3228
CountAllAlliedAgents();
3329
}
3430

35-
private void OnHideoutBattleStart()
36-
{
31+
private void OnHideoutBattleStart() {
3732
CountAllAlliedAgents();
3833
}
3934

40-
private void OnPlayerBuilt()
41-
{
35+
private void OnPlayerBuilt() {
4236
CountAllAlliedAgents();
4337
}
4438

45-
private void OnAllyAgentBuilt(Agent agent)
46-
{
39+
private void OnAllyAgentBuilt(Agent agent) {
4740
AddAgent(agent);
4841
}
4942

50-
private void OnAllyAgentRemoved(Agent agent)
51-
{
43+
private void OnAllyAgentRemoved(Agent agent) {
5244
RemoveAgent(agent);
5345
}
5446

55-
private void OnAllyFiredMissile(Agent agent)
56-
{
57-
if (AgentHashCodeToCurrentArrows.ContainsKey(agent.GetHashCode()))
58-
{
47+
private void OnAllyFiredMissile(Agent agent) {
48+
if (AgentHashCodeToCurrentArrows.ContainsKey(agent.GetHashCode())) {
5949
AgentHashCodeToCurrentArrows[agent.GetHashCode()]--;
6050
}
6151
AddToRemainingArrows(-1);
6252
}
6353

64-
private void OnAllyPickedUpAmmo(Agent agent, SpawnedItemEntity item)
65-
{
66-
if (!AgentHashCodeToCurrentArrows.ContainsKey(agent.GetHashCode()))
67-
{
54+
private void OnAllyPickedUpAmmo(Agent agent, SpawnedItemEntity item) {
55+
if (!AgentHashCodeToCurrentArrows.ContainsKey(agent.GetHashCode())) {
6856
return;
6957
}
7058

7159
short lastKnownAmmoOnAgent = AgentHashCodeToCurrentArrows[agent.GetHashCode()];
7260
short newAmmoOnAgent = CalculateRemainingAmmo(agent);
73-
short amountPickedUp = (short) (newAmmoOnAgent - lastKnownAmmoOnAgent);
61+
short amountPickedUp = (short)(newAmmoOnAgent - lastKnownAmmoOnAgent);
7462
AgentHashCodeToCurrentArrows[agent.GetHashCode()] += amountPickedUp;
7563
AddToRemainingArrows(amountPickedUp);
7664
}
7765

78-
internal void CountAllAlliedAgents(bool countRemainingArrows = false)
79-
{
66+
internal void CountAllAlliedAgents(bool countRemainingArrows = false) {
8067
foreach (Agent agent in AacMissionBehavior.Mission.Agents) // todo: can instead maybe get player's MBTeam an iterate through friendly agents directly
8168
{
82-
if (Utils.IsPlayerAlly(agent, AacMissionBehavior.PlayerAgent))
83-
{
69+
if (Utils.IsPlayerAlly(agent, AacMissionBehavior.PlayerAgent)) {
8470
AddAgent(agent, countRemainingArrows);
8571
}
8672
}
8773
}
8874

89-
internal void ForgetState()
90-
{
75+
internal void ForgetState() {
9176
AgentHashCodeToCurrentArrows.Clear();
9277
AddToRemainingArrows(-RemainingArrows);
9378
AddToMaxArrows(-MaxArrows);
9479
}
9580

96-
internal void RecountAllAlliedAgents()
97-
{
81+
internal void RecountAllAlliedAgents() {
9882
ForgetState();
9983
CountAllAlliedAgents(true);
10084
}
10185

102-
internal void AddToRemainingArrows(int deltaRemainingArrows)
103-
{
86+
internal void AddToRemainingArrows(int deltaRemainingArrows) {
10487
RemainingArrows += deltaRemainingArrows;
10588
RemainingArrowsUpdateEvent?.Invoke(RemainingArrows);
10689
}
10790

108-
internal void AddToMaxArrows(int deltaMaxArrows)
109-
{
91+
internal void AddToMaxArrows(int deltaMaxArrows) {
11092
MaxArrows += deltaMaxArrows;
11193
MaxArrowsUpdateEvent?.Invoke(MaxArrows);
11294
}
11395

114-
internal void AddAgent(Agent agent, bool countRemaining = false)
115-
{
96+
internal void AddAgent(Agent agent, bool countRemaining = false) {
11697
int agentHashCode = agent.GetHashCode();
117-
if (AgentHashCodeToCurrentArrows.ContainsKey(agentHashCode))
118-
{
98+
if (AgentHashCodeToCurrentArrows.ContainsKey(agentHashCode)) {
11999
return;
120100
}
121101

122-
if (agent.Equipment == null)
123-
{
102+
if (agent.Equipment == null) {
124103
return;
125104
}
126105

127106
short maxAmmo = CalculateMaxAmmo(agent);
128107
AddToMaxArrows(maxAmmo);
129108

130109
short remainingAmmo;
131-
if (countRemaining)
132-
{
110+
if (countRemaining) {
133111
remainingAmmo = CalculateRemainingAmmo(agent);
134-
}
135-
else
136-
{
112+
} else {
137113
remainingAmmo = maxAmmo;
138114
}
139115

140116
AgentHashCodeToCurrentArrows.Add(agentHashCode, remainingAmmo);
141117
AddToRemainingArrows(remainingAmmo);
142118
}
143119

144-
internal void RemoveAgent(Agent agent)
145-
{
120+
internal void RemoveAgent(Agent agent) {
146121
int agentHashCode = agent.GetHashCode();
147-
if (!AgentHashCodeToCurrentArrows.ContainsKey(agentHashCode))
148-
{
122+
if (!AgentHashCodeToCurrentArrows.ContainsKey(agentHashCode)) {
149123
return;
150124
}
151125

@@ -156,30 +130,28 @@ internal void RemoveAgent(Agent agent)
156130
AddToMaxArrows(-maxAmmo);
157131
}
158132

159-
private static short CalculateRemainingAmmo(Agent agent)
160-
{
133+
private static short CalculateRemainingAmmo(Agent agent) {
161134
MissionWeapon weaponFromSlot0 = agent.Equipment[EquipmentIndex.Weapon0];
162-
short ammoFromSlot0 = weaponFromSlot0.Equals(MissionWeapon.Invalid) || weaponFromSlot0.IsShield() ? (short) 0 : weaponFromSlot0.Amount;
135+
short ammoFromSlot0 = weaponFromSlot0.Equals(MissionWeapon.Invalid) || weaponFromSlot0.IsShield() ? (short)0 : weaponFromSlot0.Amount;
163136
MissionWeapon weaponFromSlot1 = agent.Equipment[EquipmentIndex.Weapon1];
164-
short ammoFromSlot1 = weaponFromSlot1.Equals(MissionWeapon.Invalid) || weaponFromSlot1.IsShield() ? (short) 0 : weaponFromSlot1.Amount;
137+
short ammoFromSlot1 = weaponFromSlot1.Equals(MissionWeapon.Invalid) || weaponFromSlot1.IsShield() ? (short)0 : weaponFromSlot1.Amount;
165138
MissionWeapon weaponFromSlot2 = agent.Equipment[EquipmentIndex.Weapon2];
166-
short ammoFromSlot2 = weaponFromSlot2.Equals(MissionWeapon.Invalid) || weaponFromSlot2.IsShield() ? (short) 0 : weaponFromSlot2.Amount;
139+
short ammoFromSlot2 = weaponFromSlot2.Equals(MissionWeapon.Invalid) || weaponFromSlot2.IsShield() ? (short)0 : weaponFromSlot2.Amount;
167140
MissionWeapon weaponFromSlot3 = agent.Equipment[EquipmentIndex.Weapon3];
168-
short ammoFromSlot3 = weaponFromSlot3.Equals(MissionWeapon.Invalid) || weaponFromSlot3.IsShield() ? (short) 0 : weaponFromSlot3.Amount;
141+
short ammoFromSlot3 = weaponFromSlot3.Equals(MissionWeapon.Invalid) || weaponFromSlot3.IsShield() ? (short)0 : weaponFromSlot3.Amount;
169142
MissionWeapon weaponFromSlot4 = agent.Equipment[EquipmentIndex.Weapon4];
170-
short ammoFromSlot4 = weaponFromSlot4.Equals(MissionWeapon.Invalid) || weaponFromSlot4.IsShield() ? (short) 0 : weaponFromSlot4.Amount;
143+
short ammoFromSlot4 = weaponFromSlot4.Equals(MissionWeapon.Invalid) || weaponFromSlot4.IsShield() ? (short)0 : weaponFromSlot4.Amount;
171144

172-
return (short) (ammoFromSlot0 + ammoFromSlot1 + ammoFromSlot2 + ammoFromSlot3 + ammoFromSlot4);
145+
return (short)(ammoFromSlot0 + ammoFromSlot1 + ammoFromSlot2 + ammoFromSlot3 + ammoFromSlot4);
173146
}
174147

175-
private static short CalculateMaxAmmo(Agent agent)
176-
{
148+
private static short CalculateMaxAmmo(Agent agent) {
177149
int arrowAmmo = agent.Equipment.GetMaxAmmo(WeaponClass.Arrow);
178150
int boltAmmo = agent.Equipment.GetMaxAmmo(WeaponClass.Bolt);
179151
int javelinAmmo = agent.Equipment.GetMaxAmmo(WeaponClass.Javelin);
180152
int axeAmmo = agent.Equipment.GetMaxAmmo(WeaponClass.ThrowingAxe);
181153

182-
return (short) (arrowAmmo + boltAmmo + javelinAmmo + axeAmmo);
154+
return (short)(arrowAmmo + boltAmmo + javelinAmmo + axeAmmo);
183155
}
184156
}
185157
}

0 commit comments

Comments
 (0)