Another batch of DoAfter fixes (#14351)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction;
|
||||
@@ -18,24 +17,12 @@ namespace Content.Server.Repairable
|
||||
public override void Initialize()
|
||||
{
|
||||
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(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))
|
||||
if (!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
||||
return;
|
||||
|
||||
if (component.Damage != null)
|
||||
@@ -43,6 +30,7 @@ namespace Content.Server.Repairable
|
||||
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}");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// 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",
|
||||
("target", component.Owner),
|
||||
("target", uid),
|
||||
("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;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RepairFinishedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid User;
|
||||
public EntityUid Used;
|
||||
|
||||
public RepairFinishedEvent(EntityUid user, EntityUid used)
|
||||
{
|
||||
User = user;
|
||||
Used = used;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user