Skip to content

Commit

Permalink
extraction WIP but we gotta sidequest momentarily
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 committed Jul 13, 2024
1 parent 13fd4fb commit cd297d0
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Initialize()

private void OnAnalysisConsoleAfterAutoHandleState(Entity<AnalysisConsoleComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (_ui.TryGetOpenUi<AnalysisConsoleBoundUserInterface>(ent.Owner, ArtifactAnalzyerUiKey.Key, out var bui))
if (_ui.TryGetOpenUi<AnalysisConsoleBoundUserInterface>(ent.Owner, ArtifactAnalyzerUiKey.Key, out var bui))
bui.Update(ent);
}

Expand All @@ -32,7 +32,7 @@ private void OnAnalyzerAfterAutoHandleState(Entity<ArtifactAnalyzerComponent> en
if (!TryGetAnalysisConsole(ent, out var analysisConsole))
return;

if (_ui.TryGetOpenUi<AnalysisConsoleBoundUserInterface>(analysisConsole.Value.Owner, ArtifactAnalzyerUiKey.Key, out var bui))
if (_ui.TryGetOpenUi<AnalysisConsoleBoundUserInterface>(analysisConsole.Value.Owner, ArtifactAnalyzerUiKey.Key, out var bui))
bui.Update(analysisConsole.Value);
}
}
18 changes: 17 additions & 1 deletion Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
</BoxContainer>
</PanelContainer>
<customControls:HSeparator StyleClasses="HighDivider" Margin="0 15 0 10"/>
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<BoxContainer Name="ExtractContainer" Orientation="Vertical" VerticalExpand="True" Visible="False">
<PanelContainer HorizontalExpand="True" VerticalExpand="True" RectClipContent="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<BoxContainer Margin="10 10 10 5" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<ScrollContainer HScrollEnabled="False" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer HorizontalExpand="True" VerticalExpand="True">
<RichTextLabel Name="ExtractionResearchLabel" VerticalAlignment="Top" HorizontalAlignment="Left"/>
</BoxContainer>
</ScrollContainer>
<Control MinHeight="5"/>
<RichTextLabel Name="ExtractionSumLabel" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
</BoxContainer>
</PanelContainer>
</BoxContainer>
<BoxContainer Name="NodeViewContainer" Orientation="Vertical" VerticalExpand="True">
<ScrollContainer HScrollEnabled="False" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Vertical" HorizontalExpand="False" VerticalExpand="True">
<Label Name="NoneSelectedLabel" Text="{Loc 'analysis-console-no-node'}" HorizontalAlignment="Center" VerticalAlignment="Center" VerticalExpand="True" Visible="False"/>
Expand Down
90 changes: 87 additions & 3 deletions Content.Client/Xenoarchaeology/Ui/AnalysisConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using System.Linq;
using System.Text;
using Content.Client.Message;
using Content.Client.Resources;
using Content.Client.UserInterface.Controls;
using Content.Client.Xenoarchaeology.Artifact;
using Content.Client.Xenoarchaeology.Equipment;
using Content.Shared.NameIdentifier;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Content.Shared.Xenoarchaeology.Equipment.Components;
using Robust.Client.Audio;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Audio;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.Xenoarchaeology.Ui;

Expand All @@ -20,13 +25,20 @@ public sealed partial class AnalysisConsoleMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _ent = default!;
[Dependency] private readonly IResourceCache _resCache = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
private readonly ArtifactAnalyzerSystem _artifactAnalyzer;
private readonly XenoArtifactSystem _xenoArtifact;
private readonly AudioSystem _audio;

private Entity<AnalysisConsoleComponent> _owner;
private Entity<XenoArtifactNodeComponent>? _currentNode;

private readonly List<(string, int)> _nodeExtractionValues = new();
private TimeSpan? _nextExtractStringTime;
private int _extractionSum;
private readonly FormattedMessage _extractionMessage = new();

public event Action? OnServerSelectionButtonPressed;
public event Action? OnExtractButtonPressed;

Expand All @@ -37,6 +49,7 @@ public AnalysisConsoleMenu(EntityUid owner)

_xenoArtifact = _ent.System<XenoArtifactSystem>();
_artifactAnalyzer = _ent.System<ArtifactAnalyzerSystem>();
_audio = _ent.System<AudioSystem>();

if (BackPanel.PanelOverride is StyleBoxTexture tex)
tex.Texture = _resCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
Expand All @@ -59,14 +72,85 @@ public AnalysisConsoleMenu(EntityUid owner)
OnServerSelectionButtonPressed?.Invoke();
};

//TODO: extract button
ExtractButton.OnPressed += StartExtract;

