ECS verbs and update context menu (#4594)
* Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
This commit is contained in:
32
Content.Server/Weapon/Ranged/Ammunition/AmmunitionSystem.cs
Normal file
32
Content.Server/Weapon/Ranged/Ammunition/AmmunitionSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Ammunition
|
||||
{
|
||||
public sealed class AmmunitionSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<AmmoBoxComponent, GetAlternativeVerbsEvent>(AddDumpVerb);
|
||||
}
|
||||
|
||||
private void AddDumpVerb(EntityUid uid, AmmoBoxComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (component.AmmoLeft == 0)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("dump-vert-get-data-text");
|
||||
verb.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
|
||||
verb.Act = () => component.EjectContents(10);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,9 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Weapon.Ranged.Barrels.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -92,6 +90,10 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
if (_unspawnedCount > 0)
|
||||
{
|
||||
ammo = Owner.EntityManager.SpawnEntity(_fillPrototype, Owner.Transform.Coordinates);
|
||||
|
||||
// when dumping from held ammo box, this detaches the spawned ammo from the player.
|
||||
ammo.Transform.AttachParentToContainerOrGrid();
|
||||
|
||||
_unspawnedCount--;
|
||||
}
|
||||
|
||||
@@ -183,7 +185,7 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EjectContents(int count)
|
||||
public void EjectContents(int count)
|
||||
{
|
||||
var ejectCount = Math.Min(count, Capacity);
|
||||
var ejectAmmo = new List<IEntity>(ejectCount);
|
||||
@@ -213,31 +215,6 @@ namespace Content.Server.Weapon.Ranged.Ammunition.Components
|
||||
return TryUse(eventArgs.User);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// So if you have 200 rounds in a box and that suddenly creates 200 entities you're not having a fun time
|
||||
[Verb]
|
||||
private sealed class DumpVerb : Verb<AmmoBoxComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, AmmoBoxComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("dump-vert-get-data-text");
|
||||
data.Visibility = component.AmmoLeft > 0 ? VerbVisibility.Visible : VerbVisibility.Disabled;
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, AmmoBoxComponent component)
|
||||
{
|
||||
component.EjectContents(10);
|
||||
}
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
message.AddMarkup("\n" + Loc.GetString("ammo-box-component-on-examine-caliber-description", ("caliber", _caliber)));
|
||||
|
||||
149
Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs
Normal file
149
Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Weapon.Ranged.Barrels.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Weapon.Ranged.Barrels
|
||||
{
|
||||
public sealed class BarrelSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<RevolverBarrelComponent, GetAlternativeVerbsEvent>(AddSpinVerb);
|
||||
|
||||
SubscribeLocalEvent<ServerBatteryBarrelComponent, GetAlternativeVerbsEvent>(AddEjectCellVerb);
|
||||
SubscribeLocalEvent<ServerBatteryBarrelComponent, GetInteractionVerbsEvent>(AddInsertCellVerb);
|
||||
|
||||
SubscribeLocalEvent<BoltActionBarrelComponent, GetInteractionVerbsEvent>(AddToggleBoltVerb);
|
||||
|
||||
SubscribeLocalEvent<ServerMagazineBarrelComponent, GetInteractionVerbsEvent>(AddMagazineInteractionVerbs);
|
||||
SubscribeLocalEvent<ServerMagazineBarrelComponent, GetAlternativeVerbsEvent>(AddEjectMagazineVerb);
|
||||
}
|
||||
|
||||
private void AddSpinVerb(EntityUid uid, RevolverBarrelComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (component.Capacity <= 1 || component.ShotsLeft == 0)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = Loc.GetString("spin-revolver-verb-get-data-text");
|
||||
verb.IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png";
|
||||
verb.Act = () =>
|
||||
{
|
||||
component.Spin();
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("spin-revolver-verb-on-activate"));
|
||||
};
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddToggleBoltVerb(EntityUid uid, BoltActionBarrelComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = component.BoltOpen
|
||||
? Loc.GetString("close-bolt-verb-get-data-text")
|
||||
: Loc.GetString("open-bolt-verb-get-data-text");
|
||||
verb.Act = () => component.BoltOpen = !component.BoltOpen;
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
// TODO VERBS EJECTABLES Standardize eject/insert verbs into a single system?
|
||||
// Really, why isn't this just PowerCellSlotComponent?
|
||||
private void AddEjectCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!component.PowerCellRemovable ||
|
||||
component.PowerCell == null ||
|
||||
!_actionBlockerSystem.CanPickup(args.User))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = component.PowerCell.Owner.Name;
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Act = () => component.TryEjectCell(args.User);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddInsertCellVerb(EntityUid uid, ServerBatteryBarrelComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Using == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
component.PowerCell != null ||
|
||||
!args.Using.HasComponent<BatteryComponent>() ||
|
||||
!_actionBlockerSystem.CanDrop(args.User))
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = args.Using.Name;
|
||||
verb.Category = VerbCategory.Insert;
|
||||
verb.Act = () => component.TryInsertPowerCell(args.Using);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddEjectMagazineVerb(EntityUid uid, ServerMagazineBarrelComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract ||
|
||||
!component.HasMagazine ||
|
||||
!_actionBlockerSystem.CanPickup(args.User))
|
||||
return;
|
||||
|
||||
if (component.MagNeedsOpenBolt && !component.BoltOpen)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
verb.Text = component.MagazineContainer.ContainedEntity!.Name;
|
||||
verb.Category = VerbCategory.Eject;
|
||||
verb.Act = () => component.RemoveMagazine(args.User);
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void AddMagazineInteractionVerbs(EntityUid uid, ServerMagazineBarrelComponent component, GetInteractionVerbsEvent args)
|
||||
{
|
||||
if (args.Hands == null ||
|
||||
!args.CanAccess ||
|
||||
!args.CanInteract)
|
||||
return;
|
||||
|
||||
// Toggle bolt verb
|
||||
Verb toggleBolt = new();
|
||||
toggleBolt.Text = component.BoltOpen
|
||||
? Loc.GetString("close-bolt-verb-get-data-text")
|
||||
: Loc.GetString("open-bolt-verb-get-data-text");
|
||||
toggleBolt.Act = () => component.BoltOpen = !component.BoltOpen;
|
||||
args.Verbs.Add(toggleBolt);
|
||||
|
||||
// Are we holding a mag that we can insert?
|
||||
if (args.Using == null ||
|
||||
!component.CanInsertMagazine(args.User, args.Using) ||
|
||||
!_actionBlockerSystem.CanDrop(args.User))
|
||||
return;
|
||||
|
||||
// Insert mag verb
|
||||
Verb insert = new();
|
||||
insert.Text = args.Using.Name;
|
||||
insert.Category = VerbCategory.Insert;
|
||||
insert.Act = () => component.InsertMagazine(args.User, args.Using);
|
||||
args.Verbs.Add(insert);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -333,47 +331,5 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
message.AddMarkup("\n" + Loc.GetString("bolt-action-barrel-component-on-examine", ("caliber", _caliber)));
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class OpenBoltVerb : Verb<BoltActionBarrelComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, BoltActionBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("open-bolt-verb-get-data-text");
|
||||
data.Visibility = component.BoltOpen ? VerbVisibility.Invisible : VerbVisibility.Visible;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, BoltActionBarrelComponent component)
|
||||
{
|
||||
component.BoltOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class CloseBoltVerb : Verb<BoltActionBarrelComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, BoltActionBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("close-bolt-verb-get-data-text");
|
||||
data.Visibility = component.BoltOpen ? VerbVisibility.Visible : VerbVisibility.Invisible;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, BoltActionBarrelComponent component)
|
||||
{
|
||||
component.BoltOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -268,34 +266,5 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
return TryInsertBullet(eventArgs.User, eventArgs.Using);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class SpinRevolverVerb : Verb<RevolverBarrelComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, RevolverBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("spin-revolver-verb-get-data-text");
|
||||
if (component.Capacity <= 1)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = component.ShotsLeft > 0 ? VerbVisibility.Visible : VerbVisibility.Disabled;
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png";
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, RevolverBarrelComponent component)
|
||||
{
|
||||
component.Spin();
|
||||
component.Owner.PopupMessage(user, Loc.GetString("spin-revolver-verb-on-activate"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,14 @@ using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
@@ -46,7 +42,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
[DataField("powerCellPrototype")]
|
||||
private string? _powerCellPrototype = default;
|
||||
[DataField("powerCellRemovable")]
|
||||
[ViewVariables] private bool _powerCellRemovable = default;
|
||||
[ViewVariables] public bool PowerCellRemovable = default;
|
||||
|
||||
public override int ShotsLeft
|
||||
{
|
||||
@@ -226,7 +222,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
public override bool UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
if (!_powerCellRemovable)
|
||||
if (!PowerCellRemovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -239,9 +235,9 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
return TryEjectCell(eventArgs.User);
|
||||
}
|
||||
|
||||
private bool TryEjectCell(IEntity user)
|
||||
public bool TryEjectCell(IEntity user)
|
||||
{
|
||||
if (PowerCell == null || !_powerCellRemovable)
|
||||
if (PowerCell == null || !PowerCellRemovable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -278,36 +274,5 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
return TryInsertPowerCell(eventArgs.Using);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
public sealed class EjectCellVerb : Verb<ServerBatteryBarrelComponent>
|
||||
{
|
||||
public override bool AlternativeInteraction => true;
|
||||
|
||||
protected override void GetData(IEntity user, ServerBatteryBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) || !component._powerCellRemovable)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.PowerCell == null)
|
||||
{
|
||||
data.Text = Loc.GetString("eject-cell-verb-get-data-text-no-cell");
|
||||
data.Visibility = VerbVisibility.Disabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Text = Loc.GetString("eject-cell-verb-get-data-text");
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ServerBatteryBarrelComponent component)
|
||||
{
|
||||
component.TryEjectCell(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,10 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Weapon.Ranged.Ammunition.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged;
|
||||
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -35,8 +33,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
[ViewVariables]
|
||||
private ContainerSlot _chamberContainer = default!;
|
||||
[ViewVariables] public bool HasMagazine => _magazineContainer.ContainedEntity != null;
|
||||
private ContainerSlot _magazineContainer = default!;
|
||||
[ViewVariables] public bool HasMagazine => MagazineContainer.ContainedEntity != null;
|
||||
public ContainerSlot MagazineContainer = default!;
|
||||
|
||||
[ViewVariables] public MagazineType MagazineTypes => _magazineTypes;
|
||||
[DataField("magazineTypes")]
|
||||
@@ -55,7 +53,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
count++;
|
||||
}
|
||||
|
||||
var magazine = _magazineContainer.ContainedEntity;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null)
|
||||
{
|
||||
count += magazine.GetComponent<RangedMagazineComponent>().ShotsLeft;
|
||||
@@ -71,7 +69,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
// Chamber
|
||||
var count = 1;
|
||||
var magazine = _magazineContainer.ContainedEntity;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null)
|
||||
{
|
||||
count += magazine.GetComponent<RangedMagazineComponent>().Capacity;
|
||||
@@ -153,7 +151,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
(int, int)? count = null;
|
||||
var magazine = _magazineContainer.ContainedEntity;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
if (magazine != null && magazine.TryGetComponent(out RangedMagazineComponent? rangedMagazineComponent))
|
||||
{
|
||||
count = (rangedMagazineComponent.ShotsLeft, rangedMagazineComponent.Capacity);
|
||||
@@ -176,12 +174,12 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
}
|
||||
|
||||
_chamberContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-chamber");
|
||||
_magazineContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-magazine", out var existing);
|
||||
MagazineContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-magazine", out var existing);
|
||||
|
||||
if (!existing && _magFillPrototype != null)
|
||||
{
|
||||
var magEntity = Owner.EntityManager.SpawnEntity(_magFillPrototype, Owner.Transform.Coordinates);
|
||||
_magazineContainer.Insert(magEntity);
|
||||
MagazineContainer.Insert(magEntity);
|
||||
}
|
||||
Dirty();
|
||||
}
|
||||
@@ -244,7 +242,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
_appearanceComponent?.SetData(BarrelBoltVisuals.BoltOpen, BoltOpen);
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, _magazineContainer.ContainedEntity != null);
|
||||
_appearanceComponent?.SetData(MagazineBarrelVisuals.MagLoaded, MagazineContainer.ContainedEntity != null);
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoCount, ShotsLeft);
|
||||
_appearanceComponent?.SetData(AmmoVisuals.AmmoMax, Capacity);
|
||||
}
|
||||
@@ -298,7 +296,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
}
|
||||
|
||||
// Try and pull a round from the magazine to replace the chamber if possible
|
||||
var magazine = _magazineContainer.ContainedEntity;
|
||||
var magazine = MagazineContainer.ContainedEntity;
|
||||
var nextRound = magazine?.GetComponent<RangedMagazineComponent>().TakeAmmo();
|
||||
|
||||
if (nextRound == null)
|
||||
@@ -312,7 +310,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundAutoEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
|
||||
_magazineContainer.Remove(magazine);
|
||||
MagazineContainer.Remove(magazine);
|
||||
SendNetworkMessage(new MagazineAutoEjectMessage());
|
||||
}
|
||||
return true;
|
||||
@@ -320,7 +318,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
|
||||
public void RemoveMagazine(IEntity user)
|
||||
{
|
||||
var mag = _magazineContainer.ContainedEntity;
|
||||
var mag = MagazineContainer.ContainedEntity;
|
||||
|
||||
if (mag == null)
|
||||
{
|
||||
@@ -333,7 +331,7 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
return;
|
||||
}
|
||||
|
||||
_magazineContainer.Remove(mag);
|
||||
MagazineContainer.Remove(mag);
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundMagEject.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent? handsComponent))
|
||||
@@ -345,41 +343,59 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public bool CanInsertMagazine(IEntity user, IEntity magazine, bool quiet = true)
|
||||
{
|
||||
if (!magazine.TryGetComponent(out RangedMagazineComponent? magazineComponent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((MagazineTypes & magazineComponent.MagazineType) == 0)
|
||||
{
|
||||
if (!quiet)
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-wrong-magazine-type"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (magazineComponent.Caliber != _caliber)
|
||||
{
|
||||
if (!quiet)
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-wrong-caliber"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_magNeedsOpenBolt && !BoltOpen)
|
||||
{
|
||||
if (!quiet)
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-bolt-closed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MagazineContainer.ContainedEntity == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!quiet)
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-already-holding-magazine"));
|
||||
return false;
|
||||
}
|
||||
|
||||
public void InsertMagazine(IEntity user, IEntity magazine)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundMagInsert.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
Owner.PopupMessage(user, Loc.GetString("server-magazine-barrel-component-interact-using-success"));
|
||||
MagazineContainer.Insert(magazine);
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
// Insert magazine
|
||||
if (eventArgs.Using.TryGetComponent(out RangedMagazineComponent? magazineComponent))
|
||||
if (CanInsertMagazine(eventArgs.User, eventArgs.Using, quiet: false))
|
||||
{
|
||||
if ((MagazineTypes & magazineComponent.MagazineType) == 0)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("server-magazine-barrel-component-interact-using-wrong-magazine-type"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (magazineComponent.Caliber != _caliber)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("server-magazine-barrel-component-interact-using-wrong-caliber"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_magNeedsOpenBolt && !BoltOpen)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("server-magazine-barrel-component-interact-using-bolt-closed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_magazineContainer.ContainedEntity == null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundMagInsert.GetSound(), Owner, AudioParams.Default.WithVolume(-2));
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("server-magazine-barrel-component-interact-using-success"));
|
||||
_magazineContainer.Insert(eventArgs.Using);
|
||||
Dirty();
|
||||
UpdateAppearance();
|
||||
return true;
|
||||
}
|
||||
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("server-magazine-barrel-component-interact-using-already-holding-magazine"));
|
||||
return false;
|
||||
InsertMagazine(eventArgs.User, eventArgs.Using);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Insert 1 ammo
|
||||
@@ -424,80 +440,6 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
||||
message.AddMarkup("\n" + Loc.GetString("server-magazine-barrel-component-on-examine-magazine-type", ("magazineType", magazineType)));
|
||||
}
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class EjectMagazineVerb : Verb<ServerMagazineBarrelComponent>
|
||||
{
|
||||
public override bool AlternativeInteraction => true;
|
||||
|
||||
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("eject-magazine-verb-get-data-text");
|
||||
data.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
|
||||
if (component.MagNeedsOpenBolt)
|
||||
{
|
||||
data.Visibility = component.HasMagazine && component.BoltOpen
|
||||
? VerbVisibility.Visible
|
||||
: VerbVisibility.Disabled;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = component.HasMagazine ? VerbVisibility.Visible : VerbVisibility.Disabled;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ServerMagazineBarrelComponent component)
|
||||
{
|
||||
component.RemoveMagazine(user);
|
||||
}
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class OpenBoltVerb : Verb<ServerMagazineBarrelComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("open-bolt-verb-get-data-text");
|
||||
data.Visibility = component.BoltOpen ? VerbVisibility.Invisible : VerbVisibility.Visible;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ServerMagazineBarrelComponent component)
|
||||
{
|
||||
component.BoltOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class CloseBoltVerb : Verb<ServerMagazineBarrelComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, ServerMagazineBarrelComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("close-bolt-verb-get-data-text");
|
||||
data.Visibility = component.BoltOpen ? VerbVisibility.Visible : VerbVisibility.Invisible;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ServerMagazineBarrelComponent component)
|
||||
{
|
||||
component.BoltOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.Weapon
|
||||
{
|
||||
public override string Name => "WeaponCapacitorCharger";
|
||||
|
||||
protected override bool IsEntityCompatible(IEntity entity)
|
||||
public override bool IsEntityCompatible(IEntity entity)
|
||||
{
|
||||
return entity.TryGetComponent(out ServerBatteryBarrelComponent? battery) && battery.PowerCell != null ||
|
||||
entity.TryGetComponent(out PowerCellSlotComponent? slot) && slot.HasCell;
|
||||
|
||||
Reference in New Issue
Block a user