-
Notifications
You must be signed in to change notification settings - Fork 292
[ADD] Сцепка для каталки и мешка для трупов на квадроцикле #3209
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
ultradyper
wants to merge
3
commits into
AdventureTimeSS14:master
Choose a base branch
from
ultradyper:feat/atv-trailer-hitch
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,11 @@ | ||
| using Robust.Shared.GameStates; | ||
|
|
||
| namespace Content.Shared.ADT.Vehicle.Trailer; | ||
|
|
||
| /// <summary> | ||
| /// Маркер прицепа: каталка или мешок для трупов, цепляемый к сцепке транспорта. | ||
| /// </summary> | ||
| [RegisterComponent, NetworkedComponent] | ||
| public sealed partial class ADTTrailerComponent : Component | ||
| { | ||
| } |
46 changes: 46 additions & 0 deletions
46
Content.Shared/ADT/Vehicle/Trailer/ADTVehicleHitchComponent.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,46 @@ | ||
| using System.Numerics; | ||
| using Robust.Shared.GameStates; | ||
| using Robust.Shared.Prototypes; | ||
|
|
||
| namespace Content.Shared.ADT.Vehicle.Trailer; | ||
|
|
||
| /// <summary> | ||
| /// Компонент транспорта со сцепкой: создаёт дочернюю сущность-сцепку, к которой цепляются прицепы. | ||
| /// </summary> | ||
| [RegisterComponent, NetworkedComponent] | ||
| public sealed partial class ADTVehicleHitchComponent : Component | ||
| { | ||
| /// <summary> | ||
| /// Прототип создаваемой сцепки. | ||
| /// </summary> | ||
| [DataField] | ||
| public EntProtoId HitchPrototype = "ADTVehicleHitch"; | ||
|
|
||
| /// <summary> | ||
| /// Смещение сцепки относительно транспорта. | ||
| /// </summary> | ||
| [DataField] | ||
| public Vector2 HitchOffset = new(0, 0.55f); | ||
|
|
||
| /// <summary> | ||
| /// Радиус поиска прицепа вокруг сцепки. | ||
| /// </summary> | ||
| [DataField] | ||
| public float AttachRange = 2.5f; | ||
|
|
||
| /// <summary> | ||
| /// Действие водителя: прицепить или отцепить прицеп. | ||
| /// </summary> | ||
| [DataField] | ||
| public EntProtoId ToggleAction = "ADTActionTrailerToggle"; | ||
|
|
||
| /// <summary> | ||
| /// Созданная сцепка. | ||
| /// </summary> | ||
| public EntityUid? Hitch; | ||
|
|
||
| /// <summary> | ||
| /// Созданное действие прицепа. | ||
| /// </summary> | ||
| public EntityUid? ToggleActionEntity; | ||
| } |
11 changes: 11 additions & 0 deletions
11
Content.Shared/ADT/Vehicle/Trailer/ADTVehicleHitchStrapComponent.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,11 @@ | ||
| using Robust.Shared.GameStates; | ||
|
|
||
| namespace Content.Shared.ADT.Vehicle.Trailer; | ||
|
|
||
| /// <summary> | ||
| /// Маркер сущности-сцепки транспорта. | ||
| /// </summary> | ||
| [RegisterComponent, NetworkedComponent] | ||
| public sealed partial class ADTVehicleHitchStrapComponent : Component | ||
| { | ||
| } |
242 changes: 242 additions & 0 deletions
242
Content.Shared/ADT/Vehicle/Trailer/SharedADTVehicleTrailerSystem.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,242 @@ | ||
| using System.Linq; | ||
| using System.Numerics; | ||
| using Content.Shared.Actions; | ||
| using Content.Shared.Actions.Components; | ||
| using Content.Shared.Buckle; | ||
| using Content.Shared.Buckle.Components; | ||
| using Content.Shared.Containers; | ||
| using Content.Shared.Foldable; | ||
| using Content.Shared.Interaction; | ||
| using Content.Shared.Popups; | ||
| using Content.Shared.Vehicle.Components; | ||
| using Robust.Shared.Containers; | ||
| using Robust.Shared.Map; | ||
| using Robust.Shared.Network; | ||
|
|
||
| namespace Content.Shared.ADT.Vehicle.Trailer; | ||
|
|
||
| /// <summary> | ||
| /// Событие действия водителя: прицепить или отцепить прицеп от сцепки. | ||
| /// </summary> | ||
| public sealed partial class ADTTrailerToggleActionEvent : InstantActionEvent | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Сцепки транспорта и прицепы: создание сцепки, прицепление и отцепление каталоги/мешков для трупов. | ||
| /// </summary> | ||
| public sealed partial class SharedADTVehicleTrailerSystem : EntitySystem | ||
| { | ||
| [Dependency] private readonly INetManager _netManager = default!; | ||
| [Dependency] private readonly SharedBuckleSystem _buckle = default!; | ||
| [Dependency] private readonly SharedActionsSystem _actions = default!; | ||
| [Dependency] private readonly SharedPopupSystem _popup = default!; | ||
| [Dependency] private readonly SharedTransformSystem _transform = default!; | ||
| [Dependency] private readonly SharedContainerSystem _container = default!; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<ADTVehicleHitchComponent, MapInitEvent>(OnHitchMapInit); | ||
| SubscribeLocalEvent<ADTVehicleHitchComponent, EntityTerminatingEvent>(OnVehicleTerminating); | ||
| SubscribeLocalEvent<ADTVehicleHitchComponent, StrappedEvent>(OnVehicleStrapped); | ||
| SubscribeLocalEvent<ADTVehicleHitchComponent, UnstrappedEvent>(OnVehicleUnstrapped); | ||
| SubscribeLocalEvent<ADTVehicleHitchComponent, ADTTrailerToggleActionEvent>(OnTrailerToggleAction); | ||
|
|
||
| SubscribeLocalEvent<ADTTrailerComponent, InteractHandEvent>(OnTrailerInteractHand); | ||
| SubscribeLocalEvent<ADTTrailerComponent, FoldedEvent>(OnTrailerFolded); | ||
| SubscribeLocalEvent<ADTTrailerComponent, EntityTerminatingEvent>(OnTrailerTerminating); | ||
| } | ||
|
|
||
| private void OnHitchMapInit(Entity<ADTVehicleHitchComponent> ent, ref MapInitEvent args) | ||
| { | ||
| if (!_netManager.IsServer || ent.Comp.Hitch != null) | ||
| return; | ||
|
|
||
| var hitch = Spawn(ent.Comp.HitchPrototype, Transform(ent).Coordinates); | ||
| if (!TryComp<ADTVehicleHitchStrapComponent>(hitch, out _)) | ||
| { | ||
| Log.Error($"Failed to spawn hitch {ent.Comp.HitchPrototype} for {ToPrettyString(ent)}"); | ||
| return; | ||
| } | ||
|
|
||
| ent.Comp.Hitch = hitch; | ||
| Dirty(ent); | ||
|
|
||
| _transform.SetCoordinates(hitch, new EntityCoordinates(ent.Owner, ent.Comp.HitchOffset)); | ||
| } | ||
|
|
||
| private void OnVehicleTerminating(Entity<ADTVehicleHitchComponent> ent, ref EntityTerminatingEvent args) | ||
| { | ||
| if (ent.Comp.Hitch is not { } hitch) | ||
| return; | ||
|
|
||
| // Выкинуть прицепы на карту, иначе они удалятся вместе с транспортом: | ||
| // при Terminating транспорта ванильный Unbuckle пропускает PlaceNextTo | ||
| if (TryComp<StrapComponent>(hitch, out var strap)) | ||
| { | ||
| foreach (var buckled in strap.BuckledEntities.ToArray()) | ||
| { | ||
| var xform = Transform(buckled); | ||
| _transform.SetCoordinates(buckled, xform, _transform.ToCoordinates(_transform.ToMapCoordinates(xform.Coordinates))); | ||
| _buckle.Unbuckle(buckled, null); | ||
| } | ||
| } | ||
| // Хич - ребёнок транспорта, движок удалит его сам в RecursiveFlagEntityTermination | ||
| } | ||
|
|
||
| private void OnVehicleStrapped(Entity<ADTVehicleHitchComponent> ent, ref StrappedEvent args) | ||
| { | ||
| var rider = args.Buckle.Owner; | ||
| if (!TryComp<ActionsComponent>(rider, out var actions)) | ||
| return; | ||
|
|
||
| _actions.AddAction(rider, ref ent.Comp.ToggleActionEntity, ent.Comp.ToggleAction, ent.Owner, actions); | ||
| } | ||
|
|
||
| private void OnVehicleUnstrapped(Entity<ADTVehicleHitchComponent> ent, ref UnstrappedEvent args) | ||
| { | ||
| _actions.RemoveProvidedActions(args.Buckle.Owner, ent.Owner); | ||
| } | ||
|
|
||
| private void OnTrailerToggleAction(Entity<ADTVehicleHitchComponent> ent, ref ADTTrailerToggleActionEvent args) | ||
| { | ||
| if (_netManager.IsClient) | ||
| return; | ||
|
|
||
| args.Handled = ToggleTrailer(ent, args.Performer); | ||
| } | ||
|
|
||
| private bool ToggleTrailer(Entity<ADTVehicleHitchComponent> ent, EntityUid user) | ||
| { | ||
| // Действие только для текущего водителя этого транспорта | ||
| if (!TryComp<RiderComponent>(user, out var rider) || rider.Vehicle != ent.Owner) | ||
| return false; | ||
|
|
||
| if (ent.Comp.Hitch is not { } hitch || !TryComp<StrapComponent>(hitch, out var strap)) | ||
| return false; | ||
|
|
||
| if (strap.BuckledEntities.Count == 0) | ||
| { | ||
| if (!TryFindTrailer(ent, hitch, out var trailer) || | ||
| !TryComp<BuckleComponent>(trailer, out var buckle) || | ||
| !_buckle.TryBuckle(trailer, user, hitch, buckle)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| _popup.PopupEntity(Loc.GetString("adt-trailer-attached"), ent.Owner, user); | ||
| return true; | ||
| } | ||
|
|
||
| var buckled = strap.BuckledEntities.First(); | ||
| // Прямой Unbuckle: CanUnbuckle блокируется коллизией квадроцикла между водителем и сцепкой | ||
| _buckle.Unbuckle(buckled, null); | ||
|
|
||
| // Отодвинуть прицеп от сцепки за корму, чтобы отцепление было заметно | ||
| var away = _transform.GetWorldPosition(hitch) - _transform.GetWorldPosition(ent); | ||
| if (away == Vector2.Zero) | ||
| away = new Vector2(0, 1); | ||
| away = Vector2.Normalize(away); | ||
|
|
||
| _transform.SetWorldPosition(buckled, _transform.GetWorldPosition(hitch) + away * 0.8f); | ||
|
|
||
| _popup.PopupEntity(Loc.GetString("adt-trailer-unattached"), ent.Owner, user); | ||
| return true; | ||
| } | ||
|
|
||
| private void OnTrailerInteractHand(Entity<ADTTrailerComponent> ent, ref InteractHandEvent args) | ||
| { | ||
| if (args.Handled || !_netManager.IsServer) | ||
| return; | ||
|
|
||
| if (!TryComp<BuckleComponent>(ent, out var buckle) || buckle.BuckledTo != null) | ||
| return; | ||
|
|
||
| if (!TryFindHitch(ent.Owner, out var hitch)) | ||
| return; | ||
|
|
||
| if (!_buckle.TryBuckle(ent.Owner, args.User, hitch, buckle)) | ||
| return; | ||
|
|
||
| args.Handled = true; | ||
| _popup.PopupEntity(Loc.GetString("adt-trailer-attached"), ent.Owner, args.User); | ||
| } | ||
|
|
||
| private void OnTrailerFolded(Entity<ADTTrailerComponent> ent, ref FoldedEvent args) | ||
| { | ||
| if (!args.IsFolded || !_netManager.IsServer) | ||
| return; | ||
|
|
||
| if (!TryComp<BuckleComponent>(ent, out var buckle) || buckle.BuckledTo == null) | ||
| return; | ||
|
|
||
| _buckle.Unbuckle(ent.Owner, null); | ||
| } | ||
|
|
||
| private void OnTrailerTerminating(Entity<ADTTrailerComponent> ent, ref EntityTerminatingEvent args) | ||
| { | ||
| // Убрать прицеп из списка сцепки, чтобы не осталось мёртвого uid | ||
| if (TryComp<BuckleComponent>(ent, out var buckle) && buckle.BuckledTo != null) | ||
| _buckle.Unbuckle(ent.Owner, null); | ||
| } | ||
|
|
||
| private bool TryFindTrailer(Entity<ADTVehicleHitchComponent> ent, EntityUid hitch, out EntityUid trailer) | ||
| { | ||
| trailer = default; | ||
| var hitchPos = _transform.ToMapCoordinates(Transform(hitch).Coordinates); | ||
| var maxRangeSq = ent.Comp.AttachRange * ent.Comp.AttachRange; | ||
|
|
||
| var bestDist = maxRangeSq; | ||
| var query = EntityQueryEnumerator<ADTTrailerComponent, BuckleComponent, TransformComponent>(); | ||
| while (query.MoveNext(out var candidate, out _, out var buckle, out var xform)) | ||
| { | ||
| if (buckle.BuckledTo != null || _container.IsEntityInContainer(candidate)) | ||
| continue; | ||
|
|
||
| if (xform.MapID != hitchPos.MapId) | ||
| continue; | ||
|
|
||
| var dist = (hitchPos.Position - _transform.ToMapCoordinates(xform.Coordinates).Position).LengthSquared(); | ||
| if (dist > bestDist) | ||
| continue; | ||
|
|
||
| bestDist = dist; | ||
| trailer = candidate; | ||
| } | ||
|
|
||
| return trailer != default; | ||
| } | ||
|
|
||
| private bool TryFindHitch(EntityUid trailer, out EntityUid hitch) | ||
| { | ||
| hitch = default; | ||
| var trailerPos = _transform.ToMapCoordinates(Transform(trailer).Coordinates); | ||
|
|
||
| var bestDist = float.MaxValue; | ||
| var query = EntityQueryEnumerator<ADTVehicleHitchComponent, TransformComponent>(); | ||
| while (query.MoveNext(out var uid, out var comp, out var xform)) | ||
| { | ||
| if (comp.Hitch is not { } hitchUid) | ||
| continue; | ||
|
|
||
| if (xform.MapID != trailerPos.MapId) | ||
| continue; | ||
|
|
||
| // Только свободная сцепка: один прицеп на одну сцепку | ||
| if (!TryComp<StrapComponent>(hitchUid, out var strap) || strap.BuckledEntities.Count != 0) | ||
| continue; | ||
|
|
||
| var range = comp.AttachRange; | ||
| var dist = (trailerPos.Position - _transform.ToMapCoordinates(xform.Coordinates).Position).LengthSquared(); | ||
| if (dist > range * range || dist > bestDist) | ||
| continue; | ||
|
|
||
| bestDist = dist; | ||
| hitch = hitchUid; | ||
| } | ||
|
|
||
| return hitch != default; | ||
| } | ||
| } | ||
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
8 changes: 8 additions & 0 deletions
8
Resources/Locale/en-US/ADT/prototypes/Entities/Objects/Vehicles/vehicles.ftl
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,8 @@ | ||
| ent-ADTVehicleATVMedic = medical ATV | ||
| .desc = An ATV with a hitch for carrying rollerbeds and body bags. | ||
|
|
||
| ent-ADTActionTrailerToggle = Trailer | ||
| .desc = Attach or detach a trailer from the ATV hitch. | ||
|
|
||
| adt-trailer-attached = The trailer is attached to the ATV. | ||
| adt-trailer-unattached = The trailer is detached from the ATV. |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Измеряйте расстояние до сцепки, а не до транспорта.
TryFindHitchполучаетhitchUid, но на строке 232 использует координатыxformтранспорта. Поэтому ручное подключение не сработает, если прицеп находится в пределахAttachRangeот сцепки, но вне этого радиуса от центра ATV. Действие водителя уже использует координаты сцепки вTryFindTrailer.Предлагаемое исправление
📝 Committable suggestion
🤖 Prompt for AI Agents