forked from mipen/BannerlordTweaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweakedSettlementFoodModel.cs
40 lines (37 loc) · 1.41 KB
/
TweakedSettlementFoodModel.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
using System;
using System.Linq;
using System.Windows.Forms;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.SandBox.GameComponents;
using TaleWorlds.Localization;
using BannerlordTweaks.Lib;
namespace BannerlordTweaks
{
public class TweakedSettlementFoodModel : DefaultSettlementFoodModel
{
public override float CalculateTownFoodStocksChange(Town town, StatExplainer explanation = null)
{
float baseVal = base.CalculateTownFoodStocksChange(town, explanation);
if (Settings.Instance.SettlementFoodBonusEnabled)
{
try
{
ExplainedNumber en = new ExplainedNumber(baseVal, explanation);
explanation?.Lines.Remove(explanation.Lines.Last());
if (town.IsCastle)
en.Add(Settings.Instance.CastleFoodBonus, new TextObject("Military rations"));
else if (town.IsTown)
en.Add(Settings.Instance.TownFoodBonus, new TextObject("Citizen food drive"));
return en.ResultNumber;
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred in TweakedSettlementFoodModel: {ex.ToStringFull()}");
return baseVal;
}
}
else
return baseVal;
}
}
}