Skip to content

Commit

Permalink
early finish handler
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Mar 8, 2025
1 parent 1143d12 commit 113943a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 12 deletions.
98 changes: 88 additions & 10 deletions Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
using Content.Server.Station.Components;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Content.Shared.NPC;
using Content.Server._NF.Salvage;
using Content.Shared.NPC.Components;
using Content.Server.Salvage.Expeditions;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.IdentityManagement;

namespace Content.Server.Salvage;

Expand Down Expand Up @@ -40,9 +47,9 @@ private void OnSalvageClaimMessage(EntityUid uid, SalvageExpeditionConsoleCompon

if (activeExpeditionCount >= _configurationManager.GetCVar(NFCCVars.SalvageExpeditionMaxActive))
{
PlayDenySound(uid, component);
PlayDenySound((uid, component));
_popupSystem.PopupEntity(Loc.GetString("shuttle-ftl-too-many"), uid, PopupType.MediumCaution);
UpdateConsoles(station.Value, data);
UpdateConsoles((station.Value, data));
return;
}
// End Frontier
Expand All @@ -60,17 +67,17 @@ private void OnSalvageClaimMessage(EntityUid uid, SalvageExpeditionConsoleCompon
|| _station.GetLargestGrid(stationData) is not { Valid: true } ourGrid
|| !TryComp<MapGridComponent>(ourGrid, out var gridComp))
{
PlayDenySound(uid, component);
PlayDenySound((uid, component));
_popupSystem.PopupEntity(Loc.GetString("shuttle-ftl-invalid"), uid, PopupType.MediumCaution);
UpdateConsoles(station.Value, data);
UpdateConsoles((station.Value, data));
return;
}

if (HasComp<FTLComponent>(ourGrid))
{
PlayDenySound(uid, component);
PlayDenySound((uid, component));
_popupSystem.PopupEntity(Loc.GetString("shuttle-ftl-recharge"), uid, PopupType.MediumCaution);
UpdateConsoles(station.Value, data); // Sure, why not?
UpdateConsoles((station.Value, data));
return;
}

Expand All @@ -88,9 +95,9 @@ private void OnSalvageClaimMessage(EntityUid uid, SalvageExpeditionConsoleCompon
continue;
}

PlayDenySound(uid, component);
PlayDenySound((uid, component));
_popupSystem.PopupEntity(Loc.GetString("shuttle-ftl-proximity"), uid, PopupType.MediumCaution);
UpdateConsoles(station.Value, data);
UpdateConsoles((station.Value, data));
return;
}
}
Expand All @@ -101,12 +108,83 @@ private void OnSalvageClaimMessage(EntityUid uid, SalvageExpeditionConsoleCompon
var mission = GetMission(missionparams.MissionType, _prototypeManager.Index<SalvageDifficultyPrototype>(missionparams.Difficulty), missionparams.Seed); // Frontier: add MissionType
data.NextOffer = _timing.CurTime + mission.Duration + TimeSpan.FromSeconds(1);

_labelSystem.Label(cdUid, GetFTLName(_prototypeManager.Index<LocalizedDatasetPrototype>("NamesBorer"), missionparams.Seed));
_audio.PlayPvs(component.PrintSound, uid);
// _labelSystem.Label(cdUid, GetFTLName(_prototypeManager.Index<LocalizedDatasetPrototype>("NamesBorer"), missionparams.Seed)); // Frontier: no disc
// _audio.PlayPvs(component.PrintSound, uid); // Frontier: no disc

UpdateConsoles((station.Value, data));
}

