-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathHealthCondition.cs
118 lines (97 loc) · 4.27 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
using System.Collections.Generic;
using System.Linq;
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.Length == 0 ? 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>();
/// <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 MTBE of this condition randomly appearing every day
/// </summary>
public double MTBE { get; set; } = -1;
/// <summary>
/// List of all chance modifiers for this condition
/// </summary>
public List<MTBEModifier> MTBEModifiers { get; set; }
/// <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 void Load(ConfigNode node)
{
Name = node.GetValue("name");
Title = node.GetString("title");
Description = node.GetString("description", "");
Visible = node.GetBool("visible", true);
Stackable = node.GetBool("stackable");
IncompatibleConditions.AddRange(node.GetValues("incompatibleCondition"));
Logic.Load(node);
HPChangePerDay = node.GetDouble("hpChangePerDay");
HP = node.GetDouble("hp");
RestoreHP = node.GetBool("restoreHP");
Incapacitated = node.GetBool("incapacitated");
MTBE = node.GetDouble("mtbe", -1);
MTBEModifiers = new List<MTBEModifier>(node.GetNodes(MTBEModifier.ConfigNodeName).Select(n => new MTBEModifier(n)));
Outcomes = new List<Outcome>(node.GetNodes("OUTCOME").Select(n => new Outcome(n)));
}
public HealthCondition(ConfigNode n) => Load(n);
public bool IsCompatibleWith(string condition) => !IncompatibleConditions.Contains(condition);
public bool IsCompatibleWith(List<HealthCondition> conditions) => !conditions.Any(hc => IncompatibleConditions.Contains(hc.Name));
/// <summary>
/// Returns actual chance per day of this condition considering all modifiers
/// </summary>
public double GetMTBE(ProtoCrewMember pcm) => MTBEModifier.Calculate(MTBEModifiers, MTBE, pcm);
public override string ToString() => $"{Title} ({Name}): {Description}";
}
}