SponsorLoadoutSystem
This commit is contained in:
parent
293e88ac94
commit
9b78c5e9d9
3 changed files with 74 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<StartingGearPrototype> Equipment;
|
||||
|
||||
[DataField("whitelistJobs", customTypeSerializer: typeof(PrototypeIdListSerializer<JobPrototype>))]
|
||||
public List<string>? WhitelistJobs { get; }
|
||||
|
||||
[DataField("blacklistJobs", customTypeSerializer: typeof(PrototypeIdListSerializer<JobPrototype>))]
|
||||
public List<string>? BlacklistJobs { get; }
|
||||
|
||||
[DataField("speciesRestriction")]
|
||||
public List<string>? SpeciesRestrictions { get; }
|
||||
}
|
||||
|
|
@ -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<PlayerSpawnCompleteEvent>(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<SponsorLoadoutPrototype>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue