forked from GarwelGarwel/KerbalHealth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quirk.cs
105 lines (93 loc) · 3.66 KB
/
Quirk.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KerbalHealth
{
/// <summary>
/// Describes a health quirk
/// </summary>
public class Quirk
{
public string Name { get; set; }
string title;
public string Title
{
get => title ?? Name;
set => title = value;
}
public string Description { get; set; }
public bool IsVisible { get; set; } = true;
public int MinLevel { get; set; } = 0;
public List<string> IncompatibleQuirks { get; set; } = new List<string>();
public double CourageWeight { get; set; } = 1;
public double StupidityWeight { get; set; } = 1;
public List<HealthEffect> Effects { get; set; } = new List<HealthEffect>();
/// <summary>
/// Returns true if this quirk can be assigned to the given kerbal at a certain experience level
/// </summary>
/// <param name="khs"></param>
/// <param name="level"></param>
/// <returns></returns>
public bool IsAvailableTo(KerbalHealthStatus khs, int level)
{
if (level < MinLevel) return false;
foreach (string q in IncompatibleQuirks)
if (khs.Quirks.Contains(Core.GetQuirk(q))) return false;
return true;
}
/// <summary>
/// Returns true if this quirk can be assigned to the given kerbal at a his/her current experience level
/// </summary>
/// <param name="khs"></param>
/// <returns></returns>
public bool IsAvailableTo(KerbalHealthStatus khs) => IsAvailableTo(khs, khs.PCM.experienceLevel);
/// <summary>
/// Applies valid effects of this quirk to the given kerbal's HealthModifierSet
/// </summary>
/// <param name="khs"></param>
/// <param name="hms"></param>
public void Apply(KerbalHealthStatus khs, HealthModifierSet hms)
{
Core.Log("Applying " + Name + " quirk to " + khs.Name + ".");
foreach (HealthEffect eff in Effects)
if (eff.IsApplicable(khs)) eff.Apply(hms);
}
public override bool Equals(object obj) => (obj is Quirk) && (obj != null) && (((Quirk)obj).Name == Name);
public override int GetHashCode() => Name.GetHashCode();
public override string ToString()
{
string res = Title + ".";
if ((Description != null) && (Description != "")) res += "\n" + Description;
if (Effects.Count == 1) res += "\nEffect: " + Effects[0];
if (Effects.Count > 1)
{
res += "\nEffects:";
foreach (HealthEffect he in Effects)
res += "\n" + he;
}
return res;
}
public Quirk(ConfigNode node)
{
Name = node.GetValue("name");
Title = node.GetValue("title");
Description = node.GetValue("description");
IsVisible = Core.GetBool(node, "visible", true);
MinLevel = Core.GetInt(node, "minLevel");
foreach (string t in node.GetValues("incompatibleWith"))
IncompatibleQuirks.Add(t);
CourageWeight = Core.GetDouble(node, "courageWeight", 1);
StupidityWeight = Core.GetDouble(node, "stupidityWeight", 1);
Effects = new List<HealthEffect>();
foreach (ConfigNode n in node.GetNodes("EFFECT"))
Effects.Add(new HealthEffect(n));
Core.Log("Quirk loaded: " + this);
}
public Quirk(string name)
{
Name = name;
IsVisible = false;
}
}
}