Files
wwdpublic/Content.Shared/Customization/Systems/CharacterRequirements.Profile.cs
RedBurningPhoenix 60d7000fc0 [Port] Hobo and Maid (#20)
* MAID AND BOMZH (#605)

* First

* Second

* oops

* translate

* rework

* resprite

* resprite1

* a

* forgot

* Reorganisation

* whatthefuckiamdoing

* blyat

* REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

* character-requirements, loadouts and other

* burnthis

* *clap*
2024-09-01 14:21:33 +07:00

219 lines
8.1 KiB
C#

using System.Linq;
using Content.Shared.Clothing.Loadouts.Prototypes;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Traits;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Customization.Systems;
/// <summary>
/// Requires the profile to be within an age range
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterAgeRequirement : CharacterRequirement
{
[DataField(required: true)]
public int Min;
[DataField(required: true)]
public int Max;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
reason = FormattedMessage.FromMarkup(Loc.GetString("character-age-requirement",
("inverted", Inverted), ("min", Min), ("max", Max)));
return profile.Age >= Min && profile.Age <= Max;
}
}
/// <summary>
/// Requires the profile to use either a Backpack, Satchel, or Duffelbag
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterBackpackTypeRequirement : CharacterRequirement
{
[DataField(required: true)]
public BackpackPreference Preference;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
reason = FormattedMessage.FromMarkup(Loc.GetString("character-backpack-type-requirement",
("inverted", Inverted),
("type", Loc.GetString($"humanoid-profile-editor-preference-{Preference.ToString().ToLower()}"))));
return profile.Backpack == Preference;
}
}
/// <summary>
/// Requires the profile to use either Jumpsuits or Jumpskirts
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterClothingPreferenceRequirement : CharacterRequirement
{
[DataField(required: true)]
public ClothingPreference Preference;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
reason = FormattedMessage.FromMarkup(Loc.GetString("character-clothing-preference-requirement",
("inverted", Inverted),
("preference", Loc.GetString($"humanoid-profile-editor-preference-{Preference.ToString().ToLower()}"))));
return profile.Clothing == Preference;
}
}
/// <summary>
/// Requires the profile to be a certain species
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterSpeciesRequirement : CharacterRequirement
{
[DataField(required: true)]
public List<ProtoId<SpeciesPrototype>> Species;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "green";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-species-requirement",
("inverted", Inverted),
("species", $"[color={color}]{string.Join($"[/color], [color={color}]",
Species.Select(s => Loc.GetString(prototypeManager.Index(s).Name)))}[/color]")));
return Species.Contains(profile.Species);
}
}
/// <summary>
/// Requires the profile to have one of the specified traits
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterTraitRequirement : CharacterRequirement
{
[DataField(required: true)]
public List<ProtoId<TraitPrototype>> Traits;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "lightblue";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-trait-requirement",
("inverted", Inverted),
("traits", $"[color={color}]{string.Join($"[/color], [color={color}]",
Traits.Select(t => Loc.GetString($"trait-name-{t}")))}[/color]")));
return Traits.Any(t => profile.TraitPreferences.Contains(t.ToString()));
}
}
/// <summary>
/// Requires the profile to have one of the specified loadouts
/// </summary>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterLoadoutRequirement : CharacterRequirement
{
[DataField(required: true)]
public List<ProtoId<LoadoutPrototype>> Loadouts;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "lightblue";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-loadout-requirement",
("inverted", Inverted),
("loadouts", $"[color={color}]{string.Join($"[/color], [color={color}]",
Loadouts.Select(l => Loc.GetString($"loadout-name-{l}")))}[/color]")));
return Loadouts.Any(l => profile.LoadoutPreferences.Contains(l.ToString()));
}
}
// White Dream
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterSexRequirement : CharacterRequirement
{
[DataField(required: true)]
public Sex RequiredSex;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "green";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-sex-requirement",
("inverted", Inverted),
("sex", $"[color={color}]{string.Join($"[/color], [color={color}]",
RequiredSex.ToString())}[/color]")));
return profile.Sex == RequiredSex;
}
}
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class CharacterGenderRequirement : CharacterRequirement
{
[DataField(required: true)]
public Gender RequiredGender;
public override bool IsValid(JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, bool whitelisted,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "green";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-gender-requirement",
("inverted", Inverted),
("gender", $"[color={color}]{string.Join($"[/color], [color={color}]",
GenderToString())}[/color]")));
return profile.Gender == RequiredGender;
}
private string GenderToString()
{
return RequiredGender switch
{
Gender.Male => Loc.GetString("humanoid-profile-editor-pronouns-male-text"),
Gender.Female => Loc.GetString("humanoid-profile-editor-pronouns-female-text"),
_ => Loc.GetString("unknown")
};
}
}
// White Dream