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

crawling adjustments #1265

Merged
merged 7 commits into from
Jan 11, 2025
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Explosion.Components;
using Content.Server.Explosion.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Map;
Expand Down Expand Up @@ -77,6 +78,7 @@ private void FragmentIntoProjectiles(EntityUid uid, ProjectileGrenadeComponent c
// slightly uneven, doesn't really change much, but it looks better
var direction = angle.ToVec().Normalized();
var velocity = _random.NextVector2(component.MinVelocity, component.MaxVelocity);
EnsureComp<TargetedProjectileComponent>(contentUid); // imp - ensure projectile is a TargetedProjectile with no target to hit crawling players
_gun.ShootProjectile(contentUid, direction, velocity, uid, null);
}
}
Expand Down
1 change: 1 addition & 0 deletions Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private void UpdateRanged(float frameTime)
return;
}

_gun.SetTarget(gun, comp.Target);
_gun.AttemptShoot(uid, gunUid, gun, targetCordinates);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref Pr
return;

var other = args.OtherEntity;
if (TryComp(other, out ProjectileComponent? projectile) &&
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)

if (TryComp(other, out TargetedProjectileComponent? targeted) &&
(targeted.Target == null || targeted.Target == ent))
return;

if (TryComp(other, out ProjectileComponent? projectile))
{
// Prevents shooting out of while inside of crates
var shooter = projectile.Shooter;
Expand Down
1 change: 0 additions & 1 deletion Content.Shared/Standing/StandingStateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public sealed partial class StandingStateComponent : Component
public enum StandingState
{
Lying,
GettingUp,
Standing,
}
// WD EDIT END
9 changes: 5 additions & 4 deletions Content.Shared/Standing/StandingStateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
if (!Resolve(uid, ref standingState, false))
return false;

return standingState.CurrentState is StandingState.Lying or StandingState.GettingUp;
return standingState.CurrentState is StandingState.Lying;
}

