Light replacer (#3701)
* Add graphics * Barebone light replacer * Now light replacer stores bulbs * More interactions * Added text messages * Better light refil * Add light replacer to locker and lathe * Added sound * Fixed ignore error * Better inhand * You don't like this commas? * Fixed typo * Deferring spawning * Moved interaction logic to system Co-authored-by: Alex Evgrashin <evgrashin.adl@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -62,12 +62,13 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
[ViewVariables] [DataField("ignoreGhostsBoo")]
|
||||
private bool _ignoreGhostsBoo;
|
||||
|
||||
[DataField("bulb")]
|
||||
private LightBulbType BulbType = LightBulbType.Tube;
|
||||
[DataField("bulb")] private LightBulbType _bulbType = LightBulbType.Tube;
|
||||
public LightBulbType BulbType => _bulbType;
|
||||
|
||||
[ViewVariables] private ContainerSlot _lightBulbContainer = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private LightBulbComponent? LightBulb
|
||||
public LightBulbComponent? LightBulb
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -126,6 +127,15 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to replace current bulb with a new one
|
||||
/// </summary>
|
||||
public bool ReplaceBulb(IEntity bulb)
|
||||
{
|
||||
EjectBulb();
|
||||
return InsertBulb(bulb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts the bulb if possible.
|
||||
/// </summary>
|
||||
@@ -134,7 +144,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
{
|
||||
if (LightBulb != null) return false;
|
||||
if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb)) return false;
|
||||
if (lightBulb.Type != BulbType) return false;
|
||||
if (lightBulb.Type != _bulbType) return false;
|
||||
|
||||
var inserted = _lightBulbContainer.Insert(bulb);
|
||||
|
||||
@@ -149,7 +159,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// <summary>
|
||||
/// Ejects the bulb to a mob's hand if possible.
|
||||
/// </summary>
|
||||
private void EjectBulb(IEntity user)
|
||||
private void EjectBulb(IEntity? user = null)
|
||||
{
|
||||
if (LightBulb == null) return;
|
||||
|
||||
@@ -160,9 +170,17 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
|
||||
if (!_lightBulbContainer.Remove(bulb.Owner)) return;
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent? hands)
|
||||
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
||||
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
|
||||
if (user != null)
|
||||
{
|
||||
if (!user.TryGetComponent(out HandsComponent? hands)
|
||||
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
||||
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
|
||||
}
|
||||
else
|
||||
{
|
||||
bulb.Owner.Transform.Coordinates = Owner.Transform.Coordinates;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -259,7 +277,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
{
|
||||
if (_hasLampOnSpawn)
|
||||
{
|
||||
var prototype = BulbType switch
|
||||
var prototype = _bulbType switch
|
||||
{
|
||||
LightBulbType.Bulb => "LightBulb",
|
||||
LightBulbType.Tube => "LightTube",
|
||||
|
||||
Reference in New Issue
Block a user