From 9b78c5e9d9d2bb4e97f3d0d4b69df3418af04fac Mon Sep 17 00:00:00 2001 From: VigersRay Date: Fri, 12 Jul 2024 04:53:31 +0300 Subject: [PATCH] SponsorLoadoutSystem --- Content.Client/Entry/EntryPoint.cs | 1 + .../SponsorLoadout/SponsorLoadoutPrototype.cs | 23 +++++++++ .../SponsorLoadout/SponsorLoadoutSystem.cs | 50 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutPrototype.cs create mode 100644 Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutSystem.cs diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 7e939a0bc0..eb314fd2b8 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -121,6 +121,7 @@ namespace Content.Client.Entry _prototypeManager.RegisterIgnore("alertLevels"); _prototypeManager.RegisterIgnore("nukeopsRole"); _prototypeManager.RegisterIgnore("stationGoal"); // Sunrise-StationGoal + _prototypeManager.RegisterIgnore("sponsorLoadout"); // Sunrise-Sponsors _prototypeManager.RegisterIgnore("ghostRoleRaffleDecider"); _componentFactory.GenerateNetIds(); diff --git a/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutPrototype.cs b/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutPrototype.cs new file mode 100644 index 0000000000..ddd50663a3 --- /dev/null +++ b/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutPrototype.cs @@ -0,0 +1,23 @@ +using Content.Shared.Roles; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; + +namespace Content.Server._Sunrise.SponsorLoadout; + +[Prototype("sponsorLoadout")] +public sealed class SponsorLoadoutPrototype : IPrototype +{ + [IdDataField] public string ID { get; } = default!; + + [DataField(required: true)] + public ProtoId Equipment; + + [DataField("whitelistJobs", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public List? WhitelistJobs { get; } + + [DataField("blacklistJobs", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public List? BlacklistJobs { get; } + + [DataField("speciesRestriction")] + public List? SpeciesRestrictions { get; } +} diff --git a/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutSystem.cs b/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutSystem.cs new file mode 100644 index 0000000000..e5679a1d25 --- /dev/null +++ b/Content.Server/_Sunrise/SponsorLoadout/SponsorLoadoutSystem.cs @@ -0,0 +1,50 @@ +using Content.Server.GameTicking; +using Content.Server.Station.Systems; +using Robust.Shared.Prototypes; +using Content.Sunrise.Interfaces.Shared; + +namespace Content.Server._Sunrise.SponsorLoadout; + +public sealed class SponsorLoadoutSystem : EntitySystem +{ + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly StationSpawningSystem _spawn = default!; + private ISharedSponsorsManager? _sponsorsManager; + + public override void Initialize() + { + IoCManager.Instance!.TryResolveType(out _sponsorsManager); + SubscribeLocalEvent(OnPlayerSpawned); + } + + private void OnPlayerSpawned(PlayerSpawnCompleteEvent ev) + { + if (_sponsorsManager == null) + return; + + if (!_sponsorsManager.TryGetPrototypes(ev.Player.UserId, out var prototypes)) + return; + foreach (var loadoutId in prototypes) + { + if (!_prototypeManager.TryIndex(loadoutId, out var loadout)) + continue; + var isSponsorHave = !prototypes.Contains(loadoutId); + var isWhitelisted = ev.JobId != null && + loadout.WhitelistJobs != null && + !loadout.WhitelistJobs.Contains(ev.JobId); + var isBlacklisted = ev.JobId != null && + loadout.BlacklistJobs != null && + loadout.BlacklistJobs.Contains(ev.JobId); + var isSpeciesRestricted = loadout.SpeciesRestrictions != null && + loadout.SpeciesRestrictions.Contains(ev.Profile.Species); + + if (isSponsorHave || isWhitelisted || isBlacklisted || isSpeciesRestricted) + continue; + + if (!_prototypeManager.TryIndex(loadout.Equipment, out var startingGear)) + continue; + + _spawn.EquipStartingGear(ev.Mob, startingGear); + } + } +}