Skip to content
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

Ползать != парить над столами #321

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Content.Client/ADT/Crawling/CrawlingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Content.Shared.ADT.Crawling;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
using Robust.Client.GameObjects;

namespace Content.Client.ADT.Crawling;

public sealed partial class CrawlingSystem : SharedCrawlingSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CrawlerComponent, AppearanceChangeEvent>(OnAppearanceChange);
}

private void OnAppearanceChange(EntityUid uid, CrawlerComponent comp, AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;

if (_appearance.TryGetData<bool>(uid, CrawlingVisuals.Crawling, out var crawling, args.Component) && crawling)
{
args.Sprite.DrawDepth = (int) DrawDepth.SmallMobs;
}
else if (_appearance.TryGetData<bool>(uid, CrawlingVisuals.Standing, out var standing, args.Component) && standing)
{
if (TryPrototype(uid, out var proto) && proto.Components.TryGetComponent("SpriteComponent", out var sprite)) // TODO нормальное читание прототипа. Этот вариант не работает, потому маленьким мобам ползание не добавляем
{
var spriteComp = (SpriteComponent) sprite;
if (spriteComp != null)
args.Sprite.DrawDepth = spriteComp.DrawDepth;
else
args.Sprite.DrawDepth = (int) DrawDepth.Mobs;
}
else
args.Sprite.DrawDepth = (int) DrawDepth.Mobs;
}

}
}
7 changes: 7 additions & 0 deletions Content.Server/ADT/Crawling/CrawlingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared.ADT.Crawling;

namespace Content.Server.ADT.Crawling;

public sealed partial class CrawlingSystem : SharedCrawlingSystem
{
}
2 changes: 1 addition & 1 deletion Content.Shared/ADT/Crawling/CrawlingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Content.Shared.ADT.Crawling;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(CrawlingSystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedCrawlingSystem))]
public sealed partial class CrawlingComponent : Component
{
[ViewVariables, DataField("sprintSpeedModifier"), AutoNetworkedField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@
using Robust.Shared.Player;
using Content.Shared.Movement.Systems;
using Content.Shared.Alert;
using Content.Shared.Climbing.Components;
using Content.Shared.Popups;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Map.Components;
using Content.Shared.Climbing.Systems;
using Content.Shared.Climbing.Events;

namespace Content.Shared.ADT.Crawling;
public sealed partial class CrawlingSystem : EntitySystem

public abstract class SharedCrawlingSystem : EntitySystem
{
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly BonkSystem _bonk = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -31,9 +42,11 @@ public override void Initialize()
SubscribeLocalEvent<CrawlingComponent, ComponentShutdown>(OnCrawlSlowRemove);
SubscribeLocalEvent<CrawlingComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);

SubscribeLocalEvent<CrawlerComponent, MapInitEvent>(OnCrawlerInit);

CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleCrawling, InputCmdHandler.FromDelegate(ToggleCrawlingKeybind, handle: false))
.Register<CrawlingSystem>();
.Register<SharedCrawlingSystem>();
}

private void ToggleCrawlingKeybind(ICommonSession? session)
Expand Down Expand Up @@ -64,6 +77,15 @@ private void OnDoAfter(EntityUid uid, CrawlerComponent component, CrawlStandupDo
{
if (args.Cancelled)
return;

foreach (var item in _lookup.GetEntitiesInRange<ClimbableComponent>(Transform(uid).Coordinates, 0.25f))
{
if (HasComp<ClimbableComponent>(item))
{
_bonk.TryBonk(uid, item, source: uid);
return;
}
}
_standing.Stand(uid);
}
private void OnStandUp(EntityUid uid, CrawlerComponent component, StandAttemptEvent args)
Expand Down Expand Up @@ -99,17 +121,27 @@ private void OnGetExplosionResistance(EntityUid uid, CrawlerComponent component,
private void OnCrawlSlowdownInit(EntityUid uid, CrawlingComponent component, ComponentInit args)
{
_movementSpeedModifier.RefreshMovementSpeedModifiers(uid);
_appearance.SetData(uid, CrawlingVisuals.Standing, false);
_appearance.SetData(uid, CrawlingVisuals.Crawling, true);
}
private void OnCrawlSlowRemove(EntityUid uid, CrawlingComponent component, ComponentShutdown args)
{
component.SprintSpeedModifier = 1f;
component.WalkSpeedModifier = 1f;
_movementSpeedModifier.RefreshMovementSpeedModifiers(uid);
_appearance.SetData(uid, CrawlingVisuals.Crawling, false);
_appearance.SetData(uid, CrawlingVisuals.Standing, true);
}
private void OnRefreshMovespeed(EntityUid uid, CrawlingComponent component, RefreshMovementSpeedModifiersEvent args)
{
args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier);
}

private void OnCrawlerInit(EntityUid uid, CrawlerComponent comp, MapInitEvent args)
{
_appearance.SetData(uid, CrawlingVisuals.Standing, true);
_appearance.SetData(uid, CrawlingVisuals.Crawling, false);
}
}

[Serializable, NetSerializable]
Expand All @@ -121,3 +153,10 @@ public sealed partial class CrawlStandupDoAfterEvent : SimpleDoAfterEvent
public sealed partial class CrawlingKeybindEvent
{
}

[NetSerializable, Serializable]
public enum CrawlingVisuals : byte
{
Standing,
Crawling,
}
Loading