Skip to content

Commit fa1fd62

Browse files
author
markb5
committed
pathing fix again
1 parent a011820 commit fa1fd62

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/engine/entity/Player.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dotenv/config';
22

33
import { PlayerInfoProt, Visibility } from '@2004scape/rsbuf';
4-
import { CollisionFlag } from '@2004scape/rsmod-pathfinder';
4+
import { CollisionFlag, CollisionType } from '@2004scape/rsmod-pathfinder';
55

66
import Component from '#/cache/config/Component.js';
77
import FontType from '#/cache/config/FontType.js';
@@ -37,7 +37,7 @@ import { PlayerQueueRequest, PlayerQueueType, QueueType, ScriptArgument } from '
3737
import { PlayerStat, PlayerStatEnabled, PlayerStatFree, PlayerStatNameMap } from '#/engine/entity/PlayerStat.js';
3838
import InputTracking from '#/engine/entity/tracking/InputTracking.js';
3939
import { WealthEventParams } from '#/engine/entity/tracking/WealthEvent.js';
40-
import { changeNpcCollision, changePlayerCollision, reachedEntity, reachedLoc, reachedObj } from '#/engine/GameMap.js';
40+
import { changeNpcCollision, changePlayerCollision, findNaivePath, reachedEntity, reachedLoc, reachedObj } from '#/engine/GameMap.js';
4141
import { Inventory, InventoryListener } from '#/engine/Inventory.js';
4242
import ScriptFile from '#/engine/script/ScriptFile.js';
4343
import ScriptPointer from '#/engine/script/ScriptPointer.js';
@@ -1094,6 +1094,24 @@ export default class Player extends PathingEntity {
10941094
}
10951095
}
10961096

1097+
naivePathToTarget() {
1098+
if (!this.target) {
1099+
return;
1100+
}
1101+
let angle = 0;
1102+
if (this.target instanceof Loc) {
1103+
angle = this.target.angle;
1104+
}
1105+
1106+
const { x, z } = CoordGrid.unpackCoord(this.waypoints[0]);
1107+
1108+
// If no waypoint, or waypoint is further than 1 tile from target, set new dest
1109+
if (this.waypointIndex === -1 || Math.abs(this.target.x - x) > 1 || Math.abs(this.target.z - z) > 1) {
1110+
const waypoints = findNaivePath(this.level, this.x, this.z, this.target.x, this.target.z, this.width, this.length, this.target.width, this.target.length, angle, CollisionType.NORMAL);
1111+
this.queueWaypoints(waypoints);
1112+
}
1113+
}
1114+
10971115
// https://youtu.be/_NmFftkMm0I?si=xSgb8GCydgUXUayR&t=79
10981116
// to allow p_walk (sets player destination tile) during walktriggers
10991117
// we process walktriggers from regular movement in client input,

0 commit comments

Comments
 (0)