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
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -42,16 +52,26 @@ namespace Content.Server.Chemistry.Components
|
||||
/// Amount to inject or draw on each usage. If the injector is inject only, it will
|
||||
/// attempt to inject it's entire contents upon use.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("transferAmount")]
|
||||
private FixedPoint2 _transferAmount = FixedPoint2.New(5);
|
||||
|
||||
/// <summary>
|
||||
/// Initial storage volume of the injector
|
||||
/// Injection delay (seconds) when the target is a mob.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("initialMaxVolume")]
|
||||
private FixedPoint2 _initialMaxVolume = FixedPoint2.New(15);
|
||||
/// <remarks>
|
||||
/// The base delay has a minimum of 1 second, but this will still be modified if the target is incapacitated or
|
||||
/// in combat mode.
|
||||
/// </remarks>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("delay")]
|
||||
public float Delay = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Token for interrupting a do-after action (e.g., injection another player). If not null, implies
|
||||
/// component is currently "in use".
|
||||
/// </summary>
|
||||
public CancellationTokenSource? CancelToken;
|
||||
|
||||
private InjectorToggleMode _toggleState;
|
||||
|
||||
@@ -112,9 +132,18 @@ namespace Content.Server.Chemistry.Components
|
||||
/// <param name="eventArgs"></param>
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (CancelToken != null)
|
||||
{
|
||||
CancelToken.Cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
||||
return false;
|
||||
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
|
||||
return false;
|
||||
|
||||
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
|
||||
//Make sure we have the attacking entity
|
||||
if (eventArgs.Target is not {Valid: true} target ||
|
||||
@@ -123,6 +152,14 @@ namespace Content.Server.Chemistry.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the target a mob? If yes, use a do-after to give them time to respond.
|
||||
if (_entities.HasComponent<MobStateComponent>(target) ||
|
||||
_entities.HasComponent<BloodstreamComponent>(target))
|
||||
{
|
||||
if (!await TryInjectDoAfter(eventArgs.User, target))
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle injecting/drawing for solutions
|
||||
if (ToggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
@@ -162,6 +199,75 @@ namespace Content.Server.Chemistry.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send informative pop-up messages and wait for a do-after to complete.
|
||||
/// </summary>
|
||||
public async Task<bool> TryInjectDoAfter(EntityUid user, EntityUid target)
|
||||
{
|
||||
var popupSys = EntitySystem.Get<SharedPopupSystem>();
|
||||
|
||||
// Create a pop-up for the user
|
||||
popupSys.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, Filter.Entities(user));
|
||||
|
||||
// Get entity for logging. Log with EntityUids when?
|
||||
var logSys = EntitySystem.Get<AdminLogSystem>();
|
||||
|
||||
var actualDelay = MathF.Max(Delay, 1f);
|
||||
if (user != target)
|
||||
{
|
||||
// Create a pop-up for the target
|
||||
var userName = _entities.GetComponent<MetaDataComponent>(user).EntityName;
|
||||
popupSys.PopupEntity(Loc.GetString("injector-component-injecting-target",
|
||||
("user", userName)), user, Filter.Entities(target));
|
||||
|
||||
// Check if the target is incapacitated or in combat mode and modify time accordingly.
|
||||
if (_entities.TryGetComponent<MobStateComponent>(target, out var mobState) &&
|
||||
mobState.IsIncapacitated())
|
||||
{
|
||||
actualDelay /= 2;
|
||||
}
|
||||
else if (_entities.TryGetComponent<CombatModeComponent>(target, out var combat) &&
|
||||
combat.IsInCombatMode)
|
||||
{
|
||||
// Slightly increase the delay when the target is in combat mode. Helps prevents cheese injections in
|
||||
// combat with fast syringes & lag.
|
||||
actualDelay += 1;
|
||||
}
|
||||
|
||||
// Add an admin log, using the "force feed" log type. It's not quite feeding, but the effect is the same.
|
||||
if (ToggleState == InjectorToggleMode.Inject)
|
||||
{
|
||||
logSys.Add(LogType.ForceFeed,
|
||||
$"{_entities.ToPrettyString(user)} is attempting to inject a solution into {_entities.ToPrettyString(target)}");
|
||||
// TODO solution pretty string.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Self-injections take half as long.
|
||||
actualDelay /= 2;
|
||||
|
||||
if (ToggleState == InjectorToggleMode.Inject)
|
||||
logSys.Add(LogType.Ingestion,
|
||||
$"{_entities.ToPrettyString(user)} is attempting to inject themselves with a solution.");
|
||||
//TODO solution pretty string.
|
||||
}
|
||||
|
||||
CancelToken = new();
|
||||
var status = await EntitySystem.Get<DoAfterSystem>().WaitDoAfter(
|
||||
new DoAfterEventArgs(user, actualDelay, CancelToken.Token, target)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
MovementThreshold = 1.0f
|
||||
});
|
||||
CancelToken = null;
|
||||
|
||||
return status == DoAfterStatus.Finished;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when use key is pressed when held in active hand
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user