Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ИИ станции... (пока не трогать) #147

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ae48af8
ИИ станции... (пока не трогать)
FaDeOkno Nov 21, 2023
b9acabf
Update PostMapInitTest.cs
Schrodinger71 Nov 21, 2023
002a4ca
Create StationAISystem.cs
Schrodinger71 Nov 21, 2023
8b7a0e7
Create ShowHealthBarsComponent.cs
Schrodinger71 Nov 21, 2023
fd93f16
Create AICameraList.xaml
Schrodinger71 Nov 21, 2023
a2bb727
Create AICameraList.xaml.cs
Schrodinger71 Nov 21, 2023
c7fa3f5
Create AICameraListBoundUserInterface.cs
Schrodinger71 Nov 21, 2023
40cb74a
Update AICameraList.xaml.cs
Schrodinger71 Nov 21, 2023
909e865
Rename AICameraListBoundUserInterface.cs to AICameraListBoundUserInt…
Schrodinger71 Nov 21, 2023
59a25b5
Rename Content.Client/ADT/Content.Client/ADT/StationAI/UI / AICameraL…
Schrodinger71 Nov 21, 2023
e3cb481
Rename AICameraList.xamlAICameraList.xamlAICameraListBoundUserInterfa…
Schrodinger71 Nov 21, 2023
66b4293
Update InnateItemSystem.cs
Schrodinger71 Nov 21, 2023
30c136d
Create FugitiveSystem.cs
Schrodinger71 Nov 21, 2023
c93f9e7
Create EvilTwinRule.cs
Schrodinger71 Nov 21, 2023
c1034e6
Create EvilTwinComponent.cs
Schrodinger71 Nov 21, 2023
f8870d8
Create EvilTwinRoleComponent.cs
Schrodinger71 Nov 21, 2023
4afb001
Rename EvilTwinRoleComponent.cs to EvilTwinRoleComponent.cs
Schrodinger71 Nov 21, 2023
09fa1a0
Rename EvilTwinComponent.cs to EvilTwinComponent.cs
Schrodinger71 Nov 21, 2023
72905d9
Create EvilTwinRuleComponent.cs
Schrodinger71 Nov 21, 2023
afbf5ec
Create EvilTwinKillCondition.cs
Schrodinger71 Nov 21, 2023
e34ac25
Create EvilTwinSpawnerComponent.cs
Schrodinger71 Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Content.Client/ADT/StationAI/Systems/StationAISystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Shared.ADT.EntityHealthBar;

Check failure on line 1 in Content.Client/ADT/StationAI/Systems/StationAISystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'EntityHealthBar' does not exist in the namespace 'Content.Shared.ADT' (are you missing an assembly reference?)

Check failure on line 1 in Content.Client/ADT/StationAI/Systems/StationAISystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'EntityHealthBar' does not exist in the namespace 'Content.Shared.ADT' (are you missing an assembly reference?)
using Content.Shared.ADT.StationAI.Events;

namespace Content.Client.Backmen.StationAI;

public sealed class StationAISystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<NetworkedAIHealthOverlayEvent>(OnHealthOverlayEvent);
}

private void OnHealthOverlayEvent(NetworkedAIHealthOverlayEvent args)
{
var uid = GetEntity(args.Performer);

if (!_entityManager.TryGetComponent<ShowHealthBarsComponent>(uid, out var health))
{
health = _entityManager.AddComponent<ShowHealthBarsComponent>(uid);
}
else
{
_entityManager.RemoveComponent<ShowHealthBarsComponent>(uid);
}
}
}
14 changes: 14 additions & 0 deletions Content.Client/ADT/StationAI/UI/AICameraList.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
MinWidth="450" MinHeight="350" Title="{Loc ai-warp-menu-title}">
<BoxContainer Name="Box" Orientation="Vertical" Margin="5">
<BoxContainer Orientation="Horizontal" Margin="0 5 0 5">
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'ai-warp-menu-search-placeholder'}" HorizontalExpand="True" Margin="0 0 2 0"/>
<Button Name="Refresh" Text="{Loc 'ai-warp-menu-refresh'}" Margin="2 0 0 0"/>
</BoxContainer>

