Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DrSmugleaf authored and Aidenkrz committed Dec 16, 2024
1 parent 01fd903 commit 0da467e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ private void OnShootRequest(RequestShootEvent ev, EntitySessionEventArgs args)

private void OnPredictedMapInit(Entity<PredictedProjectileServerComponent> ent, ref MapInitEvent args)
{
if (ent.Comp.Shooter == null)
{
Log.Warning($"{nameof(PredictedProjectileServerComponent)} map initialized with a null shooter session!");
return;
}

_predicted[(ent.Comp.Shooter.UserId, ent.Comp.ClientId)] = ent;
}

private void OnPredictedRemove<T>(Entity<PredictedProjectileServerComponent> ent, ref T args)
{
if (ent.Comp.Shooter == null)
return;

_predicted.Remove((ent.Comp.Shooter.UserId, ent.Comp.ClientId));
}

Expand Down Expand Up @@ -173,7 +182,7 @@ private bool Collides(

MapCoordinates lowestCoordinate = default;
var otherCoordinates = EntityCoordinates.Invalid;
var ping = projectile.Comp1.Shooter.Channel.Ping;
var ping = projectile.Comp1.Shooter?.Channel.Ping ?? 0;
// Use 1.5 due to the trip buffer.
var sentTime = _timing.CurTime - TimeSpan.FromMilliseconds(ping * 1.5);
var pingTime = TimeSpan.FromMilliseconds(ping);
Expand Down Expand Up @@ -236,7 +245,7 @@ private void ProcessPredictedHit(PredictedProjectileHitEvent ev, ICommonSession
return;
}

if (predictedProjectile.Shooter.UserId != player.UserId.UserId)
if (predictedProjectile.Shooter?.UserId != player.UserId.UserId)
return;

if (!_projectileQuery.TryComp(projectile, out var projectileComp) ||
Expand Down
8 changes: 6 additions & 2 deletions Content.Shared/Projectiles/SharedProjectileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ public void ProjectileCollide(Entity<ProjectileComponent, PhysicsComponent> proj
var deleted = Deleted(target);

var filter = Filter.Pvs(coordinates, entityMan: EntityManager);
if (_guns.GunPrediction && TryComp(projectile, out PredictedProjectileServerComponent? serverProjectile))
filter = filter.RemovePlayer(serverProjectile.Shooter);
if (_guns.GunPrediction &&
TryComp(projectile, out PredictedProjectileServerComponent? serverProjectile) &&
serverProjectile.Shooter is { } shooter)
{
filter = filter.RemovePlayer(shooter);
}

if (modifiedDamage is not null && (EntityManager.EntityExists(component.Shooter) || EntityManager.EntityExists(component.Weapon)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Content.Shared._RMC14.Weapons.Ranged.Prediction;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class PredictedProjectileServerComponent : Component
{
public ICommonSession Shooter;
public ICommonSession? Shooter;

[DataField, AutoNetworkedField]
public int ClientId;
Expand Down

0 comments on commit 0da467e

Please sign in to comment.