Skip to content

Commit

Permalink
Fix Multiple Species Requirements (DeltaV-Station#595)
Browse files Browse the repository at this point in the history
# Description

Fixed species requirements, they can now be used for ORs.
Improved trait/loadout requirement code, made the colors per-item
instead of on the commas too.
Removed group exclusion requirements in favor of the aforementioned.
  • Loading branch information
DEATHB4DEFEAT authored Jul 26, 2024
1 parent 92dcd72 commit 7a8a0ad
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 222 deletions.
88 changes: 19 additions & 69 deletions Content.Shared/Customization/Systems/CharacterRequirements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,20 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha
public sealed partial class CharacterSpeciesRequirement : CharacterRequirement
{
[DataField(required: true)]
public ProtoId<SpeciesPrototype> Species;
public List<ProtoId<SpeciesPrototype>> Species;

public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
const string color = "green";
reason = FormattedMessage.FromMarkup(Loc.GetString("character-species-requirement",
("inverted", Inverted),
("species", Loc.GetString($"species-name-{Species.ToString().ToLower()}"))));
return profile.Species == Species;
("species", $"[color={color}]{string.Join($"[/color], [color={color}]",
Species.Select(s => Loc.GetString(prototypeManager.Index(s).Name)))}[/color]")));

return Species.Contains(profile.Species);
}
}

Expand All @@ -150,8 +153,11 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
reason = FormattedMessage.FromMarkup(Loc.GetString("character-trait-requirement", ("inverted", Inverted),
("traits", string.Join(", ", Traits.Select(t => Loc.GetString($"trait-name-{t}"))))));
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()));
}
Expand All @@ -168,11 +174,15 @@ public sealed partial class CharacterLoadoutRequirement : CharacterRequirement
public List<ProtoId<LoadoutPrototype>> Loadouts;

public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes, IEntityManager entityManager, IPrototypeManager prototypeManager,
IConfigurationManager configManager, out FormattedMessage? reason)
Dictionary<string, TimeSpan> playTimes,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
reason = FormattedMessage.FromMarkup(Loc.GetString("character-loadout-requirement", ("inverted", Inverted),
("loadouts", string.Join(", ", Loadouts.Select(l => Loc.GetString($"loadout-{l}"))))));
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()));
}
Expand Down Expand Up @@ -468,63 +478,3 @@ public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCha
}

#endregion

#region Prototype Groups

/// <summary>
/// Requires the profile to not have any of the specified traits
/// </summary>
/// <remarks>
/// Only works if you put this prototype in the denied prototypes' requirements too.
/// Can't be inverted, use <see cref="CharacterTraitRequirement"/>
/// </remarks>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class TraitGroupExclusionRequirement : CharacterRequirement
{
[DataField(required: true)]
public List<ProtoId<TraitPrototype>> Prototypes;

public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
var invalid = profile.TraitPreferences.Any(t => Prototypes.Contains(t));

reason = FormattedMessage.FromMarkup(Loc.GetString("character-trait-group-exclusion-requirement",
("traits", string.Join(", ", Prototypes.Select(t => Loc.GetString($"trait-name-{t}"))))));

return Inverted ? invalid : !invalid;
}
}

/// <summary>
/// Requires the profile to not have any of the specified loadouts
/// </summary>
/// <remarks>
/// Only works if you put this prototype in the denied prototypes' requirements too.
/// Can't be inverted, use <see cref="CharacterLoadoutRequirement"/>
/// </remarks>
[UsedImplicitly]
[Serializable, NetSerializable]
public sealed partial class LoadoutGroupExclusionRequirement : CharacterRequirement
{
[DataField(required: true)]
public List<ProtoId<LoadoutPrototype>> Prototypes;

public override bool IsValid(IPrototype prototype, JobPrototype job, HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
IEntityManager entityManager, IPrototypeManager prototypeManager, IConfigurationManager configManager,
out FormattedMessage? reason)
{
var invalid = profile.LoadoutPreferences.Any(l => Prototypes.Contains(l));

reason = FormattedMessage.FromMarkup(Loc.GetString("character-loadout-group-exclusion-requirement",
("loadouts", string.Join(", ", Prototypes.Select(l => Loc.GetString($"loadout-{l}"))))));

return Inverted ? invalid : !invalid;
}
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public bool CheckRequirementsValid(IPrototype prototype, List<CharacterRequireme
valid = !requirement.Inverted;
}

if (reason != null) // To appease the compiler
if (reason != null)
reasons.Add(reason);
}