// Frontier: early expedition end
private void OnSalvageFinishMessage(EntityUid entity, SalvageExpeditionConsoleComponent component, FinishSalvageMessage e)
{
var station = _station.GetOwningStation(entity);
if (!TryComp<SalvageExpeditionDataComponent>(station, out var data) || !data.CanFinish)
return;

// Based on SalvageSystem.Runner:OnConsoleFTLAttempt
if (!TryComp(entity, out TransformComponent? xform)) // Get the console's grid (if you move it, rip you)
{
PlayDenySound((entity, component));
_popupSystem.PopupEntity(Loc.GetString("salvage-expedition-shuttle-not-found"), entity, PopupType.MediumCaution);
UpdateConsoles((station.Value, data));
return;
}

// Frontier: check if any player characters or friendly ghost roles are outside
var query = EntityQueryEnumerator<MindContainerComponent, MobStateComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var mindContainer, out var _, out var mobXform))
{
if (mobXform.MapUid != xform.MapUid)
continue;

// Not player controlled (ghosted)
if (!mindContainer.HasMind)
continue;

// NPC, definitely not a person
if (HasComp<ActiveNPCComponent>(uid) || HasComp<NFSalvageMobRestrictionsComponent>(uid))
continue;

// Hostile ghost role, continue
if (TryComp(uid, out NpcFactionMemberComponent? npcFaction))
{
var hostileFactions = npcFaction.HostileFactions;
if (hostileFactions.Contains("NanoTrasen")) // Nasty - what if we need pirate expeditions?
continue;
}

// Okay they're on salvage, so are they on the shuttle.
if (mobXform.GridUid != xform.GridUid)
{
PlayDenySound((entity, component));
_popupSystem.PopupEntity(Loc.GetString("salvage-expedition-not-everyone-aboard", ("target", Identity.Entity(uid, EntityManager))), entity, PopupType.MediumCaution);
UpdateConsoles((station.Value, data));
return;
}
}
// End SalvageSystem.Runner:OnConsoleFTLAttempt

data.CanFinish = false;
UpdateConsoles((station.Value, data));

var map = Transform(entity).MapUid;

if (!TryComp<SalvageExpeditionComponent>(map, out var expedition))
return;

const int departTime = 20;
var newEndTime = _timing.CurTime + TimeSpan.FromSeconds(departTime);

if (expedition.EndTime <= newEndTime)
return;

expedition.EndTime = newEndTime;
expedition.Stage = ExpeditionStage.FinalCountdown;

Announce(map.Value, Loc.GetString("salvage-expedition-announcement-early-finish", ("departTime", departTime)));
}
// End Frontier: early expedition end

private void OnSalvageConsoleInit(Entity<SalvageExpeditionConsoleComponent> console, ref ComponentInit args)
{
UpdateConsole(console);
Expand Down
5 changes: 4 additions & 1 deletion Content.Server/Salvage/SalvageSystem.Expeditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
using Robust.Shared.Prototypes;
using Content.Server._NF.Salvage; // Frontier
using Content.Shared._NF.CCVar;
using Content.Shared.Salvage; // Frontier
using Content.Shared.Salvage;
using Content.Server._NF.Salvage.Expeditions; // Frontier

namespace Content.Server.Salvage;

Expand All @@ -40,6 +41,8 @@ private void InitializeExpeditions()
SubscribeLocalEvent<SalvageExpeditionConsoleComponent, ComponentInit>(OnSalvageConsoleInit);
SubscribeLocalEvent<SalvageExpeditionConsoleComponent, EntParentChangedMessage>(OnSalvageConsoleParent);
SubscribeLocalEvent<SalvageExpeditionConsoleComponent, ClaimSalvageMessage>(OnSalvageClaimMessage);
SubscribeLocalEvent<SalvageExpeditionDataComponent, ExpeditionSpawnCompleteEvent>(OnExpeditionSpawnComplete); // Frontier: more gracefully handle expedition generation failures
SubscribeLocalEvent<SalvageExpeditionConsoleComponent, FinishSalvageMessage>(OnSalvageFinishMessage); // Frontier: For early finish

SubscribeLocalEvent<SalvageExpeditionComponent, MapInitEvent>(OnExpeditionMapInit);
SubscribeLocalEvent<SalvageExpeditionComponent, ComponentShutdown>(OnExpeditionShutdown);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Salvage/SalvageSystem.Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void OnFTLCompleted(ref FTLCompletedEvent args)
if (TryComp<SalvageExpeditionDataComponent>(component.Station, out var data))
{
data.CanFinish = true;
UpdateConsoles(component.Station, data);
UpdateConsoles((component.Station, data));
}
// End Frontier: early finish

Expand Down

0 comments on commit 113943a

Please sign in to comment.