Files
crystall-punk-14/Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs
Vera Aguilera Puerto 3f79e3754f Merge branch 'master' into 2021-12-03-remove-IEntity-komm-süsser-todd
# Conflicts:
#	Content.Client/Crayon/CrayonDecalVisualizer.cs
#	Content.Client/Tabletop/TabletopSystem.cs
#	Content.IntegrationTests/Tests/InventoryHelpersTest.cs
#	Content.Server/AI/EntitySystems/AiSystem.cs
#	Content.Server/AI/Utility/AiLogic/UtilityAI.cs
#	Content.Server/AME/AMENodeGroup.cs
#	Content.Server/Administration/AdminVerbSystem.cs
#	Content.Server/Body/Systems/RespiratorSystem.cs
#	Content.Server/Chemistry/Components/InjectorComponent.cs
#	Content.Server/Chemistry/TileReactions/CleanTileReaction.cs
#	Content.Server/Chemistry/TileReactions/SpillTileReaction.cs
#	Content.Server/Crayon/CrayonComponent.cs
#	Content.Server/Doors/Components/ServerDoorComponent.cs
#	Content.Server/Explosion/EntitySystems/TriggerSystem.cs
#	Content.Server/Fluids/Components/MopComponent.cs
#	Content.Server/Fluids/Components/SpillExtensions.cs
#	Content.Server/Fluids/EntitySystems/PuddleSystem.cs
#	Content.Server/Instruments/InstrumentSystem.cs
#	Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
#	Content.Server/Nutrition/EntitySystems/FoodSystem.cs
#	Content.Server/PneumaticCannon/PneumaticCannonSystem.cs
#	Content.Server/Storage/Components/EntityStorageComponent.cs
#	Content.Server/Storage/Components/StorageFillComponent.cs
#	Content.Server/Stunnable/StunbatonSystem.cs
#	Content.Server/Throwing/ThrowHelper.cs
#	Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs
#	Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs
#	Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs
#	Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
#	Content.Shared/Damage/Components/DamageableComponent.cs
#	Content.Shared/Damage/Systems/DamageableSystem.cs
#	Content.Shared/MobState/Components/MobStateComponent.cs
#	Content.Shared/Slippery/SharedSlipperySystem.cs
2021-12-07 17:48:49 +01:00

122 lines
4.8 KiB
C#

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.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using System;
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, EntInsertedIntoContainerMessage>(OnCellSlotUpdated);
SubscribeLocalEvent<ServerBatteryBarrelComponent, EntRemovedFromContainerMessage>(OnCellSlotUpdated);
SubscribeLocalEvent<BoltActionBarrelComponent, GetInteractionVerbsEvent>(AddToggleBoltVerb);
SubscribeLocalEvent<ServerMagazineBarrelComponent, GetInteractionVerbsEvent>(AddMagazineInteractionVerbs);
SubscribeLocalEvent<ServerMagazineBarrelComponent, GetAlternativeVerbsEvent>(AddEjectMagazineVerb);
}
private void OnCellSlotUpdated(EntityUid uid, ServerBatteryBarrelComponent component, ContainerModifiedMessage args)
{
if (args.Container.ID == component.CellSlot.ID)
component.UpdateAppearance();
}
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);
}
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 = EntityManager.GetComponent<MetaDataComponent>(component.MagazineContainer.ContainedEntity!.Value).EntityName;
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 is not {Valid: true} @using ||
!component.CanInsertMagazine(args.User, @using) ||
!_actionBlockerSystem.CanDrop(args.User))
return;
// Insert mag verb
Verb insert = new();
insert.Text = EntityManager.GetComponent<MetaDataComponent>(@using).EntityName;
insert.Category = VerbCategory.Insert;
insert.Act = () => component.InsertMagazine(args.User, @using);
args.Verbs.Add(insert);
}
}
}