-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/WWhiteDreamProject/wwdpublic
- Loading branch information
Showing
91 changed files
with
1,214 additions
and
261 deletions.
There are no files selected for viewing
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
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
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
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,82 @@ | ||
using Content.Shared._White.Standing; | ||
using Content.Shared.Buckle; | ||
using Content.Shared.Rotation; | ||
using Content.Shared.Standing; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Client._White.Standing; | ||
|
||
public sealed class LayingDownSystem : SharedLayingDownSystem | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly IEyeManager _eyeManager = default!; | ||
[Dependency] private readonly StandingStateSystem _standing = default!; | ||
[Dependency] private readonly AnimationPlayerSystem _animation = default!; | ||
[Dependency] private readonly SharedBuckleSystem _buckle = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<LayingDownComponent, MoveEvent>(OnMovementInput); | ||
|
||
SubscribeNetworkEvent<CheckAutoGetUpEvent>(OnCheckAutoGetUp); | ||
} | ||
|
||
private void OnMovementInput(EntityUid uid, LayingDownComponent component, MoveEvent args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
if (!_standing.IsDown(uid)) | ||
return; | ||
|
||
if (_buckle.IsBuckled(uid)) | ||
return; | ||
|
||
if (_animation.HasRunningAnimation(uid, "rotate")) | ||
return; | ||
|
||
if (!TryComp<TransformComponent>(uid, out var transform) | ||
|| !TryComp<SpriteComponent>(uid, out var sprite) | ||
|| !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals)) | ||
{ | ||
return; | ||
} | ||
|
||
var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation)); | ||
|
||
if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North) | ||
{ | ||
rotationVisuals.HorizontalRotation = Angle.FromDegrees(270); | ||
sprite.Rotation = Angle.FromDegrees(270); | ||
return; | ||
} | ||
|
||
rotationVisuals.HorizontalRotation = Angle.FromDegrees(90); | ||
sprite.Rotation = Angle.FromDegrees(90); | ||
} | ||
|
||
private void OnCheckAutoGetUp(CheckAutoGetUpEvent ev, EntitySessionEventArgs args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
var uid = GetEntity(ev.User); | ||
|
||
if (!TryComp<TransformComponent>(uid, out var transform) || !TryComp<RotationVisualsComponent>(uid, out var rotationVisuals)) | ||
return; | ||
|
||
var rotation = transform.LocalRotation + (_eyeManager.CurrentEye.Rotation - (transform.LocalRotation - transform.WorldRotation)); | ||
|
||
if (rotation.GetDir() is Direction.SouthEast or Direction.East or Direction.NorthEast or Direction.North) | ||
{ | ||
rotationVisuals.HorizontalRotation = Angle.FromDegrees(270); | ||
return; | ||
} | ||
|
||
rotationVisuals.HorizontalRotation = Angle.FromDegrees(90); | ||
} | ||
} |
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,126 @@ | ||
using System.Numerics; | ||
using Content.Client.Viewport; | ||
using Content.Shared._White; | ||
using Content.Shared._White.Telescope; | ||
using Content.Shared.Input; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.Player; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Input; | ||
using Robust.Shared.Input.Binding; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Client._White.Telescope; | ||
|
||
public sealed class TelescopeSystem : SharedTelescopeSystem | ||
{ | ||
[Dependency] private readonly InputSystem _inputSystem = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IInputManager _input = default!; | ||
[Dependency] private readonly IEyeManager _eyeManager = default!; | ||
[Dependency] private readonly IUserInterfaceManager _uiManager = default!; | ||
[Dependency] private readonly IConfigurationManager _cfg = default!; | ||
|
||
private ScalingViewport? _viewport; | ||
private bool _holdLookUp; | ||
private bool _toggled; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
_cfg.OnValueChanged(WhiteCVars.HoldLookUp, | ||
val => | ||
{ | ||
var input = val ? null : InputCmdHandler.FromDelegate(_ => _toggled = !_toggled); | ||
_input.SetInputCommand(ContentKeyFunctions.LookUp, input); | ||
_holdLookUp = val; | ||
_toggled = false; | ||
}, | ||
true); | ||
} | ||
|
||
public override void FrameUpdate(float frameTime) | ||
{ | ||
base.FrameUpdate(frameTime); | ||
|
||
if (_timing.ApplyingState || !_timing.IsFirstTimePredicted || !_input.MouseScreenPosition.IsValid) | ||
return; | ||
|
||
var player = _player.LocalEntity; | ||
|
||
var telescope = GetRightTelescope(player); | ||
|
||
if (telescope == null) | ||
{ | ||
_toggled = false; | ||
return; | ||
} | ||
|
||
if (!TryComp<EyeComponent>(player, out var eye)) | ||
return; | ||
|
||
var offset = Vector2.Zero; | ||
|
||
if (_holdLookUp) | ||
{ | ||
if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down) | ||
{ | ||
RaiseEvent(offset); | ||
return; | ||
} | ||
} | ||
else if (!_toggled) | ||
{ | ||
RaiseEvent(offset); | ||
return; | ||
} | ||
|
||
var mousePos = _input.MouseScreenPosition; | ||
|
||
if (_uiManager.MouseGetControl(mousePos) as ScalingViewport is { } viewport) | ||
_viewport = viewport; | ||
|
||
if (_viewport == null) | ||
return; | ||
|
||
var centerPos = _eyeManager.WorldToScreen(eye.Eye.Position.Position + eye.Offset); | ||
|
||
var diff = mousePos.Position - centerPos; | ||
var len = diff.Length(); | ||
|
||
var size = _viewport.PixelSize; | ||
|
||
var maxLength = Math.Min(size.X, size.Y) * 0.4f; | ||
var minLength = maxLength * 0.2f; | ||
|
||
if (len > maxLength) | ||
{ | ||
diff *= maxLength / len; | ||
len = maxLength; | ||
} | ||
|
||
var divisor = maxLength * telescope.Divisor; | ||
|
||
if (len > minLength) | ||
{ | ||
diff -= diff * minLength / len; | ||
offset = new Vector2(diff.X / divisor, -diff.Y / divisor); | ||
offset = new Angle(-eye.Rotation.Theta).RotateVec(offset); | ||
} | ||
|
||
RaiseEvent(offset); | ||
} | ||
|
||
private void RaiseEvent(Vector2 offset) | ||
{ | ||
RaisePredictiveEvent(new EyeOffsetChangedEvent | ||
{ | ||
Offset = offset | ||
}); | ||
} | ||
} |
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
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
76 changes: 76 additions & 0 deletions
76
Content.IntegrationTests/Tests/GameRules/AntagPreferenceTest.cs
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,76 @@ | ||
#nullable enable | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Content.Server.Antag; | ||
using Content.Server.Antag.Components; | ||
using Content.Server.GameTicking; | ||
using Content.Shared.GameTicking; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.IntegrationTests.Tests.GameRules; | ||
|
||
// Once upon a time, players in the lobby weren't ever considered eligible for antag roles. | ||
// Lets not let that happen again. | ||
[TestFixture] | ||
public sealed class AntagPreferenceTest | ||
{ | ||
[Test] | ||
public async Task TestLobbyPlayersValid() | ||
{ | ||
await using var pair = await PoolManager.GetServerClient(new PoolSettings | ||
{ | ||
DummyTicker = false, | ||
Connected = true, | ||
InLobby = true | ||
}); | ||
|
||
var server = pair.Server; | ||
var client = pair.Client; | ||
var ticker = server.System<GameTicker>(); | ||
var sys = server.System<AntagSelectionSystem>(); | ||
|
||
// Initially in the lobby | ||
Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby)); | ||
Assert.That(client.AttachedEntity, Is.Null); | ||
Assert.That(ticker.PlayerGameStatuses[client.User!.Value], Is.EqualTo(PlayerGameStatus.NotReadyToPlay)); | ||
|
||
EntityUid uid = default; | ||
await server.WaitPost(() => uid = server.EntMan.Spawn("Traitor")); | ||
var rule = new Entity<AntagSelectionComponent>(uid, server.EntMan.GetComponent<AntagSelectionComponent>(uid)); | ||
var def = rule.Comp.Definitions.Single(); | ||
|
||
// IsSessionValid & IsEntityValid are preference agnostic and should always be true for players in the lobby. | ||
// Though maybe that will change in the future, but then GetPlayerPool() needs to be updated to reflect that. | ||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
|
||
// By default, traitor/antag preferences are disabled, so the pool should be empty. | ||
var sessions = new List<ICommonSession>{pair.Player!}; | ||
var pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(0)); | ||
|
||
// Opt into the traitor role. | ||
await pair.SetAntagPref("Traitor", true); | ||
|
||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(1)); | ||
pool.TryPickAndTake(pair.Server.ResolveDependency<IRobustRandom>(), out var picked); | ||
Assert.That(picked, Is.EqualTo(pair.Player)); | ||
Assert.That(sessions.Count, Is.EqualTo(1)); | ||
|
||
// opt back out | ||
await pair.SetAntagPref("Traitor", false); | ||
|
||
Assert.That(sys.IsSessionValid(rule, pair.Player, def), Is.True); | ||
Assert.That(sys.IsEntityValid(client.AttachedEntity, def), Is.True); | ||
pool = sys.GetPlayerPool(rule, sessions, def); | ||
Assert.That(pool.Count, Is.EqualTo(0)); | ||
|
||
await server.WaitPost(() => server.EntMan.DeleteEntity(uid)); | ||
await pair.CleanReturnAsync(); | ||
} | ||
} |
Oops, something went wrong.