public bool Down(EntityUid uid,
Expand All @@ -38,7 +38,8 @@ public bool Down(EntityUid uid,
bool force = true,
StandingStateComponent? standingState = null,
AppearanceComponent? appearance = null,
HandsComponent? hands = null)
HandsComponent? hands = null,
bool intentional = true)
{
// TODO: This should actually log missing comps...
if (!Resolve(uid, ref standingState, false))
Expand All @@ -47,7 +48,7 @@ public bool Down(EntityUid uid,
// Optional component.
Resolve(uid, ref appearance, ref hands, false);

if (standingState.CurrentState is StandingState.Lying or StandingState.GettingUp)
if (standingState.CurrentState is StandingState.Lying)
return true;

// This is just to avoid most callers doing this manually saving boilerplate
Expand Down Expand Up @@ -76,7 +77,7 @@ public bool Down(EntityUid uid,
_appearance.SetData(uid, RotationVisuals.RotationState, RotationState.Horizontal, appearance);

// Change collision masks to allow going under certain entities like flaps and tables
if (TryComp(uid, out FixturesComponent? fixtureComponent))
if (TryComp(uid, out FixturesComponent? fixtureComponent) && !intentional)
{
foreach (var (key, fixture) in fixtureComponent.Fixtures)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace Content.Shared.Weapons.Ranged.Components;
public sealed partial class TargetedProjectileComponent : Component
{
[DataField, AutoNetworkedField]
public EntityUid Target;
public EntityUid? Target;
}
8 changes: 8 additions & 0 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ private void StopShooting(EntityUid uid, GunComponent gun)
Dirty(uid, gun);
}

/// <summary>
/// Sets the targeted entity of the gun. Should be called before attempting to shoot to avoid shooting over the target.
/// </summary>
public void SetTarget(GunComponent gun, EntityUid target)
{
gun.Target = target;
}

/// <summary>
/// Attempts to shoot at the target coordinates. Resets the shot counter after every shot.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions Content.Shared/_Goobstation/Standing/LayingDownComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Content.Shared._Goobstation.Standing;
public sealed partial class LayingDownComponent : Component
{
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public float StandingUpTime { get; set; } = 1f;
public TimeSpan Cooldown { get; set; } = TimeSpan.FromSeconds(2.5);

[DataField, AutoNetworkedField]
public TimeSpan NextLayDown;

[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public float SpeedModify { get; set; } = .25f;
Expand All @@ -16,7 +19,10 @@ public sealed partial class LayingDownComponent : Component
public bool AutoGetUp;
}
[Serializable, NetSerializable]
public sealed class ChangeLayingDownEvent : CancellableEntityEventArgs;
public sealed class ChangeLayingDownEvent(bool intentional = false) : CancellableEntityEventArgs
{
public bool Intentional = intentional;
}

[Serializable, NetSerializable]
public sealed class CheckAutoGetUpEvent(NetEntity user) : CancellableEntityEventArgs
Expand Down
49 changes: 16 additions & 33 deletions Content.Shared/_Goobstation/Standing/SharedLayingDownSystem.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Content.Shared.DoAfter;
using Content.Shared.Gravity;
using Content.Shared.Input;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;

namespace Content.Shared._Goobstation.Standing;

public abstract class SharedLayingDownSystem : EntitySystem
{
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
Expand All @@ -26,7 +27,6 @@ public override void Initialize()

SubscribeNetworkEvent<ChangeLayingDownEvent>(OnChangeState);

SubscribeLocalEvent<StandingStateComponent, StandingUpDoAfterEvent>(OnStandingUpDoAfter);
SubscribeLocalEvent<LayingDownComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
SubscribeLocalEvent<LayingDownComponent, EntParentChangedMessage>(OnParentChanged);
}
Expand All @@ -47,7 +47,7 @@ private void ToggleStanding(ICommonSession? session)
return;
}

RaiseNetworkEvent(new ChangeLayingDownEvent());
RaiseNetworkEvent(new ChangeLayingDownEvent(intentional: true));
}

private void OnChangeState(ChangeLayingDownEvent ev, EntitySessionEventArgs args)
Expand All @@ -72,22 +72,17 @@ private void OnChangeState(ChangeLayingDownEvent ev, EntitySessionEventArgs args
if (HasComp<KnockedDownComponent>(uid) || !_mobState.IsAlive(uid))
return;

if (_standing.IsDown(uid, standing))
TryStandUp(uid, layingDown, standing);
else
TryLieDown(uid, layingDown, standing);
}

private void OnStandingUpDoAfter(EntityUid uid, StandingStateComponent component, StandingUpDoAfterEvent args)
{
if (args.Handled || args.Cancelled || HasComp<KnockedDownComponent>(uid) ||
_mobState.IsIncapacitated(uid) || !_standing.Stand(uid))
var isDown = _standing.IsDown(uid, standing);
if (_timing.CurTime < layingDown.NextLayDown && isDown)
{
component.CurrentState = StandingState.Lying;
_popup.PopupEntity(Loc.GetString("popup-laying-down-cooldown-stand-up"), uid, uid);
return;
}

component.CurrentState = StandingState.Standing;
if (isDown)
TryStandUp(uid, layingDown, standing);
else
TryLieDown(uid, layingDown, standing, isIntentional: ev.Intentional);
}

private void OnRefreshMovementSpeed(EntityUid uid, LayingDownComponent component, RefreshMovementSpeedModifiersEvent args)
Expand Down Expand Up @@ -122,21 +117,11 @@ standingState.CurrentState is not StandingState.Lying ||
return false;
}

var args = new DoAfterArgs(EntityManager, uid, layingDown.StandingUpTime, new StandingUpDoAfterEvent(), uid)
{
BreakOnDamage = true,
BreakOnHandChange = false,
RequireCanInteract = false
};

if (!_doAfter.TryStartDoAfter(args))
return false;

standingState.CurrentState = StandingState.GettingUp;
_standing.Stand(uid, standingState);
return true;
}

public bool TryLieDown(EntityUid uid, LayingDownComponent? layingDown = null, StandingStateComponent? standingState = null, DropHeldItemsBehavior behavior = DropHeldItemsBehavior.NoDrop)
public bool TryLieDown(EntityUid uid, LayingDownComponent? layingDown = null, StandingStateComponent? standingState = null, DropHeldItemsBehavior behavior = DropHeldItemsBehavior.NoDrop, bool isIntentional = false)
{
if (!Resolve(uid, ref standingState, false) ||
!Resolve(uid, ref layingDown, false) ||
Expand All @@ -148,14 +133,12 @@ public bool TryLieDown(EntityUid uid, LayingDownComponent? layingDown = null, St
return false;
}

_standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, false, standingState);
_standing.Down(uid, true, behavior != DropHeldItemsBehavior.NoDrop, false, standingState, intentional: isIntentional);
layingDown.NextLayDown = _timing.CurTime + layingDown.Cooldown;
return true;
}
}

[Serializable, NetSerializable]
public sealed partial class StandingUpDoAfterEvent : SimpleDoAfterEvent;

public enum DropHeldItemsBehavior : byte
{
NoDrop,
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_Goobstation/laying-down/popup.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
popup-laying-down-cooldown-stand-up = Cannot stand up yet!
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
mask: # tables should collide with other tables
- TableMask
layer:
- BulletImpassable # Goobstation - Crawling
- TableLayer
- type: SpriteFade
- type: Sprite
Expand Down Expand Up @@ -56,5 +55,4 @@
mask:
- TableMask
layer:
- TableLayer
- BulletImpassable # Goobstation - Crawling
- TableLayer
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
- TableMask
layer:
- TableLayer
- BulletImpassable #Goobstation
- type: Damageable
damageContainer: StructuralInorganic
damageModifierSet: Wood
Expand Down
Loading