* Multiple hands in gui first pass * Remove IHandsComponent interface * Create hand class and more hand textures * Refactor ServerHandsComponent to use a single list of hands * Seal SharedHand * Fix picked up items not showing on top of the hand buttons * Remove HandsGui buttons and panels dictionaries * Fix items in hands rendering * Fix wrong hand container comparison * Fix not updating the location of duplicate hands * Change ClientHandsComponent to use a SortedList instead of a dictionary * More merge conflict fixes * Change SortedList to List * Fix hand button order * Add item tooltip for more than 2 hands and updating when removing hands * Add add hand and remove hand command * Merge conflict fixes * Remove nullable reference type from ContainerSlot * Fix texture errors * Fix error when reaching 0 hands * Fix error when swapping hands with no hands * Merged remove hand methods * Fix item panel texture errors * Merge conflict fixes * Fix addhand and removehand command descriptions * Add properly displaying tooltips for 2 hands * Make hand indexes and locations consistent across the client and server * Add dropping held entity if a hand is removed * Change hand location to be calculated by index * Made different hand gui updates more consistent * Remove human body yml testing changes * Sanitize addhand and removehand commands * Merge conflict fixes * Remove testing changes * Revert body system changes * Add missing imports * Remove obsolete hands parameter in yml files * Fix broken import * Fix startup error and adding and removing hands on the same tick * Make hand container id use an uint In case someone gets more than 2 billion hands * Rename hand component files * Make hands state use an array
283 lines
8.7 KiB
C#
283 lines
8.7 KiB
C#
using Content.Server.GameObjects.Components.GUI;
|
|
using Content.Server.GameObjects.Components.Power;
|
|
using Content.Server.GameObjects.EntitySystems.Click;
|
|
using Content.Server.Interfaces.GameObjects.Components.Items;
|
|
using Content.Shared.GameObjects;
|
|
using Content.Shared.GameObjects.Components;
|
|
using Content.Shared.GameObjects.EntitySystems;
|
|
using Content.Shared.Interfaces;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
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;
|
|
|
|
namespace Content.Server.GameObjects.Components.Interactable
|
|
{
|
|
/// <summary>
|
|
/// Component that represents a handheld lightsource which can be toggled on and off.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
internal sealed class HandheldLightComponent : SharedHandheldLightComponent, IUse, IExamine, IInteractUsing, IMapInit
|
|
{
|
|
#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;
|
|
[ViewVariables] private ContainerSlot _cellContainer;
|
|
private PointLightComponent _pointLight;
|
|
private SpriteComponent _spriteComponent;
|
|
private ClothingComponent _clothingComponent;
|
|
|
|
[ViewVariables]
|
|
private BatteryComponent Cell
|
|
{
|
|
get
|
|
{
|
|
if (_cellContainer.ContainedEntity == null) return null;
|
|
|
|
_cellContainer.ContainedEntity.TryGetComponent(out BatteryComponent cell);
|
|
return cell;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Status of light, whether or not it is emitting light.
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public bool Activated { get; private set; }
|
|
|
|
bool IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
|
{
|
|
if (!eventArgs.Using.HasComponent<BatteryComponent>()) return false;
|
|
|
|
if (Cell != null) return false;
|
|
|
|
var handsComponent = eventArgs.User.GetComponent<IHandsComponent>();
|
|
|
|
if (!handsComponent.Drop(eventArgs.Using, _cellContainer))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/pistol_magin.ogg", Owner);
|
|
|
|
|
|
Dirty();
|
|
|
|
return true;
|
|
}
|
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
|
{
|
|
var loc = IoCManager.Resolve<ILocalizationManager>();
|
|
|
|
if (Activated)
|
|
{
|
|
message.AddMarkup(loc.GetString("The light is currently [color=darkgreen]on[/color]."));
|
|
}
|
|
}
|
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
|
{
|
|
return ToggleStatus(eventArgs.User);
|
|
}
|
|
|
|
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 _);
|
|
Dirty();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Illuminates the light if it is not active, extinguishes it if it is active.
|
|
/// </summary>
|
|
/// <returns>True if the light's status was toggled, false otherwise.</returns>
|
|
private bool ToggleStatus(IEntity user)
|
|
{
|
|
var item = Owner.GetComponent<ItemComponent>();
|
|
// Update sprite and light states to match the activation.
|
|
if (Activated)
|
|
{
|
|
TurnOff();
|
|
item.EquippedPrefix = "off";
|
|
}
|
|
else
|
|
{
|
|
TurnOn(user);
|
|
item.EquippedPrefix = "on";
|
|
}
|
|
|
|
// Toggle always succeeds.
|
|
return true;
|
|
}
|
|
|
|
private void TurnOff()
|
|
{
|
|
if (!Activated)
|
|
{
|
|
return;
|
|
}
|
|
|
|
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);
|
|
|
|
_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 (Wattage > cell.CurrentCharge)
|
|
{
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/button.ogg", Owner);
|
|
_notifyManager.PopupMessage(Owner, user, _localizationManager.GetString("Dead cell..."));
|
|
return;
|
|
}
|
|
|
|
Activated = true;
|
|
SetState(true);
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/flashlight_toggle.ogg", Owner);
|
|
|
|
}
|
|
|
|
private void SetState(bool on)
|
|
{
|
|
_spriteComponent.LayerSetVisible(1, on);
|
|
_pointLight.Enabled = on;
|
|
if (_clothingComponent != null)
|
|
{
|
|
_clothingComponent.ClothingEquippedPrefix = on ? "On" : "Off";
|
|
}
|
|
}
|
|
|
|
public void OnUpdate(float frameTime)
|
|
{
|
|
if (!Activated) return;
|
|
|
|
var cell = Cell;
|
|
if (cell == null || !cell.TryUseCharge(Wattage * frameTime)) TurnOff();
|
|
|
|
Dirty();
|
|
}
|
|
|
|
private void EjectCell(IEntity user)
|
|
{
|
|
if (Cell == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var cell = Cell;
|
|
|
|
if (!_cellContainer.Remove(cell.Owner))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!user.TryGetComponent(out HandsComponent hands))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
|
|
{
|
|
cell.Owner.Transform.GridPosition = user.Transform.GridPosition;
|
|
}
|
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Items/pistol_magout.ogg", Owner);
|
|
|
|
}
|
|
|
|
public override ComponentState GetComponentState()
|
|
{
|
|
if (Cell == null)
|
|
{
|
|
return new HandheldLightComponentState(null);
|
|
}
|
|
|
|
if (Wattage > Cell.CurrentCharge)
|
|
{
|
|
// Practically zero.
|
|
// This is so the item status works correctly.
|
|
return new HandheldLightComponentState(0);
|
|
}
|
|
|
|
return new HandheldLightComponentState(Cell.CurrentCharge / Cell.MaxCharge);
|
|
}
|
|
|
|
[Verb]
|
|
public sealed class EjectCellVerb : Verb<HandheldLightComponent>
|
|
{
|
|
protected override void GetData(IEntity user, HandheldLightComponent component, VerbData data)
|
|
{
|
|
if (!ActionBlockerSystem.CanInteract(user))
|
|
{
|
|
data.Visibility = VerbVisibility.Invisible;
|
|
return;
|
|
}
|
|
|
|
if (component.Cell == null)
|
|
{
|
|
data.Text = "Eject cell (cell missing)";
|
|
data.Visibility = VerbVisibility.Disabled;
|
|
}
|
|
else
|
|
{
|
|
data.Text = "Eject cell";
|
|
}
|
|
}
|
|
|
|
protected override void Activate(IEntity user, HandheldLightComponent component)
|
|
{
|
|
component.EjectCell(user);
|
|
}
|
|
}
|
|
|
|
void IMapInit.MapInit()
|
|
{
|
|
if (_cellContainer.ContainedEntity != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var cell = Owner.EntityManager.SpawnEntity("PowerCellSmallHyper", Owner.Transform.GridPosition);
|
|
_cellContainer.Insert(cell);
|
|
}
|
|
}
|
|
}
|