-
Notifications
You must be signed in to change notification settings - Fork 13
/
PartTrainingInfo.cs
61 lines (47 loc) · 1.81 KB
/
PartTrainingInfo.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
using System;
namespace KerbalHealth
{
public class PartTrainingInfo : IConfigNode
{
public const string ConfigNodeName = "TRAINING_PART";
public string Name { get; set; }
public float Complexity { get; set; }
public int Count { get; set; }
public float Level { get; set; }
public string Title => Core.GetPartTitle(Name);
public bool KSCTrainingComplete => Level >= Core.KSCTrainingCap;
public bool TrainingNow => Count > 0;
public PartTrainingInfo(ConfigNode n) => Load(n);
public PartTrainingInfo(string name, float complexity, int count, float level = 0)
{
Name = name;
Complexity = complexity;
Count = count;
Level = level;
}
public void StartTraining() => Count++;
public void StopTraining() => Count = 0;
public void Save(ConfigNode node)
{
Core.Log($"Saving training part {Name}, complexity = {Complexity:P0}, count = {Count}, level = {Level:P2}.");
node.AddValue("name", Name);
node.AddValue("complexity", Complexity);
node.AddValue("count", Count);
node.AddValue("level", Level);
}
public void Load(ConfigNode node)
{
Name = node.GetString("name");
if (Name == null)
{
Core.Log($"Training part name not found in node:\n{node}", LogLevel.Error);
return;
}
Complexity = node.GetFloat("complexity");
Count = node.GetInt("count", Complexity > 0 ? 1 : 0);
Level = node.GetFloat("level");
if (!KerbalHealthFactorsSettings.Instance.TrainingEnabled)
Level = Math.Max(Level, Core.KSCTrainingCap);
}
}
}