-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Content.Shared.Roles; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; | ||
|
||
namespace Content.Server.Backmen.Loadout; | ||
|
||
[Prototype("loadout")] | ||
public sealed class LoadoutItemPrototype : IPrototype | ||
{ | ||
[IdDataField] public string ID { get; } = default!; | ||
|
||
[DataField("entity", required: true)] | ||
public ProtoId<EntityPrototype> EntityId { get; } = default!; | ||
|
||
// Corvax-Sponsors-Start | ||
[DataField("sponsorOnly")] | ||
public bool SponsorOnly = false; | ||
// Corvax-Sponsors-End | ||
|
||
[DataField("whitelistJobs")] | ||
public List<ProtoId<JobPrototype>>? WhitelistJobs { get; } | ||
|
||
[DataField("blacklistJobs")] | ||
public List<ProtoId<JobPrototype>>? BlacklistJobs { get; } | ||
|
||
[DataField("speciesRestriction")] | ||
public List<string>? SpeciesRestrictions { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using Content.Corvax.Interfaces.Server; | ||
using Content.Server.GameTicking; | ||
using Content.Server.Hands.Systems; | ||
using Content.Server.Storage.EntitySystems; | ||
using Content.Shared.Clothing.Components; | ||
using Content.Shared.Inventory; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Backmen.Loadout; | ||
|
||
public sealed class LoadoutSystem : EntitySystem | ||
{ | ||
private const string BackpackSlotId = "back"; | ||
|
||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly InventorySystem _inventorySystem = default!; | ||
[Dependency] private readonly HandsSystem _handsSystem = default!; | ||
[Dependency] private readonly StorageSystem _storageSystem = default!; | ||
[Dependency] private readonly IServerSponsorsManager _sponsorsManager = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawned); | ||
} | ||
|
||
private void OnPlayerSpawned(PlayerSpawnCompleteEvent ev) | ||
{ | ||
if (!_sponsorsManager.TryGetPrototypes(ev.Player.UserId, out var prototypes)) | ||
return; | ||
|
||
foreach (var loadoutId in prototypes) | ||
{ | ||
// NOTE: Now is easy to not extract method because event give all info we need | ||
if (!_prototypeManager.TryIndex<LoadoutItemPrototype>(loadoutId, out var loadout)) | ||
continue; | ||
|
||
var isSponsorOnly = loadout.SponsorOnly && | ||
!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 (isSponsorOnly || isWhitelisted || isBlacklisted || isSpeciesRestricted) | ||
continue; | ||
|
||
var entity = Spawn(loadout.EntityId, Transform(ev.Mob).Coordinates); | ||
|
||
// Take in hand if not clothes | ||
if (!TryComp<ClothingComponent>(entity, out var clothing)) | ||
{ | ||
_handsSystem.TryPickup(ev.Mob, entity); | ||
continue; | ||
} | ||
|
||
// Automatically search empty slot for clothes to equip | ||
var firstSlotName = (string?)null; | ||
var isEquiped = false; | ||
|
||
if (!_inventorySystem.TryGetSlots(ev.Mob, out var slotDefinitions)) | ||
return; | ||
|
||
foreach (var slot in slotDefinitions) | ||
{ | ||
if (!clothing.Slots.HasFlag(slot.SlotFlags)) | ||
continue; | ||
|
||
firstSlotName ??= slot.Name; | ||
|
||
if (_inventorySystem.TryGetSlotEntity(ev.Mob, slot.Name, out var _)) | ||
continue; | ||
|
||
if (!_inventorySystem.TryEquip(ev.Mob, entity, slot.Name, true)) | ||
continue; | ||
|
||
isEquiped = true; | ||
break; | ||
} | ||
|
||
if (isEquiped || firstSlotName == null) | ||
continue; | ||
|
||
// Force equip to first valid clothes slot | ||
// Get occupied entity -> Insert to backpack -> Equip loadout entity | ||
if (_inventorySystem.TryGetSlotEntity(ev.Mob, firstSlotName, out var slotEntity) && | ||
_inventorySystem.TryGetSlotEntity(ev.Mob, BackpackSlotId, out var backEntity) && | ||
_storageSystem.CanInsert(backEntity.Value, slotEntity.Value, out _)) | ||
{ | ||
if(_storageSystem.Insert(backEntity.Value, slotEntity.Value, out _, playSound: false)) | ||
continue; | ||
} | ||
|
||
if (!_inventorySystem.TryEquip(ev.Mob, entity, firstSlotName, true)) | ||
{ | ||
QueueDel(entity); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Content.Corvax.Interfaces.Shared; | ||
using Robust.Shared.Network; | ||
|
||
namespace Content.Corvax.Interfaces.Server; | ||
|
||
public interface IServerLoadoutManager : ISharedSponsorsManager | ||
{ | ||
public bool TryGetPrototypes(NetUserId userId, [NotNullWhen(true)] out List<string>? prototypes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- type: loadout | ||
id: ClothingHeadHatFlowerCrownLoadout | ||
entity: ClothingHeadHatFlowerCrown | ||
|
||
- type: loadout | ||
id: ClothingHeadHatHairflowerLoadout | ||
entity: ClothingHeadHatHairflower |