Skip to content

Commit

Permalink
CVar CharacterRequirement (#1322)
Browse files Browse the repository at this point in the history
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

This takes in one CVar and one required value and simply checks if the
CVar's value as a string is equal to the required value. I could make it
use a list of them, but I really didn't think it was needed considering
CharacterAndLogic.

I also cleaned up CharacterRequirements.Profile.cs a bit.

---------

Signed-off-by: sleepyyapril <[email protected]>
Co-authored-by: VMSolidus <[email protected]>
Co-authored-by: DEATHB4DEFEAT <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 1592c0e commit 34209e6
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 61 deletions.
55 changes: 55 additions & 0 deletions Content.Shared/Customization/Systems/CharacterRequirements.Misc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared.Customization.Systems;

/// <summary>
/// Requires the server to have a specific CVar value.
/// </summary>
[UsedImplicitly, Serializable, NetSerializable,]
public sealed partial class CVarRequirement : CharacterRequirement
{
[DataField("cvar", required: true)]
public string CVar;

[DataField(required: true)]
public string RequiredValue;

public override bool IsValid(
JobPrototype job,
HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
bool whitelisted,
IPrototype prototype,
IEntityManager entityManager,
IPrototypeManager prototypeManager,
IConfigurationManager configManager,
out string? reason,
int depth = 0
)
{
if (!configManager.IsCVarRegistered(CVar))
{
reason = null;
return true;
}

const string color = "lightblue";
var cvar = configManager.GetCVar(CVar);
var isValid = cvar.ToString()! == RequiredValue;

reason = Loc.GetString(
"character-cvar-requirement",
("inverted", Inverted),
("color", color),
("cvar", CVar),
("value", RequiredValue));

return isValid;
}
}
Loading

0 comments on commit 34209e6

Please sign in to comment.