forked from Katarn2000x/DiplomacyFixes
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ExpansionismManager.cs
69 lines (59 loc) · 2.38 KB
/
ExpansionismManager.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
using DiplomacyFixes.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.SaveSystem;
namespace DiplomacyFixes
{
[SaveableClass(8)]
class ExpansionismManager
{
[SaveableField(1)]
private Dictionary<IFaction, float> _expansionism;
public static ExpansionismManager Instance { get; private set; }
public float SiegeExpansionism { get { return Settings.Instance.ExpanisonismPerSiege; } }
public float ExpansionismDecayPerDay { get { return Settings.Instance.ExpansionismDecayPerDay; } }
public float MinimumExpansionismPerFief { get { return Settings.Instance.MinimumExpansionismPerFief; } }
public float CriticalExpansionism { get { return Settings.Instance.CriticalExpansionism; } }
public float GetMinimumExpansionism(Kingdom kingdom)
{
return kingdom.Fiefs.Count() * MinimumExpansionismPerFief;
}
public ExpansionismManager()
{
this._expansionism = new Dictionary<IFaction, float>();
Instance = this;
}
public float GetExpansionism(IFaction faction)
{
return this._expansionism.TryGetValue(faction, out float result) ? result : 0f;
}
public void AddSiegeScore(IFaction faction)
{
this._expansionism.TryGetValue(faction, out float value);
this._expansionism[faction] = Math.Max(value, GetMinimumExpansionism(faction) - MinimumExpansionismPerFief) + SiegeExpansionism;
}
private static float GetMinimumExpansionism(IFaction faction)
{
return faction.IsKingdomFaction ? (faction as Kingdom).GetMinimumExpansionism() : default;
}
public void ApplyExpansionismDecay(IFaction faction)
{
if (this._expansionism.TryGetValue(faction, out float value))
{
float minimumExpansionism = faction.IsKingdomFaction ? (faction as Kingdom).GetMinimumExpansionism() : default;
this._expansionism[faction] = Math.Max(value - ExpansionismDecayPerDay, GetMinimumExpansionism(faction));
}
else
{
this._expansionism[faction] = GetMinimumExpansionism(faction);
}
}
internal void Sync()
{
Instance = this;
}
}
}