Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Novo sistema de reparo de IPCs e conserto de sistema de rastros e encriptação do IPC #76

Merged
merged 8 commits into from
Apr 20, 2024
20 changes: 2 additions & 18 deletions Content.Server/Repairable/RepairableSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Server.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Eye.Blinding.Systems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Repairable;
Expand All @@ -17,7 +15,6 @@ public sealed class RepairableSystem : SharedRepairableSystem
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly BlindableSystem _blindableSystem = default!;

public override void Initialize()
{
Expand All @@ -27,19 +24,12 @@ public override void Initialize()

private void OnRepairFinished(EntityUid uid, RepairableComponent component, RepairFinishedEvent args)
{


if (args.Cancelled)
return;
TryComp(uid, out BlindableComponent? blindcomp);
if(!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable))
return;

if (damageable.TotalDamage == 0 && blindcomp is { EyeDamage: 0 })
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);
Expand All @@ -48,8 +38,6 @@ private void OnRepairFinished(EntityUid uid, RepairableComponent component, Repa

else
{
if (blindcomp != null)
_blindableSystem.AdjustEyeDamage((uid, blindcomp), -blindcomp!.EyeDamage);
// Repair all damage
_damageableSystem.SetAllDamage(uid, damageable, 0);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
Expand All @@ -67,13 +55,9 @@ public async void Repair(EntityUid uid, RepairableComponent component, InteractU
return;

// Only try repair the target if it is damaged
TryComp(uid, out BlindableComponent? blindcomp);
if(!EntityManager.TryGetComponent(uid, out DamageableComponent? damageable))
return;
if (damageable.TotalDamage == 0 && blindcomp is { EyeDamage: 0 })
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Content.Shared.Damage;
using Content.Shared.Tools;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server._EstacaoPirata.BlindHealing
{
[RegisterComponent]
public sealed partial class BlindHealingComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] [DataField("delay")]
public int DoAfterDelay = 3;

/// <summary>
/// A multiplier that will be applied to the above if an entity is repairing themselves.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] [DataField("selfHealPenalty")]
public float SelfHealPenalty = 3f;

/// <summary>
/// Whether or not an entity is allowed to repair itself.
/// </summary>
[DataField("allowSelfHeal")]
public bool AllowSelfHeal = true;

[DataField("damageContainers", required: true)]
public List<string> DamageContainers;
}
}
157 changes: 157 additions & 0 deletions Content.Server/_EstacaoPirata/BlindHealing/BlindHealingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using Content.Server.Administration.Logs;
using Content.Server.Cargo.Components;
using Content.Server.Stack;
using Content.Shared._EstacaoPirata.BlindHealing;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Eye.Blinding.Systems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
using Content.Shared.Stacks;

namespace Content.Server._EstacaoPirata.BlindHealing
{
public sealed class BlindHealingSystem : SharedBlindHealingSystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly BlindableSystem _blindableSystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;

public override void Initialize()
{
SubscribeLocalEvent<BlindHealingComponent, UseInHandEvent>(OnUse);
SubscribeLocalEvent<BlindHealingComponent, AfterInteractEvent>(OnInteract);
SubscribeLocalEvent<BlindHealingComponent, HealingDoAfterEvent>(OnHealingFinished);
}

private void OnHealingFinished(EntityUid uid, BlindHealingComponent component, HealingDoAfterEvent args)
{
Log.Info("event started!");

if (args.Cancelled)
return;

if (args.Target == null)
return;

EntityUid target = (EntityUid) args.Target;

if(!EntityManager.TryGetComponent(target, out BlindableComponent? blindcomp))
return;

if (blindcomp is { EyeDamage: 0 })
return;

if(EntityManager.TryGetComponent(uid, out StackComponent? stackComponent))
{
double price = 1;
if(EntityManager.TryGetComponent(uid, out StackPriceComponent? stackPrice))
{
price = stackPrice.Price;
return;
}
_stackSystem.SetCount(uid, (int) (_stackSystem.GetCount(uid, stackComponent) - price), stackComponent);

}

_blindableSystem.AdjustEyeDamage((target, blindcomp), -blindcomp!.EyeDamage);

_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target}'s vision");

var str = Loc.GetString("comp-repairable-repair",
("target", uid),
("tool", args.Used!));
_popup.PopupEntity(str, uid, args.User);

}

private bool TryHealBlindness(EntityUid uid, EntityUid user, EntityUid target, float delay)
{
var doAfterEventArgs =
new DoAfterArgs(EntityManager, user, delay, new HealingDoAfterEvent(), uid, target: target, used: uid)
{
NeedHand = true,
BreakOnMove = true,
BreakOnWeightlessMove = false,
};
Log.Info("aaa");

_doAfter.TryStartDoAfter(doAfterEventArgs);
return true;
}

private void OnInteract(EntityUid uid, BlindHealingComponent component, ref AfterInteractEvent args)
{

if (args.Handled)
return;

if(!TryComp(args.User, out DamageableComponent? damageable))
return;

if (damageable.DamageContainerID != null)
{
if (!component.DamageContainers.Contains(damageable.DamageContainerID))
{
return;
}
}


if(!TryComp(args.User, out BlindableComponent? blindcomp))
return;

if (blindcomp is { EyeDamage: 0 })
return;

float delay = component.DoAfterDelay;

if (args.User == args.Target)
{
if (!component.AllowSelfHeal)
return;
delay *= component.SelfHealPenalty;
}

TryHealBlindness(uid, args.User, args.User, delay);
}

private void OnUse(EntityUid uid, BlindHealingComponent component, ref UseInHandEvent args)
{
if (args.Handled)
return;

if(!TryComp(args.User, out DamageableComponent? damageable))
return;

if (damageable.DamageContainerID != null)
{
if (!component.DamageContainers.Contains(damageable.DamageContainerID))
{
return;
}
}

if(!TryComp(args.User, out BlindableComponent? blindcomp))
return;

if (blindcomp is { EyeDamage: 0 })
return;

if (!component.AllowSelfHeal)
return;

float delay = component.DoAfterDelay;
delay *= component.SelfHealPenalty;

TryHealBlindness(uid, args.User, args.User, delay);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server.SimpleStation14.EncryptionHolderRequiresLock;

[RegisterComponent]
public sealed partial class EncryptionHolderRequiresLockComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Lock;
using Content.Shared.Radio.Components;
using Content.Shared.Radio.EntitySystems;

namespace Content.Server.SimpleStation14.EncryptionHolderRequiresLock;

public sealed class EncryptionHolderRequiresLockSystem : EntitySystem

{
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
[Dependency] private readonly EncryptionKeySystem _encryptionKeySystem = default!;

/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EncryptionHolderRequiresLockComponent, LockToggledEvent>(LockToggled);

}
private void LockToggled(EntityUid uid, EncryptionHolderRequiresLockComponent component, LockToggledEvent args)
{
if (!TryComp<LockComponent>(uid, out var lockComp) || !TryComp<EncryptionKeyHolderComponent>(uid, out var keyHolder))
return;
keyHolder.KeysUnlocked = !lockComp.Locked;
_encryptionKeySystem.UpdateChannels(uid, keyHolder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Content.Shared.Damage;
using Content.Shared.Tools;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server._EstacaoPirata.WeldingHealable
{
[RegisterComponent]
public sealed partial class WeldingHealableComponent : Component
{
}
}
Loading
Loading