* Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
257 lines
7.0 KiB
C#
257 lines
7.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Content.Server.Construction.Components;
|
|
using Content.Server.Disposal.Unit.Components;
|
|
using Content.Shared.Acts;
|
|
using Content.Shared.Disposal.Components;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Sound;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Server.Console;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.Disposal.Tube.Components
|
|
{
|
|
public abstract class DisposalTubeComponent : Component, IDisposalTubeComponent, IBreakAct
|
|
{
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
public static readonly TimeSpan ClangDelay = TimeSpan.FromSeconds(0.5);
|
|
public TimeSpan LastClang;
|
|
|
|
private bool _connected;
|
|
private bool _broken;
|
|
[DataField("clangSound")] public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
|
|
|
/// <summary>
|
|
/// Container of entities that are currently inside this tube
|
|
/// </summary>
|
|
[ViewVariables]
|
|
public Container Contents { get; private set; } = default!;
|
|
|
|
[ViewVariables]
|
|
private bool Anchored =>
|
|
!Owner.TryGetComponent(out PhysicsComponent? physics) ||
|
|
physics.BodyType == BodyType.Static;
|
|
|
|
/// <summary>
|
|
/// The directions that this tube can connect to others from
|
|
/// </summary>
|
|
/// <returns>a new array of the directions</returns>
|
|
protected abstract Direction[] ConnectableDirections();
|
|
|
|
public abstract Direction NextDirection(DisposalHolderComponent holder);
|
|
|
|
public virtual Vector2 ExitVector(DisposalHolderComponent holder)
|
|
{
|
|
return NextDirection(holder).ToVec();
|
|
}
|
|
|
|
protected Direction DirectionTo(IDisposalTubeComponent other)
|
|
{
|
|
return (other.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).GetDir();
|
|
}
|
|
|
|
public IDisposalTubeComponent? NextTube(DisposalHolderComponent holder)
|
|
{
|
|
var nextDirection = NextDirection(holder);
|
|
var oppositeDirection = new Angle(nextDirection.ToAngle().Theta + Math.PI).GetDir();
|
|
|
|
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
|
var position = Owner.Transform.Coordinates;
|
|
foreach (var entity in grid.GetInDir(position, nextDirection))
|
|
{
|
|
if (!Owner.EntityManager.TryGetComponent(entity, out IDisposalTubeComponent? tube))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!tube.CanConnect(oppositeDirection, this))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!CanConnect(nextDirection, tube))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
return tube;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public bool Remove(DisposalHolderComponent holder)
|
|
{
|
|
var removed = Contents.Remove(holder.Owner);
|
|
holder.ExitDisposals();
|
|
return removed;
|
|
}
|
|
|
|
public bool TransferTo(DisposalHolderComponent holder, IDisposalTubeComponent to)
|
|
{
|
|
var position = holder.Owner.Transform.LocalPosition;
|
|
if (!to.Contents.Insert(holder.Owner))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
holder.Owner.Transform.LocalPosition = position;
|
|
|
|
Contents.Remove(holder.Owner);
|
|
holder.EnterTube(to);
|
|
|
|
return true;
|
|
}
|
|
|
|
// TODO: Make disposal pipes extend the grid
|
|
private void Connect()
|
|
{
|
|
if (_connected || _broken)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_connected = true;
|
|
}
|
|
|
|
public bool CanConnect(Direction direction, IDisposalTubeComponent with)
|
|
{
|
|
if (!_connected)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (_broken)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!ConnectableDirections().Contains(direction))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void Disconnect()
|
|
{
|
|
if (!_connected)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_connected = false;
|
|
|
|
foreach (var entity in Contents.ContainedEntities.ToArray())
|
|
{
|
|
if (!entity.TryGetComponent(out DisposalHolderComponent? holder))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
holder.ExitDisposals();
|
|
}
|
|
}
|
|
|
|
public void PopupDirections(IEntity entity)
|
|
{
|
|
var directions = string.Join(", ", ConnectableDirections());
|
|
|
|
Owner.PopupMessage(entity, Loc.GetString("disposal-tube-component-popup-directions-text", ("directions", directions)));
|
|
}
|
|
|
|
private void UpdateVisualState()
|
|
{
|
|
if (!Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var state = _broken
|
|
? DisposalTubeVisualState.Broken
|
|
: Anchored
|
|
? DisposalTubeVisualState.Anchored
|
|
: DisposalTubeVisualState.Free;
|
|
|
|
appearance.SetData(DisposalTubeVisuals.VisualState, state);
|
|
}
|
|
|
|
public void AnchoredChanged()
|
|
{
|
|
if (!Owner.TryGetComponent(out PhysicsComponent? physics))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (physics.BodyType == BodyType.Static)
|
|
{
|
|
OnAnchor();
|
|
}
|
|
else
|
|
{
|
|
OnUnAnchor();
|
|
}
|
|
}
|
|
|
|
private void OnAnchor()
|
|
{
|
|
Connect();
|
|
UpdateVisualState();
|
|
}
|
|
|
|
private void OnUnAnchor()
|
|
{
|
|
Disconnect();
|
|
UpdateVisualState();
|
|
}
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
Contents = ContainerHelpers.EnsureContainer<Container>(Owner, Name);
|
|
Owner.EnsureComponent<AnchorableComponent>();
|
|
}
|
|
|
|
protected override void Startup()
|
|
{
|
|
base.Startup();
|
|
|
|
Owner.EnsureComponent<PhysicsComponent>(out var physicsComponent);
|
|
if (physicsComponent.BodyType != BodyType.Static)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Connect();
|
|
UpdateVisualState();
|
|
}
|
|
|
|
protected override void OnRemove()
|
|
{
|
|
base.OnRemove();
|
|
|
|
Disconnect();
|
|
}
|
|
|
|
void IBreakAct.OnBreak(BreakageEventArgs eventArgs)
|
|
{
|
|
_broken = true; // TODO: Repair
|
|
Disconnect();
|
|
UpdateVisualState();
|
|
}
|
|
}
|
|
}
|