Skip to content

Commit

Permalink
Species sponsor (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 authored Oct 2, 2023
1 parent 6e4608b commit 3af93f8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void SelectCharacter(int slot)
public void UpdateCharacter(ICharacterProfile profile, int slot)
{
// Corvax-Sponsors-Start
var allowedMarkings = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{};
profile.EnsureValid(allowedMarkings);
var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{};
profile.EnsureValid(sponsorPrototypes);
// Corvax-Sponsors-End
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Expand Down
4 changes: 4 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt
#region Species

_speciesList = prototypeManager.EnumeratePrototypes<SpeciesPrototype>().Where(o => o.RoundStart).ToList();
// Corvax-Sponsors-Start
if (_sponsorsMgr != null)
_speciesList = _speciesList.Where(p => !p.SponsorOnly || _sponsorsMgr.Prototypes.Contains(p.ID)).ToList();
// Corvax-Sponsors-End
for (var i = 0; i < _speciesList.Count; i++)
{
var name = Loc.GetString(_speciesList[i].Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ private async void HandleUpdateCharacterMessage(MsgUpdateCharacter message)

// Corvax-Sponsors-Start: Ensure removing sponsor markings if client somehow bypassed client filtering
// WARN! It's not removing markings from DB!
var allowedMarkings = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes)
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
profile.EnsureValid(allowedMarkings);
profile.EnsureValid(sponsorPrototypes);
// Corvax-Sponsors-End
var profiles = new Dictionary<int, ICharacterProfile>(curPrefs.Characters)
{
Expand Down Expand Up @@ -204,10 +204,10 @@ async Task LoadPrefs()
// Corvax-Sponsors-Start: Remove sponsor markings from expired sponsors
foreach (var (_, profile) in prefs.Characters)
{
var allowedMarkings = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes)
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
profile.EnsureValid(allowedMarkings);
profile.EnsureValid(sponsorPrototypes);
}
// Corvax-Sponsors-End
prefsData.Prefs = prefs;
Expand Down
8 changes: 4 additions & 4 deletions Content.Shared/Humanoid/HumanoidCharacterAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static Color ClampColor(Color color)
return new(color.RByte, color.GByte, color.BByte);
}

public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearance appearance, string species, Sex sex, string[] sponsorMarkings)
public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearance appearance, string species, Sex sex, string[] sponsorPrototypes)
{
var hairStyleId = appearance.HairStyleId;
var facialHairStyleId = appearance.FacialHairStyleId;
Expand All @@ -208,7 +208,7 @@ public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearanc
// Corvax-Sponsors-Start
if (proto.TryIndex(hairStyleId, out MarkingPrototype? hairProto) &&
hairProto.SponsorOnly &&
!sponsorMarkings.Contains(hairStyleId))
!sponsorPrototypes.Contains(hairStyleId))
{
hairStyleId = HairStyles.DefaultHairStyle;
}
Expand All @@ -222,7 +222,7 @@ public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearanc
// Corvax-Sponsors-Start
if (proto.TryIndex(facialHairStyleId, out MarkingPrototype? facialHairProto) &&
facialHairProto.SponsorOnly &&
!sponsorMarkings.Contains(facialHairStyleId))
!sponsorPrototypes.Contains(facialHairStyleId))
{
facialHairStyleId = HairStyles.DefaultFacialHairStyle;
}
Expand All @@ -242,7 +242,7 @@ public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearanc

markingSet.EnsureSpecies(species, skinColor, markingManager);
markingSet.EnsureSexes(sex, markingManager);
markingSet.FilterSponsor(sponsorMarkings, markingManager); // Corvax-Sponsors
markingSet.FilterSponsor(sponsorPrototypes, markingManager); // Corvax-Sponsors
}

return new HumanoidCharacterAppearance(
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public sealed class SpeciesPrototype : IPrototype
[DataField("roundStart", required: true)]
public bool RoundStart { get; private set; } = false;

// Corvax-Sponsors-Start
/// <summary>
/// Whether the species is available only for sponsors
/// </summary>
[DataField("sponsorOnly")]
public bool SponsorOnly = false;
// Corvax-Sponsors-End

// The below two are to avoid fetching information about the species from the entity
// prototype.

Expand Down
12 changes: 10 additions & 2 deletions Content.Shared/Preferences/HumanoidCharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public bool MemberwiseEquals(ICharacterProfile maybeOther)
return Appearance.MemberwiseEquals(other.Appearance);
}

public void EnsureValid(string[] sponsorMarkings)
public void EnsureValid(string[] sponsorPrototypes)
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();

Expand All @@ -380,6 +380,14 @@ public void EnsureValid(string[] sponsorMarkings)
speciesPrototype = prototypeManager.Index<SpeciesPrototype>(Species);
}

// Corvax-Sponsors-Start: Reset to human if player not sponsor
if (speciesPrototype.SponsorOnly && !sponsorPrototypes.Contains(Species))
{
Species = SharedHumanoidAppearanceSystem.DefaultSpecies;
speciesPrototype = prototypeManager.Index<SpeciesPrototype>(Species);
}
// Corvax-Sponsors-End

var sex = Sex switch
{
Sex.Male => Sex.Male,
Expand Down Expand Up @@ -453,7 +461,7 @@ public void EnsureValid(string[] sponsorMarkings)
flavortext = FormattedMessage.RemoveMarkup(FlavorText);
}

var appearance = HumanoidCharacterAppearance.EnsureValid(Appearance, Species, Sex, sponsorMarkings);
var appearance = HumanoidCharacterAppearance.EnsureValid(Appearance, Species, Sex, sponsorPrototypes);

var prefsUnavailableMode = PreferenceUnavailable switch
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Preferences/ICharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface ICharacterProfile
/// <summary>
/// Makes this profile valid so there's no bad data like negative ages.
/// </summary>
void EnsureValid(string[] sponsorMarkings); // Corvax-Sponsors: Integrated filtering for sponsor markings
void EnsureValid(string[] sponsorPrototypes); // Corvax-Sponsors: Integrated filtering for sponsor prototypes (markings/species/etc)
}
}

0 comments on commit 3af93f8

Please sign in to comment.