Another batch of DoAfter fixes (#14351)
This commit is contained in:
@@ -77,9 +77,15 @@ public sealed class SharpSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnDoAfter(EntityUid uid, SharpComponent component, DoAfterEvent args)
|
private void OnDoAfter(EntityUid uid, SharpComponent component, DoAfterEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.Cancelled || !TryComp<ButcherableComponent>(args.Args.Target, out var butcher))
|
if (args.Handled || !TryComp<ButcherableComponent>(args.Args.Target, out var butcher))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (args.Cancelled)
|
||||||
|
{
|
||||||
|
component.Butchering.Remove(args.Args.Target.Value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
component.Butchering.Remove(args.Args.Target.Value);
|
component.Butchering.Remove(args.Args.Target.Value);
|
||||||
|
|
||||||
if (_containerSystem.IsEntityInContainer(args.Args.Target.Value))
|
if (_containerSystem.IsEntityInContainer(args.Args.Target.Value))
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ namespace Content.Server.Nutrition.Components
|
|||||||
[DataField("forceDrink")]
|
[DataField("forceDrink")]
|
||||||
public bool ForceDrink;
|
public bool ForceDrink;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is the entity currently drinking or trying to make someone else drink?
|
||||||
|
/// </summary>
|
||||||
|
[DataField("drinking")]
|
||||||
|
public bool Drinking;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long it takes to drink this yourself.
|
/// How long it takes to drink this yourself.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -42,11 +42,16 @@ namespace Content.Server.Nutrition.Components
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this entity being forcefed?
|
/// Is this entity being forcefed?
|
||||||
/// Prevents the entity from being forced to eat multiple times if not self
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("forceFeed")]
|
[DataField("forceFeed")]
|
||||||
public bool ForceFeed;
|
public bool ForceFeed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this entity eating or being fed?
|
||||||
|
/// </summary>
|
||||||
|
[DataField(("eating"))]
|
||||||
|
public bool Eating;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long it takes to eat the food personally.
|
/// How long it takes to eat the food personally.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
|
|
||||||
private bool TryDrink(EntityUid user, EntityUid target, DrinkComponent drink, EntityUid item)
|
private bool TryDrink(EntityUid user, EntityUid target, DrinkComponent drink, EntityUid item)
|
||||||
{
|
{
|
||||||
if (!EntityManager.HasComponent<BodyComponent>(target) || drink.ForceDrink)
|
if (!EntityManager.HasComponent<BodyComponent>(target) || drink.Drinking)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!drink.Opened)
|
if (!drink.Opened)
|
||||||
@@ -241,6 +241,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (!_interactionSystem.InRangeUnobstructed(user, item, popup: true))
|
if (!_interactionSystem.InRangeUnobstructed(user, item, popup: true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
drink.Drinking = true;
|
||||||
drink.ForceDrink = user != target;
|
drink.ForceDrink = user != target;
|
||||||
|
|
||||||
if (drink.ForceDrink)
|
if (drink.ForceDrink)
|
||||||
@@ -286,11 +287,10 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnDoAfter(EntityUid uid, DrinkComponent component, DoAfterEvent<DrinkData> args)
|
private void OnDoAfter(EntityUid uid, DrinkComponent component, DoAfterEvent<DrinkData> args)
|
||||||
{
|
{
|
||||||
//Special cancel if they're force feeding someone.
|
if (args.Cancelled)
|
||||||
//Allows self to drink multiple times but prevents force feeding drinks to others rapidly.
|
|
||||||
if (args.Cancelled && component.ForceDrink)
|
|
||||||
{
|
{
|
||||||
component.ForceDrink = false;
|
component.ForceDrink = false;
|
||||||
|
component.Drinking = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,6 +374,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
//TODO: Grab the stomach UIDs somehow without using Owner
|
//TODO: Grab the stomach UIDs somehow without using Owner
|
||||||
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp);
|
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.Owner, drained, firstStomach.Value.Comp);
|
||||||
|
|
||||||
|
component.Drinking = false;
|
||||||
component.ForceDrink = false;
|
component.ForceDrink = false;
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (food == user || EntityManager.TryGetComponent<MobStateComponent>(food, out var mobState) && _mobStateSystem.IsAlive(food, mobState)) // Suppresses eating alive mobs
|
if (food == user || EntityManager.TryGetComponent<MobStateComponent>(food, out var mobState) && _mobStateSystem.IsAlive(food, mobState)) // Suppresses eating alive mobs
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Target can't be fed or they're already forcefeeding
|
// Target can't be fed or they're already eating
|
||||||
if (!EntityManager.HasComponent<BodyComponent>(target) || foodComp.ForceFeed)
|
if (!EntityManager.HasComponent<BodyComponent>(target) || foodComp.Eating)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_solutionContainerSystem.TryGetSolution(food, foodComp.SolutionName, out var foodSolution))
|
if (!_solutionContainerSystem.TryGetSolution(food, foodComp.SolutionName, out var foodSolution))
|
||||||
@@ -111,6 +111,7 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (!_interactionSystem.InRangeUnobstructed(user, food, popup: true))
|
if (!_interactionSystem.InRangeUnobstructed(user, food, popup: true))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
foodComp.Eating = true;
|
||||||
foodComp.ForceFeed = user != target;
|
foodComp.ForceFeed = user != target;
|
||||||
|
|
||||||
if (foodComp.ForceFeed)
|
if (foodComp.ForceFeed)
|
||||||
@@ -152,8 +153,9 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
private void OnDoAfter(EntityUid uid, FoodComponent component, DoAfterEvent<FoodData> args)
|
private void OnDoAfter(EntityUid uid, FoodComponent component, DoAfterEvent<FoodData> args)
|
||||||
{
|
{
|
||||||
//Prevents the target from being force fed food but allows the user to chow down
|
//Prevents the target from being force fed food but allows the user to chow down
|
||||||
if (args.Cancelled && component.ForceFeed)
|
if (args.Cancelled)
|
||||||
{
|
{
|
||||||
|
component.Eating = false;
|
||||||
component.ForceFeed = false;
|
component.ForceFeed = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -167,6 +169,8 @@ namespace Content.Server.Nutrition.EntitySystems
|
|||||||
if (!_bodySystem.TryGetBodyOrganComponents<StomachComponent>(args.Args.Target.Value, out var stomachs, body))
|
if (!_bodySystem.TryGetBodyOrganComponents<StomachComponent>(args.Args.Target.Value, out var stomachs, body))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
component.Eating = false;
|
||||||
|
|
||||||
var transferAmount = component.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) component.TransferAmount, args.AdditionalData.FoodSolution.Volume) : args.AdditionalData.FoodSolution.Volume;
|
var transferAmount = component.TransferAmount != null ? FixedPoint2.Min((FixedPoint2) component.TransferAmount, args.AdditionalData.FoodSolution.Volume) : args.AdditionalData.FoodSolution.Volume;
|
||||||
|
|
||||||
var split = _solutionContainerSystem.SplitSolution(uid, args.AdditionalData.FoodSolution, transferAmount);
|
var split = _solutionContainerSystem.SplitSolution(uid, args.AdditionalData.FoodSolution, transferAmount);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Content.Server.Administration.Logs;
|
using Content.Server.Administration.Logs;
|
||||||
using Content.Server.Tools;
|
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
@@ -18,24 +17,12 @@ namespace Content.Server.Repairable
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
|
SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
|
||||||
|
SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void Repair(EntityUid uid, RepairableComponent component, InteractUsingEvent args)
|
private void OnRepairFinished(EntityUid uid, RepairableComponent component, RepairFinishedEvent args)
|
||||||
{
|
{
|
||||||
// Only try repair the target if it is damaged
|
if (!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
||||||
if (!EntityManager.TryGetComponent(component.Owner, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
float delay = component.DoAfterDelay;
|
|
||||||
|
|
||||||
// Add a penalty to how long it takes if the user is repairing itself
|
|
||||||
if (args.User == args.Target)
|
|
||||||
delay *= component.SelfRepairPenalty;
|
|
||||||
|
|
||||||
var toolEvData = new ToolEventData(null);
|
|
||||||
|
|
||||||
// Can the tool actually repair this, does it have enough fuel?
|
|
||||||
if (!_toolSystem.UseTool(args.Used, args.User, uid, delay, component.QualityNeeded, toolEvData, component.FuelCost))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.Damage != null)
|
if (component.Damage != null)
|
||||||
@@ -43,6 +30,7 @@ namespace Content.Server.Repairable
|
|||||||
var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User);
|
var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User);
|
||||||
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.Total}");
|
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.Total}");
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Repair all damage
|
// Repair all damage
|
||||||
@@ -51,12 +39,43 @@ namespace Content.Server.Repairable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
component.Owner.PopupMessage(args.User,
|
uid.PopupMessage(args.User,
|
||||||
Loc.GetString("comp-repairable-repair",
|
Loc.GetString("comp-repairable-repair",
|
||||||
("target", component.Owner),
|
("target", uid),
|
||||||
("tool", args.Used)));
|
("tool", args.Used)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void Repair(EntityUid uid, RepairableComponent component, InteractUsingEvent args)
|
||||||
|
{
|
||||||
|
// Only try repair the target if it is damaged
|
||||||
|
if (!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float delay = component.DoAfterDelay;
|
||||||
|
|
||||||
|
// Add a penalty to how long it takes if the user is repairing itself
|
||||||
|
if (args.User == args.Target)
|
||||||
|
delay *= component.SelfRepairPenalty;
|
||||||
|
|
||||||
|
var toolEvData = new ToolEventData(new RepairFinishedEvent(args.User, args.Used), component.FuelCost, targetEntity:uid);
|
||||||
|
|
||||||
|
// Can the tool actually repair this, does it have enough fuel?
|
||||||
|
if (!_toolSystem.UseTool(args.Used, args.User, uid, delay, component.QualityNeeded, toolEvData, component.FuelCost))
|
||||||
|
return;
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class RepairFinishedEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public EntityUid User;
|
||||||
|
public EntityUid Used;
|
||||||
|
|
||||||
|
public RepairFinishedEvent(EntityUid user, EntityUid used)
|
||||||
|
{
|
||||||
|
User = user;
|
||||||
|
Used = used;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ namespace Content.Server.Storage.EntitySystems
|
|||||||
|
|
||||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, delay, target: targetUid, used: storageUid)
|
_doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, delay, target: targetUid, used: storageUid)
|
||||||
{
|
{
|
||||||
|
RaiseOnTarget = false,
|
||||||
BreakOnTargetMove = true,
|
BreakOnTargetMove = true,
|
||||||
BreakOnUserMove = true,
|
BreakOnUserMove = true,
|
||||||
BreakOnStun = true,
|
BreakOnStun = true,
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ public abstract class SharedDoAfterSystem : EntitySystem
|
|||||||
|
|
||||||
foreach (var (_, comp) in EntityManager.EntityQuery<ActiveDoAfterComponent, DoAfterComponent>())
|
foreach (var (_, comp) in EntityManager.EntityQuery<ActiveDoAfterComponent, DoAfterComponent>())
|
||||||
{
|
{
|
||||||
|
//Don't run the doafter if its comp or owner is deleted.
|
||||||
|
if (EntityManager.Deleted(comp.Owner) || comp.Deleted)
|
||||||
|
continue;
|
||||||
|
|
||||||
foreach (var doAfter in comp.DoAfters.Values.ToArray())
|
foreach (var doAfter in comp.DoAfters.Values.ToArray())
|
||||||
{
|
{
|
||||||
Run(comp.Owner, comp, doAfter);
|
Run(comp.Owner, comp, doAfter);
|
||||||
|
|||||||
@@ -769,6 +769,7 @@ namespace Content.Shared.Interaction
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// all interactions should only happen when in range / unobstructed, so no range check is needed
|
// all interactions should only happen when in range / unobstructed, so no range check is needed
|
||||||
|
//TODO: See why this is firing off multiple times
|
||||||
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
|
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
|
||||||
RaiseLocalEvent(target, interactUsingEvent, true);
|
RaiseLocalEvent(target, interactUsingEvent, true);
|
||||||
DoContactInteraction(user, used, interactUsingEvent);
|
DoContactInteraction(user, used, interactUsingEvent);
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ public sealed class EncryptionKeyHolderComponent : Component
|
|||||||
public Container KeyContainer = default!;
|
public Container KeyContainer = default!;
|
||||||
public const string KeyContainerName = "key_slots";
|
public const string KeyContainerName = "key_slots";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Blocks multiple attempts to remove the key
|
||||||
|
/// </summary>
|
||||||
|
[DataField("removing")]
|
||||||
|
public bool Removing;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combined set of radio channels provided by all contained keys.
|
/// Combined set of radio channels provided by all contained keys.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -37,6 +37,28 @@ public sealed class EncryptionKeySystem : EntitySystem
|
|||||||
SubscribeLocalEvent<EncryptionKeyHolderComponent, InteractUsingEvent>(OnInteractUsing);
|
SubscribeLocalEvent<EncryptionKeyHolderComponent, InteractUsingEvent>(OnInteractUsing);
|
||||||
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
||||||
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
||||||
|
SubscribeLocalEvent<EncryptionKeyHolderComponent, EncryptionRemovalFinishedEvent>(OnKeyRemoval);
|
||||||
|
SubscribeLocalEvent<EncryptionKeyHolderComponent, EncryptionRemovalCancelledEvent>(OnKeyCancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnKeyCancelled(EntityUid uid, EncryptionKeyHolderComponent component, EncryptionRemovalCancelledEvent args)
|
||||||
|
{
|
||||||
|
component.Removing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnKeyRemoval(EntityUid uid, EncryptionKeyHolderComponent component, EncryptionRemovalFinishedEvent args)
|
||||||
|
{
|
||||||
|
var contained = component.KeyContainer.ContainedEntities.ToArray();
|
||||||
|
_container.EmptyContainer(component.KeyContainer, entMan: EntityManager);
|
||||||
|
foreach (var ent in contained)
|
||||||
|
{
|
||||||
|
_hands.PickupOrDrop(args.User, ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if tool use ever gets predicted this needs changing.
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString("headset-encryption-keys-all-extracted"), uid, args.User);
|
||||||
|
_audio.PlayPvs(component.KeyExtractionSound, uid);
|
||||||
|
component.Removing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateChannels(EntityUid uid, EncryptionKeyHolderComponent component)
|
public void UpdateChannels(EntityUid uid, EncryptionKeyHolderComponent component)
|
||||||
@@ -67,7 +89,7 @@ public sealed class EncryptionKeySystem : EntitySystem
|
|||||||
|
|
||||||
private void OnInteractUsing(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
|
private void OnInteractUsing(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<ContainerManagerComponent>(uid, out var storage))
|
if (!TryComp<ContainerManagerComponent>(uid, out var storage) || args.Handled || component.Removing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
|
if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
|
||||||
@@ -109,21 +131,13 @@ public sealed class EncryptionKeySystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var toolEvData = new ToolEventData(null);
|
//This is honestly the poor mans fix because the InteractUsingEvent fires off 12 times
|
||||||
|
component.Removing = true;
|
||||||
|
|
||||||
if(!_toolSystem.UseTool(args.Used, args.User, uid, 0f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool))
|
var toolEvData = new ToolEventData(new EncryptionRemovalFinishedEvent(args.User), cancelledEv: new EncryptionRemovalCancelledEvent(), targetEntity: uid);
|
||||||
|
|
||||||
|
if(!_toolSystem.UseTool(args.Used, args.User, uid, 1f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var contained = component.KeyContainer.ContainedEntities.ToArray();
|
|
||||||
_container.EmptyContainer(component.KeyContainer, entMan: EntityManager);
|
|
||||||
foreach (var ent in contained)
|
|
||||||
{
|
|
||||||
_hands.PickupOrDrop(args.User, ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if tool use ever gets predicted this needs changing.
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString("headset-encryption-keys-all-extracted"), uid, args.User);
|
|
||||||
_audio.PlayPvs(component.KeyExtractionSound, args.Target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStartup(EntityUid uid, EncryptionKeyHolderComponent component, ComponentStartup args)
|
private void OnStartup(EntityUid uid, EncryptionKeyHolderComponent component, ComponentStartup args)
|
||||||
@@ -195,4 +209,19 @@ public sealed class EncryptionKeySystem : EntitySystem
|
|||||||
examineEvent.PushMarkup(msg);
|
examineEvent.PushMarkup(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class EncryptionRemovalFinishedEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public EntityUid User;
|
||||||
|
|
||||||
|
public EncryptionRemovalFinishedEvent(EntityUid user)
|
||||||
|
{
|
||||||
|
User = user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class EncryptionRemovalCancelledEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user