From a6a69cc60fcd3a7f13221fd622b0843d7961c595 Mon Sep 17 00:00:00 2001 From: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:05:25 +0300 Subject: [PATCH] add hrp ++++ aspect (#587) --- Content.Client/Input/ContentContexts.cs | 1 + .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 1 + .../_White/Telescope/TelescopeSystem.cs | 16 ++- .../Components/ImmersiveAspectComponent.cs | 7 ++ .../AspectsSystem/Aspects/ImmersiveAspect.cs | 100 ++++++++++++++++++ Content.Shared/Input/ContentKeyFunctions.cs | 1 + .../Components/ContentEyeComponent.cs | 4 +- .../_White/Telescope/SharedTelescopeSystem.cs | 46 +++++++- .../Prototypes/_White/Aspects/Aspects.yml | 13 +++ Resources/keybinds.yml | 6 +- 10 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 Content.Server/_White/AspectsSystem/Aspects/Components/ImmersiveAspectComponent.cs create mode 100644 Content.Server/_White/AspectsSystem/Aspects/ImmersiveAspect.cs diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index fd6eee0e7b..6756208a1a 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -82,6 +82,7 @@ namespace Content.Client.Input human.AddFunction(ContentKeyFunctions.Arcade3); human.AddFunction(ContentKeyFunctions.LieDown); // WD EDIT human.AddFunction(ContentKeyFunctions.OfferItem); // WD EDIT + human.AddFunction(ContentKeyFunctions.LookUp); // WD EDIT // actions should be common (for ghosts, mobs, etc) common.AddFunction(ContentKeyFunctions.OpenActionsMenu); diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 7cd48d338f..2a077806a2 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -193,6 +193,7 @@ namespace Content.Client.Options.UI.Tabs AddButton(ContentKeyFunctions.SaveItemLocation); AddButton(ContentKeyFunctions.OfferItem); // WD EDIT AddButton(ContentKeyFunctions.LieDown); // WD EDIT + AddButton(ContentKeyFunctions.LookUp); // WD EDIT AddCheckBox("ui-options-function-auto-get-up", _cfg.GetCVar(WhiteCVars.AutoGetUp), HandleToggleAutoGetUp); // WD EDIT AddHeader("ui-options-header-interaction-adv"); diff --git a/Content.Client/_White/Telescope/TelescopeSystem.cs b/Content.Client/_White/Telescope/TelescopeSystem.cs index 36bd8a07d4..c1f90a7b98 100644 --- a/Content.Client/_White/Telescope/TelescopeSystem.cs +++ b/Content.Client/_White/Telescope/TelescopeSystem.cs @@ -2,6 +2,7 @@ using System.Numerics; using Content.Client.Viewport; using Content.Shared._White.Telescope; using Content.Shared.Hands.Components; +using Content.Shared.Input; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Input; @@ -23,6 +24,7 @@ public sealed class TelescopeSystem : SharedTelescopeSystem private ScalingViewport? _viewport; + public override void FrameUpdate(float frameTime) { base.FrameUpdate(frameTime); @@ -32,19 +34,25 @@ public sealed class TelescopeSystem : SharedTelescopeSystem var player = _player.LocalEntity; - if (!TryComp(player, out var hands) || - !TryComp(hands.ActiveHandEntity, out var telescope) || - !TryComp(player.Value, out var eye)) + var entity = GetRightEntity(player); + + if (entity == EntityUid.Invalid) + return; + + var telescope = Comp(entity); + + if (!TryComp(player, out var eye)) return; var offset = Vector2.Zero; - if (_inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary) != BoundKeyState.Down) + if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down) { RaisePredictiveEvent(new EyeOffsetChangedEvent { Offset = offset }); + return; } diff --git a/Content.Server/_White/AspectsSystem/Aspects/Components/ImmersiveAspectComponent.cs b/Content.Server/_White/AspectsSystem/Aspects/Components/ImmersiveAspectComponent.cs new file mode 100644 index 0000000000..7cecae6d0f --- /dev/null +++ b/Content.Server/_White/AspectsSystem/Aspects/Components/ImmersiveAspectComponent.cs @@ -0,0 +1,7 @@ +namespace Content.Server._White.AspectsSystem.Aspects.Components; + +[RegisterComponent] +public sealed partial class ImmersiveAspectComponent : Component +{ + +} diff --git a/Content.Server/_White/AspectsSystem/Aspects/ImmersiveAspect.cs b/Content.Server/_White/AspectsSystem/Aspects/ImmersiveAspect.cs new file mode 100644 index 0000000000..9e95f80d32 --- /dev/null +++ b/Content.Server/_White/AspectsSystem/Aspects/ImmersiveAspect.cs @@ -0,0 +1,100 @@ +using System.Numerics; +using Content.Server.GameTicking.Rules.Components; +using Content.Server._White.AspectsSystem.Aspects.Components; +using Content.Server._White.AspectsSystem.Base; +using Content.Server.GameTicking; +using Content.Shared._White.Telescope; +using Content.Shared.Humanoid; +using Content.Shared.Movement.Components; +using Content.Shared.Movement.Systems; + +namespace Content.Server._White.AspectsSystem.Aspects; + +public sealed class ImmersiveAspect : AspectSystem +{ + + [Dependency] private readonly SharedContentEyeSystem _eye = default!; + [Dependency] private readonly SharedTelescopeSystem _telescope = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(HandleLateJoin); + } + + protected override void Started(EntityUid uid, ImmersiveAspectComponent component, GameRuleComponent gameRule, + GameRuleStartedEvent args) + { + base.Started(uid, component, gameRule, args); + + WayToHRPPlusPlus(); + } + + private void WayToHRPPlusPlus() + { + var humans = EntityQuery(); + + foreach (var human in humans) + { + var entity = human.Owner; + + if (!HasComp(entity)) + continue; + + FuckUpEye(entity, 0.6f); + AddTelescope(entity); + } + } + + private void FuckUpEye(EntityUid human, float modifier) + { + _eye.SetMaxZoom(human, new Vector2(modifier)); + _eye.SetZoom(human, new Vector2(modifier)); + } + + private void AddTelescope(EntityUid human) + { + var telescope = EnsureComp(human); + + _telescope.SetParameters((human, telescope), 0.15f, 0.07f); + } + + private void HandleLateJoin(PlayerSpawnCompleteEvent ev) + { + if (!ev.LateJoin) + return; + + if (!HasComp(ev.Mob)) + return; + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var ruleEntity, out _, out var gameRule)) + { + if (!GameTicker.IsGameRuleAdded(ruleEntity, gameRule)) + continue; + + FuckUpEye(ev.Mob, 0.6f); + AddTelescope(ev.Mob); + } + } + + + protected override void Ended(EntityUid uid, ImmersiveAspectComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args) + { + base.Ended(uid, component, gameRule, args); + + var humans = EntityQuery(); + + foreach (var human in humans) + { + var entity = human.Owner; + + if (!HasComp(entity)) + continue; + + FuckUpEye(entity, 1f); + + RemComp(entity); + } + } +} diff --git a/Content.Shared/Input/ContentKeyFunctions.cs b/Content.Shared/Input/ContentKeyFunctions.cs index 56c0299c82..ec58f104db 100644 --- a/Content.Shared/Input/ContentKeyFunctions.cs +++ b/Content.Shared/Input/ContentKeyFunctions.cs @@ -59,6 +59,7 @@ namespace Content.Shared.Input public static readonly BoundKeyFunction ResetZoom = "ResetZoom"; public static readonly BoundKeyFunction LieDown = "LieDown"; // WD EDIT public static readonly BoundKeyFunction OfferItem = "OfferItem"; // WD EDIT + public static readonly BoundKeyFunction LookUp = "LookUp"; // WD EDIT public static readonly BoundKeyFunction ArcadeUp = "ArcadeUp"; public static readonly BoundKeyFunction ArcadeDown = "ArcadeDown"; diff --git a/Content.Shared/Movement/Components/ContentEyeComponent.cs b/Content.Shared/Movement/Components/ContentEyeComponent.cs index af37ebfd78..3d6a0e401e 100644 --- a/Content.Shared/Movement/Components/ContentEyeComponent.cs +++ b/Content.Shared/Movement/Components/ContentEyeComponent.cs @@ -13,12 +13,12 @@ public sealed partial class ContentEyeComponent : Component /// /// Zoom we're lerping to. /// - [DataField("targetZoom"), AutoNetworkedField] + [DataField, AutoNetworkedField] public Vector2 TargetZoom = Vector2.One; /// /// How far we're allowed to zoom out. /// - [ViewVariables(VVAccess.ReadWrite), DataField("maxZoom"), AutoNetworkedField] + [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public Vector2 MaxZoom = Vector2.One; } diff --git a/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs b/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs index 4bb6f39053..32708d25a6 100644 --- a/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs +++ b/Content.Shared/_White/Telescope/SharedTelescopeSystem.cs @@ -2,6 +2,7 @@ using System.Numerics; using Content.Shared.Camera; using Content.Shared.Hands; using Content.Shared.Hands.Components; +using Content.Shared.Item; using Robust.Shared.Serialization; namespace Content.Shared._White.Telescope; @@ -41,19 +42,45 @@ public abstract class SharedTelescopeSystem : EntitySystem if (!TryComp(args.User, out EyeComponent? eye)) return; + if (!HasComp(ent.Owner)) + return; + SetOffset((args.User, eye), Vector2.Zero, ent); } + public EntityUid GetRightEntity(EntityUid? ent) + { + var entity = EntityUid.Invalid; + + if (TryComp(ent, out var hands) && + HasComp(hands.ActiveHandEntity) && + hands.ActiveHandEntity.HasValue) + { + entity = hands.ActiveHandEntity.Value; + } + else if (HasComp(ent)) + { + entity = ent.Value; + } + + return entity; + } + private void OnEyeOffsetChanged(EyeOffsetChangedEvent msg, EntitySessionEventArgs args) { if (args.SenderSession.AttachedEntity is not { } ent) return; - if (!TryComp(ent, out var hands) || - !TryComp(hands.ActiveHandEntity, out var telescope) || - !TryComp(ent, out EyeComponent? eye)) + if (!TryComp(ent, out EyeComponent? eye)) return; + var entity = GetRightEntity(ent); + + if (entity == EntityUid.Invalid) + return; + + var telescope = Comp(entity); + var offset = Vector2.Lerp(eye.Offset, msg.Offset, telescope.LerpAmount); SetOffset((ent, eye), offset, telescope); @@ -71,6 +98,19 @@ public abstract class SharedTelescopeSystem : EntitySystem else _eye.SetOffset(ent, offset, ent); } + + public void SetParameters(Entity ent, float? divisor = null, float? lerpAmount = null) + { + var telescope = ent.Comp; + + divisor ??= telescope.Divisor; + lerpAmount ??= telescope.LerpAmount; + + telescope.Divisor = divisor.Value; + telescope.LerpAmount = lerpAmount.Value; + + Dirty(ent.Owner, telescope); + } } [Serializable, NetSerializable] diff --git a/Resources/Prototypes/_White/Aspects/Aspects.yml b/Resources/Prototypes/_White/Aspects/Aspects.yml index 2349b60ae4..13037e37de 100644 --- a/Resources/Prototypes/_White/Aspects/Aspects.yml +++ b/Resources/Prototypes/_White/Aspects/Aspects.yml @@ -338,6 +338,19 @@ path: /Audio/White/Aspects/accent.ogg - type: RandomItemAspect +- type: entity + id: ImmersiveAspect + parent: BaseGameRule + noSpawn: true + components: + - type: Aspect + name: "Immersive" + description: "В связи с недавними трагичными событиями экипаж станции погрузился в себя" + weight: 3 + startAudio: + path: /Audio/White/Aspects/accent.ogg + - type: ImmersiveAspect + # Disabled this cause polymorph breaks stuff #- type: entity # id: SkeletonAspect diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index 4b52ffe059..add2d5cd31 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -542,4 +542,8 @@ binds: key: Num9 - function: LieDown type: State - key: U \ No newline at end of file + key: U +- function: LookUp + type: State + key: MouseRight + mod1: Space