var comp = _ent.GetComponent<AnalysisConsoleComponent>(owner);
_owner = (owner, comp);
Update((owner, comp));
SetSelectedNode(null);
}

private void StartExtract(BaseButton.ButtonEventArgs obj)
{
if (!_artifactAnalyzer.TryGetArtifactFromConsole(_owner, out var artifact))
return;

ExtractContainer.Visible = true;
NodeViewContainer.Visible = false;

_nodeExtractionValues.Clear();
_extractionSum = 0;
_extractionMessage.Clear();
_nextExtractStringTime = _timing.CurTime;

var nodes = _xenoArtifact.GetAllNodes(artifact.Value);
foreach (var node in nodes)
{
var pointValue = _xenoArtifact.GetResearchValue(node);
if (pointValue <= 0)
continue;
var nodeId = _xenoArtifact.GetNodeId(node);

var text = Loc.GetString("analysis-console-extract-value", ("id", nodeId), ("value", pointValue));
_nodeExtractionValues.Add((text, pointValue));
}

if (_nodeExtractionValues.Count == 0)
_nodeExtractionValues.Add((Loc.GetString("analysis-console-extract-none"), 0));

_nodeExtractionValues.Sort((x, y) => x.Item2.CompareTo(y.Item2));
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

if (_nextExtractStringTime == null)
return;

if (_timing.CurTime < _nextExtractStringTime)
return;

if (_nodeExtractionValues.Count == 0)
{
ExtractContainer.Visible = false;
NodeViewContainer.Visible = true;
_nextExtractStringTime = null;
return;
}

var (message, value) = _nodeExtractionValues.First();
_nodeExtractionValues.RemoveAt(0);

var delay = _nodeExtractionValues.Count == 0 ? TimeSpan.FromSeconds(3) : TimeSpan.FromSeconds(0.25);
_nextExtractStringTime = _timing.CurTime + delay;
_extractionSum += value;
_extractionMessage.AddMarkupOrThrow(message);
_extractionMessage.PushNewline();

ExtractionResearchLabel.SetMessage(_extractionMessage);
ExtractionSumLabel.SetMarkup(Loc.GetString("analysis-console-extract-sum", ("value", _extractionSum)));

if (_playerManager.LocalSession?.AttachedEntity is { } attachedEntity)
{
var volume = _nodeExtractionValues.Count == 0 ? 1f : -10f;
_audio.PlayGlobal(_owner.Comp.ScanFinishedSound, attachedEntity, AudioParams.Default.WithVolume(volume));
}

if (_nodeExtractionValues.Count == 0)
OnExtractButtonPressed?.Invoke();
}

public void Update(Entity<AnalysisConsoleComponent> ent)
{
_artifactAnalyzer.TryGetArtifactFromConsole(ent, out var arti);
Expand Down Expand Up @@ -109,7 +193,7 @@ public void SetSelectedNode(Entity<XenoArtifactNodeComponent>? node)
return;

IDValueLabel.SetMarkup(Loc.GetString("analysis-console-info-id-value",
("id", (_ent.GetComponentOrNull<NameIdentifierComponent>(node.Value)?.Identifier ?? 0).ToString("D3"))));
("id", _xenoArtifact.GetNodeId(node.Value))));

