From fa17362f121d0b2b1ca59445ec60e2133ad74873 Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:01:15 +0300 Subject: [PATCH] =?UTF-8?q?[Port]=20BlinkSystem=20/=20=D0=A1=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=BC=D0=B0=20=D0=A2=D0=B5=D0=BB=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=B0=D1=86=D0=B8=D0=B8=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add: betrayal dagger --- .../Weapons/Melee/MeleeWeaponSystem.cs | 22 ++++++ Content.Server/_White/Blink/BlinkSystem.cs | 65 ++++++++++++++++++ Content.Shared/_White/Blink/BlinkComponent.cs | 31 +++++++++ .../_White/Standing/SharedLayingDownSystem.cs | 14 ++++ .../objects/weapons/melee/daggers.ftl | 2 + .../Objects/Weapons/Melee/daggers.yml | 32 +++++++++ .../Melee/Daggers/betrayal_knife.rsi/icon.png | Bin 0 -> 388 bytes .../betrayal_knife.rsi/inhand-left.png | Bin 0 -> 334 bytes .../betrayal_knife.rsi/inhand-right.png | Bin 0 -> 339 bytes .../Daggers/betrayal_knife.rsi/meta.json | 22 ++++++ 10 files changed, 188 insertions(+) create mode 100644 Content.Server/_White/Blink/BlinkSystem.cs create mode 100644 Content.Shared/_White/Blink/BlinkComponent.cs create mode 100644 Resources/Locale/ru-RU/_white/prototypes/entities/objects/weapons/melee/daggers.ftl create mode 100644 Resources/Prototypes/_White/Entities/Objects/Weapons/Melee/daggers.yml create mode 100644 Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/icon.png create mode 100644 Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/inhand-left.png create mode 100644 Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/inhand-right.png create mode 100644 Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/meta.json diff --git a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs index 98528c691d..fbb4a6904d 100644 --- a/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Client/Weapons/Melee/MeleeWeaponSystem.cs @@ -1,5 +1,6 @@ using System.Linq; using Content.Client.Gameplay; +using Content.Shared._White.Blink; using Content.Shared.CCVar; using Content.Shared.CombatMode; using Content.Shared.Effects; @@ -128,6 +129,27 @@ public override void Update(float frameTime) return; } + // WD EDIT START + if (HasComp(weaponUid)) + { + if (!_xformQuery.TryGetComponent(entity, out var userXform) || !Timing.IsFirstTimePredicted) + { + return; + } + + var targetMap = coordinates.ToMap(EntityManager, TransformSystem); + + if (targetMap.MapId != userXform.MapID) + return; + + var userPos = TransformSystem.GetWorldPosition(userXform); + var direction = targetMap.Position - userPos; + + RaiseNetworkEvent(new BlinkEvent(GetNetEntity(weaponUid), direction)); + return; + } + // WD EDIT END + ClientHeavyAttack(entity, coordinates, weaponUid, weapon); return; } diff --git a/Content.Server/_White/Blink/BlinkSystem.cs b/Content.Server/_White/Blink/BlinkSystem.cs new file mode 100644 index 0000000000..afcf9b436d --- /dev/null +++ b/Content.Server/_White/Blink/BlinkSystem.cs @@ -0,0 +1,65 @@ +using System.Linq; +using System.Numerics; +using Content.Shared._White.Blink; +using Content.Shared._White.Standing; +using Content.Shared.Physics; +using Robust.Server.Audio; +using Robust.Server.GameObjects; +using Robust.Shared.Physics; +using Robust.Shared.Timing; + +namespace Content.Server._White.Blink; + +public sealed class BlinkSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly AudioSystem _audio = default!; + [Dependency] private readonly TransformSystem _transform = default!; + [Dependency] private readonly PhysicsSystem _physics = default!; + [Dependency] private readonly SharedLayingDownSystem _layingDown = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeAllEvent(OnBlink); + } + + private void OnBlink(BlinkEvent msg, EntitySessionEventArgs args) + { + if (args.SenderSession.AttachedEntity == null) + return; + + var user = args.SenderSession.AttachedEntity.Value; + + if (!TryComp(user, out TransformComponent? xform)) + return; + + if (!TryComp(GetEntity(msg.Weapon), out BlinkComponent? blink)) + return; + + if (blink.NextBlink > _timing.CurTime) + return; + + var blinkRate = TimeSpan.FromSeconds(1f / blink.BlinkRate); + + blink.NextBlink = _timing.CurTime + blinkRate; + + var coords = _transform.GetWorldPosition(xform); + var dir = msg.Direction.Normalized(); + var range = MathF.Min(blink.Distance, msg.Direction.Length()); + + var ray = new CollisionRay(coords, dir, (int) (CollisionGroup.Impassable | CollisionGroup.InteractImpassable)); + var rayResults = _physics.IntersectRayWithPredicate(xform.MapID, ray, range, x => x == user, false).ToList(); + + Vector2 targetPos; + if (rayResults.Count > 0) + targetPos = rayResults.MinBy(x => (x.HitPos - coords).Length()).HitPos - dir; + else + targetPos = coords + (msg.Direction.Length() > blink.Distance ? dir * blink.Distance : msg.Direction); + + _transform.SetWorldPosition(user, targetPos); + _layingDown.LieDownInRange(user, xform.Coordinates); + _audio.PlayPvs(blink.BlinkSound, user); + } +} diff --git a/Content.Shared/_White/Blink/BlinkComponent.cs b/Content.Shared/_White/Blink/BlinkComponent.cs new file mode 100644 index 0000000000..d60a69c66d --- /dev/null +++ b/Content.Shared/_White/Blink/BlinkComponent.cs @@ -0,0 +1,31 @@ +using System.Numerics; +using Robust.Shared.Audio; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared._White.Blink; + +[RegisterComponent, NetworkedComponent] +public sealed partial class BlinkComponent : Component +{ + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float Distance = 5f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float BlinkRate = 1f; + + public TimeSpan NextBlink; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public SoundSpecifier BlinkSound = new SoundPathSpecifier("/Audio/Magic/blink.ogg") + { + Params = AudioParams.Default.WithVolume(5f) + }; +} + +[Serializable, NetSerializable] +public sealed class BlinkEvent(NetEntity weapon, Vector2 direction) : EntityEventArgs +{ + public readonly NetEntity Weapon = weapon; + public readonly Vector2 Direction = direction; +} diff --git a/Content.Shared/_White/Standing/SharedLayingDownSystem.cs b/Content.Shared/_White/Standing/SharedLayingDownSystem.cs index 2406d19a37..629fdea3fe 100644 --- a/Content.Shared/_White/Standing/SharedLayingDownSystem.cs +++ b/Content.Shared/_White/Standing/SharedLayingDownSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Shared.DoAfter; using Content.Shared.Gravity; using Content.Shared.Input; @@ -6,6 +7,7 @@ using Content.Shared.Standing; using Content.Shared.Stunnable; using Robust.Shared.Input.Binding; +using Robust.Shared.Map; using Robust.Shared.Player; using Robust.Shared.Serialization; @@ -17,6 +19,7 @@ public abstract class SharedLayingDownSystem : EntitySystem [Dependency] private readonly StandingStateSystem _standing = default!; [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; [Dependency] private readonly SharedGravitySystem _gravity = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; public override void Initialize() { @@ -149,6 +152,17 @@ public bool TryLieDown(EntityUid uid, LayingDownComponent? layingDown = null, St _standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, standingState); return true; } + + public void LieDownInRange(EntityUid uid, EntityCoordinates coords, float range = 0.4f) + { + var ents = new HashSet>(); + _lookup.GetEntitiesInRange(coords, range, ents); + + foreach (var ent in ents.Where(ent => ent.Owner != uid)) + { + TryLieDown(ent, behavior:DropHeldItemsBehavior.DropIfStanding); + } + } } [Serializable, NetSerializable] diff --git a/Resources/Locale/ru-RU/_white/prototypes/entities/objects/weapons/melee/daggers.ftl b/Resources/Locale/ru-RU/_white/prototypes/entities/objects/weapons/melee/daggers.ftl new file mode 100644 index 0000000000..00ceb91748 --- /dev/null +++ b/Resources/Locale/ru-RU/_white/prototypes/entities/objects/weapons/melee/daggers.ftl @@ -0,0 +1,2 @@ +ent-BetrayalKnife = предательский кинжал + .desc = Береги спину. \ No newline at end of file diff --git a/Resources/Prototypes/_White/Entities/Objects/Weapons/Melee/daggers.yml b/Resources/Prototypes/_White/Entities/Objects/Weapons/Melee/daggers.yml new file mode 100644 index 0000000000..815e2192d9 --- /dev/null +++ b/Resources/Prototypes/_White/Entities/Objects/Weapons/Melee/daggers.yml @@ -0,0 +1,32 @@ +- type: entity + name: betrayal dagger + description: Watch your back. + parent: BaseKnife + id: BetrayalKnife + components: + - type: Sprite + sprite: _White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi + state: icon + - type: Item + size: Small + - type: MeleeWeapon + wideAnimationRotation: 180 + attackRate: 1.5 + damage: + types: + Slash: 17.5 + soundHit: + path: /Audio/Weapons/bladeslice.ogg + - type: Sharp + - type: EmbeddableProjectile + sound: /Audio/Weapons/star_hit.ogg + - type: ThrowingAngle + angle: 180 + - type: DamageOtherOnHit + damage: + types: + Slash: 20 + - type: DisarmMalus + malus: 0.225 + - type: Blink + blinkRate: 0.33 diff --git a/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/icon.png b/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..99d2f8453fedf5d41eb8e52e62f935713ca808be GIT binary patch literal 388 zcmV-~0ek+5P)-Rm=OUWB@?0}mvDFbt0vi_zr* iQ4~p8mTh~?Bk&JE#)-0qoticP0000;TVCQh)P!ecjs0j&Hk3BPsq1N}r-t^eIU#cyx z_r*W*G*qxT*f1;1V-z^g(2>q?#F*icac_%&gxmdKI;Vst0M-S0yZ`_I literal 0 HcmV?d00001 diff --git a/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/inhand-right.png b/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/inhand-right.png new file mode 100644 index 0000000000000000000000000000000000000000..8fff278de291f0f3e7baeac1dfb440fcf0cd0bbe GIT binary patch literal 339 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=oCO|{#S9F5M?jcysy3fA0|O(g zr;B4q#hkadF7moKh`2qB-_&mv(7+_JfSFapMUX47!R|_m@ub?rT**TJisj5V720$1 z7uy^0Gt6XfIK%Alj8Wk;!-PtP6E+Mfatzt_e1{FT=gxkq`u6N*u7K-bvjq;xB+gqK z#@My!#Inp;^ZNwe?bkV-I&W>Z*?q>)(A38k=W6etkG*cor+BA)-t*Hk)z{zdW0}3I z^3H?(eRd}Mm~dExD%|lieWU;6;5mNo%sX(UBa|JT=%{e?@^XR-osSS&te@Ne5 u?f=loq3da<^>>jUToBhn4cW~8gXzwV;B@b6ED69+V(@hJb6Mw<&;$V4#D1{= literal 0 HcmV?d00001 diff --git a/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/meta.json b/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/meta.json new file mode 100644 index 0000000000..0b2fd88c33 --- /dev/null +++ b/Resources/Textures/_White/Objects/Weapons/Melee/Daggers/betrayal_knife.rsi/meta.json @@ -0,0 +1,22 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Taken from tgstation at https://github.com/tgstation/tgstation/pull/49264/commits/d0dffe7ca643db2624424fdcebf45863f85c0448", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "icon" + }, + { + "name": "inhand-left", + "directions": 4 + }, + { + "name": "inhand-right", + "directions": 4 + } + ] +}