2021-02-02 05:20:24 -06:00
|
|
|
#nullable enable
|
2021-01-08 18:06:36 -07:00
|
|
|
using System;
|
2020-04-13 01:44:05 +02:00
|
|
|
using Content.Shared.Audio;
|
2021-01-08 18:06:36 -07:00
|
|
|
using Content.Shared.GameObjects.EntitySystems;
|
2020-07-18 22:51:56 -07:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-07-31 15:02:36 +02:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-04-13 01:44:05 +02:00
|
|
|
using Robust.Shared.IoC;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Maths;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2020-04-13 01:44:05 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.ViewVariables;
|
2019-03-22 23:59:13 +01:00
|
|
|
|
2020-08-13 14:40:27 +02:00
|
|
|
namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
|
|
|
|
public enum LightBulbState
|
|
|
|
|
{
|
|
|
|
|
Normal,
|
|
|
|
|
Broken,
|
|
|
|
|
Burned,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum LightBulbType
|
|
|
|
|
{
|
2019-03-24 18:05:32 +01:00
|
|
|
Bulb,
|
2019-03-22 23:59:13 +01:00
|
|
|
Tube,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Component that represents a light bulb. Can be broken, or burned, which turns them mostly useless.
|
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2021-01-08 18:06:36 -07:00
|
|
|
public class LightBulbComponent : Component, ILand, IBreakAct
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2020-04-13 01:44:05 +02:00
|
|
|
|
2019-03-22 23:59:13 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked whenever the state of the light bulb changes.
|
|
|
|
|
/// </summary>
|
2021-02-02 05:20:24 -06:00
|
|
|
public event EventHandler<EventArgs>? OnLightBulbStateChange;
|
|
|
|
|
public event EventHandler<EventArgs?>? OnLightColorChange;
|
2019-03-23 22:30:05 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("color")]
|
2019-03-23 22:30:05 +01:00
|
|
|
private Color _color = Color.White;
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] public Color Color
|
|
|
|
|
{
|
|
|
|
|
get { return _color; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_color = value;
|
|
|
|
|
OnLightColorChange?.Invoke(this, null);
|
|
|
|
|
UpdateColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-22 23:59:13 +01:00
|
|
|
|
|
|
|
|
public override string Name => "LightBulb";
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("bulb")]
|
2019-03-22 23:59:13 +01:00
|
|
|
public LightBulbType Type = LightBulbType.Tube;
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("BurningTemperature")]
|
|
|
|
|
private int _burningTemperature = 1400;
|
2019-04-06 17:11:51 +02:00
|
|
|
public int BurningTemperature => _burningTemperature;
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("PowerUse")]
|
|
|
|
|
private int _powerUse = 40;
|
2020-06-28 09:23:26 -06:00
|
|
|
public int PowerUse => _powerUse;
|
2019-04-06 17:11:51 +02:00
|
|
|
|
2019-03-22 23:59:13 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// The current state of the light bulb. Invokes the OnLightBulbStateChange event when set.
|
|
|
|
|
/// It also updates the bulb's sprite accordingly.
|
|
|
|
|
/// </summary>
|
2019-03-23 22:30:05 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] public LightBulbState State
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
|
|
|
|
get { return _state; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var sprite = Owner.GetComponent<SpriteComponent>();
|
|
|
|
|
OnLightBulbStateChange?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
_state = value;
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
|
|
|
|
case LightBulbState.Normal:
|
|
|
|
|
sprite.LayerSetState(0, "normal");
|
|
|
|
|
break;
|
|
|
|
|
case LightBulbState.Broken:
|
|
|
|
|
sprite.LayerSetState(0, "broken");
|
|
|
|
|
break;
|
|
|
|
|
case LightBulbState.Burned:
|
|
|
|
|
sprite.LayerSetState(0, "burned");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LightBulbState _state = LightBulbState.Normal;
|
|
|
|
|
|
2019-03-23 22:30:05 +01:00
|
|
|
public void UpdateColor()
|
|
|
|
|
{
|
2021-02-02 05:20:24 -06:00
|
|
|
if (!Owner.TryGetComponent(out SpriteComponent? sprite))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 22:30:05 +01:00
|
|
|
sprite.Color = Color;
|
2019-03-22 23:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-23 22:30:05 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
UpdateColor();
|
|
|
|
|
}
|
2020-04-13 01:44:05 +02:00
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void ILand.Land(LandEventArgs eventArgs)
|
2020-04-13 01:44:05 +02:00
|
|
|
{
|
2021-02-16 11:40:43 +03:00
|
|
|
PlayBreakSound();
|
2020-04-13 01:44:05 +02:00
|
|
|
State = LightBulbState.Broken;
|
|
|
|
|
}
|
2021-01-08 18:06:36 -07:00
|
|
|
|
|
|
|
|
public void OnBreak(BreakageEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
State = LightBulbState.Broken;
|
|
|
|
|
}
|
2021-02-16 11:40:43 +03:00
|
|
|
|
|
|
|
|
public void PlayBreakSound()
|
|
|
|
|
{
|
|
|
|
|
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>("GlassBreak");
|
|
|
|
|
var file = _random.Pick(soundCollection.PickFiles);
|
|
|
|
|
|
2021-03-21 09:12:03 -07:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), file, Owner);
|
2021-02-16 11:40:43 +03:00
|
|
|
}
|
2019-03-22 23:59:13 +01:00
|
|
|
}
|
|
|
|
|
}
|