// If active, state is 2. else, it is 0 or 1 based on whether or not it is unlocked.
var lockedState = _xenoArtifact.IsNodeActive(artifact.Value, node.Value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Numerics;
using Content.Client.Xenoarchaeology.Artifact;
using Content.Shared.NameIdentifier;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
Expand Down Expand Up @@ -126,7 +125,7 @@ protected override void Draw(DrawingHandleScreen handle)

handle.DrawCircle(pos, NodeRadius, Color.ToSrgb(color), false);

var text = (_entityManager.GetComponentOrNull<NameIdentifierComponent>(node)?.Identifier ?? 0).ToString("D3");
var text = artiSys.GetNodeId(node);
var dimensions = handle.GetDimensions(_font, text, 1);
handle.DrawString(_font, pos - new Vector2(dimensions.X / 2, dimensions.Y / 2), text, color);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.Salvage;
using Content.Server.Xenoarchaeology.Artifact.XAT.Components;
using Content.Shared.Clothing;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Content.Shared.Xenoarchaeology.Artifact.XAT;

Expand Down Expand Up @@ -43,10 +44,10 @@ protected override void UpdateXAT(Entity<XenoArtifactComponent> artifact, Entity
{
base.UpdateXAT(artifact, node, frameTime);

var query = EntityQueryEnumerator<MagbootsComponent, TransformComponent>();
while (query.MoveNext(out _, out var magboots, out var xform))
var query = EntityQueryEnumerator<MagbootsComponent, ItemToggleComponent, TransformComponent>();
while (query.MoveNext(out _, out _, out var itemToggle, out var xform))
{
if (!magboots.On)
if (!itemToggle.Activated)
continue;

if (!_transform.InRange(xform.Coordinates, Transform(artifact).Coordinates, node.Comp1.MagnetRange))
Expand Down
51 changes: 51 additions & 0 deletions Content.Server/Xenoarchaeology/Artifact/XenoArtifactCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Xenoarchaeology.Artifact.Components;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Toolshed;

namespace Content.Server.Xenoarchaeology.Artifact;
Expand Down Expand Up @@ -59,4 +61,53 @@ void AddHorizontalFiller(StringBuilder builder)
}
}
}

[CommandImplementation("totalResearch")]
public int TotalResearch([PipedArgument] EntityUid ent)
{
var artiSys = EntityManager.System<XenoArtifactSystem>();
var comp = EntityManager.GetComponent<XenoArtifactComponent>(ent);

var sum = 0;

var nodes = artiSys.GetAllNodes((ent, comp));
foreach (var node in nodes)
{
sum += node.Comp.ResearchValue;
}

return sum;
}

[ValidatePrototypeId<EntityPrototype>]
public const string ArtifactPrototype = "XenoArtifact";

[CommandImplementation("averageResearch")]
public float AverageResearch()
{
const int n = 100;
var sum = 0;

for (var i = 0; i < n; i++)
{
var ent = Spawn(ArtifactPrototype, MapCoordinates.Nullspace);
sum += TotalResearch(ent);
Del(ent);
}

return (float) sum / n;
}

[CommandImplementation("unlockAllNodes")]
public void UnlockAllNodes([PipedArgument] EntityUid ent)
{
var artiSys = EntityManager.System<XenoArtifactSystem>();
var comp = EntityManager.GetComponent<XenoArtifactComponent>(ent);

var nodes = artiSys.GetAllNodes((ent, comp));
foreach (var node in nodes)
{
artiSys.SetNodeUnlocked((node, node.Comp));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private void GenerateArtifactStructure(Entity<XenoArtifactComponent> ent)
GenerateArtifactSegment(ent, ref nodeCount);
}

RebuildNodeData((ent, ent));
RebuildXenoArtifactMetaData((ent, ent));
}

private void CreateTriggerPool(Entity<XenoArtifactComponent> ent, ref int size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Paper;
using Content.Server.Power.Components;
using Content.Server.Research.Systems;
using Content.Server.Xenoarchaeology.Artifact;
using Content.Shared.UserInterface;
using Content.Server.Xenoarchaeology.Equipment.Components;
using Content.Server.Xenoarchaeology.Equipment.Systems;
Expand Down Expand Up @@ -35,7 +36,6 @@ public sealed class ArtifactAnalyzerSystem : SharedArtifactAnalyzerSystem
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly ResearchSystem _research = default!;
Expand All @@ -52,12 +52,6 @@ public override void Initialize()
SubscribeLocalEvent<ActiveArtifactAnalyzerComponent, PowerChangedEvent>(OnPowerChanged);

SubscribeLocalEvent<AnalysisConsoleComponent, AnalysisConsoleExtractButtonPressedMessage>(OnExtractButton);

SubscribeLocalEvent<AnalysisConsoleComponent, ResearchClientServerSelectedMessage>((e, c, _) => UpdateUserInterface(e, c),
after: [typeof(ResearchSystem)]);
SubscribeLocalEvent<AnalysisConsoleComponent, ResearchClientServerDeselectedMessage>((e, c, _) => UpdateUserInterface(e, c),
after: [typeof(ResearchSystem)]);
SubscribeLocalEvent<AnalysisConsoleComponent, BeforeActivatableUIOpenEvent>((e, c, _) => UpdateUserInterface(e, c));
}

/// <summary>
Expand All @@ -79,9 +73,7 @@ private void UpdateUserInterface(EntityUid uid, AnalysisConsoleComponent? compon
{
if (!Resolve(uid, ref component, false))
return;

return;

}

/// <summary>
Expand Down Expand Up @@ -115,8 +107,6 @@ private void OnExtractButton(EntityUid uid, AnalysisConsoleComponent component,
//
// _popup.PopupEntity(Loc.GetString("analyzer-artifact-extract-popup"),
// component.AnalyzerEntity.Value, PopupType.Large);

UpdateUserInterface(uid, component);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public sealed partial class XenoArtifactNodeComponent : Component
[DataField]
public int MaxDurability = 5;
#endregion

#region Research
[DataField, AutoNetworkedField]
public int ResearchValue;

[DataField, AutoNetworkedField]
public int ConsumedResearchValue;
#endregion
}
Loading

0 comments on commit cd297d0

Please sign in to comment.