Bluespace lockers update (#13469)
This commit is contained in:
@@ -11,13 +11,14 @@ using Content.Server.Tools.Systems;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Coordinates;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems;
|
||||
|
||||
public sealed class BluespaceLockerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly EntityStorageSystem _entityStorage = default!;
|
||||
[Dependency] private readonly WeldableSystem _weldableSystem = default!;
|
||||
[Dependency] private readonly LockSystem _lockSystem = default!;
|
||||
@@ -38,23 +39,42 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
{
|
||||
GetTarget(uid, component);
|
||||
|
||||
if (component.BluespaceEffectOnInit)
|
||||
BluespaceEffect(uid, component);
|
||||
if (component.BehaviorProperties.BluespaceEffectOnInit)
|
||||
BluespaceEffect(uid, component, component, true);
|
||||
}
|
||||
|
||||
private void BluespaceEffect(EntityUid uid, BluespaceLockerComponent component)
|
||||
public void BluespaceEffect(EntityUid effectTargetUid, BluespaceLockerComponent effectSourceComponent, BluespaceLockerComponent? effectTargetComponent, bool bypassLimit = false)
|
||||
{
|
||||
Spawn(component.BehaviorProperties.BluespaceEffectPrototype, uid.ToCoordinates());
|
||||
if (!bypassLimit && Resolve(effectTargetUid, ref effectTargetComponent, false))
|
||||
if (effectTargetComponent!.BehaviorProperties.BluespaceEffectMinInterval > 0)
|
||||
{
|
||||
var curTimeTicks = _timing.CurTick.Value;
|
||||
if (curTimeTicks < effectTargetComponent.BluespaceEffectNextTime)
|
||||
return;
|
||||
|
||||
effectTargetComponent.BluespaceEffectNextTime = curTimeTicks + (uint) (_timing.TickRate * effectTargetComponent.BehaviorProperties.BluespaceEffectMinInterval);
|
||||
}
|
||||
|
||||
Spawn(effectSourceComponent.BehaviorProperties.BluespaceEffectPrototype, effectTargetUid.ToCoordinates());
|
||||
}
|
||||
|
||||
private void PreOpen(EntityUid uid, BluespaceLockerComponent component, StorageBeforeOpenEvent args)
|
||||
{
|
||||
EntityStorageComponent? entityStorageComponent = null;
|
||||
int transportedEntities = 0;
|
||||
|
||||
if (!Resolve(uid, ref entityStorageComponent))
|
||||
return;
|
||||
|
||||
component.CancelToken?.Cancel();
|
||||
if (component.CancelToken != null)
|
||||
{
|
||||
component.CancelToken.Cancel();
|
||||
component.CancelToken = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.BehaviorProperties.ActOnOpen)
|
||||
return;
|
||||
|
||||
// Select target
|
||||
var target = GetTarget(uid, component);
|
||||
@@ -74,11 +94,17 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
{
|
||||
if (EntityManager.HasComponent<MindComponent>(entity))
|
||||
{
|
||||
if (component.BehaviorProperties.TransportSentient)
|
||||
entityStorageComponent.Contents.Insert(entity, EntityManager);
|
||||
if (!component.BehaviorProperties.TransportSentient)
|
||||
continue;
|
||||
|
||||
entityStorageComponent.Contents.Insert(entity, EntityManager);
|
||||
transportedEntities++;
|
||||
}
|
||||
else if (component.BehaviorProperties.TransportEntities)
|
||||
{
|
||||
entityStorageComponent.Contents.Insert(entity, EntityManager);
|
||||
transportedEntities++;
|
||||
}
|
||||
}
|
||||
|
||||
// Move contained air
|
||||
@@ -90,17 +116,28 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
|
||||
// Bluespace effects
|
||||
if (component.BehaviorProperties.BluespaceEffectOnTeleportSource)
|
||||
BluespaceEffect(target.Value.uid, component);
|
||||
BluespaceEffect(target.Value.uid, component, target.Value.bluespaceLockerComponent);
|
||||
if (component.BehaviorProperties.BluespaceEffectOnTeleportTarget)
|
||||
BluespaceEffect(uid, component);
|
||||
BluespaceEffect(uid, component, component);
|
||||
}
|
||||
|
||||
DestroyAfterLimit(uid, component);
|
||||
DestroyAfterLimit(uid, component, transportedEntities);
|
||||
}
|
||||
|
||||
private bool ValidLink(EntityUid locker, EntityUid link, BluespaceLockerComponent lockerComponent)
|
||||
private bool ValidLink(EntityUid locker, EntityUid link, BluespaceLockerComponent lockerComponent, bool intendToLink = false)
|
||||
{
|
||||
return link.Valid && TryComp<EntityStorageComponent>(link, out var linkStorage) && linkStorage.LifeStage != ComponentLifeStage.Deleted && link != locker;
|
||||
if (!link.Valid ||
|
||||
!TryComp<EntityStorageComponent>(link, out var linkStorage) ||
|
||||
linkStorage.LifeStage == ComponentLifeStage.Deleted ||
|
||||
link == locker)
|
||||
return false;
|
||||
|
||||
if (lockerComponent.BehaviorProperties.InvalidateOneWayLinks &&
|
||||
!(intendToLink && lockerComponent.AutoLinksBidirectional) &&
|
||||
!(HasComp<BluespaceLockerComponent>(link) && Comp<BluespaceLockerComponent>(link).BluespaceLinks.Contains(locker)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <returns>True if any HashSet in <paramref name="a"/> would grant access to <paramref name="b"/></returns>
|
||||
@@ -120,15 +157,15 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
|
||||
private bool ValidAutolink(EntityUid locker, EntityUid link, BluespaceLockerComponent lockerComponent)
|
||||
{
|
||||
if (!ValidLink(locker, link, lockerComponent))
|
||||
if (!ValidLink(locker, link, lockerComponent, true))
|
||||
return false;
|
||||
|
||||
if (lockerComponent.PickLinksFromSameMap &&
|
||||
link.ToCoordinates().GetMapId(_entityManager) != locker.ToCoordinates().GetMapId(_entityManager))
|
||||
link.ToCoordinates().GetMapId(EntityManager) != locker.ToCoordinates().GetMapId(EntityManager))
|
||||
return false;
|
||||
|
||||
if (lockerComponent.PickLinksFromStationGrids &&
|
||||
!HasComp<StationMemberComponent>(link.ToCoordinates().GetGridUid(_entityManager)))
|
||||
!HasComp<StationMemberComponent>(link.ToCoordinates().GetGridUid(EntityManager)))
|
||||
return false;
|
||||
|
||||
if (lockerComponent.PickLinksFromResistLockers &&
|
||||
@@ -157,7 +194,7 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
return true;
|
||||
}
|
||||
|
||||
private (EntityUid uid, EntityStorageComponent storageComponent, BluespaceLockerComponent? bluespaceLockerComponent)? GetTarget(EntityUid lockerUid, BluespaceLockerComponent component)
|
||||
public (EntityUid uid, EntityStorageComponent storageComponent, BluespaceLockerComponent? bluespaceLockerComponent)? GetTarget(EntityUid lockerUid, BluespaceLockerComponent component)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@@ -179,13 +216,26 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
component.BluespaceLinks.Add(potentialLink);
|
||||
if (component.AutoLinksBidirectional || component.AutoLinksUseProperties)
|
||||
{
|
||||
var targetBluespaceComponent = EnsureComp<BluespaceLockerComponent>(potentialLink);
|
||||
var targetBluespaceComponent = CompOrNull<BluespaceLockerComponent>(potentialLink);
|
||||
|
||||
if (component.AutoLinksBidirectional)
|
||||
if (targetBluespaceComponent == null)
|
||||
{
|
||||
using var compInitializeHandle =
|
||||
EntityManager.AddComponentUninitialized<BluespaceLockerComponent>(potentialLink);
|
||||
targetBluespaceComponent = compInitializeHandle.Comp;
|
||||
|
||||
if (component.AutoLinksBidirectional)
|
||||
targetBluespaceComponent.BluespaceLinks.Add(lockerUid);
|
||||
|
||||
if (component.AutoLinksUseProperties)
|
||||
targetBluespaceComponent.BehaviorProperties = component.AutoLinkProperties with {};
|
||||
|
||||
compInitializeHandle.Dispose();
|
||||
}
|
||||
else if (component.AutoLinksBidirectional)
|
||||
{
|
||||
targetBluespaceComponent.BluespaceLinks.Add(lockerUid);
|
||||
|
||||
if (component.AutoLinksUseProperties)
|
||||
targetBluespaceComponent.BehaviorProperties = component.AutoLinkProperties with {};
|
||||
}
|
||||
}
|
||||
if (component.BluespaceLinks.Count >= component.MinBluespaceLinks)
|
||||
break;
|
||||
@@ -194,7 +244,12 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
|
||||
// If there are no possible link targets and no links, return null
|
||||
if (component.BluespaceLinks.Count == 0)
|
||||
{
|
||||
if (component.MinBluespaceLinks == 0)
|
||||
RemComp<BluespaceLockerComponent>(lockerUid);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Attempt to select, validate, and return a link
|
||||
var links = component.BluespaceLinks.ToArray();
|
||||
@@ -218,12 +273,16 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
private void PostClose(EntityUid uid, BluespaceLockerComponent component, bool doDelay = true)
|
||||
{
|
||||
EntityStorageComponent? entityStorageComponent = null;
|
||||
int transportedEntities = 0;
|
||||
|
||||
if (!Resolve(uid, ref entityStorageComponent))
|
||||
return;
|
||||
|
||||
component.CancelToken?.Cancel();
|
||||
|
||||
if (!component.BehaviorProperties.ActOnClose)
|
||||
return;
|
||||
|
||||
// Do delay
|
||||
if (doDelay && component.BehaviorProperties.Delay > 0)
|
||||
{
|
||||
@@ -249,11 +308,17 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
{
|
||||
if (EntityManager.HasComponent<MindComponent>(entity))
|
||||
{
|
||||
if (component.BehaviorProperties.TransportSentient)
|
||||
target.Value.storageComponent.Contents.Insert(entity, EntityManager);
|
||||
if (!component.BehaviorProperties.TransportSentient)
|
||||
continue;
|
||||
|
||||
target.Value.storageComponent.Contents.Insert(entity, EntityManager);
|
||||
transportedEntities++;
|
||||
}
|
||||
else if (component.BehaviorProperties.TransportEntities)
|
||||
{
|
||||
target.Value.storageComponent.Contents.Insert(entity, EntityManager);
|
||||
transportedEntities++;
|
||||
}
|
||||
}
|
||||
|
||||
// Move contained air
|
||||
@@ -287,20 +352,27 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
|
||||
// Bluespace effects
|
||||
if (component.BehaviorProperties.BluespaceEffectOnTeleportSource)
|
||||
BluespaceEffect(uid, component);
|
||||
BluespaceEffect(uid, component, component);
|
||||
if (component.BehaviorProperties.BluespaceEffectOnTeleportTarget)
|
||||
BluespaceEffect(target.Value.uid, component);
|
||||
BluespaceEffect(target.Value.uid, component, target.Value.bluespaceLockerComponent);
|
||||
|
||||
DestroyAfterLimit(uid, component);
|
||||
DestroyAfterLimit(uid, component, transportedEntities);
|
||||
}
|
||||
|
||||
private void DestroyAfterLimit(EntityUid uid, BluespaceLockerComponent component)
|
||||
private void DestroyAfterLimit(EntityUid uid, BluespaceLockerComponent component, int transportedEntities)
|
||||
{
|
||||
if (component.BehaviorProperties.DestroyAfterUsesMinItemsToCountUse > transportedEntities)
|
||||
return;
|
||||
|
||||
if (component.BehaviorProperties.ClearLinksEvery != -1)
|
||||
{
|
||||
component.UsesSinceLinkClear++;
|
||||
if (component.BehaviorProperties.ClearLinksEvery >= component.UsesSinceLinkClear)
|
||||
if (component.BehaviorProperties.ClearLinksEvery <= component.UsesSinceLinkClear)
|
||||
{
|
||||
if (component.BehaviorProperties.ClearLinksDebluespaces)
|
||||
foreach (var link in component.BluespaceLinks)
|
||||
RemComp<BluespaceLockerComponent>(link);
|
||||
|
||||
component.BluespaceLinks.Clear();
|
||||
component.UsesSinceLinkClear = 0;
|
||||
}
|
||||
@@ -316,12 +388,13 @@ public sealed class BluespaceLockerSystem : EntitySystem
|
||||
switch (component.BehaviorProperties.DestroyType)
|
||||
{
|
||||
case BluespaceLockerDestroyType.Explode:
|
||||
_explosionSystem.QueueExplosion(uid.ToCoordinates().ToMap(_entityManager),
|
||||
_explosionSystem.QueueExplosion(uid.ToCoordinates().ToMap(EntityManager),
|
||||
ExplosionSystem.DefaultExplosionPrototypeId, 4, 1, 2, maxTileBreak: 0);
|
||||
goto case BluespaceLockerDestroyType.Delete;
|
||||
case BluespaceLockerDestroyType.Delete:
|
||||
QueueDel(uid);
|
||||
break;
|
||||
default:
|
||||
case BluespaceLockerDestroyType.DeleteComponent:
|
||||
RemComp<BluespaceLockerComponent>(uid);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user