-
Notifications
You must be signed in to change notification settings - Fork 43
/
SubModule.cs
117 lines (106 loc) · 5.42 KB
/
SubModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using HarmonyLib;
using ModLib;
using SandBox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
namespace BannerlordTweaks
{
public class SubModule : MBSubModuleBase
{
public static readonly string ModuleFolderName = "zzBannerlordTweaks";
private static Harmony harmony = null;
protected override void OnBeforeInitialModuleScreenSetAsRoot()
{
if (harmony == null)
{
try
{
FileDatabase.Initialise(ModuleFolderName);
harmony = new Harmony("mod.bannerlord.mipen");
harmony.PatchAll();
if (Settings.Instance.BattleSizeTweakEnabled)
BannerlordConfig.BattleSize = Settings.Instance.BattleSize;
}
catch (Exception ex)
{
MessageBox.Show($"Error Initialising Bannerlord Tweaks:\n\n{ex.ToStringFull()}");
}
}
}
protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
{
base.OnGameStart(game, gameStarterObject);
AddModels(gameStarterObject as CampaignGameStarter);
}
private void AddModels(CampaignGameStarter gameStarter)
{
if (gameStarter != null)
{
if (Settings.Instance.TroopBattleExperienceMultiplierEnabled || Settings.Instance.ArenaHeroExperienceMultiplierEnabled || Settings.Instance.TournamentHeroExperienceMultiplierEnabled)
gameStarter.AddModel(new TweakedCombatXpModel());
if (Settings.Instance.MaxWorkshopCountTweakEnabled || Settings.Instance.WorkshopBuyingCostTweakEnabled)
gameStarter.AddModel(new TweakedWorkshopModel());
if (Settings.Instance.CompanionLimitTweakEnabled || Settings.Instance.ClanPartiesLimitTweakEnabled)
gameStarter.AddModel(new TweakedClanTierModel());
if (Settings.Instance.SettlementMilitiaBonusEnabled)
gameStarter.AddModel(new TweakedSettlementMilitiaModel());
if (Settings.Instance.SettlementFoodBonusEnabled)
gameStarter.AddModel(new TweakedSettlementFoodModel());
if (Settings.Instance.SiegeCasualtiesTweakEnabled || Settings.Instance.SiegeConstructionProgressPerDayMultiplierEnabled)
gameStarter.AddModel(new TweakedSiegeEventModel());
if (Settings.Instance.NoStillbirthsTweakEnabled || Settings.Instance.NoMaternalMortalityTweakEnabled ||
Settings.Instance.PregnancyDurationTweakEnabled || Settings.Instance.FemaleOffspringProbabilityTweakEnabled ||
Settings.Instance.TwinsProbabilityTweakEnabled)
gameStarter.AddModel(new TweakedPregnancyModel());
if (Settings.Instance.AgeTweaksEnabled)
{
TweakedAgeModel model = new TweakedAgeModel();
List<string> configErrors = model.GetConfigErrors().ToList();
if (configErrors.Any())
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("There is a configuration error in the \'Age\' tweaks from Bannerlord Tweaks.");
sb.AppendLine("Please check the below errors and fix the age settings in the settings menu:");
sb.AppendLine();
foreach (var e in configErrors)
sb.AppendLine(e);
sb.AppendLine();
sb.AppendLine("The age tweaks will not be applied until these errors have been resolved.");
sb.Append("Note that this is only a warning message and not a crash.");
MessageBox.Show(sb.ToString(), "Configuration Error in Bannerlord Tweaks");
}
else
gameStarter.AddModel(new TweakedAgeModel());
}
if (Settings.Instance.AttributeFocusPointTweakEnabled)
gameStarter.AddModel(new TweakedCharacterDevelopmentModel());
if (Settings.Instance.DifficultyTweaksEnabled)
gameStarter.AddModel(new TweakedDifficultyModel());
}
}
public override bool DoLoading(Game game)
{
if (Campaign.Current != null)
{
if (Settings.Instance.PrisonerImprisonmentTweakEnabled)
PrisonerImprisonmentTweak.Apply(Campaign.Current);
if (Settings.Instance.DailyTroopExperienceTweakEnabled)
DailyTroopExperienceTweak.Apply(Campaign.Current);
}
return base.DoLoading(game);
}
public override void OnMissionBehaviourInitialize(Mission mission)
{
if (mission == null) return;
base.OnMissionBehaviourInitialize(mission);
//if (Settings.Instance.DecapitationEnabled && !mission.HasMissionBehaviour<TournamentFightMissionController>() && !mission.HasMissionBehaviour<ArenaPracticeFightMissionController>())
// mission?.AddMissionBehaviour(new DismembermentMissionBehaviour());
}
}
}