forked from Simple-Station/Einstein-Engines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterRequirements.Logic.cs
More file actions
150 lines (128 loc) · 5.58 KB
/
Copy pathCharacterRequirements.Logic.cs
File metadata and controls
150 lines (128 loc) · 5.58 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System.Linq;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Customization.Systems;
/// <summary>
/// Requires all of the requirements to be true
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterLogicAndRequirement : CharacterRequirement
{
[DataField]
public List<CharacterRequirement> Requirements { get; private set; } = new();
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted, IPrototype prototype,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason, int depth = 0)
{
var succeeded = entityManager.EntitySysManager.GetEntitySystem<CharacterRequirementsSystem>()
.CheckRequirementsValid(Requirements, job, profile, playTimes, whitelisted, prototype, entityManager,
prototypeManager, configManager, out var reasons, depth + 1);
if (reasons.Count == 0)
{
reason = null;
return succeeded;
}
reason = new FormattedMessage();
foreach (var message in reasons)
reason.AddMessage(FormattedMessage.FromMarkup(
Loc.GetString("character-logic-and-requirement-listprefix", ("indent", new string(' ', depth * 2))) + message.ToMarkup()));
reason = FormattedMessage.FromMarkup(Loc.GetString("character-logic-and-requirement",
("inverted", Inverted), ("options", reason.ToMarkup())));
return succeeded;
}
}
/// <summary>
/// Requires any of the requirements to be true
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterLogicOrRequirement : CharacterRequirement
{
[DataField]
public List<CharacterRequirement> Requirements { get; private set; } = new();
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted, IPrototype prototype,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason, int depth = 0)
{
var succeeded = false;
var reasons = new List<FormattedMessage>();
var characterRequirements = entityManager.EntitySysManager.GetEntitySystem<CharacterRequirementsSystem>();
foreach (var requirement in Requirements)
{
if (characterRequirements.CheckRequirementValid(requirement, job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager, out var raisin, depth + 1))
{
succeeded = true;
break;
}
if (raisin != null)
reasons.Add(raisin);
}
if (reasons.Count == 0)
{
reason = null;
return succeeded;
}
reason = new FormattedMessage();
foreach (var message in reasons)
reason.AddMessage(FormattedMessage.FromMarkup(
Loc.GetString("character-logic-or-requirement-listprefix", ("indent", new string(' ', depth * 2))) + message.ToMarkup()));
reason = FormattedMessage.FromMarkup(Loc.GetString("character-logic-or-requirement",
("inverted", Inverted), ("options", reason.ToMarkup())));
return succeeded;
}
}
/// <summary>
/// Requires only one of the requirements to be true
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterLogicXorRequirement : CharacterRequirement
{
[DataField]
public List<CharacterRequirement> Requirements { get; private set; } = new();
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted, IPrototype prototype,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason, int depth = 0)
{
var reasons = new List<FormattedMessage>();
var succeeded = false;
var characterRequirements = entityManager.EntitySysManager.GetEntitySystem<CharacterRequirementsSystem>();
foreach (var requirement in Requirements)
{
if (characterRequirements.CheckRequirementValid(requirement, job, profile, playTimes, whitelisted, prototype,
entityManager, prototypeManager, configManager, out var raisin, depth + 1))
{
if (succeeded)
{
succeeded = false;
break;
}
succeeded = true;
}
if (raisin != null)
reasons.Add(raisin);
}
if (reasons.Count == 0)
{
reason = null;
return succeeded;
}
reason = new FormattedMessage();
foreach (var message in reasons)
reason.AddMessage(FormattedMessage.FromMarkup(
Loc.GetString("character-logic-xor-requirement-listprefix", ("indent", new string(' ', depth * 2))) + message.ToMarkup()));
reason = FormattedMessage.FromMarkup(Loc.GetString("character-logic-xor-requirement",
("inverted", Inverted), ("options", reason.ToMarkup())));
return succeeded;
}
}