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

Mech Update #320

Merged
merged 12 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50 changes: 28 additions & 22 deletions Content.Client/Mech/Ui/MechMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
VerticalAlignment="Center"></Label>
</ProgressBar>
</BoxContainer>
<Label Name="SlotDisplay"
HorizontalAlignment="Left"
Access="Public"
HorizontalExpand="True" />
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<Label Name="ActiveSlotDisplay" HorizontalAlignment="Left" Access="Public" HorizontalExpand="True" Margin="0 0 5 0"/>
<Label Name="PassiveSlotDisplay" HorizontalAlignment="Right" Access="Public" HorizontalExpand="True" Margin="5 0 0 0"/>
</BoxContainer>
</BoxContainer>

<SpriteView Name="MechView"
Margin="10 0 0 0"
VerticalAlignment="Center"
Expand All @@ -54,23 +54,29 @@
</BoxContainer>
<BoxContainer VerticalExpand="True" Margin="10 0 10 10" Orientation="Vertical">
<PanelContainer VerticalExpand="True" MinSize="0 200">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<ScrollContainer
HScrollEnabled="False"
HorizontalExpand="True"
MinSize="100 256"
SizeFlagsStretchRatio="2"
VerticalExpand="True">
<BoxContainer
Name="EquipmentControlContainer"
MinSize="100 256"
Orientation="Vertical"
SizeFlagsStretchRatio="2"
VerticalExpand="True">
</BoxContainer>
</ScrollContainer>
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<!-- Active Equipment -->
<Label Text="Active Equipment" Margin="5" />
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<ScrollContainer HScrollEnabled="False" MinSize="100 100" HorizontalExpand="True" SizeFlagsStretchRatio="2" VerticalExpand="True">
<BoxContainer Name="ActiveEquipmentContainer" MinSize="100 100" Orientation="Vertical" SizeFlagsStretchRatio="2" VerticalExpand="True" />
</ScrollContainer>
</PanelContainer>

<!-- Passive Equipment -->
<Label Text="Passive Equipment" Margin="5" />
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E" />
</PanelContainer.PanelOverride>
<ScrollContainer HScrollEnabled="False" MinSize="100 100" HorizontalExpand="True" SizeFlagsStretchRatio="2" VerticalExpand="True">
<BoxContainer Name="PassiveEquipmentContainer" MinSize="100 100" Orientation="Vertical" SizeFlagsStretchRatio="2" VerticalExpand="True" />
</ScrollContainer>
</PanelContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
</BoxContainer>
Expand Down
14 changes: 11 additions & 3 deletions Content.Client/Mech/Ui/MechMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Fragments;
using Content.Shared.Mech.Components;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Mech;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.XAML;
Expand Down Expand Up @@ -51,7 +53,7 @@ public void UpdateMechStats()
EnergyDisplay.Text = Loc.GetString("mech-energy-missing");
}

SlotDisplay.Text = Loc.GetString("mech-slot-display",
ActiveSlotDisplay.Text = Loc.GetString("mech-slot-display",
("amount", mechComp.MaxEquipmentAmount - mechComp.EquipmentContainer.ContainedEntities.Count));
}

Expand All @@ -60,7 +62,7 @@ public void UpdateEquipmentView()
if (!_ent.TryGetComponent<MechComponent>(_mech, out var mechComp))
return;

EquipmentControlContainer.Children.Clear();
ActiveEquipmentContainer.Children.Clear();
foreach (var ent in mechComp.EquipmentContainer.ContainedEntities)
{
if (!_ent.TryGetComponent<MetaDataComponent>(ent, out var metaData))
Expand All @@ -73,7 +75,13 @@ public void UpdateEquipmentView()

control.OnRemoveButtonPressed += () => OnRemoveButtonPressed?.Invoke(ent);

EquipmentControlContainer.AddChild(control);
if (_ent.TryGetComponent<MechEquipmentComponent>(ent, out var equipmentComp))
{
if (equipmentComp.EquipmentType == EquipmentType.Active)
ActiveEquipmentContainer.AddChild(control);
else if (equipmentComp.EquipmentType == EquipmentType.Passive)
PassiveEquipmentContainer.AddChild(control);
}
}
}

