Files
OldThink/Content.Server/Repairable/RepairableSystem.cs
ThereDrD0 a0d346096d ГНОМЫ (#411)
* This adds the basic wirework for the gnomes, very unfinished

* GNOMES ARE DONE EXCEPT FOR GLUE WOOO

* removes gnome id, fixes ai and punch sounds, comments out the code for glue to take fuel

* changed sounds to non meme versions

* HAT NOW GIVES THE GNOME ACCENT TOO

* fixes a typo with Unclippable being Unclipable

* removed cuffable component (iforgotaboutit)

* added unrevivable to gnomes so defibs wont try (it was immpossible anyways but this is better)

* removes scrap code i put in the repair system

* remove the carrot mutation code i made (its bad)
clean up some things in the repairable system

* changes accent system from rplacging g to replacing no

* Fix the conflict (plz work)

* adds another comment bleh bleh im trying to fix things

* PAIN.jpeg

* work plz?

* FIX FOR REAL

* camel case mayhaps?

* adds unfinished glue use code (you can still see lit or not lit when held >:/   )

* temporary fix

* add: GNOMES REVAMPED

* fix: fix accent, sounds and add spawners

* add: gnome seeds to seed vendor

---------

Co-authored-by: BITTERLYNX <gagestemmerman@gmail.com>
2024-07-02 12:55:25 +03:00

122 lines
5.1 KiB
C#

using Content.Server.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Repairable;
using Content.Shared.Tools;
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
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
namespace Content.Server.Repairable
{
public sealed class RepairableSystem : SharedRepairableSystem
{
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
public override void Initialize()
{
SubscribeLocalEvent<RepairableComponent, InteractUsingEvent>(Repair);
SubscribeLocalEvent<RepairableComponent, RepairFinishedEvent>(OnRepairFinished);
}
private void OnRepairFinished(EntityUid uid, RepairableComponent component, RepairFinishedEvent args)
{
ICommonSession? session = null;
if (args.Cancelled)
return;
if (!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable) || damageable.TotalDamage == 0)
return;
if (component.Damage != null)
{
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?.GetTotal()}");
}
else
{
// Repair all damage
_damageableSystem.SetAllDamage(uid, damageable, 0);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
// 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);
}
}
}
}
var str = Loc.GetString("comp-repairable-repair",
("target", uid),
("tool", args.Used!));
_popup.PopupEntity(str, uid, args.User);
}
public async void Repair(EntityUid uid, RepairableComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
// Only try repair the target if it is damaged
if (!TryComp<DamageableComponent>(uid, out var 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)
{
if (!component.AllowSelfRepair)
return;
delay *= component.SelfRepairPenalty;
}
// Run the repairing doafter
args.Handled = _toolSystem.UseTool(args.Used, args.User, uid, delay, component.QualityNeeded, new RepairFinishedEvent());
}
}
}