forked from GarwelGarwel/KerbalHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthCondition.cs
130 lines (109 loc) · 4.74 KB
/
HealthCondition.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System.Collections.Generic;
namespace KerbalHealth
{
/// <summary>
/// Holds information about a certain health condition (such as exhaustion, sickness, etc.)
/// </summary>
public class HealthCondition
{
string title;
/// <summary>
/// Internal name of the condition
/// </summary>
public string Name { get; set; }
/// <summary>
/// Displayable name of the condition (similar to Name by default)
/// </summary>
public string Title
{
get => ((title == null) || (title == "")) ? Name : title;
set => title = value;
}
/// <summary>
/// Text description of the condition, shown when it is acquired
/// </summary>
public string Description { get; set; } = "";
/// <summary>
/// Whether this condition should be visible to the player
/// </summary>
public bool Visible { get; set; } = true;
/// <summary>
/// Whether this condition can be added multiple times
/// </summary>
public bool Stackable { get; set; } = false;
/// <summary>
/// If either of these conditions exist, this one will not be randomly acquired
/// </summary>
public List<string> IncompatibleConditions { get; set; } = new List<string>();
public bool IsCompatibleWith(string condition) => !IncompatibleConditions.Contains(condition);
public bool IsCompatibleWith(List<HealthCondition> conditions)
{
foreach (HealthCondition hc in conditions)
if (IncompatibleConditions.Contains(hc.Name)) return false;
return true;
}
/// <summary>
/// Logic required for this health condition to randomly appear
/// </summary>
public Logic Logic { get; set; } = new Logic();
/// <summary>
/// HP change per day when this condition is active
/// </summary>
public double HPChangePerDay { get; set; } = 0;
/// <summary>
/// While this condition is active, kerbal's HP is changed by this amount
/// </summary>
public double HP { get; set; } = 0;
/// <summary>
/// Whether to bring HP back to its original level when the condition is removed
/// </summary>
public bool RestoreHP { get; set; } = false;
/// <summary>
/// Whether this condition turns the kerbal into a Tourist
/// </summary>
public bool Incapacitated { get; set; } = false;
/// <summary>
/// Base chance of this condition randomly appearing every day
/// </summary>
public double ChancePerDay { get; set; } = 0;
/// <summary>
/// List of all chance modifiers for this condition
/// </summary>
public List<ChanceModifier> ChanceModifiers { get; set; } = new List<ChanceModifier>();
/// <summary>
/// Returns actual chance per day of this condition considering all modifiers
/// </summary>
/// <param name="pcm"></param>
/// <returns></returns>
public double GetChancePerDay(ProtoCrewMember pcm) => ChanceModifier.Calculate(ChanceModifiers, ChancePerDay, pcm);
/// <summary>
/// Possible outcomes of the condition; it is recommended to have at least one so that it may disappear
/// </summary>
public List<Outcome> Outcomes { get; set; } = new List<Outcome>();
public override string ToString() => Title + " (" + Name + "): " + Description;
public ConfigNode ConfigNode
{
set
{
Name = value.GetValue("name");
Title = Core.GetString(value, "title");
Description = Core.GetString(value, "description", "");
Visible = Core.GetBool(value, "visible", true);
Stackable = Core.GetBool(value, "stackable");
foreach (string s in value.GetValues("incompatibleCondition"))
IncompatibleConditions.Add(s);
Logic.ConfigNode = value;
HPChangePerDay = Core.GetDouble(value, "hpChangePerDay");
HP = Core.GetDouble(value, "hp");
RestoreHP = Core.GetBool(value, "restoreHP");
Incapacitated = Core.GetBool(value, "incapacitated");
ChancePerDay = Core.GetDouble(value, "chancePerDay");
foreach (ConfigNode n in value.GetNodes("CHANCE_MODIFIER"))
ChanceModifiers.Add(new ChanceModifier(n));
foreach (ConfigNode n in value.GetNodes("OUTCOME"))
Outcomes.Add(new Outcome(n));
}
}
public HealthCondition(ConfigNode n) => ConfigNode = n;
}
}