forked from mipen/BannerlordTweaks
-
Notifications
You must be signed in to change notification settings - Fork 3
/
TweakedSettlementFoodModel.cs
46 lines (40 loc) · 2.04 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
41
42
43
44
45
46
using System;
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.SandBox.GameComponents;
using TaleWorlds.Core;
using TaleWorlds.Localization;
namespace BannerlordTweaks
{
public class TweakedSettlementFoodModel : DefaultSettlementFoodModel
{
public override float CalculateTownFoodStocksChange(Town town, StatExplainer? explanation = null)
{
if (town == null) throw new ArgumentNullException(nameof(town));
float baseVal = base.CalculateTownFoodStocksChange(town, explanation);
if (BannerlordTweaksSettings.Instance is { } settings && settings.SettlementFoodBonusEnabled)
{
ExplainedNumber en = new ExplainedNumber(baseVal, explanation);
explanation?.Lines.Remove(explanation.Lines.Last());
if (town.IsCastle)
en.Add(settings.CastleFoodBonus, new TextObject("Military rations"));
else if (town.IsTown)
en.Add(settings.TownFoodBonus, new TextObject("Citizen food drive"));
if (settings.SettlementProsperityFoodMalusTweakEnabled && settings.SettlementProsperityFoodMalusDivisor != 50)
{
float malus = town.Owner.Settlement.Prosperity / 50f;
en.Add(malus, new TextObject("shouldn't be seen!"));
explanation?.Lines.Remove(explanation.Lines.Last());
TextObject prosperityTextObj = GameTexts.FindText("str_prosperity", null);
var line = explanation?.Lines.Where((x) => !string.IsNullOrWhiteSpace(x.Name) && x.Name == prosperityTextObj.ToString()).FirstOrDefault();
if (line != null) explanation?.Lines.Remove(line);
malus = -town.Owner.Settlement.Prosperity / settings.SettlementProsperityFoodMalusDivisor;
en.Add(malus, prosperityTextObj);
}
return en.ResultNumber;
}
else
return baseVal;
}
}
}