uncloak ninja after attacking (#20892)

* raise MeleeAttackEvent on the user after swinging

* add disable bool to RevealNinja

* uncloak ninja after attacking

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas 2023-10-11 03:55:53 +01:00 committed by Debug
parent 4ca888db47
commit ba22c02c5e
4 changed files with 28 additions and 2 deletions

View File

@ -96,7 +96,7 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
/// <summary>
/// Force uncloaks the user and disables suit abilities.
/// </summary>
public void RevealNinja(EntityUid uid, EntityUid user, NinjaSuitComponent? comp = null, StealthClothingComponent? stealthClothing = null)
public void RevealNinja(EntityUid uid, EntityUid user, bool disable = true, NinjaSuitComponent? comp = null, StealthClothingComponent? stealthClothing = null)
{
if (!Resolve(uid, ref comp, ref stealthClothing))
return;
@ -104,6 +104,9 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
if (!StealthClothing.SetEnabled(uid, user, false, stealthClothing))
return;
if (!disable)
return;
// previously cloaked, disable abilities for a short time
_audio.PlayPredicted(comp.RevealSound, uid, user);
// all abilities check for a usedelay on the ninja

View File

@ -19,6 +19,7 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<SpaceNinjaComponent, AttackedEvent>(OnNinjaAttacked);
SubscribeLocalEvent<SpaceNinjaComponent, MeleeAttackEvent>(OnNinjaAttack);
SubscribeLocalEvent<SpaceNinjaComponent, ShotAttemptedEvent>(OnShotAttempted);
}
@ -74,7 +75,19 @@ public abstract class SharedSpaceNinjaSystem : EntitySystem
{
if (comp.Suit != null && TryComp<StealthClothingComponent>(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
{
Suit.RevealNinja(comp.Suit.Value, uid, null, stealthClothing);
Suit.RevealNinja(comp.Suit.Value, uid, true, null, stealthClothing);
}
}
/// <summary>
/// Handle revealing ninja if cloaked when attacking.
/// Only reveals, there is no cooldown.
/// </summary>
private void OnNinjaAttack(EntityUid uid, SpaceNinjaComponent comp, ref MeleeAttackEvent args)
{
if (comp.Suit != null && TryComp<StealthClothingComponent>(comp.Suit, out var stealthClothing) && stealthClothing.Enabled)
{
Suit.RevealNinja(comp.Suit.Value, uid, false, null, stealthClothing);
}
}

View File

@ -0,0 +1,7 @@
namespace Content.Shared.Weapons.Melee.Events;
/// <summary>
/// Event raised on the user after attacking with a melee weapon, regardless of whether it hit anything.
/// </summary>
[ByRefEvent]
public record struct MeleeAttackEvent(EntityUid Weapon);

View File

@ -426,6 +426,9 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
DoLungeAnimation(user, weapon.Angle, GetCoordinates(attack.Coordinates).ToMap(EntityManager, TransformSystem), weapon.Range, animation);
}
var attackEv = new MeleeAttackEvent(weaponUid);
RaiseLocalEvent(user, ref attackEv);
weapon.Attacking = true;
return true;
}