2020-08-22 22:29:20 +02:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Power.Components;
|
2020-04-23 00:58:43 +02:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-04-23 00:58:43 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.BarSign
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public class BarSignComponent : Component, IMapInit
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "BarSign";
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
2020-04-23 00:58:43 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("current")]
|
2020-08-22 22:29:20 +02:00
|
|
|
private string? _currentSign;
|
2020-04-23 00:58:43 +02:00
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-08-22 22:29:20 +02:00
|
|
|
public string? CurrentSign
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
|
|
|
|
get => _currentSign;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_currentSign = value;
|
|
|
|
|
UpdateSignInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
private bool Powered => !Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2020-04-23 00:58:43 +02:00
|
|
|
private void UpdateSignInfo()
|
|
|
|
|
{
|
|
|
|
|
if (_currentSign == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 22:26:59 +01:00
|
|
|
if (!_prototypeManager.TryIndex(_currentSign, out BarSignPrototype? prototype))
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
|
|
|
|
Logger.ErrorS("barSign", $"Invalid bar sign prototype: \"{_currentSign}\"");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
if (Owner.TryGetComponent(out SpriteComponent? sprite))
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!Powered)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(0, "empty");
|
|
|
|
|
sprite.LayerSetShader(0, "shaded");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(0, prototype.Icon);
|
|
|
|
|
sprite.LayerSetShader(0, "unshaded");
|
|
|
|
|
}
|
2020-04-23 00:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prototype.Name))
|
|
|
|
|
{
|
|
|
|
|
Owner.Name = prototype.Name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.Name = Loc.GetString("barsign-component-name");
|
2020-04-23 00:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Owner.Description = prototype.Description;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
UpdateSignInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 09:13:01 -06:00
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-01-03 09:13:01 -06:00
|
|
|
base.HandleMessage(message, component);
|
|
|
|
|
switch (message)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
2021-01-03 09:13:01 -06:00
|
|
|
case PowerChangedMessage powerChanged:
|
|
|
|
|
PowerOnOnPowerStateChanged(powerChanged);
|
|
|
|
|
break;
|
2020-08-22 22:29:20 +02:00
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
|
|
|
|
|
2021-01-03 09:13:01 -06:00
|
|
|
private void PowerOnOnPowerStateChanged(PowerChangedMessage e)
|
2020-04-23 00:58:43 +02:00
|
|
|
{
|
|
|
|
|
UpdateSignInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MapInit()
|
|
|
|
|
{
|
|
|
|
|
if (_currentSign != null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var prototypes = _prototypeManager.EnumeratePrototypes<BarSignPrototype>().Where(p => !p.Hidden)
|
|
|
|
|
.ToList();
|
|
|
|
|
var prototype = _robustRandom.Pick(prototypes);
|
|
|
|
|
|
|
|
|
|
CurrentSign = prototype.ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|