Skip to content

Commit

Permalink
update code to allow lawset updating
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Nov 27, 2024
1 parent 89a806f commit 7f7bbe3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Content.Server.Silicons.Laws;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Silicons.Laws;
using Content.Shared.Silicons.Laws.Components;
using Robust.Shared.Prototypes;

namespace Content.Server.Silicons.Borgs;

/// <summary>
/// Handles lawset patching when switching type.
/// If a borg is made emagged it needs its emag laws carried over.
/// </summary>
public sealed partial class BorgSwitchableTypeSystem
{
[Dependency] private readonly SiliconLawSystem _law = default!;

private void ConfigureLawset(EntityUid uid, ProtoId<SiliconLawsetPrototype> id)
{
var laws = _law.GetLawset(id);
_law.SetLaws(laws.Laws, uid);

// re-add law 0 and final law based on new lawset
if (CompOrNull<EmagSiliconLawComponent>(uid)?.OwnerName != null)
{
// raising the event manually to bypass re-emagging checks
var ev = new GotEmaggedEvent(uid); // user wont be used since OwnerName isnt null, safe to pass itself
RaiseLocalEvent(uid, ref ev);
}

// ion storms don't get mirrored because thats basically impossible to track
}
}
7 changes: 6 additions & 1 deletion Content.Server/Silicons/Borgs/BorgSwitchableTypeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Content.Server.Silicons.Borgs;
/// <summary>
/// Server-side logic for borg type switching. Handles more heavyweight and server-specific switching logic.
/// </summary>
public sealed class BorgSwitchableTypeSystem : SharedBorgSwitchableTypeSystem
public sealed partial class BorgSwitchableTypeSystem : SharedBorgSwitchableTypeSystem // DeltaV: Made partial
{
[Dependency] private readonly BorgSystem _borgSystem = default!;
[Dependency] private readonly ServerInventorySystem _inventorySystem = default!;
Expand Down Expand Up @@ -59,6 +59,11 @@ protected override void SelectBorgModule(Entity<BorgSwitchableTypeComponent> ent
}
}

// Begin DeltaV Code: Custom lawset patching
if (prototype.Lawset is {} lawset)
ConfigureLawset(ent, lawset);
// End DeltaV Code

// Configure special components
if (Prototypes.TryIndex(ent.Comp.SelectedBorgType, out var previousPrototype))
{
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Silicons/Laws/SiliconLawSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ private void OnEmagLawsAdded(EntityUid uid, SiliconLawProviderComponent componen
component.Lawset = GetLawset(component.Laws);

// Add the first emag law before the others
var name = CompOrNull<EmagSiliconLawComponent>(uid)?.OwnerName ?? Name(args.UserUid); // DeltaV: Reuse emagger name if possible
component.Lawset?.Laws.Insert(0, new SiliconLaw
{
LawString = Loc.GetString("law-emag-custom", ("name", Name(args.UserUid)), ("title", Loc.GetString(component.Lawset.ObeysTo))),
LawString = Loc.GetString("law-emag-custom", ("name", name), ("title", Loc.GetString(component.Lawset.ObeysTo))), // DeltaV: pass name from variable
Order = 0
});

Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Silicons/Borgs/BorgTypePrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Shared.Inventory;
using Content.Shared.Radio;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.Silicons.Laws; // DeltaV
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -83,6 +84,13 @@ public sealed partial class BorgTypePrototype : IPrototype
[DataField]
public EntProtoId[] DefaultModules = [];

/// <summary>
/// DeltaV: Lawset to use instead of crewsimov.
/// If the chassis is emagged or ion stormed this is ignored.
/// </summary>
[DataField]
public ProtoId<SiliconLawsetPrototype>? Lawset;

/// <summary>
/// Additional components to add to the borg entity when this type is selected.
/// </summary>
Expand Down

0 comments on commit 7f7bbe3

Please sign in to comment.