Skip to content

Commit

Permalink
[Port] BlinkSystem / Система Телепортации (#19)
Browse files Browse the repository at this point in the history
add: betrayal dagger
  • Loading branch information
Spatison authored Aug 27, 2024
1 parent a625d9e commit fa17362
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -128,6 +129,27 @@ public override void Update(float frameTime)
return;
}

// WD EDIT START
if (HasComp<BlinkComponent>(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;
}
Expand Down
65 changes: 65 additions & 0 deletions Content.Server/_White/Blink/BlinkSystem.cs
Original file line number Diff line number Diff line change
@@ -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<BlinkEvent>(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);
}
}
31 changes: 31 additions & 0 deletions Content.Shared/_White/Blink/BlinkComponent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions Content.Shared/_White/Standing/SharedLayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Content.Shared.DoAfter;
using Content.Shared.Gravity;
using Content.Shared.Input;
Expand All @@ -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;

Expand All @@ -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()
{
Expand Down Expand Up @@ -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<Entity<LayingDownComponent>>();
_lookup.GetEntitiesInRange(coords, range, ents);

foreach (var ent in ents.Where(ent => ent.Owner != uid))
{
TryLieDown(ent, behavior:DropHeldItemsBehavior.DropIfStanding);
}
}
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-BetrayalKnife = предательский кинжал
.desc = Береги спину.
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
}
]
}

0 comments on commit fa17362

Please sign in to comment.