diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index aa27026e39..cd4b7fd70e 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -67,6 +67,7 @@ + diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index f35b0d5009..bd303d0684 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -32,6 +32,7 @@ using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.EntitySystems; using Content.Server.Mobs; using Content.Server.Players; +using Content.Server.GameObjects.Components.Interactable; namespace Content.Server { @@ -101,6 +102,8 @@ namespace Content.Server factory.Register(); factory.Register(); + factory.Register(); + factory.Register(); factory.RegisterReference(); diff --git a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs new file mode 100644 index 0000000000..ea7c4903c6 --- /dev/null +++ b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs @@ -0,0 +1,78 @@ +using Content.Server.GameObjects.EntitySystems; +using SS14.Server.GameObjects; +using SS14.Shared.Enums; +using SS14.Shared.GameObjects; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Content.Server.GameObjects.Components.Interactable +{ + /// + /// Component that represents a handheld lightsource which can be toggled on and off. + /// + class HandheldLightComponent : Component, EntitySystems.IUse, EntitySystems.IExamine + { + PointLightComponent pointLight; + SpriteComponent spriteComponent; + + public override string Name => "HandheldLight"; + + /// + /// Status of light, whether or not it is emitting light. + /// + public bool Activated { get; private set; } = false; + + public override void Initialize() + { + base.Initialize(); + + pointLight = Owner.GetComponent(); + spriteComponent = Owner.GetComponent(); + } + + bool IUse.UseEntity(IEntity user) + { + return ToggleStatus(); + } + + /// + /// Illuminates the light if it is not active, extinguishes it if it is active. + /// + /// True if the light's status was toggled, false otherwise. + public bool ToggleStatus() + { + // Update the activation state. + Activated = !Activated; + + // Update sprite and light states to match the activation. + if (Activated) + { + spriteComponent.LayerSetState(0, "lantern_on"); + pointLight.State = LightState.On; + } + else + { + spriteComponent.LayerSetState(0, "lantern_off"); + pointLight.State = LightState.Off; + } + + // Toggle always succeeds. + return true; + } + + string IExamine.Examine() + { + if (Activated) + { + return "The light is currently on."; + } + + return null; + } + } +} diff --git a/Resources/Prototypes/Entities/Items.yml b/Resources/Prototypes/Entities/Items.yml index 578cea7125..d5cc9894f0 100644 --- a/Resources/Prototypes/Entities/Items.yml +++ b/Resources/Prototypes/Entities/Items.yml @@ -76,8 +76,12 @@ id: FlashlightLantern description: They light the way to freedom components: + - type: HandheldLight - type: Sprite - texture: Objects/Flashlight.png + sprite: Objects/lantern.rsi + state: lantern_off - type: Icon - texture: Objects/Flashlight.png + sprite: Objects/lantern.rsi + state: lantern_off - type: PointLight + state: Off diff --git a/Resources/Textures/Objects/lantern.rsi/lantern_off.png b/Resources/Textures/Objects/lantern.rsi/lantern_off.png new file mode 100644 index 0000000000..a7b3b4678d Binary files /dev/null and b/Resources/Textures/Objects/lantern.rsi/lantern_off.png differ diff --git a/Resources/Textures/Objects/lantern.rsi/lantern_on.png b/Resources/Textures/Objects/lantern.rsi/lantern_on.png new file mode 100644 index 0000000000..b292f1c8b2 Binary files /dev/null and b/Resources/Textures/Objects/lantern.rsi/lantern_on.png differ diff --git a/Resources/Textures/Objects/lantern.rsi/meta.json b/Resources/Textures/Objects/lantern.rsi/meta.json new file mode 100644 index 0000000000..0cb4b371cd --- /dev/null +++ b/Resources/Textures/Objects/lantern.rsi/meta.json @@ -0,0 +1,31 @@ +{ + "version": 1, + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "lantern_off", + "select": [], + "flags": {}, + "directions": 1, + "delays": [ + [ + 1.0 + ] + ] + }, + { + "name": "lantern_on", + "select": [], + "flags": {}, + "directions": 1, + "delays": [ + [ + 1.0 + ] + ] + } + ] +}