Revert "Salvage 0.1" (#5684)

This commit is contained in:
Paul Ritter
2021-12-03 23:42:38 +01:00
committed by GitHub
parent ae4d47401c
commit e4defccd33
36 changed files with 11 additions and 4812 deletions

View File

@@ -1,70 +0,0 @@
using Content.Shared.Administration;
using Content.Server.Administration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Salvage
{
[AdminCommand(AdminFlags.Admin)]
public class CallSalvageCommand : IConsoleCommand
{
public string Command => "callsalvage";
public string Description => "Starts salvage.";
public string Help => "Usage: callsalvage";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 0)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
shell.WriteLine(EntitySystem.Get<SalvageSystem>().CallSalvage());
}
}
[AdminCommand(AdminFlags.Admin)]
public class RecallSalvageCommand : IConsoleCommand
{
public string Command => "recallsalvage";
public string Description => "Forcibly recalls salvage.";
public string Help => "Usage: recallsalvage";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 0)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
shell.WriteLine(EntitySystem.Get<SalvageSystem>().ReturnSalvage());
}
}
[AdminCommand(AdminFlags.Admin)]
public class RecallSalvageNowCommand : IConsoleCommand
{
public string Command => "recallsalvagefinishnow";
public string Description => "Forcibly stops salvage immediately (will delete - good for testing).";
public string Help => "Usage: recallsalvagefinishnow";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 0)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var salvageSystem = EntitySystem.Get<SalvageSystem>();
if ((salvageSystem.State != SalvageSystemState.Active) && (salvageSystem.State != SalvageSystemState.LettingGo))
{
shell.WriteError("Incorrect state (must be in active or letting-go state)");
return;
}
salvageSystem.DeleteSalvage();
}
}
}

View File

@@ -1,33 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.NodeContainer.NodeGroups;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Examine;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.Salvage
{
/// <summary>
/// Mmmm, salvage
/// To be clear, this component is SUPPOSED to later handle magnet attraction.
/// </summary>
[RegisterComponent]
[ComponentProtoName("Salvage")]
public class SalvageComponent : Component
{
/// <summary>
/// Set this when salvage is no longer held by the magnet.
/// This starts the countdown to complete destruction.
/// </summary>
[ViewVariables] public bool Killswitch = false;
/// <summary>
/// Time killswitch has been active for.
/// </summary>
[ViewVariables] public float KillswitchTime = 0.0f;
}
}

View File

@@ -1,30 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Server.NodeContainer.NodeGroups;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Examine;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Robust.Shared.Maths;
namespace Content.Server.Salvage
{
/// <summary>
/// A salvage magnet.
/// </summary>
[RegisterComponent]
[ComponentProtoName("SalvageMagnet")]
public class SalvageMagnetComponent : Component
{
/// <summary>
/// Offset relative to magnet that salvage should spawn.
/// Keep in sync with marker sprite (if any???)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("offset")]
public Vector2 Offset = Vector2.Zero;
}
}

View File

@@ -1,38 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Objectives.Interfaces;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Salvage
{
[Prototype("salvageMap")]
public class SalvageMapPrototype : IPrototype
{
[ViewVariables]
[DataField("id", required: true)]
public string ID { get; } = default!;
/// <summary>
/// Relative directory path to the given map, i.e. `Maps/Salvage/test.yml`
/// </summary>
[ViewVariables]
[DataField("mapPath", required: true)]
public string MapPath { get; } = default!;
/// <summary>
/// Size *from 0,0* in units of the map (used to determine if it fits)
/// </summary>
[ViewVariables]
[DataField("size", required: true)]
public float Size { get; } = 1.0f;
/// <summary>
/// Name for admin use
/// </summary>
[ViewVariables]
[DataField("name")]
public string Name { get; } = "";
}
}

View File

