Skip to content

Commit

Permalink
custom ai law
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratyyy committed Sep 8, 2024
1 parent ceab636 commit b5af42f
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Content.Server/ADT/CustomAILaw/CustomAiLawBoardComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.ADT.CustomAiLawBoard;

[RegisterComponent]
public sealed partial class CustomAiLawBoardComponent : Component
{

}
41 changes: 41 additions & 0 deletions Content.Server/ADT/CustomAILaw/CustomAiLawBoardSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Content.Shared.Interaction;
using Content.Shared.Tools.Systems;
using Content.Server.Silicons.Laws;
using Content.Shared.Silicons.Laws.Components;
using Content.Server.Administration.Managers;
using Content.Server.EUI;
using Robust.Server.Player;

namespace Content.Server.ADT.CustomAiLawBoard;

public sealed class CustomAiLawBoardSystem : EntitySystem
{
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly SiliconLawSystem _siliconLawSystem = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly EuiManager _euiManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CustomAiLawBoardComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInteractUsing(EntityUid uid, CustomAiLawBoardComponent comp, InteractUsingEvent args)
{
if (args.Handled)
return;

if (!_toolSystem.HasQuality(args.Used, SharedToolSystem.PulseQuality))
return;

if (!TryComp<SiliconLawBoundComponent>(uid, out var lawBoundComponent))
return;
var ui = new SiliconLawEui(_siliconLawSystem, EntityManager, _adminManager);
if (!_playerManager.TryGetSessionByEntity(args.User, out var session))
{
return;
}
_euiManager.OpenEui(ui, session);
ui.UpdateLaws(lawBoundComponent, args.Target);
}
}
8 changes: 4 additions & 4 deletions Content.Server/Silicons/Laws/SiliconLawEui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public override EuiStateBase GetNewState()

public void UpdateLaws(SiliconLawBoundComponent? lawBoundComponent, EntityUid player)
{
if (!IsAllowed())
return;
// if (!IsAllowed())
// return; ADT Custom ai law

var laws = _siliconLawSystem.GetLaws(player, lawBoundComponent);
_laws = laws.Laws;
Expand All @@ -48,8 +48,8 @@ public override void HandleMessage(EuiMessageBase msg)
return;
}

if (!IsAllowed())
return;
// if (!IsAllowed())
// return; ADT Custom ai law

var player = _entityManager.GetEntity(message.Target);

Expand Down
48 changes: 45 additions & 3 deletions Content.Server/Silicons/Laws/SiliconLawSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Toolshed;
using Content.Server.Antag;
using Content.Server.Communications;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Nuke;
using Content.Server.NukeOps;
using Content.Server.Popups;
using Content.Server.Roles;
using Content.Server.RoundEnd;
using Content.Server.Shuttles.Events;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Components;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.GameTicking.Components;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Systems;
using Content.Shared.Nuke;
using Content.Shared.NukeOps;
using Content.Shared.Store;
using Content.Shared.Tag;
using Content.Shared.Zombies;
using Robust.Shared.Map;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Linq;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Store.Components;

namespace Content.Server.Silicons.Laws;

Expand All @@ -34,6 +63,7 @@ public sealed class SiliconLawSystem : SharedSiliconLawSystem
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly SharedRoleSystem _roles = default!;
[Dependency] private readonly NpcFactionSystem _faction = default!;

/// <inheritdoc/>
public override void Initialize()
Expand Down Expand Up @@ -275,7 +305,6 @@ public void SetLaws(List<SiliconLaw> newLaws, EntityUid target)
{
if (!TryComp<SiliconLawProviderComponent>(target, out var component))
return;

if (component.Lawset == null)
component.Lawset = new SiliconLawset();

Expand All @@ -286,17 +315,30 @@ public void SetLaws(List<SiliconLaw> newLaws, EntityUid target)
protected override void OnUpdaterInsert(Entity<SiliconLawUpdaterComponent> ent, ref EntInsertedIntoContainerMessage args)
{
// TODO: Prediction dump this
if (!TryComp(args.Entity, out SiliconLawProviderComponent? provider))
if (!TryComp(args.Entity, out SiliconLawBoundComponent? provider)) //ADT custom AI law
return;

var lawset = GetLawset(provider.Laws).Laws;
var lawset = GetLaws(args.Entity, provider).Laws; //ADT custom AI law
var query = EntityManager.CompRegistryQueryEnumerator(ent.Comp.Components);

while (query.MoveNext(out var update))
{
SetLaws(lawset, update);
}
///ADT AI Custom law start
UpdateBorgsNTLaws(lawset);
}
private void UpdateBorgsNTLaws(List<SiliconLaw> newLaws)
{
var headRevs = AllEntityQuery<SiliconLawProviderComponent, NpcFactionMemberComponent>();
while (headRevs.MoveNext(out var uid, out var lawprov, out _))
{
if (_faction.IsMember(uid, "NanoTrasen") && lawprov.Lawset != null)
lawprov.Lawset.Laws = newLaws;
}
return;
}
///ADT AI Custom law end
}

[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-ADTCustomLawCircuitBoard = плата смены законов ИИ
.desc = Модификация обычный платы законов, позволяющая полностью переписать их при помощи мультитула.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
silicon-law-ui-verb = Управление законами
silicon-law-ui-title = Кремниевые законы
silicon-law-ui-title = Законы ИИ
silicon-law-ui-new-law = Новый закон
silicon-law-ui-save = Сохранить изменения
silicon-law-ui-plus-one = +1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- type: entity
id: ADTCustomLawCircuitBoard
parent: BaseElectronics
name: custom ai law circuit board
description: An electronics board containing a lawset.
components:
- type: Sprite
sprite: Objects/Misc/module.rsi
state: cpuboard_adv
- type: SiliconLawBound
- type: CustomAiLawBoard
- type: SiliconLawProvider
laws: NTDefault

0 comments on commit b5af42f

Please sign in to comment.