2021-11-29 02:34:44 +13:00
|
|
|
using Content.Server.Administration.Logs;
|
2021-09-15 03:07:37 +10:00
|
|
|
using Content.Shared.Damage;
|
2021-11-28 14:56:53 +01:00
|
|
|
using Content.Shared.Database;
|
2021-09-15 03:07:37 +10:00
|
|
|
using Content.Shared.Interaction;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.Tools;
|
|
|
|
|
using Content.Shared.Tools.Components;
|
2021-09-15 03:07:37 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.Repairable
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class RepairableSystem : EntitySystem
|
2021-09-15 03:07:37 +10:00
|
|
|
{
|
2023-02-24 19:01:25 -05:00
|
|
|
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
|
2021-09-15 03:07:37 +10:00
|
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
2022-05-28 23:41:17 -07:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
|
2021-09-15 03:07:37 +10:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
|
2023-03-05 00:26:03 -05:00
|
|
|
SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
|
2021-09-15 03:07:37 +10:00
|
|
|
}
|
|
|
|
|
|
2023-03-05 00:26:03 -05:00
|
|
|
private void OnRepairFinished(EntityUid uid, RepairableComponent component, RepairFinishedEvent args)
|
2021-09-15 03:07:37 +10:00
|
|
|
{
|
2023-03-05 00:26:03 -05:00
|
|
|
if (!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
|
2021-09-15 03:07:37 +10:00
|
|
|
return;
|
|
|
|
|
|
2022-02-23 21:00:39 -03:00
|
|
|
if (component.Damage != null)
|
|
|
|
|
{
|
2022-10-08 12:15:27 +02:00
|
|
|
var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User);
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.Total}");
|
2022-02-23 21:00:39 -03:00
|
|
|
}
|
2023-03-05 00:26:03 -05:00
|
|
|
|
2022-02-23 21:00:39 -03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Repair all damage
|
|
|
|
|
_damageableSystem.SetAllDamage(damageable, 0);
|
2022-05-28 23:41:17 -07:00
|
|
|
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
|
2022-02-23 21:00:39 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-15 03:07:37 +10:00
|
|
|
|
2023-03-05 00:26:03 -05:00
|
|
|
uid.PopupMessage(args.User,
|
2021-09-15 03:07:37 +10:00
|
|
|
Loc.GetString("comp-repairable-repair",
|
2023-03-05 00:26:03 -05:00
|
|
|
("target", uid),
|
2021-10-07 13:01:27 +02:00
|
|
|
("tool", args.Used)));
|
2023-03-05 00:26:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2021-09-15 03:07:37 +10:00
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-05 00:26:03 -05:00
|
|
|
|
|
|
|
|
public sealed class RepairFinishedEvent : EntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
public EntityUid User;
|
|
|
|
|
public EntityUid Used;
|
|
|
|
|
|
|
|
|
|
public RepairFinishedEvent(EntityUid user, EntityUid used)
|
|
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
Used = used;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-15 03:07:37 +10:00
|
|
|
}
|