Expand Down
26 changes: 20 additions & 6 deletions Content.Server/Construction/Completions/BuildMech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public sealed partial class BuildMech : IGraphAction
[DataField("mechPrototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string MechPrototype = string.Empty;

[DataField("container")]
public string Container = "battery-container";
[DataField("batteryContainer")]
public string BatteryContainer = "battery-container";

[DataField("gasTankContainer")]
public string GasTankContainer = "gas-tank-container";

// TODO use or generalize ConstructionSystem.ChangeEntity();
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
Expand All @@ -35,22 +38,29 @@ public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager enti
var containerSystem = entityManager.EntitySysManager.GetEntitySystem<ContainerSystem>();
var mechSys = entityManager.System<MechSystem>();

if (!containerSystem.TryGetContainer(uid, Container, out var container, containerManager))
if (!containerSystem.TryGetContainer(uid, BatteryContainer, out var container, containerManager))
{
Logger.Warning($"Mech construct entity {uid} did not have the specified '{Container}' container! Aborting build mech action.");
Logger.Warning($"Mech construct entity {uid} did not have the specified '{BatteryContainer}' container! Aborting build mech action.");
return;
}

if (!containerSystem.TryGetContainer(uid, GasTankContainer, out var gasTankContainer))
{
Logger.Warning($"Mech construct entity {uid} did not have the specified '{GasTankContainer}' container! Aborting build mech action.");
return;
}

if (container.ContainedEntities.Count != 1)
{
Logger.Warning($"Mech construct entity {uid} did not have exactly one item in the specified '{Container}' container! Aborting build mech action.");
Logger.Warning($"Mech construct entity {uid} did not have exactly one item in the specified '{BatteryContainer}' container! Aborting build mech action.");
}

var cell = container.ContainedEntities[0];
var gasTank = gasTankContainer.ContainedEntities[0];

if (!entityManager.TryGetComponent<BatteryComponent>(cell, out var batteryComponent))
{
Logger.Warning($"Mech construct entity {uid} had an invalid entity in container \"{Container}\"! Aborting build mech action.");
Logger.Warning($"Mech construct entity {uid} had an invalid entity in container \"{BatteryContainer}\"! Aborting build mech action.");
return;
}

Expand All @@ -63,6 +73,10 @@ public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager enti
{
mechSys.InsertBattery(mech, cell, mechComp, batteryComponent);
containerSystem.Insert(cell, mechComp.BatterySlot);
if (mechComp.GasTankSlot.ContainedEntity == null && gasTank != null)
{
containerSystem.Insert(gasTank, mechComp.GasTankSlot);
}
}

var entChangeEv = new ConstructionChangeEntityEvent(mech, uid);
Expand Down
59 changes: 58 additions & 1 deletion Content.Server/Mech/Systems/MechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Content.Server.Mech.Components;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Shared.PowerCell;
using Content.Shared.ActionBlocker;
using Content.Shared.Actions;
using Content.Shared.Damage;
Expand All @@ -24,6 +26,7 @@
using Content.Shared.Tools.Systems;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;
using Robust.Shared.Audio.Systems;
using Robust.Shared.GameObjects;
using Robust.Shared.Containers;
Expand Down Expand Up @@ -54,6 +57,8 @@ public sealed partial class MechSystem : SharedMechSystem
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly NpcFactionSystem _factionSystem = default!;
[Dependency] private readonly SharedPointLightSystem _light = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] protected readonly IGameTiming Timing = default!;

/// <inheritdoc/>
public override void Initialize()
Expand All @@ -67,6 +72,7 @@ public override void Initialize()
SubscribeLocalEvent<MechComponent, GetVerbsEvent<AlternativeVerb>>(OnAlternativeVerb);
SubscribeLocalEvent<MechComponent, MechOpenUiEvent>(OnOpenUi);
SubscribeLocalEvent<MechComponent, RemoveBatteryEvent>(OnRemoveBattery);
SubscribeLocalEvent<MechComponent, ChargeChangedEvent>(OnChargeChanged);
SubscribeLocalEvent<MechComponent, MechEntryEvent>(OnMechEntry);
SubscribeLocalEvent<MechComponent, MechExitEvent>(OnMechExit);

Expand All @@ -91,16 +97,67 @@ public override void Initialize()
#endregion
}