@@ -1,310 +0,0 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking;
using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.GameTicking;
using Content.Shared.Interaction;
using Content.Shared.Hands.Components;
using Content.Shared.Popups;
using Robust.Server.Player;
using Robust.Server.Maps;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
namespace Content.Server.Salvage
{
public class SalvageSystem : EntitySystem
{
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IMapLoader _mapLoader = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[ViewVariables]
public EntityUid PulledObject = EntityUid.Invalid;
[ViewVariables]
public SalvageSystemState State = SalvageSystemState.Inactive;
[ViewVariables]
public float StateTimer = 0.0f;
public const float PullInTimer = 2.0f;
public const float HoldTimer = 240.0f;
public const float LeaveTimer = 60.0f;
public const float AngularVelocityRangeRadians = 0.25f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<SalvageMagnetComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<SalvageMagnetComponent, ExaminedEvent>(OnExamined);
}
private void OnExamined(EntityUid uid, SalvageMagnetComponent comp, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
switch (State)
{
case SalvageSystemState.Inactive:
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-inactive"));
break;
case SalvageSystemState.PullingIn:
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-pulling-in"));
break;
case SalvageSystemState.Active:
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-active", ("timeLeft", Math.Floor(StateTimer))));
break;
case SalvageSystemState.LettingGo:
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-letting-go"));
break;
}
}
private void Reset(RoundRestartCleanupEvent ev)
{
PulledObject = EntityUid.Invalid;
State = SalvageSystemState.Inactive;
StateTimer = 0.0f;
}
private void OnInteractHand(EntityUid uid, SalvageMagnetComponent sm, InteractHandEvent args)
{
if (args.Handled)
return;
args.Handled = true;
_popupSystem.PopupEntity(CallSalvage(), uid, Filter.Entities(args.User.Uid));
}
private bool TryGetSalvagePlacementLocation(out MapCoordinates coords, out Angle angle)
{
coords = MapCoordinates.Nullspace;
angle = Angle.Zero;
foreach (var (smc, tsc) in EntityManager.EntityQuery<SalvageMagnetComponent, TransformComponent>(true))
{
coords = new EntityCoordinates(smc.OwnerUid, smc.Offset).ToMap(EntityManager);
var grid = tsc.GridID;
if (grid != GridId.Invalid)
{
// Has a valid grid - synchronize angle so that salvage doesn't have to deal with cross-grid manipulation issues
angle = _mapManager.GetGrid(grid).WorldRotation;
}
return true;
}
return false;
}
private IEnumerable<SalvageMapPrototype> GetAllSalvageMaps()
{
return _prototypeManager.EnumeratePrototypes<SalvageMapPrototype>();
}
// String is announced
private string SpawnSalvage()
{
// In case of failure
State = SalvageSystemState.Inactive;
if (!TryGetSalvagePlacementLocation(out var spl, out var spAngle))
{
return Loc.GetString("salvage-system-announcement-spawn-magnet-lost");
}
SalvageMapPrototype? map = null;
var forcedSalvage = _configurationManager.GetCVar<string>(CCVars.SalvageForced);
List<SalvageMapPrototype> allSalvageMaps;
if (string.IsNullOrWhiteSpace(forcedSalvage))
{
allSalvageMaps = GetAllSalvageMaps().ToList();
}
else
{
allSalvageMaps = new();
if (_prototypeManager.TryIndex<SalvageMapPrototype>(forcedSalvage, out map))
{
allSalvageMaps.Add(map);
}
else
{
Logger.ErrorS("c.s.salvage", $"Unable to get forced salvage map prototype {forcedSalvage}");
}
}
for (var i = 0; i < allSalvageMaps.Count; i++)
{
map = _random.PickAndTake(allSalvageMaps);
var box2 = Box2.CenteredAround(spl.Position, new Vector2(map.Size * 2.0f, map.Size * 2.0f));
var box2rot = new Box2Rotated(box2, spAngle, spl.Position);
if (_physicsSystem.GetCollidingEntities(spl.MapId, in box2rot).Select(x => EntityManager.HasComponent<IMapGridComponent>(x.OwnerUid)).Count() > 0)
{
// collided: set map to null so we don't spawn it
map = null;
}
else
{
break;
}
}
if (map == null)
{
return Loc.GetString("salvage-system-announcement-spawn-no-debris-available");
}
var bp = _mapLoader.LoadBlueprint(spl.MapId, map.MapPath);
if (bp == null)
{
return Loc.GetString("salvage-system-announcement-spawn-debris-disintegrated");
}
PulledObject = bp.GridEntityId;
EntityManager.AddComponent<SalvageComponent>(PulledObject);
var pulledTransform = EntityManager.GetComponent<TransformComponent>(PulledObject);
pulledTransform.Coordinates = EntityCoordinates.FromMap(_mapManager, spl);
pulledTransform.WorldRotation = spAngle;
// Alright, salvage magnet is active.
State = SalvageSystemState.Active;
StateTimer = HoldTimer;
return Loc.GetString("salvage-system-announcement-arrived", ("timeLeft", StateTimer));
}
private void PulledObjectDeathOrCaptureMonitor()
{
// This code runs in Active and LettingGo states.
// It catches the situation when the pulled object is deleted by the killswitch,
// and the situation when the salvage component is removed by admin intervention (officially a "capture")
if (!EntityManager.EntityExists(PulledObject))
{
State = SalvageSystemState.Inactive;
PulledObject = EntityUid.Invalid;
_chatManager.DispatchStationAnnouncement(Loc.GetString("salvage-system-announcement-lost"), Loc.GetString("salvage-system-announcement-source"));
}
else if (!EntityManager.HasComponent<SalvageComponent>(PulledObject))
{
State = SalvageSystemState.Inactive;
PulledObject = EntityUid.Invalid;
_chatManager.DispatchStationAnnouncement(Loc.GetString("salvage-system-announcement-captured"), Loc.GetString("salvage-system-announcement-source"));
}
}
public override void Update(float frameTime)
{
switch (State)
{
case SalvageSystemState.Inactive:
break;
case SalvageSystemState.PullingIn:
StateTimer -= frameTime;
if (StateTimer <= 0.0f)
{
string report = SpawnSalvage();
_chatManager.DispatchStationAnnouncement(report, Loc.GetString("salvage-system-announcement-source"));
}
break;
case SalvageSystemState.Active:
// magnet power usage = base + (time² * factor)
// write base and factor into prototype!!!
// also determine if magnet is unpowered and if so auto-lose???
// CURRENTLY:
StateTimer -= frameTime;
if (StateTimer <= 0.0f)
{
ReturnSalvage();
}
PulledObjectDeathOrCaptureMonitor();
break;
case SalvageSystemState.LettingGo:
PulledObjectDeathOrCaptureMonitor();
break;
}
foreach (var smc in EntityManager.EntityQuery<SalvageComponent>(true))
{
if (smc.Killswitch)
{
smc.KillswitchTime += frameTime;
if (smc.KillswitchTime >= LeaveTimer)
{
EntityManager.QueueDeleteEntity(smc.OwnerUid);
}
}
}
}
public string CallSalvage()
{
// State error reports
if (State == SalvageSystemState.LettingGo)
return Loc.GetString("salvage-system-report-cooling-down");
if (State != SalvageSystemState.Inactive)
return Loc.GetString("salvage-system-report-already-active");
// Confirm
State = SalvageSystemState.PullingIn;
StateTimer = PullInTimer;
return Loc.GetString("salvage-system-report-activate-success");
}
public string ReturnSalvage()
{
if (State != SalvageSystemState.Active)
return Loc.GetString("salvage-system-report-not-active");
// Confirm
State = SalvageSystemState.LettingGo;
// Enable killswitch, announce, report success
if (EntityManager.TryGetComponent<SalvageComponent>(PulledObject, out var salvage))
{
// Schedule this to auto-delete (and ideally fly away from the station???)
salvage.Killswitch = true;
// Note "losing" is only given on killswitch activation.
// The capture message will be given instead if the salvage component is missing.
_chatManager.DispatchStationAnnouncement(Loc.GetString("salvage-system-announcement-losing", ("timeLeft", LeaveTimer)), Loc.GetString("salvage-system-announcement-source"));
}
return Loc.GetString("salvage-system-report-deactivate-success");
}
public void DeleteSalvage()
{
if ((State != SalvageSystemState.Active) && (State != SalvageSystemState.LettingGo))
return;
EntityManager.QueueDeleteEntity(PulledObject);
}
}
public enum SalvageSystemState
{
Inactive,
PullingIn, // Timer: Time left to completion
Active, // Timer: Time left to letting go
LettingGo
}
}