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

Port Mechs (Wizden PR #32346) #1018

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
16 changes: 12 additions & 4 deletions Content.Client/Mech/Ui/MechMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ public void UpdateMechStats()

var integrityPercent = mechComp.Integrity / mechComp.MaxIntegrity;
IntegrityDisplayBar.Value = integrityPercent.Float();
IntegrityDisplay.Text = Loc.GetString("mech-integrity-display", ("amount", (integrityPercent*100).Int()));
IntegrityDisplay.Text = Loc.GetString("mech-integrity-display", ("amount", (integrityPercent * 100).Int()));

var energyPercent = mechComp.Energy / mechComp.MaxEnergy;
EnergyDisplayBar.Value = energyPercent.Float();
EnergyDisplay.Text = Loc.GetString("mech-energy-display", ("amount", (energyPercent*100).Int()));
if (mechComp.MaxEnergy != 0f)
{
var energyPercent = mechComp.Energy / mechComp.MaxEnergy;
EnergyDisplayBar.Value = energyPercent.Float();
EnergyDisplay.Text = Loc.GetString("mech-energy-display", ("amount", (energyPercent * 100).Int()));
}
else
{
EnergyDisplayBar.Value = 0f;
EnergyDisplay.Text = Loc.GetString("mech-energy-missing");
}

SlotDisplay.Text = Loc.GetString("mech-slot-display",
("amount", mechComp.MaxEquipmentAmount - mechComp.EquipmentContainer.ContainedEntities.Count));
Expand Down
4 changes: 4 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Camera;
using Content.Shared.CombatMode;
using Content.Shared.Mech.Components;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
Expand Down Expand Up @@ -144,6 +145,9 @@ public override void Update(float frameTime)

var entity = entityNull.Value;

if (TryComp<MechPilotComponent>(entity, out var mechPilot))
entity = mechPilot.Mech;

if (!TryGetGun(entity, out var gunUid, out var gun))
{
return;
Expand Down
46 changes: 46 additions & 0 deletions Content.Server/Mech/Equipment/EntitySystems/MechGunSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Server.Mech.Systems;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Mech.Components;
using Content.Shared.Mech.Equipment.Components;
using Content.Shared.Weapons.Ranged.Systems;

namespace Content.Server.Mech.Equipment.EntitySystems;
public sealed class MechGunSystem : EntitySystem
{
[Dependency] private readonly MechSystem _mech = default!;
[Dependency] private readonly BatterySystem _battery = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MechEquipmentComponent, GunShotEvent>(MechGunShot);
}

private void MechGunShot(EntityUid uid, MechEquipmentComponent component, ref GunShotEvent args)
{
if (!component.EquipmentOwner.HasValue
|| !HasComp<MechComponent>(component.EquipmentOwner.Value)
|| !TryComp<BatteryComponent>(uid, out var battery))
return;

ChargeGunBattery(uid, battery);
}

private void ChargeGunBattery(EntityUid uid, BatteryComponent component)
{
if (!TryComp<MechEquipmentComponent>(uid, out var mechEquipment)
|| mechEquipment.EquipmentOwner is null
|| !TryComp<MechComponent>(mechEquipment.EquipmentOwner.Value, out var mech))
return;

var chargeDelta = component.MaxCharge - component.CurrentCharge;
// TODO: The battery charge of the mech would be spent directly when fired.
if (chargeDelta <= 0
|| mech.Energy - chargeDelta < 0
|| !_mech.TryChangeEnergy(mechEquipment.EquipmentOwner.Value, -chargeDelta, mech))
return;

_battery.SetCharge(uid, component.MaxCharge, component);
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Mech/Components/MechComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace Content.Shared.Mech.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class MechComponent : Component
{
/// <summary>
/// Whether or not an emag disables it.
/// </summary>
[DataField, AutoNetworkedField]
public bool BreakOnEmag = true;

/// <summary>
/// How much "health" the mech has left.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/Mech/EntitySystems/SharedMechSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
Expand All @@ -15,6 +17,8 @@
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
Expand Down Expand Up @@ -49,6 +53,7 @@ public override void Initialize()
SubscribeLocalEvent<MechComponent, GetAdditionalAccessEvent>(OnGetAdditionalAccess);
SubscribeLocalEvent<MechComponent, DragDropTargetEvent>(OnDragDrop);
SubscribeLocalEvent<MechComponent, CanDropTargetEvent>(OnCanDragDrop);
SubscribeLocalEvent<MechComponent, GotEmaggedEvent>(OnEmagged);

SubscribeLocalEvent<MechPilotComponent, GetMeleeWeaponEvent>(OnGetMeleeWeapon);
SubscribeLocalEvent<MechPilotComponent, CanAttackFromContainerEvent>(OnCanAttackFromContainer);
Expand Down Expand Up @@ -447,6 +452,15 @@ private void OnCanDragDrop(EntityUid uid, MechComponent component, ref CanDropTa
args.CanDrop |= !component.Broken && CanInsert(uid, args.Dragged, component);
}

private void OnEmagged(EntityUid uid, MechComponent component, ref GotEmaggedEvent args)
{
if (!component.BreakOnEmag)
return;

args.Handled = true;
component.EquipmentWhitelist = null;
Dirty(uid, component);
}
}

/// <summary>
Expand Down
14 changes: 5 additions & 9 deletions Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared.Interaction;
using Content.Shared.Inventory;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Mech.Components;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee.Components;
Expand Down Expand Up @@ -185,16 +186,11 @@ private void OnLightAttack(LightAttackEvent msg, EntitySessionEventArgs args)

private void OnHeavyAttack(HeavyAttackEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity == null)
{
return;
}

if (!TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon) ||
weaponUid != GetEntity(msg.Weapon))
{
if (args.SenderSession.AttachedEntity == null
|| HasComp<MechPilotComponent>(args.SenderSession.AttachedEntity)
|| !TryGetWeapon(args.SenderSession.AttachedEntity.Value, out var weaponUid, out var weapon)
|| weaponUid != GetEntity(msg.Weapon))
return;
}

AttemptAttack(args.SenderSession.AttachedEntity.Value, weaponUid, weapon, msg, args.SenderSession);
}
Expand Down
34 changes: 26 additions & 8 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Item; // Delta-V: Felinids in duffelbags can't shoot.
using Content.Shared.Mech.Components;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Tag;
Expand Down Expand Up @@ -130,9 +131,10 @@ private void OnShootRequest(RequestShootEvent msg, EntitySessionEventArgs args)
!_combatMode.IsInCombatMode(user) ||
!TryGetGun(user.Value, out var ent, out var gun) ||
HasComp<ItemComponent>(user)) // Delta-V: Felinids in duffelbags can't shoot.
{
return;
}

