80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Content.Shared.Shuttles.Components;
|
|
using Content.Shared.Procedural;
|
|
using Content.Shared.Salvage.Expeditions;
|
|
using Content.Shared.Dataset;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Salvage;
|
|
|
|
public sealed partial class SalvageSystem
|
|
{
|
|
public static readonly EntProtoId CoordinatesDisk = "CoordinatesDisk";
|
|
public static readonly ProtoId<LocalizedDatasetPrototype> PlanetNames = "NamesBorer";
|
|
|
|
private void OnSalvageClaimMessage(EntityUid uid, SalvageExpeditionConsoleComponent component, ClaimSalvageMessage args)
|
|
{
|
|
var station = _station.GetOwningStation(uid);
|
|
|
|
if (!TryComp<SalvageExpeditionDataComponent>(station, out var data) || data.Claimed)
|
|
return;
|
|
|
|
if (!data.Missions.TryGetValue(args.Index, out var missionparams))
|
|
return;
|
|
|
|
var cdUid = Spawn(CoordinatesDisk, Transform(uid).Coordinates);
|
|
SpawnMission(missionparams, station.Value, cdUid);
|
|
|
|
data.ActiveMission = args.Index;
|
|
var mission = GetMission(_prototypeManager.Index<SalvageDifficultyPrototype>(missionparams.Difficulty), missionparams.Seed);
|
|
data.NextOffer = _timing.CurTime + mission.Duration + TimeSpan.FromSeconds(1);
|
|
|
|
_labelSystem.Label(cdUid, GetFTLName(_prototypeManager.Index(PlanetNames), missionparams.Seed));
|
|
_audio.PlayPvs(component.PrintSound, uid);
|
|
|
|
UpdateConsoles((station.Value, data));
|
|
}
|
|
|
|
private void OnSalvageConsoleInit(Entity<SalvageExpeditionConsoleComponent> console, ref ComponentInit args)
|
|
{
|
|
UpdateConsole(console);
|
|
}
|
|
|
|
private void OnSalvageConsoleParent(Entity<SalvageExpeditionConsoleComponent> console, ref EntParentChangedMessage args)
|
|
{
|
|
UpdateConsole(console);
|
|
}
|
|
|
|
private void UpdateConsoles(Entity<SalvageExpeditionDataComponent> component)
|
|
{
|
|
var state = GetState(component);
|
|
|
|
var query = AllEntityQuery<SalvageExpeditionConsoleComponent, UserInterfaceComponent, TransformComponent>();
|
|
while (query.MoveNext(out var uid, out _, out var uiComp, out var xform))
|
|
{
|
|
var station = _station.GetOwningStation(uid, xform);
|
|
|
|
if (station != component.Owner)
|
|
continue;
|
|
|
|
_ui.SetUiState((uid, uiComp), SalvageConsoleUiKey.Expedition, state);
|
|
}
|
|
}
|
|
|
|
private void UpdateConsole(Entity<SalvageExpeditionConsoleComponent> component)
|
|
{
|
|
var station = _station.GetOwningStation(component);
|
|
SalvageExpeditionConsoleState state;
|
|
|
|
if (TryComp<SalvageExpeditionDataComponent>(station, out var dataComponent))
|
|
{
|
|
state = GetState(dataComponent);
|
|
}
|
|
else
|
|
{
|
|
state = new SalvageExpeditionConsoleState(TimeSpan.Zero, false, true, 0, new List<SalvageMissionParams>());
|
|
}
|
|
|
|
_ui.SetUiState(component.Owner, SalvageConsoleUiKey.Expedition, state);
|
|
}
|
|
}
|