-
-
Notifications
You must be signed in to change notification settings - Fork 78
Децентрализация механик Scp939 #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WardexOfficial
wants to merge
28
commits into
space-sunrise:master
Choose a base branch
from
WardexOfficial:refactor-wrdx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
45637dc
refactor-step-1
WardexOfficial 8fa71ef
Merge branch 'master' into refactor-wrdx
WardexOfficial 263c9e4
пхех
WardexOfficial 8eb8c69
Merge branch 'refactor-wrdx' of https://github.com/WardexOfficial/fir…
WardexOfficial 5f2985e
пупупу
WardexOfficial 902f1e5
гребаные акшионы 939
WardexOfficial 762fdf3
Доработки
WardexOfficial be49d4e
Merge branch 'master' into refactor-wrdx
WardexOfficial f39e0fb
пупупу
WardexOfficial 6910232
Merge branch 'refactor-wrdx' of https://github.com/WardexOfficial/fir…
WardexOfficial 638f5b2
bruuh
WardexOfficial ae7e2b3
Merge branch 'master' into refactor-wrdx
WardexOfficial 7678d70
Merge branch 'refactor-wrdx' of https://github.com/WardexOfficial/fir…
WardexOfficial 834c45c
ойе, остатки
WardexOfficial 61a66bc
Вишинка на торте
WardexOfficial e0ea076
Merge branch 'master' into refactor-wrdx
WardexOfficial 300c5c4
да ёп
WardexOfficial 9bfeb32
Merge branch 'refactor-wrdx' of https://github.com/WardexOfficial/fir…
WardexOfficial 1d450bc
брууум
WardexOfficial 1392bcb
Merge branch 'master' into refactor-wrdx
WardexOfficial 1b28542
пупупу
WardexOfficial c45219a
ой
WardexOfficial 630b585
ой x2
WardexOfficial ef050d6
а ты прав
WardexOfficial ea9c550
ScpTriggerOnAction
WardexOfficial 6530359
кхм
WardexOfficial cd03e51
пупупу
WardexOfficial dd1dd3f
Merge branch 'master' into refactor-wrdx
WardexOfficial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 8 additions & 9 deletions
17
...nt/_Scp/Scp939/Scp939HudSystem.Overlay.cs → .../ScpOnSoundVisibilityHudSystem.Overlay.cs
This file contains hidden or 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
324 changes: 324 additions & 0 deletions
324
Content.Client/_Scp/Other/ScpOnSoundVisibility/ScpOnSoundVisibilityHudSystem.cs
This file contains hidden or 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,324 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Content.Client.Overlays; | ||
| using Content.Client.SSDIndicator; | ||
| using Content.Shared._Scp.Other.ScpOnSoundVisibility; | ||
| using Content.Shared.Examine; | ||
| using Content.Shared.Inventory.Events; | ||
| using Content.Shared.Movement.Components; | ||
| using Content.Shared.Standing; | ||
| using Content.Shared.StatusIcon.Components; | ||
| using Content.Shared.Throwing; | ||
| using Content.Shared.Weapons.Melee.Events; | ||
| using Content.Shared.Whitelist; | ||
| using Robust.Client.GameObjects; | ||
| using Robust.Client.Graphics; | ||
| using Robust.Client.Player; | ||
| using Robust.Shared.Physics.Components; | ||
| using Robust.Shared.Physics.Events; | ||
| using Robust.Shared.Random; | ||
| using Robust.Shared.Timing; | ||
|
|
||
| namespace Content.Client._Scp.Other.ScpOnSoundVisibility; | ||
|
|
||
| public sealed partial class ScpOnSoundVisibilityHudSystem : EquipmentHudSystem<ScpOnSoundVisibilityViewerComponent> | ||
| { | ||
| [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; | ||
| [Dependency] private readonly IGameTiming _timing = default!; | ||
| [Dependency] private readonly IRobustRandom _random = default!; | ||
| [Dependency] private readonly IPlayerManager _playerManager = default!; | ||
| [Dependency] private readonly SpriteSystem _sprite = default!; | ||
|
|
||
| public readonly List<(Entity<SpriteComponent> Ent, float BaseAlpha)> CachedBaseAlphas = new(64); | ||
|
|
||
| private EntityQuery<EyeComponent> _eyeQuery; | ||
| private EntityQuery<MovementSpeedModifierComponent> _movementSpeedQuery; | ||
| private EntityQuery<PhysicsComponent> _physicsQuery; | ||
| private EntityQuery<ScpOnSoundVisibilityViewerComponent> _viewerQuery; | ||
|
|
||
| private ScpOnSoundVisibilitySetAlphaOverlay _setAlphaOverlay = default!; | ||
| private ScpOnSoundVisibilityResetAlphaOverlay _resetAlphaOverlay = default!; | ||
|
|
||
| private bool _overlaysPresented; | ||
| private TimeSpan _nextUpdateTime; | ||
| private readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(0.05); | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| InitializeOverlay(); | ||
|
|
||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, GetStatusIconsEvent>(OnGetStatusIcons, after: [typeof(SSDIndicatorSystem)]); | ||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, ExamineAttemptEvent>(OnExamine); | ||
|
|
||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, StartCollideEvent>(OnStartCollide); | ||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, EndCollideEvent>(OnEndCollide); | ||
|
|
||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, MoveEvent>(OnMove); | ||
|
|
||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, ThrowEvent>(OnThrow); | ||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, StoodEvent>(OnStood); | ||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, MeleeAttackEvent>(OnMeleeAttack); | ||
| SubscribeLocalEvent<ActiveScpOnSoundVisibilityComponent, DownedEvent>(OnDown); | ||
|
|
||
| _eyeQuery = GetEntityQuery<EyeComponent>(); | ||
| _movementSpeedQuery = GetEntityQuery<MovementSpeedModifierComponent>(); | ||
| _physicsQuery = GetEntityQuery<PhysicsComponent>(); | ||
| _viewerQuery = GetEntityQuery<ScpOnSoundVisibilityViewerComponent>(); | ||
|
|
||
| _setAlphaOverlay = new(); | ||
| _resetAlphaOverlay = new(); | ||
| } | ||
|
|
||
| public override void Shutdown() | ||
| { | ||
| RestoreCachedBaseAlphas(); | ||
| RemoveOverlays(); | ||
|
|
||
| _setAlphaOverlay.Dispose(); | ||
| _resetAlphaOverlay.Dispose(); | ||
|
|
||
| base.Shutdown(); | ||
| } | ||
|
|
||
| private void OnExamine(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref ExamineAttemptEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| if (!TryGetLocalViewer(out var viewer)) | ||
| return; | ||
|
|
||
| var visibility = GetVisibility(ent); | ||
|
|
||
| if (visibility < viewer.Value.Comp.ExamineHideThreshold) | ||
| args.Cancel(); | ||
| } | ||
|
|
||
| private void OnGetStatusIcons(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref GetStatusIconsEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| if (!TryGetLocalViewer(out var viewer)) | ||
| return; | ||
|
|
||
| var visibility = GetVisibility(ent); | ||
|
|
||
| if (visibility <= viewer.Value.Comp.StatusIconClearThreshold) | ||
| args.StatusIcons.Clear(); | ||
| } | ||
|
|
||
| protected override void UpdateInternal(RefreshEquipmentHudEvent<ScpOnSoundVisibilityViewerComponent> args) | ||
| { | ||
| base.UpdateInternal(args); | ||
|
|
||
| AddOverlays(); | ||
| } | ||
|
|
||
| protected override void DeactivateInternal() | ||
| { | ||
| base.DeactivateInternal(); | ||
|
|
||
| _nextUpdateTime = TimeSpan.Zero; | ||
|
|
||
| RestoreCachedBaseAlphas(); | ||
| RemoveOverlays(); | ||
| } | ||
|
|
||
| public override void Update(float frameTime) | ||
| { | ||
| base.Update(frameTime); | ||
|
|
||
| if (!IsActive) | ||
| return; | ||
|
|
||
| if (_timing.RealTime < _nextUpdateTime) | ||
| return; | ||
|
|
||
| if (!TryGetLocalViewer(out var viewer)) | ||
| return; | ||
|
|
||
| var delta = (float)(_timing.RealTime - (_nextUpdateTime - UpdateInterval)).TotalSeconds; | ||
| _nextUpdateTime = _timing.RealTime + UpdateInterval; | ||
|
WardexOfficial marked this conversation as resolved.
|
||
|
|
||
| var query = EntityQueryEnumerator<ActiveScpOnSoundVisibilityComponent>(); | ||
| while (query.MoveNext(out var visibilityEnt, out var visibilityComponent)) | ||
| { | ||
| if (visibilityComponent.OnCollide) | ||
| continue; | ||
|
|
||
| if (viewer.Value.Owner == visibilityEnt) | ||
| continue; | ||
|
|
||
| if (visibilityComponent.VisibilityAcc >= visibilityComponent.HideTime) | ||
| continue; | ||
|
|
||
| visibilityComponent.VisibilityAcc = MathF.Min(visibilityComponent.VisibilityAcc + delta, visibilityComponent.HideTime); | ||
| } | ||
| } | ||
|
|
||
| public bool CanDraw(in OverlayDrawArgs args) | ||
| { | ||
| if (!IsActive) | ||
| return false; | ||
|
|
||
| if (_playerManager.LocalEntity is not { } player) | ||
| return false; | ||
|
|
||
| if (!_eyeQuery.TryComp(player, out var eye)) | ||
| return false; | ||
|
|
||
| return args.Viewport.Eye == eye.Eye; | ||
| } | ||
|
|
||
| public void RestoreCachedBaseAlphas() | ||
| { | ||
| foreach (var (ent, baseAlpha) in CachedBaseAlphas) | ||
| { | ||
| if (!EntityManager.EntityExists(ent)) | ||
| continue; | ||
|
|
||
| _sprite.SetColor(ent.AsNullable(), ent.Comp.Color.WithAlpha(baseAlpha)); | ||
| } | ||
|
|
||
| CachedBaseAlphas.Clear(); | ||
| } | ||
|
|
||
| public static float GetVisibility(Entity<ActiveScpOnSoundVisibilityComponent> ent) | ||
| { | ||
| var acc = ent.Comp.VisibilityAcc; | ||
|
|
||
| if (acc > ent.Comp.HideTime) | ||
| return 0; | ||
|
|
||
| return Math.Clamp(1f - (acc / ent.Comp.HideTime), 0f, 1f); | ||
| } | ||
|
|
||
| private void OnMove(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref MoveEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| if (!TryGetLocalViewer(out var viewer)) | ||
| return; | ||
|
|
||
| if (ent.Comp.OnCollide) | ||
| return; | ||
|
|
||
| if (ent.Owner == viewer.Value.Owner) | ||
| return; | ||
|
|
||
| // В зависимости от наличие защит или проблем со зрением изменяется то, насколько хорошо мы видим жертву | ||
| if (ModifyAcc(ent, out var modifier)) // Если зрение затруднено | ||
| { | ||
| ent.Comp.VisibilityAcc *= modifier; | ||
| } | ||
| else if (_whitelist.IsWhitelistPass(viewer.Value.Comp.Protections, ent)) // Если имеется защита(тихое хождение) | ||
| { | ||
| return; | ||
| } | ||
| else // Если со зрением все ок | ||
| { | ||
| ent.Comp.VisibilityAcc = 0; | ||
| } | ||
|
WardexOfficial marked this conversation as resolved.
|
||
|
|
||
| if (!_movementSpeedQuery.TryComp(ent, out var speedModifierComponent) | ||
| || !_physicsQuery.TryComp(ent, out var physicsComponent)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var currentVelocity = physicsComponent.LinearVelocity.Length(); | ||
|
|
||
| if (speedModifierComponent.BaseWalkSpeed > currentVelocity) | ||
| ent.Comp.VisibilityAcc = ent.Comp.HideTime / 2f; | ||
| } | ||
|
|
||
| private void OnStartCollide(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref StartCollideEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| ent.Comp.OnCollide = true; | ||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void OnEndCollide(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref EndCollideEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| ent.Comp.OnCollide = false; | ||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void OnThrow(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref ThrowEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void OnStood(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref StoodEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void OnMeleeAttack(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref MeleeAttackEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void OnDown(Entity<ActiveScpOnSoundVisibilityComponent> ent, ref DownedEvent args) | ||
| { | ||
| if (!IsActive) | ||
| return; | ||
|
|
||
| MobDidSomething(ent); | ||
| } | ||
|
|
||
| private void MobDidSomething(Entity<ActiveScpOnSoundVisibilityComponent> ent) | ||
| { | ||
| ent.Comp.VisibilityAcc = ScpOnSoundVisibilityComponent.InitialVisibilityAcc; | ||
| } | ||
|
|
||
| // TODO: Переделать под статус эффект и добавить его в панель статус эффектов, а то непонятно игруну | ||
|
WardexOfficial marked this conversation as resolved.
|
||
| private bool ModifyAcc(Entity<ActiveScpOnSoundVisibilityComponent> ent, out float modifier) | ||
| { | ||
| // 1 = отсутствие модификатора | ||
| modifier = 1f; | ||
|
|
||
| if (!TryGetLocalViewer(out var viewer)) | ||
| return false; | ||
|
|
||
| if (!viewer.Value.Comp.PoorEyesight) | ||
| return false; | ||
|
|
||
| modifier = _random.NextFloat(ent.Comp.MinValue, ent.Comp.MaxValue); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private bool TryGetLocalViewer([NotNullWhen(true)] out Entity<ScpOnSoundVisibilityViewerComponent>? ent) | ||
| { | ||
| ent = null; | ||
| var localPlayer = _playerManager.LocalEntity; | ||
|
|
||
| if (localPlayer == null) | ||
| return false; | ||
|
|
||
| if (!_viewerQuery.TryComp(localPlayer, out var comp)) | ||
| return false; | ||
|
|
||
| ent = (localPlayer.Value, comp); | ||
| return true; | ||
| } | ||
| } | ||
10 changes: 5 additions & 5 deletions
10
...nt/_Scp/Scp939/Scp939ResetAlphaOverlay.cs → .../ScpOnSoundVisibilityResetAlphaOverlay.cs
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.