if (TryComp<MechPilotComponent>(user.Value, out var mechPilot))
user = mechPilot.Mech;

if (ent != GetEntity(msg.Gun))
return;
Expand All @@ -147,14 +149,16 @@ private void OnStopShootRequest(RequestStopShootEvent ev, EntitySessionEventArgs
{
var gunUid = GetEntity(ev.Gun);

if (args.SenderSession.AttachedEntity == null ||
!TryComp<GunComponent>(gunUid, out var gun) ||
!TryGetGun(args.SenderSession.AttachedEntity.Value, out _, out var userGun))
{
var user = args.SenderSession.AttachedEntity;

if (user == null)
return;
}

if (userGun != gun)
if (TryComp<MechPilotComponent>(user.Value, out var mechPilot))
user = mechPilot.Mech;

if (!TryGetGun(user.Value, out var ent, out var gun)
|| ent != gunUid)
return;

StopShooting(gunUid, gun);
Expand All @@ -173,6 +177,15 @@ public bool TryGetGun(EntityUid entity, out EntityUid gunEntity, [NotNullWhen(tr
gunEntity = default;
gunComp = null;

if (TryComp<MechComponent>(entity, out var mech)
&& mech.CurrentSelectedEquipment.HasValue
&& TryComp<GunComponent>(mech.CurrentSelectedEquipment.Value, out var mechGun))
{
gunEntity = mech.CurrentSelectedEquipment.Value;
gunComp = mechGun;
return true;
}

if (EntityManager.TryGetComponent(entity, out HandsComponent? hands) &&
hands.ActiveHandEntity is { } held &&
TryComp(held, out GunComponent? gun))
Expand Down Expand Up @@ -277,8 +290,11 @@ private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
var shots = 0;
var lastFire = gun.NextFire;

Log.Debug($"Nextfire={gun.NextFire} curTime={curTime}");

while (gun.NextFire <= curTime)
{
Log.Debug("Shots++");
gun.NextFire += fireRate;
shots++;
}
Expand All @@ -302,6 +318,8 @@ private void AttemptShoot(EntityUid user, EntityUid gunUid, GunComponent gun)
throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!");
}

Log.Debug($"Shots fired: {shots}");

var attemptEv = new AttemptShootEvent(user, null);
RaiseLocalEvent(gunUid, ref attemptEv);

Expand Down
16 changes: 15 additions & 1 deletion Resources/Locale/en-US/lathe/lathe-categories.ftl
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
lathe-category-ammo = Ammo
lathe-category-circuitry = Circuitry
lathe-category-lights = Lights
lathe-category-mechs = Mechs
lathe-category-parts = Parts
lathe-category-robotics = Robotics
lathe-category-tools = Tools
lathe-category-weapons = Weapons

lathe-category-food = Food
lathe-category-chemicals = Chemicals
lathe-category-materials = Materials

lathe-category-mechs-vim = Vim
lathe-category-mechs-honker = H.O.N.K.
lathe-category-mechs-hamptr = H.A.M.P.T.R.
lathe-category-mechs-ripley = Riley
lathe-category-mechs-ripleymkii = Riley MK-II
lathe-category-mechs-clarke = Clarke
lathe-category-mechs-gygax = Gygax
lathe-category-mechs-durand = Durand
lathe-category-mechs-equipment = Mech equipment
lathe-category-mechs-weapons = Mech weapons
1 change: 1 addition & 0 deletions Resources/Locale/en-US/mech/mech.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mech-menu-title = mech control panel

mech-integrity-display = Integrity: {$amount}%
mech-energy-display = Energy: {$amount}%
mech-energy-missing = Energy: MISSING
mech-slot-display = Open Slots: {$amount}

mech-no-enter = You cannot pilot this.
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/research/technologies.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ research-technology-power-generation = Power Generation
research-technology-atmospheric-tech = Atmospherics
research-technology-shuttlecraft = Shuttlecraft
research-technology-ripley-aplu = Ripley APLU
research-technology-ripley-mkii = Ripley MK-II
research-technology-clarke = Clarke
research-technology-gygax = Gygax
research-technology-durand = Durand
research-technology-advanced-atmospherics = Advanced Atmospherics
research-technology-advanced-tools = Advanced Tools
research-technology-mechanized-salvaging = Mechanized Salvaging
Expand All @@ -36,6 +40,7 @@ research-technology-portable-microfusion-weaponry = Portable Microfusion Weaponr
research-technology-experimental-battery-ammo = Experimental Battery Ammo
research-technology-basic-shuttle-armament = Shuttle basic armament
research-technology-advanced-shuttle-weapon = Advanced shuttle weapons
research-technology-explosive-mech-ammunition = Explosive Mech Ammunition

research-technology-basic-robotics = Basic Robotics
research-technology-basic-anomalous-research = Basic Anomalous Research
Expand Down Expand Up @@ -67,6 +72,7 @@ research-technology-robotic-cleanliness = Robotic Cleanliness
research-technology-advanced-cleaning = Advanced Cleaning
research-technology-meat-manipulation = Meat Manipulation
research-technology-honk-mech = H.O.N.K. Mech
research-technology-honk-weapons = Bananium Weapons
research-technology-advanced-spray = Advanced Spray
research-technology-bluespace-cargo-transport = Bluespace Cargo Transport
research-technology-quantum-fiber-weaving = Quantum Fiber Weaving
Expand Down
6 changes: 6 additions & 0 deletions Resources/Locale/en-US/store/uplink-catalog.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ uplink-reinforcement-radio-desc = Radio in a reinforcement agent of extremely q
uplink-reinforcement-radio-cyborg-assault-name = Syndicate Assault Cyborg Teleporter
uplink-reinforcement-radio-cyborg-assault-desc = A lean, mean killing machine with access to an Energy Sword, LMG, Cryptographic Sequencer, and a Pinpointer.

uplink-mech-teleporter-heavy-name = Heavy Mech teleporter
uplink-mech-teleporter-heavy-desc = Contains Cybersan heavy armored mech with integrated chainsword, Ultra AC-2, LBX AC 10 "Scattershot", BRM-6 Missile Rack and P-X Tesla Cannon.

uplink-mech-teleporter-assault-name = Assault Mech teleporter
uplink-mech-teleporter-assault-desc = Contains Cybersan lightly armored mech with integrated chainsword, LBX AC 10 "Scattershot", SRM-8 Light Missile Rack and P-X Tesla Cannon.

uplink-stealth-box-name = Stealth Box
uplink-stealth-box-desc = A box outfitted with stealth technology, sneak around with this and don't move too fast now!

Expand Down
30 changes: 30 additions & 0 deletions Resources/Prototypes/Catalog/Fills/Crates/syndicate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,33 @@
components:
- type: SurplusBundle
totalPrice: 125

- type: entity
id: CrateCybersunDarkGygaxBundle
suffix: Filled
parent: CrateSyndicate
name: Cybersun gygax bundle
description: Contains a set of Cybersan light armored mechs.
components:
- type: StorageFill
contents:
- id: MechGygaxSyndieFilled
- id: DoubleEmergencyOxygenTankFilled
- id: DoubleEmergencyNitrogenTankFilled
- id: ToolboxSyndicateFilled
- id: PlushieNuke

- type: entity
id: CrateCybersunMaulerBundle
suffix: Filled
parent: CrateSyndicate
name: Cybersun mauler bundle
description: Contains a set of Cybersan heavy armored mechs.
components:
- type: StorageFill
contents:
- id: MechMaulerSyndieFilled
- id: DoubleEmergencyOxygenTankFilled
- id: DoubleEmergencyNitrogenTankFilled
- id: ToolboxSyndicateFilled
- id: PlushieNuke
Loading
Loading