-using Content.Shared.Research.Systems;
+using Content.Shared.Research.Systems;
namespace Content.Client.Research;
-public sealed class ResearchSystem : SharedResearchSystem
-{
-
-}
+public sealed class ResearchSystem : SharedResearchSystem;
namespace Content.Client.Research.UI;
[UsedImplicitly]
-public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface
+public sealed class ResearchConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
{
[ViewVariables]
private ResearchConsoleMenu? _consoleMenu;
- public ResearchConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
- {
- }
-
protected override void Open()
{
base.Open();
- var owner = Owner;
-
_consoleMenu = this.CreateWindow<ResearchConsoleMenu>();
- _consoleMenu.SetEntity(owner);
+ _consoleMenu.SetEntity(Owner);
+
+ _consoleMenu.OnTechnologyRediscoverPressed += () =>
+ {
+ SendMessage(new ConsoleRediscoverTechnologyMessage());
+ };
_consoleMenu.OnTechnologyCardPressed += id =>
{
if (state is not ResearchConsoleBoundInterfaceState castState)
return;
+
_consoleMenu?.UpdatePanels(castState);
_consoleMenu?.UpdateInformationPanel(castState);
}
-<controls:FancyWindow xmlns="https://spacestation14.io"
+<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
</BoxContainer>
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalAlignment="Right">
<Button Name="ServerButton" Text="{Loc 'research-console-menu-server-selection-button'}" MinHeight="40"/>
+ <Button Name="RediscoverButton" Margin="0 5 0 0" ToolTip="{Loc 'research-console-menu-server-rediscover-tooltip'}" MinHeight="40"/>
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Horizontal"
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
+using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.Research.UI;
public sealed partial class ResearchConsoleMenu : FancyWindow
{
public Action<string>? OnTechnologyCardPressed;
+ public Action? OnTechnologyRediscoverPressed;
public Action? OnServerButtonPressed;
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IPlayerManager _player = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
+
private readonly ResearchSystem _research;
private readonly SpriteSystem _sprite;
private readonly AccessReaderSystem _accessReader;
+ // if set to null - we are waiting for server info and should not let rerolls
+ private TimeSpan? _nextRediscover;
+ private int _rediscoverCost;
+ private int _serverPoints;
+
+ private TimeSpan _nextUpdate;
+ private readonly TimeSpan _updateInterval = TimeSpan.FromMilliseconds(500);
+
public EntityUid Entity;
public ResearchConsoleMenu()
_accessReader = _entity.System<AccessReaderSystem>();
ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke();
+ RediscoverButton.OnPressed += OnRediscoverPressed;
}
public void SetEntity(EntityUid entity)
MinHeight = 10
});
- var hasAccess = _player.LocalEntity is not { } local ||
- !_entity.TryGetComponent<AccessReaderComponent>(Entity, out var access) ||
- _accessReader.IsAllowed(local, Entity, access);
+ var hasAccess = HasAccess();
foreach (var techId in database.CurrentTechnologyCards)
{
var tech = _prototype.Index<TechnologyPrototype>(techId);
SyncTechnologyList(UnlockedCardsContainer, unlockedTech);
}
+ private void UpdateRediscoverButton()
+ {
+ RediscoverButton.Disabled = !HasAccess() || _serverPoints < _rediscoverCost || _timing.CurTime < _nextRediscover;
+ RediscoverButton.Text = Loc.GetString("research-console-menu-server-rediscover-button", ("cost", _rediscoverCost));
+ }
+
public void UpdateInformationPanel(ResearchConsoleBoundInterfaceState state)
{
var amountMsg = new FormattedMessage();
};
TierDisplayContainer.AddChild(control);
}
+
+ _serverPoints = state.Points;
+ _rediscoverCost = state.RediscoverCost;
+ _nextRediscover = state.NextRediscover;
+
+ UpdateRediscoverButton();
+ }
+
+ private void OnRediscoverPressed(BaseButton.ButtonEventArgs args)
+ {
+ RediscoverButton.Disabled = true;
+ _nextRediscover = null;
+
+ OnTechnologyRediscoverPressed?.Invoke();
+ }
+
+ private bool HasAccess()
+ {
+ return _player.LocalEntity is not { } local
+ || !_entity.TryGetComponent<AccessReaderComponent>(Entity, out var access)
+ || _accessReader.IsAllowed(local, Entity, access);
}
/// <summary>
container.Children.Remove(techControl);
}
}
+
+ /// <inheritdoc />
+ protected override void FrameUpdate(FrameEventArgs args)
+ {
+ base.FrameUpdate(args);
+
+ if(_nextUpdate > _timing.CurTime)
+ return;
+
+ _nextUpdate = _timing.CurTime + _updateInterval;
+
+ if (!RediscoverButton.Disabled)
+ return;
+
+ if (_nextRediscover == null || _nextRediscover > _timing.CurTime)
+ return;
+
+ UpdateRediscoverButton();
+ }
}
private void InitializeConsole()
{
SubscribeLocalEvent<ResearchConsoleComponent, ConsoleUnlockTechnologyMessage>(OnConsoleUnlock);
+ SubscribeLocalEvent<ResearchConsoleComponent, ConsoleRediscoverTechnologyMessage>(OnRediscoverTechnology);
SubscribeLocalEvent<ResearchConsoleComponent, BeforeActivatableUIOpenEvent>(OnConsoleBeforeUiOpened);
SubscribeLocalEvent<ResearchConsoleComponent, ResearchServerPointsChangedEvent>(OnPointsChanged);
SubscribeLocalEvent<ResearchConsoleComponent, ResearchRegistrationChangedEvent>(OnConsoleRegistrationChanged);
SubscribeLocalEvent<ResearchConsoleComponent, GotEmaggedEvent>(OnEmagged);
}
+ private void OnRediscoverTechnology(
+ EntityUid uid,
+ ResearchConsoleComponent console,
+ ConsoleRediscoverTechnologyMessage args
+ )
+ {
+ var act = args.Actor;
+
+ if (!this.IsPowered(uid, EntityManager))
+ return;
+
+ if (!HasAccess(uid, act))
+ {
+ _popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), act);
+ return;
+ }
+
+ if (!TryGetClientServer(uid, out var serverEnt, out var serverComponent))
+ return;
+
+ if(serverComponent.NextRediscover > _timing.CurTime)
+ return;
+
+ var rediscoverCost = serverComponent.RediscoverCost;
+ if (rediscoverCost > serverComponent.Points)
+ return;
+
+ serverComponent.NextRediscover = _timing.CurTime + serverComponent.RediscoverInterval;
+
+ ModifyServerPoints(serverEnt.Value, -rediscoverCost);
+ UpdateTechnologyCards(serverEnt.Value);
+ SyncClientWithServer(uid);
+ UpdateConsoleInterface(uid);
+ }
+
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
{
var act = args.Actor;
if (!PrototypeManager.TryIndex<TechnologyPrototype>(args.Id, out var technologyPrototype))
return;
- if (TryComp<AccessReaderComponent>(uid, out var access) && !_accessReader.IsAllowed(act, uid, access))
+ if (!HasAccess(uid, act))
{
_popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), act);
return;
if (!Resolve(uid, ref component, ref clientComponent, false))
return;
- ResearchConsoleBoundInterfaceState state;
-
- if (TryGetClientServer(uid, out _, out var serverComponent, clientComponent))
- {
- var points = clientComponent.ConnectedToServer ? serverComponent.Points : 0;
- state = new ResearchConsoleBoundInterfaceState(points);
- }
- else
+
+ var points = 0;
+ var nextRediscover = TimeSpan.MaxValue;
+ var rediscoverCost = 0;
+ if (TryGetClientServer(uid, out _, out var serverComponent, clientComponent) && clientComponent.ConnectedToServer)
{
- state = new ResearchConsoleBoundInterfaceState(default);
+ points = serverComponent.Points;
+ nextRediscover = serverComponent.NextRediscover;
+ rediscoverCost = serverComponent.RediscoverCost;
}
+ var state = new ResearchConsoleBoundInterfaceState(points, nextRediscover, rediscoverCost);
_uiSystem.SetUiState(uid, ResearchConsoleUiKey.Key, state);
}
args.Handled = true;
}
+
+ private bool HasAccess(EntityUid uid, EntityUid act)
+ {
+ return TryComp<AccessReaderComponent>(uid, out var access) && _accessReader.IsAllowed(act, uid, access);
+ }
}
if (args.Server != null)
return;
component.MainDiscipline = null;
- component.CurrentTechnologyCards = new List<string>();
- component.SupportedDisciplines = new List<ProtoId<TechDisciplinePrototype>>();
- component.UnlockedTechnologies = new List<ProtoId<TechnologyPrototype>>();
- component.UnlockedRecipes = new List<ProtoId<LatheRecipePrototype>>();
+ component.CurrentTechnologyCards = new();
+ component.SupportedDisciplines = new();
+ component.UnlockedTechnologies = new();
+ component.UnlockedRecipes = new();
Dirty(uid, component);
}
}
using Robust.Shared.GameStates;
-using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Research.Components;
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
public sealed partial class ResearchServerComponent : Component
{
/// <summary>
/// The name of the server
/// </summary>
[AutoNetworkedField]
- [DataField("serverName"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public string ServerName = "RDSERVER";
/// <summary>
/// The amount of points on the server.
/// </summary>
[AutoNetworkedField]
- [DataField("points"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public int Points;
+ /// <summary>
+ /// Cost of technology research options reroll.
+ /// </summary>
+ [AutoNetworkedField]
+ [DataField]
+ public int RediscoverCost = 2000;
+
/// <summary>
/// A unique numeric id representing the server
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public List<EntityUid> Clients = new();
- [DataField("nextUpdateTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdateTime = TimeSpan.Zero;
- [DataField("researchConsoleUpdateTime"), ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public TimeSpan ResearchConsoleUpdateTime = TimeSpan.FromSeconds(1);
+
+ /// <summary>
+ /// Time when next reroll for tech to research will be available.
+ /// </summary>
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
+ public TimeSpan NextRediscover;
+
+ /// <summary>
+ /// Minimal interval between rediscover actions.
+ /// </summary>
+ [DataField]
+ public TimeSpan RediscoverInterval = TimeSpan.FromSeconds(1);
}
/// <summary>
/// Event raised on a server's clients when the point value of the server is changed.
/// </summary>
-/// <param name="Server"></param>
-/// <param name="Total"></param>
-/// <param name="Delta"></param>
[ByRefEvent]
public readonly record struct ResearchServerPointsChangedEvent(EntityUid Server, int Total, int Delta);
/// <summary>
/// Event raised every second to calculate the amount of points added to the server.
/// </summary>
-/// <param name="Server"></param>
-/// <param name="Points"></param>
[ByRefEvent]
public record struct ResearchServerGetPointsPerSecondEvent(EntityUid Server, int Points);
}
[Serializable, NetSerializable]
- public sealed class ConsoleUnlockTechnologyMessage : BoundUserInterfaceMessage
+ public sealed class ConsoleUnlockTechnologyMessage(string id) : BoundUserInterfaceMessage
{
- public string Id;
-
- public ConsoleUnlockTechnologyMessage(string id)
- {
- Id = id;
- }
+ public string Id = id;
}
+ [Serializable, NetSerializable]
+ public sealed class ConsoleRediscoverTechnologyMessage : BoundUserInterfaceMessage;
+
[Serializable, NetSerializable]
public sealed class ConsoleServerSelectionMessage : BoundUserInterfaceMessage
{
}
[Serializable, NetSerializable]
- public sealed class ResearchConsoleBoundInterfaceState : BoundUserInterfaceState
+ public sealed class ResearchConsoleBoundInterfaceState(int points, TimeSpan nextRediscover, int rediscoverCost) : BoundUserInterfaceState
{
- public int Points;
- public ResearchConsoleBoundInterfaceState(int points)
- {
- Points = points;
- }
+ public int Points = points;
+
+ public TimeSpan NextRediscover = nextRediscover;
+
+ public int RediscoverCost = rediscoverCost;
}
}
using Content.Shared.Research.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.Research.Components;
/// A main discipline that locks out other discipline technology past a certain tier.
/// </summary>
[AutoNetworkedField]
- [DataField("mainDiscipline", customTypeSerializer: typeof(PrototypeIdSerializer<TechDisciplinePrototype>))]
- public string? MainDiscipline;
+ [DataField]
+ public ProtoId<TechDisciplinePrototype>? MainDiscipline;
[AutoNetworkedField]
- [DataField("currentTechnologyCards")]
- public List<string> CurrentTechnologyCards = new();
+ [DataField]
+ public List<ProtoId<TechnologyPrototype>> CurrentTechnologyCards = new();
/// <summary>
/// Which research disciplines are able to be unlocked
research-console-menu-server-selection-button = Server list
research-console-menu-server-sync-button = Sync
research-console-menu-server-research-button = Research
+research-console-menu-server-rediscover-button = Rediscover ({$cost})
+research-console-menu-server-rediscover-tooltip = Reroll list of technologies to research
research-console-available-text = Researchable Technologies
research-console-unlocked-text = Unlocked Technologies
research-console-tier-discipline-info = Tier {$tier}, [color={$color}]{$discipline}[/color]