-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20ccb5e
commit be1ba4a
Showing
12 changed files
with
195 additions
and
169 deletions.
There are no files selected for viewing
81 changes: 0 additions & 81 deletions
81
Content.Server/Stories/Reflectors/EmitterRefrectorSystem.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System.Numerics; | ||
using Content.Server.Weapons.Ranged.Systems; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Projectiles; | ||
using Direction = Robust.Shared.Maths.Direction; | ||
using Content.Shared.Stories.Reflectors; | ||
using Content.Shared.Whitelist; | ||
using Content.Shared.Weapons.Ranged.Components; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Network; | ||
|
||
namespace Content.Server.Stories.Reflectors; | ||
public sealed class ReflectorSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
[Dependency] private readonly INetManager _netManager = default!; | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
[Dependency] private readonly GunSystem _gun = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<ReflectorComponent, ProjectileReflectAttemptEvent>(OnReflectCollide); | ||
} | ||
|
||
private void OnReflectCollide(EntityUid uid, ReflectorComponent component, ref ProjectileReflectAttemptEvent args) | ||
{ | ||
if (args.Cancelled) | ||
return; | ||
|
||
var collisionDirection = CalculateCollisionDirection(uid, args.ProjUid); | ||
if (component.BlockedDirections.Contains(collisionDirection.ToString())) | ||
return; | ||
|
||
if (TryReflectProjectile(uid, component, args.ProjUid , collisionDirection)) | ||
args.Cancelled = true; | ||
} | ||
private Direction CalculateCollisionDirection(EntityUid uid, EntityUid projectile) | ||
{ | ||
var projWorldPos = _transform.GetWorldPosition(projectile); | ||
var uidWorldMatrix = _transform.GetInvWorldMatrix(Transform(uid)); | ||
var localCollisionPoint = Vector2.Transform(projWorldPos, uidWorldMatrix); | ||
|
||
return localCollisionPoint.ToAngle().GetCardinalDir(); | ||
|
||
} | ||
|
||
private bool TryReflectProjectile(EntityUid user, ReflectorComponent component , EntityUid projectile, Direction collisionDirection) | ||
{ | ||
if (!TryComp<ReflectiveComponent>(projectile, out var reflective) || | ||
reflective.Reflective == 0x0 || | ||
!TryComp<GunComponent>(user, out var gunComponent) || | ||
_whitelistSystem.IsBlacklistPass(component.Blacklist, projectile) || | ||
_whitelistSystem.IsWhitelistFail(component.Whitelist, projectile)) | ||
{ | ||
return false; | ||
} | ||
|
||
var targetOffset = ReflectBasedOnType(component, collisionDirection); | ||
if (!targetOffset.HasValue) | ||
return false; | ||
|
||
var xform = Transform(user); | ||
var targetPos = new EntityCoordinates(user, targetOffset.Value); | ||
|
||
_transform.SetLocalPosition(projectile, xform.LocalPosition + xform.LocalRotation.RotateVec(targetOffset.Value)); | ||
|
||
_gun.Shoot(user, gunComponent, projectile, xform.Coordinates, targetPos, out _); | ||
|
||
if (_netManager.IsServer) | ||
_popup.PopupEntity(Loc.GetString("reflect-shot"), user); | ||
|
||
return true; | ||
} | ||
|
||
private Vector2 ReflectAngular(Direction collisionDirection) | ||
{ | ||
return collisionDirection switch | ||
{ | ||
Direction.North => Vector2.UnitY, | ||
Direction.South => -Vector2.UnitY, | ||
Direction.East => -Vector2.UnitX, | ||
Direction.West => Vector2.UnitX, | ||
_ => throw new ArgumentOutOfRangeException(nameof(collisionDirection)), | ||
}; | ||
} | ||
private Vector2? ReflectBasedOnType(ReflectorComponent component, Direction collisionDirection) | ||
{ | ||
return component.State switch | ||
{ | ||
ReflectorType.Simple => component.ReflectionDirection?.ToVec(), | ||
ReflectorType.Angular => ReflectAngular(collisionDirection), | ||
_ => throw new ArgumentOutOfRangeException(nameof(component.State), component.State, "Invalid ReflectorType encountered."), | ||
}; | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
Content.Shared/Stories/Reflectors/EmitterRefrectorComponent.cs
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
Content.Shared/Stories/Reflectors/ReflectCountComponent.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Stories.Reflectors; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
public sealed partial class ReflectorComponent : Component | ||
{ | ||
[DataField] | ||
public EntityWhitelist? Whitelist; | ||
|
||
[DataField] | ||
public EntityWhitelist? Blacklist; | ||
|
||
[DataField] | ||
public List<string> BlockedDirections = new(); | ||
|
||
[DataField] | ||
public Direction? ReflectionDirection; | ||
|
||
[DataField, AutoNetworkedField] | ||
public ReflectorType State = ReflectorType.Simple; | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public enum ReflectorType | ||
{ | ||
Simple, | ||
Angular, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.