* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
109 lines
4.4 KiB
C#
109 lines
4.4 KiB
C#
using Content.Server.Power.Components;
|
|
using Content.Server.Power.EntitySystems;
|
|
using Content.Server.Power.Events;
|
|
using Content.Server.Stunnable.Components;
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Damage.Events;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Item;
|
|
using Content.Shared.Item.ItemToggle;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Stunnable;
|
|
|
|
namespace Content.Server.Stunnable.Systems
|
|
{
|
|
public sealed class StunbatonSystem : SharedStunbatonSystem
|
|
{
|
|
[Dependency] private readonly SharedItemSystem _item = default!;
|
|
[Dependency] private readonly RiggableSystem _riggableSystem = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly BatterySystem _battery = default!;
|
|
[Dependency] private readonly SharedItemToggleSystem _itemToggle = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BatteryComponent, ExaminedEvent>(OnExamined);
|
|
SubscribeLocalEvent<StunbatonComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
|
SubscribeLocalEvent<StunbatonComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
|
|
SubscribeLocalEvent<StunbatonComponent, ItemToggleActivateAttemptEvent>(TryTurnOn);
|
|
SubscribeLocalEvent<StunbatonComponent, ItemToggleDoneEvent>(ToggleDone);
|
|
}
|
|
|
|
private void OnStaminaHitAttempt(Entity<StunbatonComponent> entity, ref StaminaDamageOnHitAttemptEvent args)
|
|
{
|
|
if (!_itemToggle.IsActivated(entity.Owner) ||
|
|
!TryComp<BatteryComponent>(entity.Owner, out var battery) || !_battery.TryUseCharge(entity.Owner, entity.Comp.EnergyPerUse, battery))
|
|
{
|
|
args.Cancelled = true;
|
|
return;
|
|
}
|
|
|
|
if (battery.CurrentCharge < entity.Comp.EnergyPerUse)
|
|
{
|
|
_itemToggle.Toggle(entity.Owner, predicted: false);
|
|
}
|
|
}
|
|
|
|
private void OnExamined(Entity<BatteryComponent> entity, ref ExaminedEvent args)
|
|
{
|
|
var onMsg = _itemToggle.IsActivated(entity.Owner)
|
|
? Loc.GetString("comp-stunbaton-examined-on")
|
|
: Loc.GetString("comp-stunbaton-examined-off");
|
|
args.PushMarkup(onMsg);
|
|
|
|
var chargeMessage = Loc.GetString("stunbaton-component-on-examine-charge",
|
|
("charge", (int) (entity.Comp.CurrentCharge / entity.Comp.MaxCharge * 100)));
|
|
args.PushMarkup(chargeMessage);
|
|
}
|
|
|
|
private void ToggleDone(Entity<StunbatonComponent> entity, ref ItemToggleDoneEvent args)
|
|
{
|
|
if (!TryComp<ItemComponent>(entity, out var item))
|
|
return;
|
|
|
|
_item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off", item);
|
|
}
|
|
|
|
private void TryTurnOn(Entity<StunbatonComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
|
{
|
|
if (!TryComp<BatteryComponent>(entity, out var battery) || battery.CurrentCharge < entity.Comp.EnergyPerUse)
|
|
{
|
|
args.Cancelled = true;
|
|
if (args.User != null)
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("stunbaton-component-low-charge"), (EntityUid) args.User, (EntityUid) args.User);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (TryComp<RiggableComponent>(entity, out var rig) && rig.IsRigged)
|
|
{
|
|
_riggableSystem.Explode(entity.Owner, battery, args.User);
|
|
}
|
|
}
|
|
|
|
// https://github.com/space-wizards/space-station-14/pull/17288#discussion_r1241213341
|
|
private void OnSolutionChange(Entity<StunbatonComponent> entity, ref SolutionContainerChangedEvent args)
|
|
{
|
|
// Explode if baton is activated and rigged.
|
|
if (!TryComp<RiggableComponent>(entity, out var riggable) ||
|
|
!TryComp<BatteryComponent>(entity, out var battery))
|
|
return;
|
|
|
|
if (_itemToggle.IsActivated(entity.Owner) && riggable.IsRigged)
|
|
_riggableSystem.Explode(entity.Owner, battery);
|
|
}
|
|
|
|
private void SendPowerPulse(EntityUid target, EntityUid? user, EntityUid used)
|
|
{
|
|
RaiseLocalEvent(target, new PowerPulseEvent()
|
|
{
|
|
Used = used,
|
|
User = user
|
|
});
|
|
}
|
|
}
|
|
}
|