Hypospray ECS + admin logging (#12536)

Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>
Co-authored-by: Kara <lunarautomaton6@gmail.com>
close https://github.com/space-wizards/space-station-14/issues/12414
This commit is contained in:
corentt
2022-11-19 17:07:50 +01:00
committed by GitHub
parent dad7d17c10
commit 01d71a77bb
3 changed files with 98 additions and 107 deletions

View File

@@ -1,17 +1,7 @@
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Interaction.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.IdentityManagement;
using Content.Shared.MobState.Components;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Interaction;
using Content.Server.Weapons.Melee;
namespace Content.Server.Chemistry.Components
{
@@ -29,97 +19,7 @@ namespace Content.Server.Chemistry.Components
public FixedPoint2 TransferAmount { get; set; } = FixedPoint2.New(5);
[DataField("injectSound")]
private SoundSpecifier _injectSound = new SoundPathSpecifier("/Audio/Items/hypospray.ogg");
protected override void Initialize()
{
base.Initialize();
Dirty();
}
public bool TryDoInject(EntityUid? target, EntityUid user)
{
if (!EligibleEntity(target, _entMan))
return false;
string? msgFormat = null;
if (target == user)
{
msgFormat = "hypospray-component-inject-self-message";
}
else if (EligibleEntity(user, _entMan) && _entMan.EntitySysManager.GetEntitySystem<InteractionSystem>().TryRollClumsy(user, ClumsyFailChance))
{
msgFormat = "hypospray-component-inject-self-clumsy-message";
target = user;
}
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
solutionsSys.TryGetSolution(Owner, SolutionName, out var hypoSpraySolution);
if (hypoSpraySolution == null || hypoSpraySolution.CurrentVolume == 0)
{
user.PopupMessageCursor(Loc.GetString("hypospray-component-empty-message"));
return true;
}
if (!solutionsSys.TryGetInjectableSolution(target.Value, out var targetSolution))
{
user.PopupMessage(user,
Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target.Value, _entMan))));
return false;
}
user.PopupMessage(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message",
("other", target)));
if (target != user)
{
target.Value.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message"));
var meleeSys = EntitySystem.Get<MeleeWeaponSystem>();
var angle = Angle.FromWorldVec(_entMan.GetComponent<TransformComponent>(target.Value).WorldPosition - _entMan.GetComponent<TransformComponent>(user).WorldPosition);
// TODO: This should just be using melee attacks...
// meleeSys.SendLunge(angle, user);
}
SoundSystem.Play(_injectSound.GetSound(), Filter.Pvs(user), user);
// Get transfer amount. May be smaller than _transferAmount if not enough room
var realTransferAmount = FixedPoint2.Min(TransferAmount, targetSolution.AvailableVolume);
if (realTransferAmount <= 0)
{
user.PopupMessage(user,
Loc.GetString("hypospray-component-transfer-already-full-message",
("owner", target)));
return true;
}
// Move units from attackSolution to targetSolution
var removedSolution =
EntitySystem.Get<SolutionContainerSystem>()
.SplitSolution(Owner, hypoSpraySolution, realTransferAmount);
if (!targetSolution.CanAddSolution(removedSolution))
{
return true;
}
removedSolution.DoEntityReaction(target.Value, ReactionMethod.Injection);
EntitySystem.Get<SolutionContainerSystem>().TryAddSolution(target.Value, targetSolution, removedSolution);
static bool EligibleEntity([NotNullWhen(true)] EntityUid? entity, IEntityManager entMan)
{
// TODO: Does checking for BodyComponent make sense as a "can be hypospray'd" tag?
// In SS13 the hypospray ONLY works on mobs, NOT beakers or anything else.
return entMan.HasComponent<SolutionContainerManagerComponent>(entity)
&& entMan.HasComponent<MobStateComponent>(entity);
}
return true;
}
public SoundSpecifier InjectSound = new SoundPathSpecifier("/Audio/Items/hypospray.ogg");
public override ComponentState GetComponentState()
{