2024-01-13 12:24:00 +03:00
|
|
|
using Content.Shared.Ghost;
|
2024-01-28 18:37:24 +07:00
|
|
|
using Content.Shared._White.CustomGhostSystem;
|
2023-05-01 17:32:16 +06:00
|
|
|
using Robust.Server.Player;
|
2024-01-13 12:24:00 +03:00
|
|
|
using Robust.Shared.Player;
|
2023-05-01 17:32:16 +06:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2024-01-28 18:18:54 +07:00
|
|
|
namespace Content.Server._White.CustomGhostSpriteSystem;
|
2023-05-01 17:32:16 +06:00
|
|
|
|
|
|
|
|
public sealed class CustomGhostSpriteSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
2024-01-13 12:24:00 +03:00
|
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
2023-05-01 17:32:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-08-18 00:17:13 +03:00
|
|
|
|
2023-05-01 17:32:16 +06:00
|
|
|
SubscribeLocalEvent<GhostComponent, PlayerAttachedEvent>(OnShit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnShit(EntityUid uid, GhostComponent component, PlayerAttachedEvent args)
|
|
|
|
|
{
|
2024-08-18 00:17:13 +03:00
|
|
|
if (!_playerManager.TryGetSessionByEntity(uid, out var session))
|
2023-05-01 17:32:16 +06:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TrySetCustomSprite(uid, session.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void TrySetCustomSprite(EntityUid ghostUid, string ckey)
|
|
|
|
|
{
|
|
|
|
|
var prototypes = _prototypeManager.EnumeratePrototypes<CustomGhostPrototype>();
|
|
|
|
|
|
|
|
|
|
foreach (var customGhostPrototype in prototypes)
|
|
|
|
|
{
|
2024-08-18 00:17:13 +03:00
|
|
|
if (!string.Equals(customGhostPrototype.Ckey, ckey, StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
|
continue;
|
2023-05-01 17:32:16 +06:00
|
|
|
|
2024-08-18 00:17:13 +03:00
|
|
|
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.Sprite, customGhostPrototype.CustomSpritePath.ToString());
|
|
|
|
|
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.SizeOverride, customGhostPrototype.SizeOverride);
|
2023-05-01 17:32:16 +06:00
|
|
|
|
2024-08-18 00:17:13 +03:00
|
|
|
if (customGhostPrototype.AlphaOverride > 0)
|
|
|
|
|
_appearanceSystem.SetData(ghostUid, CustomGhostAppearance.AlphaOverride, customGhostPrototype.AlphaOverride);
|
2023-05-14 02:35:20 +03:00
|
|
|
|
2024-08-18 00:17:13 +03:00
|
|
|
if (customGhostPrototype.GhostName != string.Empty)
|
|
|
|
|
_metaData.SetEntityName(ghostUid, customGhostPrototype.GhostName ?? "null");
|
2023-05-14 02:35:20 +03:00
|
|
|
|
2024-08-18 00:17:13 +03:00
|
|
|
if (customGhostPrototype.GhostDescription != string.Empty)
|
|
|
|
|
_metaData.SetEntityDescription(ghostUid, customGhostPrototype.GhostDescription);
|
2023-05-14 02:35:20 +03:00
|
|
|
|
2024-08-18 00:17:13 +03:00
|
|
|
return;
|
2023-05-01 17:32:16 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|