Самодельные отражайки (#6)

* Ghetto Mirror Shield

* Protorypes for ghetto mirrors

* locale

* idk, works fine on my machine

* forsenPls

(cherry picked from commit 4505739fd9430bcc578da3dec932d9aa7ca933ca)
This commit is contained in:
BIGZi0348
2024-09-21 17:10:02 +03:00
committed by keslik
parent 7138d9bbdf
commit 7f74203c33
20 changed files with 370 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using Content.Shared.Damage;
using Robust.Shared.GameStates;
// WD Engi Exclusive
namespace Content.Shared.DamageableClothing;
/// <summary>
/// This component goes on an equippable item that should take damage while in use.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class DamageableClothingComponent : Component
{
/// <summary>
/// The entity that's wearing the item.
/// </summary>
[ViewVariables, AutoNetworkedField]
public EntityUid? User;
/// <summary>
/// The damage modifier to use on item.
/// </summary>
[DataField]
public DamageModifierSet DamageModifier = default!;
}

View File

@@ -0,0 +1,16 @@
// WD Engi Exclusive
namespace Content.Shared.DamageableClothing;
/// <summary>
/// This component gets dynamically added to an Entity via the <see cref="DamageableClothing"/>
/// </summary>
[RegisterComponent]
public sealed partial class DamageableClothingUserComponent : Component
{
/// <summary>
/// The entity that's also being damaged.
/// </summary>
[DataField]
public EntityUid? ItemId;
}

View File

@@ -0,0 +1,43 @@
using Robust.Shared.Timing;
using Content.Shared.Inventory.Events;
// WD Engi Exclusive
namespace Content.Shared.DamageableClothing;
public sealed partial class DamageableClothingSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override void Initialize()
{
base.Initialize();
InitializeUser();
SubscribeLocalEvent<DamageableClothingComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<DamageableClothingComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<DamageableClothingComponent, ComponentShutdown>(OnShutdown);
}
private void OnEquipped(EntityUid uid, DamageableClothingComponent component, GotEquippedEvent args)
{
if (_gameTiming.ApplyingState)
return;
component.User = args.Equipee;
var userComp = EnsureComp<DamageableClothingUserComponent>(args.Equipee);
userComp.ItemId = args.Equipment;
}
private void OnUnequipped(EntityUid uid, DamageableClothingComponent component, GotUnequippedEvent args)
{
RemCompDeferred<DamageableClothingUserComponent>(args.Equipee);
component.User = null;
}
private void OnShutdown(EntityUid uid, DamageableClothingComponent component, ComponentShutdown args)
{
if (component.User != null)
{
RemCompDeferred<DamageableClothingUserComponent>(component.User.Value);
component.User = null;
}
}
}

View File

@@ -0,0 +1,46 @@
using Content.Shared.Damage;
// WD Engi Exclusive
namespace Content.Shared.DamageableClothing;
public sealed partial class DamageableClothingSystem
{
[Dependency] private readonly DamageableSystem _damageable = default!;
private void InitializeUser()
{
SubscribeLocalEvent<DamageableClothingUserComponent, DamageModifyEvent>(OnUserDamageModified);
SubscribeLocalEvent<DamageableClothingComponent, DamageModifyEvent>(OnDamageModified);
SubscribeLocalEvent<DamageableClothingUserComponent, EntityTerminatingEvent>(OnEntityTerminating);
}
private void OnUserDamageModified(EntityUid uid, DamageableClothingUserComponent component, DamageModifyEvent args)
{
if (TryComp<DamageableClothingComponent>(component.ItemId, out var blocking))
{
if (args.Damage.GetTotal() <= 0)
return;
if (!TryComp<DamageableComponent>(component.ItemId, out var dmgComp))
return;
var blockFraction = 1;
blockFraction = Math.Clamp(blockFraction, 0, 1);
_damageable.TryChangeDamage(component.ItemId, blockFraction * args.OriginalDamage);
}
}
private void OnDamageModified(EntityUid uid, DamageableClothingComponent component, DamageModifyEvent args)
{
var modifier = component.DamageModifier;
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modifier);
}
private void OnEntityTerminating(EntityUid uid, DamageableClothingUserComponent component, ref EntityTerminatingEvent args)
{
if (!TryComp<DamageableClothingComponent>(component.ItemId, out var blockingComponent))
return;
RemCompDeferred<DamageableClothingUserComponent>(uid);
}
}