public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<PowerCellDrawComponent, MechComponent>();

while (query.MoveNext(out var uid, out var comp, out var mechComp))
{
if (!mechComp.Light)
continue;

if (Timing.CurTime < comp.NextUpdateTime)
continue;

comp.NextUpdateTime += comp.Delay;

if (mechComp.BatterySlot.ContainedEntity == null
|| !TryComp<BatteryComponent>(mechComp.BatterySlot.ContainedEntity.Value, out var battery) )
continue;

if (!_battery.TryUseCharge(mechComp.BatterySlot.ContainedEntity.Value, comp.DrawRate))
continue;

var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
RaiseLocalEvent(uid, ref ev);
}
}


private void OnToggleLightEvent(EntityUid uid, MechComponent component, ToggleActionEvent args)
{
if (args.Handled)
return;

if (!_light.TryGetLight(uid, out var light))
if (component.BatterySlot.ContainedEntity == null
|| !TryComp<BatteryComponent>(component.BatterySlot.ContainedEntity, out var battery)
|| battery.CurrentCharge <= 0)
return;

args.Handled = true;

ToggleLight(uid, component);
}

private void OnChargeChanged(Entity<MechComponent> ent, ref ChargeChangedEvent args)
{
if (args.Charge == 0 && ent.Comp.Light)
ToggleLight(ent.Owner, ent.Comp);

ent.Comp.Energy = args.Charge;
ent.Comp.MaxEnergy = args.MaxCharge;

_actionBlocker.UpdateCanMove(ent.Owner);

Dirty(ent.Owner, ent.Comp);
}

public void ToggleLight(EntityUid uid, MechComponent component)
{
if (!_light.TryGetLight(uid, out var light))
return;

_light.SetEnabled(uid, !component.Light, comp: light);

_actions.SetToggled(component.MechToggleLightActionEntity, !component.Light);
Expand Down
11 changes: 10 additions & 1 deletion Content.Shared/Mech/Components/MechComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public sealed partial class MechComponent : Component

[ViewVariables]
public readonly string BatterySlotId = "mech-battery-slot";

/// <summary>
/// The slot the gas tank is stored in.
/// </summary>
[ViewVariables]
public ContainerSlot GasTankSlot = default!;

[ViewVariables]
public readonly string GasTankSlotId = "mech-gas-tank-slot";

/// <summary>
/// A multiplier used to calculate how much of the damage done to a mech
Expand Down Expand Up @@ -194,7 +203,7 @@ public sealed partial class MechComponent : Component
public SoundSpecifier CriticalDamageSound = new SoundPathSpecifier("/Audio/Mecha/critnano.ogg");

[DataField]
public bool FirstStart = true;
public bool FirstStart = false;

[DataField]
public bool PlayPowerSound = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.DoAfter;
using Content.Shared.Mech.Components;
using Content.Shared.Mech;
using Robust.Shared.Serialization;

namespace Content.Shared.Mech.Equipment.Components;
Expand All @@ -19,6 +20,8 @@ public sealed partial class MechEquipmentComponent : Component
/// The mech that the equipment is inside of.
/// </summary>
[ViewVariables] public EntityUid? EquipmentOwner;

[ViewVariables] public EquipmentType EquipmentType = EquipmentType.Active;
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Mech/SharedMech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public enum MechVisualLayers : byte
Light
}

[Serializable, NetSerializable]
public enum EquipmentType : byte
{
Active,
Passive
}

/// <summary>
/// Event raised on equipment when it is inserted into a mech
/// </summary>
Expand Down
Loading
Loading