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-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.Repairable;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.Tools;
|
2023-10-24 00:20:33 +11:00
|
|
|
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
2024-07-02 12:55:25 +03:00
|
|
|
using Content.Server.DoAfter;
|
|
|
|
|
using Content.Server.EUI;
|
|
|
|
|
using Content.Server.Ghost;
|
|
|
|
|
using Content.Server.Popups;
|
|
|
|
|
using Content.Shared.Damage;
|
|
|
|
|
using Content.Shared.DoAfter;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Interaction.Components;
|
|
|
|
|
using Content.Shared.Interaction.Events;
|
|
|
|
|
using Content.Shared.Mind;
|
|
|
|
|
using Content.Shared.Mobs;
|
|
|
|
|
using Content.Shared.Mobs.Components;
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
|
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
using Content.Shared.Tools.Components;
|
|
|
|
|
using Content.Server.Construction.Conditions;
|
|
|
|
|
//many of these arent reqired but some seem neessesary so ill leave them for now
|
2021-09-15 03:07:37 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.Repairable
|
|
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
public sealed class RepairableSystem : SharedRepairableSystem
|
2021-09-15 03:07:37 +10:00
|
|
|
{
|
2024-07-02 12:55:25 +03:00
|
|
|
[Dependency] private readonly EuiManager _euiManager = default!;
|
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!;
|
2023-10-15 22:56:09 -07:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
2022-05-28 23:41:17 -07:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
|
2024-07-02 12:55:25 +03:00
|
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
|
|
|
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
|
|
|
|
|
[Dependency] private readonly SharedMindSystem _mind = 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
|
|
|
{
|
2024-07-02 12:55:25 +03:00
|
|
|
ICommonSession? session = null;
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
if (args.Cancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
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);
|
2023-10-15 22:56:09 -07:00
|
|
|
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} by {damageChanged?.GetTotal()}");
|
2024-07-02 12:55:25 +03:00
|
|
|
}
|
2022-02-23 21:00:39 -03:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Repair all damage
|
2023-03-13 00:19:05 +11:00
|
|
|
_damageableSystem.SetAllDamage(uid, 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
|
|
|
|
2024-07-02 12:55:25 +03:00
|
|
|
// this is to revive gnomes and call their ghost back
|
|
|
|
|
//check for target for threshholds, i hardly understand WHY this works but it does so i wont touch it
|
|
|
|
|
if (TryComp(uid, out MobThresholdsComponent? mobthresholds))
|
|
|
|
|
{
|
|
|
|
|
if (_mobThreshold.TryGetThresholdForState(uid, MobState.Dead, out var threshold) &&
|
|
|
|
|
TryComp<DamageableComponent>(uid, out var damageableComponent) &&
|
|
|
|
|
damageableComponent.TotalDamage < threshold)
|
|
|
|
|
{
|
|
|
|
|
_mobState.ChangeMobState(uid, MobState.Alive, null, uid);
|
|
|
|
|
}
|
|
|
|
|
if (_mind.TryGetMind(uid, out _, out var mind) &&
|
|
|
|
|
mind.Session is { } playerSession)
|
|
|
|
|
{
|
|
|
|
|
session = playerSession;
|
|
|
|
|
// notify them they're being revived.
|
|
|
|
|
if (mind.CurrentEntity != uid)
|
|
|
|
|
{
|
|
|
|
|
_euiManager.OpenEui(new ReturnToBodyEui(mind, _mind), session);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-10-15 22:56:09 -07:00
|
|
|
var str = Loc.GetString("comp-repairable-repair",
|
|
|
|
|
("target", uid),
|
|
|
|
|
("tool", args.Used!));
|
|
|
|
|
_popup.PopupEntity(str, uid, args.User);
|
2023-03-05 00:26:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void Repair(EntityUid uid, RepairableComponent component, InteractUsingEvent args)
|
|
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-05 00:26:03 -05:00
|
|
|
// Only try repair the target if it is damaged
|
2023-06-28 01:46:48 +00:00
|
|
|
if (!TryComp<DamageableComponent>(uid, out var damageable) || damageable.TotalDamage == 0)
|
2023-03-05 00:26:03 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
float delay = component.DoAfterDelay;
|
|
|
|
|
|
|
|
|
|
// Add a penalty to how long it takes if the user is repairing itself
|
|
|
|
|
if (args.User == args.Target)
|
2023-08-12 17:39:58 -04:00
|
|
|
{
|
|
|
|
|
if (!component.AllowSelfRepair)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-05 00:26:03 -05:00
|
|
|
delay *= component.SelfRepairPenalty;
|
2023-08-12 17:39:58 -04:00
|
|
|
}
|
2023-03-05 00:26:03 -05:00
|
|
|
|
2023-06-28 01:46:48 +00:00
|
|
|
// Run the repairing doafter
|
|
|
|
|
args.Handled = _toolSystem.UseTool(args.Used, args.User, uid, delay, component.QualityNeeded, new RepairFinishedEvent());
|
2023-03-05 00:26:03 -05:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-15 03:07:37 +10:00
|
|
|
}
|