Expeditions QOL (#15599)

This commit is contained in:
metalgearsloth
2023-04-21 15:05:50 +10:00
committed by GitHub
parent e780c6a98a
commit 0ebcba370f
7 changed files with 76 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ using System.Linq;
using Content.Client.Computer;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Content.Shared.Parallax.Biomes;
using Content.Shared.Procedural.Loot;
using Content.Shared.Salvage;
@@ -12,6 +13,7 @@ using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
@@ -21,6 +23,7 @@ namespace Content.Client.Salvage.UI;
public sealed partial class SalvageExpeditionWindow : FancyWindow,
IComputerWindow<EmergencyConsoleBoundUserInterfaceState>
{
private readonly IConfigurationManager _cfgManager;
private readonly IGameTiming _timing;
private readonly IPrototypeManager _prototype;
private readonly SharedSalvageSystem _salvage;
@@ -33,6 +36,7 @@ public sealed partial class SalvageExpeditionWindow : FancyWindow,
public SalvageExpeditionWindow()
{
RobustXamlLoader.Load(this);
_cfgManager = IoCManager.Resolve<IConfigurationManager>();
_timing = IoCManager.Resolve<IGameTiming>();
_prototype = IoCManager.Resolve<IPrototypeManager>();
_salvage = IoCManager.Resolve<IEntityManager>().EntitySysManager.GetEntitySystem<SharedSalvageSystem>();
@@ -80,7 +84,7 @@ public sealed partial class SalvageExpeditionWindow : FancyWindow,
switch (missionParams.Difficulty)
{
case DifficultyRating.None:
case DifficultyRating.Minimal:
difficultyColor = Color.FromHex("#52B4E996");
break;
case DifficultyRating.Minor:
@@ -287,8 +291,8 @@ public sealed partial class SalvageExpeditionWindow : FancyWindow,
else
{
var cooldown = _cooldown
? SharedSalvageSystem.MissionFailedCooldown
: SharedSalvageSystem.MissionCooldown;
? TimeSpan.FromSeconds(_cfgManager.GetCVar(CCVars.SalvageExpeditionFailedCooldown))
: TimeSpan.FromSeconds(_cfgManager.GetCVar(CCVars.SalvageExpeditionCooldown));
NextOfferBar.Value = 1f - (float) (remaining / cooldown);
NextOfferText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";

View File

@@ -5,6 +5,7 @@ using Content.Server.CPUJob.JobQueues.Queues;
using Content.Server.Salvage.Expeditions;
using Content.Server.Salvage.Expeditions.Structure;
using Content.Server.Station.Systems;
using Content.Shared.CCVar;
using Content.Shared.Examine;
using Content.Shared.Salvage;
@@ -22,6 +23,9 @@ public sealed partial class SalvageSystem
private readonly List<(SpawnSalvageMissionJob Job, CancellationTokenSource CancelToken)> _salvageJobs = new();
private const double SalvageJobTime = 0.002;
private float _cooldown;
private float _failedCooldown;
private void InitializeExpeditions()
{
SubscribeLocalEvent<StationInitializedEvent>(OnSalvageExpStationInit);
@@ -36,6 +40,46 @@ public sealed partial class SalvageSystem
SubscribeLocalEvent<SalvageExpeditionComponent, EntityUnpausedEvent>(OnExpeditionUnpaused);
SubscribeLocalEvent<SalvageStructureComponent, ExaminedEvent>(OnStructureExamine);
_cooldown = _configurationManager.GetCVar(CCVars.SalvageExpeditionCooldown);
_failedCooldown = _configurationManager.GetCVar(CCVars.SalvageExpeditionFailedCooldown);
_configurationManager.OnValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange);
_configurationManager.OnValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange);
}
private void ShutdownExpeditions()
{
_configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange);
_configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange);
}
private void SetCooldownChange(float obj)
{
// Update the active cooldowns if we change it.
var diff = obj - _cooldown;
var query = AllEntityQuery<SalvageExpeditionDataComponent>();
while (query.MoveNext(out var comp))
{
comp.NextOffer += TimeSpan.FromSeconds(diff);
}
_cooldown = obj;
}
private void SetFailedCooldownChange(float obj)
{
var diff = obj - _failedCooldown;
var query = AllEntityQuery<SalvageExpeditionDataComponent>();
while (query.MoveNext(out var comp))
{
comp.NextOffer += TimeSpan.FromSeconds(diff);
}
_failedCooldown = obj;
}
private void OnExpeditionShutdown(EntityUid uid, SalvageExpeditionComponent component, ComponentShutdown args)
@@ -96,7 +140,7 @@ public sealed partial class SalvageSystem
continue;
comp.Cooldown = false;
comp.NextOffer += MissionCooldown;
comp.NextOffer += TimeSpan.FromSeconds(_cooldown);
GenerateMissions(comp);
UpdateConsoles(comp);
}
@@ -144,13 +188,13 @@ public sealed partial class SalvageSystem
if (expedition.Completed)
{
_sawmill.Debug($"Completed mission {expedition.MissionParams.MissionType} with seed {expedition.MissionParams.Seed}");
component.NextOffer = _timing.CurTime + MissionCooldown;
component.NextOffer = _timing.CurTime + TimeSpan.FromSeconds(_cooldown);
Announce(expedition.Owner, Loc.GetString("salvage-expedition-mission-completed"));
}
else
{
_sawmill.Debug($"Failed mission {expedition.MissionParams.MissionType} with seed {expedition.MissionParams.Seed}");
component.NextOffer = _timing.CurTime + MissionFailedCooldown;
component.NextOffer = _timing.CurTime + TimeSpan.FromSeconds(_failedCooldown);
Announce(expedition.Owner, Loc.GetString("salvage-expedition-mission-failed"));
}

