2024-04-12 21:09:54 +03:00
|
|
|
using System.Linq;
|
2024-08-02 13:51:54 +03:00
|
|
|
using Content.Shared._CP14.MeleeWeapon.Components;
|
2024-04-12 21:09:54 +03:00
|
|
|
using Content.Shared.Damage;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Placeable;
|
2024-08-02 13:51:54 +03:00
|
|
|
using Content.Shared.Popups;
|
2024-04-12 21:09:54 +03:00
|
|
|
using Content.Shared.Timing;
|
|
|
|
|
using Content.Shared.Weapons.Melee.Events;
|
|
|
|
|
using Content.Shared.Wieldable;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2024-08-05 15:22:14 +03:00
|
|
|
using Robust.Shared.Network;
|
2024-04-12 21:09:54 +03:00
|
|
|
|
2024-08-02 13:51:54 +03:00
|
|
|
namespace Content.Shared._CP14.MeleeWeapon.EntitySystems;
|
2024-04-12 21:09:54 +03:00
|
|
|
|
2024-04-20 11:51:04 +03:00
|
|
|
public sealed class CP14SharpeningSystem : EntitySystem
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
|
|
|
|
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
2024-08-02 13:51:54 +03:00
|
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
2024-08-05 15:22:14 +03:00
|
|
|
[Dependency] private readonly INetManager _net = default!;
|
2024-04-12 21:09:54 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2025-04-18 13:51:15 +03:00
|
|
|
SubscribeLocalEvent<CP14SharpenedComponent, GetMeleeDamageEvent>(OnGetMeleeDamage,
|
|
|
|
|
after: [typeof(SharedWieldableSystem)]);
|
2024-04-20 11:51:04 +03:00
|
|
|
SubscribeLocalEvent<CP14SharpenedComponent, ExaminedEvent>(OnExamined);
|
|
|
|
|
SubscribeLocalEvent<CP14SharpenedComponent, MeleeHitEvent>(OnMeleeHit);
|
2024-04-12 21:09:54 +03:00
|
|
|
|
2024-04-20 11:51:04 +03:00
|
|
|
SubscribeLocalEvent<CP14SharpeningStoneComponent, AfterInteractEvent>(OnAfterInteract);
|
|
|
|
|
SubscribeLocalEvent<CP14SharpeningStoneComponent, ActivateInWorldEvent>(OnInteract);
|
2024-04-12 21:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-18 13:51:15 +03:00
|
|
|
public static void ReduceSharpness(Entity<CP14SharpenedComponent> ent, DamageSpecifier dmg)
|
|
|
|
|
{
|
|
|
|
|
ent.Comp.Sharpness =
|
|
|
|
|
MathHelper.Clamp(ent.Comp.Sharpness - dmg.GetTotal().Float() * ent.Comp.SharpnessDamageBy1Damage, 0.1f, 1f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnMeleeHit(Entity<CP14SharpenedComponent> sharpened, ref MeleeHitEvent args)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
|
|
|
|
if (!args.HitEntities.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-18 13:51:15 +03:00
|
|
|
ReduceSharpness(sharpened, args.BaseDamage);
|
2024-04-12 21:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
2024-04-20 11:51:04 +03:00
|
|
|
private void OnInteract(Entity<CP14SharpeningStoneComponent> stone, ref ActivateInWorldEvent args)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<ItemPlacerComponent>(stone, out var itemPlacer))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (itemPlacer.PlacedEntities.Count <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var item in itemPlacer.PlacedEntities)
|
|
|
|
|
{
|
2024-04-20 11:51:04 +03:00
|
|
|
if (!TryComp<CP14SharpenedComponent>(item, out var sharpened))
|
2024-04-12 21:09:54 +03:00
|
|
|
continue;
|
|
|
|
|
|
2024-06-15 16:55:04 +03:00
|
|
|
SharpThing(stone, item, sharpened, args.User);
|
2024-04-12 21:09:54 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 11:51:04 +03:00
|
|
|
private void OnAfterInteract(Entity<CP14SharpeningStoneComponent> stone, ref AfterInteractEvent args)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
2024-04-20 11:51:04 +03:00
|
|
|
if (!args.CanReach || args.Target == null || !TryComp<CP14SharpenedComponent>(args.Target, out var sharpened))
|
2024-04-12 21:09:54 +03:00
|
|
|
return;
|
|
|
|
|
|
2025-02-23 23:29:45 +03:00
|
|
|
if (TryComp<UseDelayComponent>(stone, out var useDelay) && _useDelay.IsDelayed((stone, useDelay)))
|
2024-04-12 21:09:54 +03:00
|
|
|
return;
|
|
|
|
|
|
2024-06-15 16:55:04 +03:00
|
|
|
SharpThing(stone, args.Target.Value, sharpened, args.User);
|
2024-04-12 21:09:54 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-18 13:51:15 +03:00
|
|
|
private void SharpThing(Entity<CP14SharpeningStoneComponent> stone,
|
|
|
|
|
EntityUid target,
|
|
|
|
|
CP14SharpenedComponent component,
|
|
|
|
|
EntityUid user)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
2025-04-18 13:51:15 +03:00
|
|
|
var ev = new SharpingEvent
|
2024-06-15 16:55:04 +03:00
|
|
|
{
|
|
|
|
|
User = user,
|
|
|
|
|
Target = target,
|
|
|
|
|
};
|
|
|
|
|
RaiseLocalEvent(stone, ev);
|
|
|
|
|
|
|
|
|
|
if (!ev.Canceled)
|
|
|
|
|
{
|
2024-08-05 15:22:14 +03:00
|
|
|
_audio.PlayPredicted(stone.Comp.SharpeningSound, target, user);
|
2024-04-12 21:09:54 +03:00
|
|
|
|
2024-06-15 16:55:04 +03:00
|
|
|
_damageableSystem.TryChangeDamage(stone, stone.Comp.SelfDamage);
|
|
|
|
|
_damageableSystem.TryChangeDamage(target, stone.Comp.TargetDamage);
|
2024-04-12 21:09:54 +03:00
|
|
|
|
2024-06-15 16:55:04 +03:00
|
|
|
component.Sharpness = MathHelper.Clamp01(component.Sharpness + stone.Comp.SharpnessHeal);
|
2024-08-02 13:51:54 +03:00
|
|
|
|
2024-08-05 15:22:14 +03:00
|
|
|
if (_net.IsServer)
|
|
|
|
|
{
|
|
|
|
|
Spawn("EffectSparks", Transform(target).Coordinates);
|
|
|
|
|
if (component.Sharpness >= 0.99)
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("sharpening-ready"), target, user);
|
|
|
|
|
}
|
2024-06-15 16:55:04 +03:00
|
|
|
}
|
2024-04-12 21:09:54 +03:00
|
|
|
|
|
|
|
|
_useDelay.TryResetDelay(stone);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-20 11:51:04 +03:00
|
|
|
private void OnExamined(Entity<CP14SharpenedComponent> sharpened, ref ExaminedEvent args)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
2025-04-18 13:51:15 +03:00
|
|
|
foreach (var (threshold, locString) in sharpened.Comp.SharpnessExamineThresholds.OrderByDescending(x => x.Key))
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
2025-04-18 13:51:15 +03:00
|
|
|
if (!(sharpened.Comp.Sharpness > threshold) && threshold != 0)
|
|
|
|
|
continue;
|
|
|
|
|
args.PushMarkup(Loc.GetString(locString));
|
2024-04-12 21:09:54 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-18 13:51:15 +03:00
|
|
|
private static void OnGetMeleeDamage(Entity<CP14SharpenedComponent> sharpened, ref GetMeleeDamageEvent args)
|
2024-04-12 21:09:54 +03:00
|
|
|
{
|
2025-03-19 13:36:46 +03:00
|
|
|
var slashDamage = args.Damage.DamageDict.GetValueOrDefault("Slash");
|
|
|
|
|
var piercingDamage = args.Damage.DamageDict.GetValueOrDefault("Piercing");
|
|
|
|
|
|
|
|
|
|
args.Damage.DamageDict["Slash"] = slashDamage * sharpened.Comp.Sharpness;
|
|
|
|
|
args.Damage.DamageDict["Piercing"] = piercingDamage * sharpened.Comp.Sharpness;
|
|
|
|
|
args.Damage.DamageDict["Blunt"] = (slashDamage + piercingDamage) / 2 * (1f - sharpened.Comp.Sharpness);
|
2024-04-12 21:09:54 +03:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-15 16:55:04 +03:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Caused on a sharpening stone when someone tries to sharpen an object with it
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class SharpingEvent : EntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
public bool Canceled = false;
|
|
|
|
|
public EntityUid User;
|
|
|
|
|
public EntityUid Target;
|
|
|
|
|
}
|