Files
OldThink/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs

272 lines
8.2 KiB
C#
Raw Normal View History

using Content.Server.GameObjects.Components.Power;
using Content.Server.GameObjects.Components.Sound;
2018-11-21 20:58:11 +01:00
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects;
using Content.Server.Utility;
2018-11-21 20:58:11 +01:00
using Content.Shared.GameObjects;
2020-01-09 00:27:52 +01:00
using Content.Shared.GameObjects.Components;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
namespace Content.Server.GameObjects.Components.Interactable
{
/// <summary>
2018-11-21 20:58:11 +01:00
/// Component that represents a handheld lightsource which can be toggled on and off.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
2019-07-31 15:02:36 +02:00
[RegisterComponent]
2020-05-23 17:23:25 +02:00
internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing, IMapInit
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
#pragma warning disable 649
[Dependency] private readonly ISharedNotifyManager _notifyManager;
[Dependency] private readonly ILocalizationManager _localizationManager;
#pragma warning restore 649
[ViewVariables(VVAccess.ReadWrite)] public float Wattage { get; set; } = 10;
2018-11-21 20:58:11 +01:00
[ViewVariables] private ContainerSlot _cellContainer;
private PointLightComponent _pointLight;
private SpriteComponent _spriteComponent;
private ClothingComponent _clothingComponent;
2018-11-21 20:58:11 +01:00
[ViewVariables]
private PowerCellComponent Cell
{
get
{
2018-11-21 20:58:11 +01:00
if (_cellContainer.ContainedEntity == null) return null;
_cellContainer.ContainedEntity.TryGetComponent(out PowerCellComponent cell);
return cell;
}
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// <summary>
2018-11-21 20:58:11 +01:00
/// Status of light, whether or not it is emitting light.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
2018-09-09 15:34:43 +02:00
[ViewVariables]
2018-11-21 20:58:11 +01:00
public bool Activated { get; private set; }
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
2020-05-23 17:23:25 +02:00
bool IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
2018-11-21 20:58:11 +01:00
{
2020-05-23 17:23:25 +02:00
if (!eventArgs.Using.HasComponent<PowerCellComponent>()) return false;
2018-11-21 20:58:11 +01:00
if (Cell != null) return false;
var handsComponent = eventArgs.User.GetComponent<IHandsComponent>();
2020-05-23 17:23:25 +02:00
if (!handsComponent.Drop(eventArgs.Using, _cellContainer))
{
return false;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/items/weapons/pistol_magin.ogg", Owner);
Dirty();
return true;
2018-11-21 20:58:11 +01:00
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
2018-11-21 20:58:11 +01:00
{
var loc = IoCManager.Resolve<ILocalizationManager>();
if (Activated)
{
message.AddMarkup(loc.GetString("The light is currently [color=darkgreen]on[/color]."));
}
2018-11-21 20:58:11 +01:00
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
2018-11-21 20:58:11 +01:00
{
return ToggleStatus(eventArgs.User);
2018-11-21 20:58:11 +01:00
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
public override void Initialize()
{
base.Initialize();
_pointLight = Owner.GetComponent<PointLightComponent>();
_spriteComponent = Owner.GetComponent<SpriteComponent>();
Owner.TryGetComponent(out _clothingComponent);
_cellContainer =
ContainerManagerComponent.Ensure<ContainerSlot>("flashlight_cell_container", Owner, out var existed);
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
/// <summary>
2018-11-21 20:58:11 +01:00
/// Illuminates the light if it is not active, extinguishes it if it is active.
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
/// </summary>
/// <returns>True if the light's status was toggled, false otherwise.</returns>
private bool ToggleStatus(IEntity user)
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
// Update sprite and light states to match the activation.
if (Activated)
{
TurnOff();
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
else
{
TurnOn(user);
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
// Toggle always succeeds.
return true;
}
private void TurnOff()
{
if (!Activated)
{
return;
}
2019-07-30 13:31:46 +02:00
SetState(false);
Activated = false;
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/items/flashlight_toggle.ogg", Owner);
}
private void TurnOn(IEntity user)
{
if (Activated)
{
return;
}
var cell = Cell;
if (cell == null)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/machines/button.ogg", Owner);
2020-01-09 00:27:52 +01:00
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Cell missing..."));
return;
}
// To prevent having to worry about frame time in here.
// Let's just say you need a whole second of charge before you can turn it on.
// Simple enough.
if (cell.AvailableCharge(1) < Wattage)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/machines/button.ogg", Owner);
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
return;
}
Activated = true;
2019-07-30 13:31:46 +02:00
SetState(true);
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/items/flashlight_toggle.ogg", Owner);
}
2019-07-30 13:31:46 +02:00
private void SetState(bool on)
{
2019-07-30 13:31:46 +02:00
_spriteComponent.LayerSetVisible(1, on);
_pointLight.Enabled = on;
if (_clothingComponent != null)
{
2019-07-30 13:31:46 +02:00
_clothingComponent.ClothingEquippedPrefix = on ? "On" : "Off";
}
}
2018-11-21 20:58:11 +01:00
public void OnUpdate(float frameTime)
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
{
2018-11-21 20:58:11 +01:00
if (!Activated) return;
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
2018-11-21 20:58:11 +01:00
var cell = Cell;
if (cell == null || !cell.TryDeductWattage(Wattage, frameTime)) TurnOff();
2020-01-09 00:27:52 +01:00
Dirty();
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
2018-11-21 20:58:11 +01:00
private void EjectCell(IEntity user)
{
if (Cell == null)
{
return;
}
2018-11-21 20:58:11 +01:00
var cell = Cell;
if (!_cellContainer.Remove(cell.Owner))
{
return;
}
if (!user.TryGetComponent(out HandsComponent hands))
{
return;
}
2018-11-21 20:58:11 +01:00
if (!hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
{
cell.Owner.Transform.GridPosition = user.Transform.GridPosition;
}
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/items/weapons/pistol_magout.ogg", Owner);
2018-11-21 20:58:11 +01:00
}
2020-01-09 00:27:52 +01:00
public override ComponentState GetComponentState()
{
if (Cell == null)
{
return new HandheldLightComponentState(null);
}
if (Cell.AvailableCharge(1) < Wattage)
{
// Practically zero.
// This is so the item status works correctly.
return new HandheldLightComponentState(0);
}
return new HandheldLightComponentState(Cell.Charge / Cell.Capacity);
}
2018-11-21 20:58:11 +01:00
[Verb]
public sealed class EjectCellVerb : Verb<HandheldLightComponent>
{
protected override void GetData(IEntity user, HandheldLightComponent component, VerbData data)
{
if (component.Cell == null)
{
data.Text = "Eject cell (cell missing)";
data.Visibility = VerbVisibility.Disabled;
}
else
{
data.Text = "Eject cell";
}
2018-11-21 20:58:11 +01:00
}
protected override void Activate(IEntity user, HandheldLightComponent component)
{
2018-11-21 20:58:11 +01:00
component.EjectCell(user);
}
}
void IMapInit.MapInit()
{
if (_cellContainer.ContainedEntity != null)
{
return;
}
2020-01-09 00:27:52 +01:00
var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper", Owner.Transform.GridPosition);
_cellContainer.Insert(cell);
}
Toggleable flashlight (#106) Fixes second half of #92 Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design. Adds: - Handheld light component for toggling light activation - Lantern sprite with on and off layers - Lantern prototype updates Known issues: - When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame. - Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency. - Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 08:39:20 -07:00
}
}