<Label Name="Text" Text="{Loc 'ai-warp-menu-no-cameras'}" />
<TabContainer Name="SubnetList" VerticalExpand="True" Margin="0 5" />
</BoxContainer>
</controls:FancyWindow>
123 changes: 123 additions & 0 deletions Content.Client/ADT/StationAI/UI/AICameraList.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System.Linq;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Content.Shared.ADT.StationAI;
using Robust.Client.UserInterface.Controls;
using Content.Client.UserInterface.Controls;

namespace Content.Client.ADT.StationAI.UI;

[GenerateTypedNameReferences]
public sealed partial class AICameraList : FancyWindow
{
private List<EntityUid> _cameras = new();
public event Action? TryUpdateCameraList;
public event Action<EntityUid>? WarpToCamera;

public AICameraList()
{
RobustXamlLoader.Load(this);

SearchBar.OnTextChanged += (_) => FillCameraList(SearchBar.Text);
Refresh.OnPressed += (_) => UpdateCameraList();
}

private void ItemSelected(ItemList.ItemListSelectedEventArgs obj)
{
var meta = obj.ItemList[obj.ItemIndex].Metadata;
if (meta == null ||
meta is not AICameraComponent camera ||
camera.Enabled == false)
return;

WarpToCamera?.Invoke(camera.Owner);
}

private void FillCameraList(string? filter = null)
{
foreach (var child in SubnetList.Children.ToArray())
{
child.Dispose();
}

if (_cameras.Count == 0)
{
Text.Text = Loc.GetString("ai-warp-menu-no-cameras");
return;
}

Text.Text = Loc.GetString("ai-warp-menu-select-camera");

var namedCameraList = new List<(string, List<string>, EntityUid)>();
var categoryList = new List<string>();

foreach (var uid in _cameras.ToArray())
{
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<AICameraComponent>(uid, out var camera)) continue;

if (camera.Enabled == false) continue;

namedCameraList.Add((camera.CameraName, camera.CameraCategories, uid));
}

namedCameraList.Sort((a, b) => a.Item1.CompareTo(b.Item1));

foreach (var (name, categories, uid) in namedCameraList.ToArray())
{
if (categories.Count == 0) continue;

foreach (var category in categories.ToArray().Where(category => !categoryList.Contains(category.Replace("SurveillanceCamera", ""))))
{
categoryList.Add(category.Replace("SurveillanceCamera", ""));
}
}

categoryList.Sort();

foreach (var tab in categoryList.ToArray().Select(category => new ItemList()
{
Name = category
}))
{
tab.OnItemSelected += ItemSelected;
SubnetList.AddChild(tab);
}

foreach (var (name, categories, uid) in namedCameraList.ToArray())
{
if (!string.IsNullOrEmpty(filter) && !name.ToLowerInvariant().Contains(filter.Trim().ToLowerInvariant()))
continue;

if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<AICameraComponent>(uid, out var camera)) continue;

if (camera.Enabled == false) continue;

foreach (var category in categories.ToArray())
foreach (var child in SubnetList.Children.ToArray())
{
if (child.Name != category.Replace("SurveillanceCamera", "")) continue;
if (child is not ItemList list) continue;

ItemList.Item cameraItem = new(list)
{
Metadata = camera,
Text = camera.CameraName
};

list.Add(cameraItem);
}
}
}

public void UpdateCameraList(List<EntityUid>? cameras = null)
{
if (cameras == null)
{
TryUpdateCameraList?.Invoke();
return;
}

_cameras = cameras;
FillCameraList();
}
}
49 changes: 49 additions & 0 deletions Content.Client/ADT/StationAI/UI/AICameraListBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Content.Shared.ADT.StationAI.Events;

namespace Content.Client.ADT.StationAI.UI;

/// <summary>
/// Initializes a <see cref="AICameraList"/> and updates it when new server messages are received.
/// </summary>
public sealed class AICameraListBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private AICameraList _window = new AICameraList();

public AICameraListBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
var netId = _entityManager.GetNetEntity(owner);
_window.TryUpdateCameraList += () => SendMessage(new AICameraListMessage(netId));
_window.WarpToCamera += (uid) => SendMessage(new AICameraWarpMessage(netId, _entityManager.GetNetEntity(uid)));
}

protected override void Open()
{
base.Open();

if (State != null) UpdateState(State);

_window.OpenCentered();
}

/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (_window == null || state is not AIBoundUserInterfaceState cast)
return;

