* some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable™️ * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge™️ * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
166 lines
5.7 KiB
C#
166 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Content.Server.MachineLinking.Events;
|
|
using Content.Server.MachineLinking.Models;
|
|
using Content.Server.Power.Components;
|
|
using Content.Server.Stunnable;
|
|
using Content.Shared.Conveyor;
|
|
using Content.Shared.Item;
|
|
using Content.Shared.MachineLinking;
|
|
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
|
|
namespace Content.Server.Conveyor
|
|
{
|
|
public class ConveyorSystem : EntitySystem
|
|
{
|
|
[Dependency] private StunSystem _stunSystem = default!;
|
|
[Dependency] private IEntityLookup _entityLookup = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ConveyorComponent, SignalReceivedEvent>(OnSignalReceived);
|
|
SubscribeLocalEvent<ConveyorComponent, PortDisconnectedEvent>(OnPortDisconnected);
|
|
SubscribeLocalEvent<ConveyorComponent, LinkAttemptEvent>(OnLinkAttempt);
|
|
SubscribeLocalEvent<ConveyorComponent, PowerChangedEvent>(OnPowerChanged);
|
|
}
|
|
|
|
private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args)
|
|
{
|
|
UpdateAppearance(component);
|
|
}
|
|
|
|
private void UpdateAppearance(ConveyorComponent component)
|
|
{
|
|
if (EntityManager.TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance))
|
|
{
|
|
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent?>(component.Owner, out var receiver) && receiver.Powered)
|
|
{
|
|
appearance.SetData(ConveyorVisuals.State, component.State);
|
|
}
|
|
else
|
|
{
|
|
appearance.SetData(ConveyorVisuals.State, ConveyorState.Off);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnLinkAttempt(EntityUid uid, ConveyorComponent component, LinkAttemptEvent args)
|
|
{
|
|
if (args.TransmitterComponent.Outputs.GetPort(args.TransmitterPort).Signal is TwoWayLeverSignal signal &&
|
|
signal != TwoWayLeverSignal.Middle)
|
|
{
|
|
args.Cancel();
|
|
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true);
|
|
component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link"));
|
|
}
|
|
}
|
|
|
|
private void OnPortDisconnected(EntityUid uid, ConveyorComponent component, PortDisconnectedEvent args)
|
|
{
|
|
SetState(component, TwoWayLeverSignal.Middle);
|
|
}
|
|
|
|
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
|
|
{
|
|
switch (args.Port)
|
|
{
|
|
case "state":
|
|
SetState(component, (TwoWayLeverSignal) args.Value!);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SetState(ConveyorComponent component, TwoWayLeverSignal signal)
|
|
{
|
|
component.State = signal switch
|
|
{
|
|
TwoWayLeverSignal.Left => ConveyorState.Reversed,
|
|
TwoWayLeverSignal.Middle => ConveyorState.Off,
|
|
TwoWayLeverSignal.Right => ConveyorState.Forward,
|
|
_ => ConveyorState.Off
|
|
};
|
|
UpdateAppearance(component);
|
|
}
|
|
|
|
public bool CanRun(ConveyorComponent component)
|
|
{
|
|
if (component.State == ConveyorState.Off)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) &&
|
|
!receiver.Powered)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (EntityManager.HasComponent<SharedItemComponent>(component.Owner))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculates the angle in which entities on top of this conveyor
|
|
/// belt are pushed in
|
|
/// </summary>
|
|
/// <returns>
|
|
/// The angle when taking into account if the conveyor is reversed
|
|
/// </returns>
|
|
public Angle GetAngle(ConveyorComponent component)
|
|
{
|
|
var adjustment = component.State == ConveyorState.Reversed ? MathHelper.Pi/2 : -MathHelper.Pi/2;
|
|
var radians = MathHelper.DegreesToRadians(component.Angle);
|
|
|
|
return new Angle(EntityManager.GetComponent<TransformComponent>(component.Owner).LocalRotation.Theta + radians + adjustment);
|
|
}
|
|
|
|
public IEnumerable<(EntityUid, IPhysBody)> GetEntitiesToMove(ConveyorComponent comp)
|
|
{
|
|
//todo uuuhhh cache this
|
|
foreach (var entity in _entityLookup.GetEntitiesIntersecting(comp.Owner, flags: LookupFlags.Approximate))
|
|
{
|
|
if (Deleted(entity))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (entity == comp.Owner)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!EntityManager.TryGetComponent(entity, out IPhysBody? physics) ||
|
|
physics.BodyType == BodyType.Static || physics.BodyStatus == BodyStatus.InAir || entity.IsWeightless())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (EntityManager.HasComponent<IMapGridComponent>(entity))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (entity.IsInContainer())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
yield return (entity, physics);
|
|
}
|
|
}
|
|
}
|
|
}
|