Expand Down
15 changes: 8 additions & 7 deletions Resources/Locale/en-US/customization/character-requirements.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ character-age-requirement = You must {$inverted ->
character-species-requirement = You must {$inverted ->
[true] not be
*[other] be
} a [color=green]{$species}[/color]
} a {$species}
character-trait-requirement = You must {$inverted ->
[true] not have
*[other] have
} one of these traits: [color=lightblue]{$traits}[/color]
} one of these traits: {$traits}
character-loadout-requirement = You must {$inverted ->
[true] not have
*[other] have
} one of these loadouts: {$loadouts}
character-backpack-type-requirement = You must {$inverted ->
[true] not use
*[other] use
} a [color=lightblue]{$type}[/color] as your bag
} a [color=brown]{$type}[/color] as your bag
character-clothing-preference-requirement = You must {$inverted ->
[true] not wear
*[other] wear
} a [color=lightblue]{$type}[/color]
} a [color=white]{$type}[/color]
character-job-requirement = You must {$inverted ->
[true] not be
Expand All @@ -34,6 +38,3 @@ character-timer-overall-insufficient = You require [color=yellow]{TOSTRING($time
character-timer-overall-too-high = You require [color=yellow]{TOSTRING($time, "0")}[/color] fewer minutes of playtime
character-timer-role-insufficient = You require [color=yellow]{TOSTRING($time, "0")}[/color] more minutes with [color={$departmentColor}]{$job}[/color]
character-timer-role-too-high = You require[color=yellow] {TOSTRING($time, "0")}[/color] fewer minutes with [color={$departmentColor}]{$job}[/color]
character-trait-group-exclusion-requirement = You cannot have one of the following traits if you select this: {$traits}
character-loadout-group-exclusion-requirement = You cannot have one of the following loadouts if you select this: {$loadouts}
7 changes: 2 additions & 5 deletions Resources/Locale/en-US/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ trait-description-Stutter = You t-t-talk with a bit of a s-s-stutter...
trait-name-Snoring = Snoring
trait-description-Snoring = You will snore while sleeping.
trait-name-NormalVisionHarpy = Trichromat Modification
trait-description-NormalVisionHarpy = Your eyes have been modified by means of advanced medicine to see in the standard colors of Red, Green, and Blue.
trait-name-Southern = Southern Drawl
trait-description-Southern = You have a different way of speakin'.
trait-name-NormalVisionVulpkanin = Trichromat Modification
trait-description-NormalVisionVulpkanin = Your eyes have been modified by means of advanced medicine to see in the standard colors of Red, Green, and Blue.
trait-name-NormalVision = Trichromat Modification
trait-description-NormalVision = Your eyes have been modified by means of advanced medicine to see in the standard colors of Red, Green, and Blue.
trait-name-Thieving = Thieving
trait-description-Thieving =
Expand Down
14 changes: 6 additions & 8 deletions Resources/Prototypes/DeltaV/Traits/altvision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Vulpkanin
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Vulpkanin
- Harpy
- !type:CharacterTraitRequirement
inverted: true
traits:
Expand All @@ -23,10 +22,9 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Vulpkanin
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Vulpkanin
- Harpy
- !type:CharacterTraitRequirement
inverted: true
traits:
Expand Down
6 changes: 4 additions & 2 deletions Resources/Prototypes/Loadouts/Jobs/engineering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- StationEngineer
Expand Down Expand Up @@ -54,7 +55,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- StationEngineer
Expand Down
27 changes: 18 additions & 9 deletions Resources/Prototypes/Loadouts/Jobs/medical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -67,7 +68,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -85,7 +87,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -103,7 +106,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -121,7 +125,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -139,7 +144,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand All @@ -157,7 +163,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand Down Expand Up @@ -211,7 +218,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- Paramedic
Expand Down Expand Up @@ -262,7 +270,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- MedicalDoctor
Expand Down
5 changes: 3 additions & 2 deletions Resources/Prototypes/Loadouts/Jobs/science.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
requirements:
- !type:CharacterSpeciesRequirement
inverted: true
species: Harpy
species:
- Harpy
- !type:CharacterJobRequirement
jobs:
- Scientist
Expand Down Expand Up @@ -116,7 +117,7 @@
items:
- ClothingEyesEyepatchHudDiag

## Robes
# Robes
- type: loadout
id: LoadoutOuterRobeTechPriest
category: Outer
Expand Down
Loading

0 comments on commit 7a8a0ad

Please sign in to comment.