_window.UpdateCameraList(_entityManager.GetEntityList(cast.Cameras));
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window.Dispose();
}
}
5 changes: 3 additions & 2 deletions Content.IntegrationTests/Tests/PostMapInitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ await server.WaitPost(() =>
Assert.That(lateSpawns, Is.GreaterThan(0), $"Found no latejoin spawn points on {mapProto}");
}

/*


// Test all availableJobs have spawnPoints
// This is done inside gamemap test because loading the map takes ages and we already have it.
Expand All @@ -275,6 +275,7 @@ await server.WaitPost(() =>
.Select(x => x.Key);
var spawnPoints = entManager.EntityQuery<SpawnPointComponent>()
.Where(spawnpoint => spawnpoint.SpawnType == SpawnPointType.Job)
.Where(x=>x.Key != "SAI") // backmen: SAI
.Select(spawnpoint => spawnpoint.Job.ID)
.Distinct();
List<string> missingSpawnPoints = new();
Expand All @@ -287,7 +288,7 @@ await server.WaitPost(() =>
Assert.That(missingSpawnPoints, Has.Count.EqualTo(0),
$"There is no spawnpoint for {string.Join(", ", missingSpawnPoints)} on {mapProto}.");

*/

}

try
Expand Down
11 changes: 11 additions & 0 deletions Content.Server/ADT/EvilTwin/EvilTwinComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Content.Shared.Mind;

namespace Content.Server.ADT.EvilTwin;

[RegisterComponent]
public sealed partial class EvilTwinComponent : Component
{
public EntityUid? TwinMindId;
public MindComponent? TwinMind;
public EntityUid? TwinEntity;
}
1 change: 1 addition & 0 deletions Content.Server/ADT/EvilTwin/EvilTwinKillCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

12 changes: 12 additions & 0 deletions Content.Server/ADT/EvilTwin/EvilTwinRoleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Content.Shared.Mind;
using Content.Shared.Roles;

namespace Content.Server.ADT.EvilTwin;

[RegisterComponent]
public sealed partial class EvilTwinRoleComponent : AntagonistRoleComponent
{
public EntityUid? Target { get; set; }
public EntityUid? TargetMindId { get; set; }
public MindComponent? TargetMind { get; set; }
}
9 changes: 9 additions & 0 deletions Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Server.ADT.EvilTwin.StationEvents;

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

Check failure on line 1 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'StationEvents' does not exist in the namespace 'Content.Server.ADT.EvilTwin' (are you missing an assembly reference?)

namespace Content.Server.ADT.EvilTwin;

[RegisterComponent, Access(typeof(EvilTwinRule))]

Check failure on line 5 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'EvilTwinRule' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 5 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'EvilTwinRule' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 5 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'EvilTwinRule' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 5 in Content.Server/ADT/EvilTwin/EvilTwinRuleComponent.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'EvilTwinRule' could not be found (are you missing a using directive or an assembly reference?)
public sealed partial class EvilTwinRuleComponent : Component
{

}
9 changes: 9 additions & 0 deletions Content.Server/ADT/EvilTwin/EvilTwinSpawnerComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server.ADT.EvilTwin;

[RegisterComponent]
public sealed partial class EvilTwinSpawnerComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("target")]
public EntityUid TargetForce { get; set; } = EntityUid.Invalid;
}
19 changes: 19 additions & 0 deletions Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Events;
using Robust.Shared.Random;

namespace Content.Server.Backmen.EvilTwin.StationEvents;
public sealed partial class EvilTwinRule : StationEventSystem<EvilTwinRuleComponent>

Check failure on line 6 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)
{
protected override void Started(EntityUid uid, EvilTwinRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)

Check failure on line 8 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'EvilTwinRuleComponent' could not be found (are you missing a using directive or an assembly reference?)
{
base.Started(uid, component, gameRule, args);

if(!_evilTwinSystem.MakeTwin(out _))
{
Sawmill.Warning("Map not have latejoin spawnpoints for creating evil twin spawner");
}
}

[Dependency] private readonly EvilTwinSystem _evilTwinSystem = default!;

Check failure on line 18 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'EvilTwinSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 18 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'EvilTwinSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 18 in Content.Server/ADT/EvilTwin/StationEvents /EvilTwinRule.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'EvilTwinSystem' could not be found (are you missing a using directive or an assembly reference?)
}
Loading
Loading