Skip to content

Commit

Permalink
Изменяемые законы боргов (#43)
Browse files Browse the repository at this point in the history
* Done, needs testing

* Own file with ui loc

* Primary constructor

* Requests

* Disable button
  • Loading branch information
FireNameFN authored Nov 22, 2024
1 parent a4b1611 commit c0f94dd
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ protected override void Open()
_window = this.CreateWindow<RoboticsConsoleWindow>();
_window.SetEntity(Owner);

// Corvax-Next-MutableLaws-Start
_window.OnChangeLawsPressed += address =>
{
SendMessage(new RoboticsConsoleChangeLawsMessage(address));
};
// Corvax-Next-MutableLaws-End
_window.OnDisablePressed += address =>
{
SendMessage(new RoboticsConsoleDisableMessage(address));
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Robotics/UI/RoboticsConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
</BoxContainer>
<controls:StripeBack>
<BoxContainer Name="DangerZone" Margin="5" Orientation="Horizontal" HorizontalExpand="True" HorizontalAlignment="Center" Visible="False">
<Button Name="DisableButton" Text="{Loc 'robotics-console-disable'}" StyleClasses="OpenRight"/>
<!-- Corvax-Next-MutableLaws-Start -->
<Button Name="ChangeLawsButton" Text="{Loc 'robotics-console-change-laws'}" StyleClasses="OpenRight" Disabled="True"/>
<Button Name="DisableButton" Text="{Loc 'robotics-console-disable'}" StyleClasses="OpenBoth"/>
<!-- Corvax-Next-MutableLaws-End -->
<Button Name="DestroyButton" Text="{Loc 'robotics-console-destroy'}" StyleClasses="OpenLeft"/>
</BoxContainer>
<Label Name="LockedMessage" Text="{Loc 'robotics-console-locked-message'}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Robotics/UI/RoboticsConsoleWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
private readonly LockSystem _lock;
private readonly SpriteSystem _sprite;

public Action<string>? OnChangeLawsPressed; // Corvax-Next-MutableLaws
public Action<string>? OnDisablePressed;
public Action<string>? OnDestroyPressed;

Expand Down Expand Up @@ -51,6 +52,12 @@ public RoboticsConsoleWindow()
};

// these won't throw since buttons are only visible if a borg is selected
// Corvax-Next-MutableLaws-Start
ChangeLawsButton.OnPressed += _ =>
{
OnChangeLawsPressed?.Invoke(_selected!);
};
// Corvax-Next-MutableLaws-End
DisableButton.OnPressed += _ =>
{
OnDisablePressed?.Invoke(_selected!);
Expand Down Expand Up @@ -80,6 +87,7 @@ public void UpdateState(RoboticsConsoleState state)
var hasCyborgs = _cyborgs.Count > 0;
NoCyborgs.Visible = !hasCyborgs;
CyborgsContainer.Visible = hasCyborgs;
ChangeLawsButton.Disabled = !state.HasCircuitBoard; // Corvax-Next-MutableLaws
PopulateCyborgs();

PopulateData();
Expand Down
48 changes: 47 additions & 1 deletion Content.Server/Robotics/Systems/RoboticsConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Robust.Server.GameObjects;
using Robust.Shared.Timing;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Containers;

namespace Content.Server.Research.Systems;

Expand All @@ -26,6 +28,7 @@ public sealed class RoboticsConsoleSystem : SharedRoboticsConsoleSystem
[Dependency] private readonly LockSystem _lock = default!;
[Dependency] private readonly RadioSystem _radio = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly ItemSlotsSystem _slots = default!;

// almost never timing out more than 1 per tick so initialize with that capacity
private List<string> _removing = new(1);
Expand All @@ -35,9 +38,14 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<RoboticsConsoleComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
// Corvax-Next-MutableLaws-Start
SubscribeLocalEvent<RoboticsConsoleComponent, EntInsertedIntoContainerMessage>(OnInserted);
SubscribeLocalEvent<RoboticsConsoleComponent, EntRemovedFromContainerMessage>(OnRemoved);
// Corvax-Next-MutableLaws-End
Subs.BuiEvents<RoboticsConsoleComponent>(RoboticsConsoleUiKey.Key, subs =>
{
subs.Event<BoundUIOpenedEvent>(OnOpened);
subs.Event<RoboticsConsoleChangeLawsMessage>(OnChangeLaws); // Corvax-Next-MutableLaws
subs.Event<RoboticsConsoleDisableMessage>(OnDisable);
subs.Event<RoboticsConsoleDestroyMessage>(OnDestroy);
// TODO: camera stuff
Expand Down Expand Up @@ -89,11 +97,49 @@ private void OnPacketReceived(Entity<RoboticsConsoleComponent> ent, ref DeviceNe
UpdateUserInterface(ent);
}

// Corvax-Next-MutableLaws-Start
private void OnInserted(Entity<RoboticsConsoleComponent> ent, ref EntInsertedIntoContainerMessage args)
{
UpdateUserInterface(ent);
}

private void OnRemoved(Entity<RoboticsConsoleComponent> ent, ref EntRemovedFromContainerMessage args)
{
UpdateUserInterface(ent);
}
// Corvax-Next-MutableLaws-End

private void OnOpened(Entity<RoboticsConsoleComponent> ent, ref BoundUIOpenedEvent args)
{
UpdateUserInterface(ent);
}

// Corvax-Next-MutableLaws-Start
private void OnChangeLaws(Entity<RoboticsConsoleComponent> ent, ref RoboticsConsoleChangeLawsMessage args)
{
if (_lock.IsLocked(ent.Owner))
return;

if (!ent.Comp.Cyborgs.TryGetValue(args.Address, out var data))
return;

if (!_slots.TryGetSlot(ent, ent.Comp.CircuitBoardItemSlot, out var slot) || slot.Item is null)
return;

var payload = new NetworkPayload()
{
[DeviceNetworkConstants.Command] = RoboticsConsoleConstants.NET_CHANGE_LAWS_COMMAND,
[RoboticsConsoleConstants.NET_CIRCUIT_BOARD] = slot.Item.Value,
};

_deviceNetwork.QueuePacket(ent, args.Address, payload);

var message = Loc.GetString(ent.Comp.ChangeLawsMessage, ("name", data.Name));
_radio.SendRadioMessage(ent, message, ent.Comp.RadioChannel, ent);
_adminLogger.Add(LogType.Action, LogImpact.High, $"{ToPrettyString(args.Actor):user} changed laws of borg {data.Name} with address {args.Address}");
}
// Corvax-Next-MutableLaws-End

private void OnDisable(Entity<RoboticsConsoleComponent> ent, ref RoboticsConsoleDisableMessage args)
{
if (_lock.IsLocked(ent.Owner))
Expand Down Expand Up @@ -140,7 +186,7 @@ private void OnDestroy(Entity<RoboticsConsoleComponent> ent, ref RoboticsConsole

private void UpdateUserInterface(Entity<RoboticsConsoleComponent> ent)
{
var state = new RoboticsConsoleState(ent.Comp.Cyborgs);
var state = new RoboticsConsoleState(ent.Comp.Cyborgs, _slots.TryGetSlot(ent, ent.Comp.CircuitBoardItemSlot, out var slot) && slot.HasItem); // Corvax-Next-MutableLaws
_ui.SetUiState(ent.Owner, RoboticsConsoleUiKey.Key, state);
}
}
27 changes: 26 additions & 1 deletion Content.Server/Silicons/Borgs/BorgSystem.Transponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Explosion.Components;
using Content.Server.Silicons.Laws;
using Robust.Shared.Audio;
using Content.Shared.Silicons.Laws.Components;

namespace Content.Server.Silicons.Borgs;

/// <inheritdoc/>
public sealed partial class BorgSystem
{
[Dependency] private readonly SiliconLawSystem _law = default!;

private void InitializeTransponder()
{
SubscribeLocalEvent<BorgTransponderComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
Expand Down Expand Up @@ -83,12 +88,32 @@ private void OnPacketReceived(Entity<BorgTransponderComponent> ent, ref DeviceNe
if (!payload.TryGetValue(DeviceNetworkConstants.Command, out string? command))
return;

if (command == RoboticsConsoleConstants.NET_DISABLE_COMMAND)
// Corvax-Next-MutableLaws-Start
if (command == RoboticsConsoleConstants.NET_CHANGE_LAWS_COMMAND)
{
if (payload.TryGetValue(RoboticsConsoleConstants.NET_CIRCUIT_BOARD, out EntityUid circuitBoard))
ChangeLaws(ent, circuitBoard);
}
// Corvax-Next-MutableLaws-End
else if (command == RoboticsConsoleConstants.NET_DISABLE_COMMAND)
Disable(ent);
else if (command == RoboticsConsoleConstants.NET_DESTROY_COMMAND)
Destroy(ent);
}

// Corvax-Next-MutableLaws-Start
private void ChangeLaws(EntityUid ent, EntityUid circuitBoard)
{
if (CheckEmagged(ent, "destroyed"))
return;

if (!TryComp<SiliconLawProviderComponent>(circuitBoard, out var law))
return;

_law.SetLaws(_law.GetLawset(law.Laws).Laws, ent, law.LawUploadSound);
}
// Corvax-Next-MutableLaws-End

private void Disable(Entity<BorgTransponderComponent, BorgChassisComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp2) || ent.Comp2.BrainEntity == null || ent.Comp1.NextDisable != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public sealed partial class RoboticsConsoleComponent : Component
[DataField]
public ProtoId<RadioChannelPrototype> RadioChannel = "Science";

// Corvax-Next-MutableLaws-Start
[DataField]
public string CircuitBoardItemSlot = "circuit_holder";

[DataField]
public LocId ChangeLawsMessage = "robotics-console-cyborg-change-laws";
// Corvax-Next-MutableLaws-End

/// <summary>
/// Radio message sent when destroying a borg.
/// </summary>
Expand Down
16 changes: 15 additions & 1 deletion Content.Shared/Robotics/RoboticsConsoleUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@ public sealed class RoboticsConsoleState : BoundUserInterfaceState
/// </summary>
public Dictionary<string, CyborgControlData> Cyborgs;

public RoboticsConsoleState(Dictionary<string, CyborgControlData> cyborgs)
public bool HasCircuitBoard; // Corvax-Next-MutableLaws

public RoboticsConsoleState(Dictionary<string, CyborgControlData> cyborgs, bool hasCircuitBoard) // Corvax-Next-MutableLaws
{
Cyborgs = cyborgs;
HasCircuitBoard = hasCircuitBoard; // Corvax-Next-MutableLaws
}
}

// Corvax-Next-MutableLaws-Start
[Serializable, NetSerializable]
public sealed class RoboticsConsoleChangeLawsMessage(string address) : BoundUserInterfaceMessage
{
public readonly string Address = address;
}
// Corvax-Next-MutableLaws-End

/// <summary>
/// Message to disable the selected cyborg.
/// </summary>
Expand Down Expand Up @@ -129,6 +140,9 @@ public static class RoboticsConsoleConstants
public const string NET_CYBORG_DATA = "cyborg-data";

// sent by robotics console to cyborgs on Cyborg Control frequency
public const string NET_CHANGE_LAWS_COMMAND = "cyborg-change-laws"; // Corvax-Next-MutableLaws
public const string NET_DISABLE_COMMAND = "cyborg-disable";
public const string NET_DESTROY_COMMAND = "cyborg-destroy";

public const string NET_CIRCUIT_BOARD = "cyborg-circuit-board"; // Corvax-Next-MutableLaws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
robotics-console-change-laws = Изменить законы
robotics-console-cyborg-change-laws = Законы { $name } изменены!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
research-technology-advanced-robotics = Продвинутая робототехника
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,21 @@
access: [["ResearchDirector"]]
- type: Lock
unlockOnClick: false
# Corvax-Next-MutableLaws-Start
- type: ItemSlots
slots:
circuit_holder:
name: circuit-holder
whitelist:
requireAll: true
components:
- SiliconLawProvider
- Item
- type: ContainerContainer
containers:
circuit_holder: !type:ContainerSlot
board: !type:Container
# Corvax-Next-MutableLaws-End

- type: entity
id: StationAiUploadComputer
Expand Down
13 changes: 13 additions & 0 deletions Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,19 @@
- ReagentGrinderIndustrialMachineCircuitboard
- JukeboxCircuitBoard
- SalvageExpeditionsComputerCircuitboard # Corvax-Cringe
# Corvax-Next-MutableLaws-Start
- AsimovCircuitBoard
- CorporateCircuitBoard
- NTDefaultCircuitBoard
- CommandmentCircuitBoard
- PaladinCircuitBoard
- LiveLetLiveCircuitBoard
- StationEfficiencyCircuitBoard
- RobocopCircuitBoard
- DungeonMasterCircuitBoard
- ArtistCircuitBoard
- NutimovCircuitBoard
# Corvax-Next-MutableLaws-End
- type: EmagLatheRecipes
emagDynamicRecipes:
- ShuttleGunDusterCircuitboard
Expand Down
24 changes: 24 additions & 0 deletions Resources/Prototypes/Research/experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@
- WeaponParticleDecelerator
- HoloprojectorField

# Corvax-Next-MutableLaws-Start
- type: technology
id: AdvancedRobotics
name: research-technology-advanced-robotics
icon:
sprite: Mobs/Silicon/station_ai.rsi
state: ai
discipline: Experimental
tier: 2
cost: 7500
recipeUnlocks:
- AsimovCircuitBoard
- CorporateCircuitBoard
- NTDefaultCircuitBoard
- CommandmentCircuitBoard
- PaladinCircuitBoard
- LiveLetLiveCircuitBoard
- StationEfficiencyCircuitBoard
- RobocopCircuitBoard
- DungeonMasterCircuitBoard
- ArtistCircuitBoard
- NutimovCircuitBoard
# Corvax-Next-MutableLaws-End

# Tier 3

- type: technology
Expand Down
54 changes: 54 additions & 0 deletions Resources/Prototypes/_CorvaxNext/Recipes/Lathes/circuit_boards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
- type: latheRecipe
parent: BaseCircuitboardRecipe
id: AsimovCircuitBoard
result: AsimovCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: CorporateCircuitBoard
result: CorporateCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: NTDefaultCircuitBoard
result: NTDefaultCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: CommandmentCircuitBoard
result: CommandmentCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: PaladinCircuitBoard
result: PaladinCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: LiveLetLiveCircuitBoard
result: LiveLetLiveCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: StationEfficiencyCircuitBoard
result: StationEfficiencyCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: RobocopCircuitBoard
result: RobocopCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: DungeonMasterCircuitBoard
result: DungeonMasterCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: ArtistCircuitBoard
result: ArtistCircuitBoard

- type: latheRecipe
parent: BaseCircuitboardRecipe
id: NutimovCircuitBoard
result: NutimovCircuitBoard

0 comments on commit c0f94dd

Please sign in to comment.