View File

@@ -71,6 +71,12 @@ namespace Content.Server.Salvage
InitializeRunner();
}
public override void Shutdown()
{
base.Shutdown();
ShutdownExpeditions();
}
private void OnRoundEnd(GameRunLevelChangedEvent ev)
{
if(ev.New != GameRunLevel.InRound)

View File

@@ -1328,8 +1328,16 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<string>
SalvageForced = CVarDef.Create("salvage.forced", "", CVar.SERVERONLY);
/*
/// <summary>
/// Cooldown for successful missions.
/// </summary>
public static readonly CVarDef<float>
SalvageExpeditionCooldown = CVarDef.Create("salvage.expedition_cooldown", 300f, CVar.REPLICATED);
public static readonly CVarDef<float>
SalvageExpeditionFailedCooldown = CVarDef.Create("salvage.expedition_failed_cooldown", 900f, CVar.REPLICATED);
/*
* Flavor
*/

View File

@@ -17,9 +17,6 @@ public abstract class SharedSalvageSystem : EntitySystem
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
public static readonly TimeSpan MissionCooldown = TimeSpan.FromMinutes(5);
public static readonly TimeSpan MissionFailedCooldown = TimeSpan.FromMinutes(15);
#region Descriptions
public string GetMissionDescription(SalvageMission mission)
@@ -60,7 +57,7 @@ public abstract class SharedSalvageSystem : EntitySystem
{
switch (rating)
{
case DifficultyRating.None:
case DifficultyRating.Minimal:
return 1;
case DifficultyRating.Minor:
return 2;
@@ -227,7 +224,7 @@ public enum SalvageMissionType : byte
[Serializable, NetSerializable]
public enum DifficultyRating : byte
{
None,
Minimal,
Minor,
Moderate,
Hazardous,

View File

@@ -11,6 +11,10 @@ grid_splitting = false
[procgen]
preload = false
[salvage]
expedition_cooldown = 30.0
expedition_failed_cooldown = 30.0
[shuttle]
# Wastes startup time
auto_call_time = 0

View File

@@ -23,7 +23,7 @@ salvage-expedition-desc-structure = Destroy {$count} {$structure} inside the are
salvage-expedition-type-Mining = Mining
salvage-expedition-type-Destruction = Destruction
salvage-expedition-difficulty-None = None
salvage-expedition-difficulty-None = Minimal
salvage-expedition-difficulty-Minor = Minor
salvage-expedition-difficulty-Moderate = Moderate
salvage-expedition-difficulty-Hazardous = Hazardous