diff --git a/Content.Client/Salvage/UI/SalvageExpeditionWindow.xaml.cs b/Content.Client/Salvage/UI/SalvageExpeditionWindow.xaml.cs index fb4d6de165..03184ae715 100644 --- a/Content.Client/Salvage/UI/SalvageExpeditionWindow.xaml.cs +++ b/Content.Client/Salvage/UI/SalvageExpeditionWindow.xaml.cs @@ -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 { + 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(); _timing = IoCManager.Resolve(); _prototype = IoCManager.Resolve(); _salvage = IoCManager.Resolve().EntitySysManager.GetEntitySystem(); @@ -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}"; diff --git a/Content.Server/Salvage/SalvageSystem.Expeditions.cs b/Content.Server/Salvage/SalvageSystem.Expeditions.cs index 9787e3a5d3..467f753590 100644 --- a/Content.Server/Salvage/SalvageSystem.Expeditions.cs +++ b/Content.Server/Salvage/SalvageSystem.Expeditions.cs @@ -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(OnSalvageExpStationInit); @@ -36,6 +40,46 @@ public sealed partial class SalvageSystem SubscribeLocalEvent(OnExpeditionUnpaused); SubscribeLocalEvent(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(); + + 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(); + + 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")); } diff --git a/Content.Server/Salvage/SalvageSystem.cs b/Content.Server/Salvage/SalvageSystem.cs index 3a3e2190b9..60023b7f9e 100644 --- a/Content.Server/Salvage/SalvageSystem.cs +++ b/Content.Server/Salvage/SalvageSystem.cs @@ -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) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index a13592364d..0e07fc4afc 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1328,8 +1328,16 @@ namespace Content.Shared.CCVar public static readonly CVarDef SalvageForced = CVarDef.Create("salvage.forced", "", CVar.SERVERONLY); - /* + /// + /// Cooldown for successful missions. + /// + public static readonly CVarDef + SalvageExpeditionCooldown = CVarDef.Create("salvage.expedition_cooldown", 300f, CVar.REPLICATED); + public static readonly CVarDef + SalvageExpeditionFailedCooldown = CVarDef.Create("salvage.expedition_failed_cooldown", 900f, CVar.REPLICATED); + + /* * Flavor */ diff --git a/Content.Shared/Salvage/SharedSalvageSystem.cs b/Content.Shared/Salvage/SharedSalvageSystem.cs index 06e5d1faba..13e05eacdf 100644 --- a/Content.Shared/Salvage/SharedSalvageSystem.cs +++ b/Content.Shared/Salvage/SharedSalvageSystem.cs @@ -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, diff --git a/Resources/ConfigPresets/Build/development.toml b/Resources/ConfigPresets/Build/development.toml index aa4172331a..1cf67b8945 100644 --- a/Resources/ConfigPresets/Build/development.toml +++ b/Resources/ConfigPresets/Build/development.toml @@ -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 diff --git a/Resources/Locale/en-US/procedural/expeditions.ftl b/Resources/Locale/en-US/procedural/expeditions.ftl index b5cd2f2837..62e59445f5 100644 --- a/Resources/Locale/en-US/procedural/expeditions.ftl +++ b/Resources/Locale/en-US/procedural/expeditions.ftl @@ -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