make rnd console require science access (#17671)

This commit is contained in:
Nemanja
2023-06-29 14:19:19 -04:00
committed by GitHub
parent 872a008a12
commit 8f5282fb89
6 changed files with 34 additions and 3 deletions

View File

@@ -1,8 +1,11 @@
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Research.Components; using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes; using Content.Shared.Research.Prototypes;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -19,9 +22,11 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
[Dependency] private readonly IEntityManager _entity = default!; [Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private readonly TechnologyDatabaseComponent? _technologyDatabase; private readonly TechnologyDatabaseComponent? _technologyDatabase;
private readonly ResearchSystem _research; private readonly ResearchSystem _research;
private readonly SpriteSystem _sprite; private readonly SpriteSystem _sprite;
private readonly AccessReaderSystem _accessReader = default!;
public readonly EntityUid Entity; public readonly EntityUid Entity;
@@ -32,6 +37,7 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
_research = _entity.System<ResearchSystem>(); _research = _entity.System<ResearchSystem>();
_sprite = _entity.System<SpriteSystem>(); _sprite = _entity.System<SpriteSystem>();
_accessReader = _entity.System<AccessReaderSystem>();
Entity = entity; Entity = entity;
ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke(); ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke();
@@ -60,10 +66,14 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
{ {
MinHeight = 10 MinHeight = 10
}); });
var hasAccess = _player.LocalPlayer?.ControlledEntity is not { } local ||
!_entity.TryGetComponent<AccessReaderComponent>(Entity, out var access) ||
_accessReader.IsAllowed(local, access);
foreach (var techId in _technologyDatabase.CurrentTechnologyCards) foreach (var techId in _technologyDatabase.CurrentTechnologyCards)
{ {
var tech = _prototype.Index<TechnologyPrototype>(techId); var tech = _prototype.Index<TechnologyPrototype>(techId);
var cardControl = new TechnologyCardControl(tech, _prototype, _sprite, GetTechnologyDescription(tech), state.Points); var cardControl = new TechnologyCardControl(tech, _prototype, _sprite, GetTechnologyDescription(tech), state.Points, hasAccess);
cardControl.OnPressed += () => OnTechnologyCardPressed?.Invoke(techId); cardControl.OnPressed += () => OnTechnologyCardPressed?.Invoke(techId);
TechnologyCardsContainer.AddChild(cardControl); TechnologyCardsContainer.AddChild(cardControl);
} }

View File

@@ -13,7 +13,7 @@ public sealed partial class TechnologyCardControl : Control
{ {
public Action? OnPressed; public Action? OnPressed;
public TechnologyCardControl(TechnologyPrototype technology, IPrototypeManager prototypeManager, SpriteSystem spriteSys, FormattedMessage description, int points) public TechnologyCardControl(TechnologyPrototype technology, IPrototypeManager prototypeManager, SpriteSystem spriteSys, FormattedMessage description, int points, bool hasAccess)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
@@ -30,7 +30,10 @@ public sealed partial class TechnologyCardControl : Control
TechnologyTexture.Texture = spriteSys.Frame0(technology.Icon); TechnologyTexture.Texture = spriteSys.Frame0(technology.Icon);
ResearchButton.Disabled = points < technology.Cost; if (!hasAccess)
ResearchButton.ToolTip = Loc.GetString("research-console-no-access-popup");
ResearchButton.Disabled = points < technology.Cost || !hasAccess;
ResearchButton.OnPressed += _ => OnPressed?.Invoke(); ResearchButton.OnPressed += _ => OnPressed?.Invoke();
} }
} }

View File

@@ -1,6 +1,7 @@
using Content.Server.Power.EntitySystems; using Content.Server.Power.EntitySystems;
using Content.Server.Research.Components; using Content.Server.Research.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.Access.Components;
using Content.Shared.Research.Components; using Content.Shared.Research.Components;
namespace Content.Server.Research.Systems; namespace Content.Server.Research.Systems;
@@ -18,9 +19,18 @@ public sealed partial class ResearchSystem
private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args) private void OnConsoleUnlock(EntityUid uid, ResearchConsoleComponent component, ConsoleUnlockTechnologyMessage args)
{ {
if (args.Session.AttachedEntity is not { } ent)
return;
if (!this.IsPowered(uid, EntityManager)) if (!this.IsPowered(uid, EntityManager))
return; return;
if (TryComp<AccessReaderComponent>(uid, out var access) && !_accessReader.IsAllowed(ent, access))
{
_popup.PopupEntity(Loc.GetString("research-console-no-access-popup"), ent);
return;
}
if (!UnlockTechnology(uid, args.Id)) if (!UnlockTechnology(uid, args.Id))
return; return;

View File

@@ -1,5 +1,7 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.Access.Systems;
using Content.Shared.Popups;
using Content.Shared.Research.Components; using Content.Shared.Research.Components;
using Content.Shared.Research.Systems; using Content.Shared.Research.Systems;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -12,7 +14,9 @@ namespace Content.Server.Research.Systems
public sealed partial class ResearchSystem : SharedResearchSystem public sealed partial class ResearchSystem : SharedResearchSystem
{ {
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize() public override void Initialize()
{ {

View File

@@ -14,3 +14,5 @@ research-console-cost = Cost: [color=orchid]{$amount}[/color]
research-console-unlocks-list-start = Unlocks: research-console-unlocks-list-start = Unlocks:
research-console-unlocks-list-entry = - [color=yellow]{$name}[/color] research-console-unlocks-list-entry = - [color=yellow]{$name}[/color]
research-console-unlocks-list-entry-generic = - [color=green]{$text}[/color] research-console-unlocks-list-entry-generic = - [color=green]{$text}[/color]
research-console-no-access-popup = No access!

View File

@@ -385,6 +385,8 @@
priority: Low priority: Low
- type: Computer - type: Computer
board: ResearchComputerCircuitboard board: ResearchComputerCircuitboard
- type: AccessReader
access: [["Research"]]
- type: PointLight - type: PointLight
radius: 1.5 radius: 1.5
energy: 1.6 energy: 1.6