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

Replace obsolete functions in NPC systems #31448

Merged
merged 1 commit into from
Aug 26, 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
7 changes: 4 additions & 3 deletions Content.Server/NPC/Systems/NPCJukeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class NPCJukeSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly MeleeWeaponSystem _melee = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private EntityQuery<NPCMeleeCombatComponent> _npcMeleeQuery;
Expand Down Expand Up @@ -59,7 +60,7 @@ private void OnJukeSteering(EntityUid uid, NPCJukeComponent component, ref NPCSt
return;
}

var currentTile = grid.CoordinatesToTile(args.Transform.Coordinates);
var currentTile = _mapSystem.CoordinatesToTile(args.Transform.GridUid.Value, grid, args.Transform.Coordinates);

if (component.TargetTile == null)
{
Expand All @@ -72,7 +73,7 @@ private void OnJukeSteering(EntityUid uid, NPCJukeComponent component, ref NPCSt
for (var i = 0; i < 8; i++)
{
var index = (startIndex + i) % 8;
var neighbor = ((Direction) index).ToIntVec() + currentTile;
var neighbor = ((Direction)index).ToIntVec() + currentTile;
var valid = true;

// TODO: Probably make this a helper on engine maybe
Expand Down Expand Up @@ -116,7 +117,7 @@ private void OnJukeSteering(EntityUid uid, NPCJukeComponent component, ref NPCSt
return;
}

var targetCoords = grid.GridTileToWorld(component.TargetTile.Value);
var targetCoords = _mapSystem.GridTileToWorld(args.Transform.GridUid.Value, grid, component.TargetTile.Value);
var targetDir = (targetCoords.Position - args.WorldPosition);
targetDir = args.OffsetRotation.RotateVec(targetDir);
const float weight = 1f;
Expand Down
12 changes: 6 additions & 6 deletions Content.Server/NPC/Systems/NPCSteeringSystem.Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void ApplySeek(Span<float> interest, Vector2 direction, float weight)
if (weight == 0f || direction == Vector2.Zero)
return;

var directionAngle = (float) direction.ToAngle().Theta;
var directionAngle = (float)direction.ToAngle().Theta;

for (var i = 0; i < InterestDirections; i++)
{
Expand Down Expand Up @@ -166,8 +166,8 @@ private bool TrySeek(
}

// Check if mapids match.
var targetMap = targetCoordinates.ToMap(EntityManager, _transform);
var ourMap = ourCoordinates.ToMap(EntityManager, _transform);
var targetMap = _transform.ToMapCoordinates(targetCoordinates);
var ourMap = _transform.ToMapCoordinates(ourCoordinates);

if (targetMap.MapId != ourMap.MapId)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ private bool TrySeek(
return false;
}

targetMap = targetCoordinates.ToMap(EntityManager, _transform);
targetMap = _transform.ToMapCoordinates(targetCoordinates);

// Can't make it again.
if (ourMap.MapId != targetMap.MapId)
Expand Down Expand Up @@ -429,7 +429,7 @@ public void PrunePath(EntityUid uid, MapCoordinates mapCoordinates, Vector2 dire

if (TryComp<PhysicsComponent>(uid, out var physics))
{
mask = (CollisionGroup) physics.CollisionMask;
mask = (CollisionGroup)physics.CollisionMask;
}

for (var i = 0; i < nodes.Count; i++)
Expand All @@ -439,7 +439,7 @@ public void PrunePath(EntityUid uid, MapCoordinates mapCoordinates, Vector2 dire
if (!node.Data.IsFreeSpace)
break;

var nodeMap = node.Coordinates.ToMap(EntityManager, _transform);
var nodeMap = _transform.ToMapCoordinates(node.Coordinates);

// If any nodes are 'behind us' relative to the target we'll prune them.
// This isn't perfect but should fix most cases of stutter stepping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void GetObstacleEntities(PathPoly poly, int mask, int layer, List<Entity
return;
}

foreach (var ent in grid.GetLocalAnchoredEntities(poly.Box))
foreach (var ent in _mapSystem.GetLocalAnchoredEntities(poly.GraphUid, grid, poly.Box))
{
if (!_physicsQuery.TryGetComponent(ent, out var body) ||
!body.Hard ||
Expand Down
1 change: 1 addition & 0 deletions Content.Server/NPC/Systems/NPCSteeringSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public sealed partial class NPCSteeringSystem : SharedNPCSteeringSystem
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
[Dependency] private readonly PathfindingSystem _pathfindingSystem = default!;
[Dependency] private readonly PryingSystem _pryingSystem = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
[Dependency] private readonly SharedMoverController _mover = default!;
Expand Down
Loading