Cargo Telepad (#2579)

* Cargo telepad

* fixes error

* more efficient tile lookup

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
GraniteSidewalk
2020-12-18 20:14:26 -06:00
committed by GitHub
parent 185923a7da
commit 89f8d0f34c
13 changed files with 262 additions and 53 deletions

View File

@@ -1,4 +1,4 @@
namespace Content.Client
namespace Content.Client
{
public static class IgnoredComponents
{
@@ -225,7 +225,8 @@
"MachineFrame",
"MachineBoard",
"ChemicalAmmo",
"BiologicalSurgeryData"
"BiologicalSurgeryData",
"CargoTelepad",
};
}
}

View File

@@ -109,7 +109,8 @@ namespace Content.Client.UserInterface.Cargo
var buttons = new HBoxContainer();
CallShuttleButton = new Button()
{
Text = Loc.GetString("Call Shuttle"),
//Text = Loc.GetString("Call Shuttle"),
Text = Loc.GetString("Activate Telepad"), //Shuttle code pending
TextAlign = Label.AlignMode.Center,
SizeFlagsHorizontal = SizeFlags.FillExpand
};

View File

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using Content.Server.Cargo;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems;
@@ -10,10 +10,15 @@ using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Collections.Generic;
using System.Linq;
namespace Content.Server.GameObjects.Components.Cargo
{
@@ -22,6 +27,7 @@ namespace Content.Server.GameObjects.Components.Cargo
public class CargoConsoleComponent : SharedCargoConsoleComponent, IActivate
{
[Dependency] private readonly ICargoOrderDataManager _cargoOrderDataManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[ViewVariables]
public int Points = 1000;
@@ -149,19 +155,48 @@ namespace Content.Server.GameObjects.Components.Cargo
break;
}
case CargoConsoleShuttleMessage _:
{
//var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(orders.Database);
//orders.Database.ClearOrderCapacity();
// TODO replace with shuttle code
// TEMPORARY loop for spawning stuff on telepad (looks for a telepad adjacent to the console)
IEntity? cargoTelepad = null;
var indices = Owner.Transform.Coordinates.ToVector2i(Owner.EntityManager, _mapManager);
var offsets = new Vector2i[] { new Vector2i(0, 1), new Vector2i(1, 1), new Vector2i(1, 0), new Vector2i(1, -1),
new Vector2i(0, -1), new Vector2i(-1, -1), new Vector2i(-1, 0), new Vector2i(-1, 1), };
var adjacentEntities = new List<IEnumerable<IEntity>>(); //Probably better than IEnumerable.concat
foreach (var offset in offsets)
{
adjacentEntities.Add((indices+offset).GetEntitiesInTileFast(Owner.Transform.GridID));
}
foreach (var enumerator in adjacentEntities)
{
foreach (IEntity entity in enumerator)
{
if (entity.HasComponent<CargoTelepadComponent>() && entity.TryGetComponent<PowerReceiverComponent>(out var powerReceiver) && powerReceiver.Powered)
{
cargoTelepad = entity;
break;
}
}
}
if (cargoTelepad != null)
{
if (cargoTelepad.TryGetComponent<CargoTelepadComponent>(out var telepadComponent))
{
var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(orders.Database);
orders.Database.ClearOrderCapacity();
// TODO replace with shuttle code
// TEMPORARY loop for spawning stuff on top of console
foreach (var order in approvedOrders)
{
if (!PrototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product))
continue;
for (var i = 0; i < order.Amount; i++)
{
Owner.EntityManager.SpawnEntity(product.Product, Owner.Transform.Coordinates);
telepadComponent.QueueTeleport(product);
}
}
}
}
break;

View File

@@ -0,0 +1,101 @@
#nullable enable
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Prototypes.Cargo;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using System.Collections.Generic;
namespace Content.Server.GameObjects.Components.Cargo
{
//This entire class is a PLACEHOLDER for the cargo shuttle.
[RegisterComponent]
public class CargoTelepadComponent : Component
{
public override string Name => "CargoTelepad";
private const float TeleportDuration = 0.5f;
private const float TeleportDelay = 15f;
private List<CargoProductPrototype> _teleportQueue = new List<CargoProductPrototype>();
private CargoTelepadState _currentState = CargoTelepadState.Unpowered;
public override void OnAdd()
{
base.OnAdd();
var receiver = Owner.EnsureComponent<PowerReceiverComponent>();
receiver.OnPowerStateChanged += PowerUpdate;
}
public override void OnRemove()
{
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
receiver.OnPowerStateChanged -= PowerUpdate;
}
base.OnRemove();
}
public void QueueTeleport(CargoProductPrototype product)
{
_teleportQueue.Add(product);
TeleportLoop();
}
private void PowerUpdate(object? sender, PowerStateEventArgs args)
{
if (args.Powered && _currentState == CargoTelepadState.Unpowered) {
_currentState = CargoTelepadState.Idle;
if(Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
spriteComponent.LayerSetState(0, "pad-idle");
TeleportLoop();
}
else if (!args.Powered)
{
_currentState = CargoTelepadState.Unpowered;
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
spriteComponent.LayerSetState(0, "pad-offline");
}
}
private void TeleportLoop()
{
if (_currentState == CargoTelepadState.Idle && _teleportQueue.Count > 0)
{
_currentState = CargoTelepadState.Charging;
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
spriteComponent.LayerSetState(0, "pad-idle");
Owner.SpawnTimer((int) (TeleportDelay * 1000), () =>
{
if (!Deleted && !Owner.Deleted && _currentState == CargoTelepadState.Charging && _teleportQueue.Count > 0)
{
_currentState = CargoTelepadState.Teleporting;
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
spriteComponent.LayerSetState(0, "pad-beam");
Owner.SpawnTimer((int) (TeleportDuration * 1000), () =>
{
if (!Deleted && !Owner.Deleted && _currentState == CargoTelepadState.Teleporting && _teleportQueue.Count > 0)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/machines/phasein.ogg", Owner, AudioParams.Default.WithVolume(-8f));
Owner.EntityManager.SpawnEntity(_teleportQueue[0].Product, Owner.Transform.Coordinates);
_teleportQueue.RemoveAt(0);
if (Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
spriteComponent.LayerSetState(0, "pad-idle");
_currentState = CargoTelepadState.Idle;
TeleportLoop();
}
});
}
});
}
}
private enum CargoTelepadState { Unpowered, Idle, Charging, Teleporting };
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,26 @@
- type: entity
name: cargo telepad
id: cargoTelepad
description: "Temporary cargo delivery for developing Nanotrasen stations! Warning: destroying this while goods are in transit will lose them forever!"
placement:
mode: SnapgridCenter
components:
- type: Clickable
- type: InteractionOutline
- type: Physics
mass: 25
anchored: true
shapes:
- !type:PhysShapeAabb
bounds: "-0.45, -0.45, 0.00, 0.45"
layer: [ Passable ]
- type: Sprite
sprite: Constructible/Power/cargo_teleporter.rsi
state: pad-offline
- type: Destructible
deadThreshold: 75
resistances: metallicResistances
- type: Anchorable
- type: Pullable
- type: PowerReceiver
- type: CargoTelepad

View File

@@ -0,0 +1,45 @@
{
"version":1,
"size":{
"x":32,
"y":32
},
"license":"CC-BY-SA-3.0",
"copyright":"Taken from /vg/station at commit 5c50dee8fb2a55d6be3b3c9c90a782a618a5506e",
"states":[
{
"name":"pad-beam",
"directions":1,
"delays":[
[
0.1,
0.1,
0.1,
0.1,
0.1
]
]
},
{
"name":"pad-idle",
"directions":1,
"delays":[
[
0.2,
0.2,
0.2,
0.2
]
]
},
{
"name":"pad-offline",
"directions":1,
"delays":[
[
1.0
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B