()
| 326 | } |
| 327 | |
| 328 | protected *generator(): IterableIterator<Npc> { |
| 329 | if (this.type === NpcIteratorType.ZONE) { |
| 330 | for (const npc of World.gameMap.getZone(this.x, this.z, this.level).getAllNpcsSafe(true)) { |
| 331 | if (World.currentTick > this.tick) { |
| 332 | throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.'); |
| 333 | } |
| 334 | yield npc; |
| 335 | } |
| 336 | } else if (this.type === NpcIteratorType.DISTANCE) { |
| 337 | for (let x: number = this.maxX; x >= this.minX; x--) { |
| 338 | const zoneX: number = x << 3; |
| 339 | for (let z: number = this.maxZ; z >= this.minZ; z--) { |
| 340 | const zoneZ: number = z << 3; |
| 341 | for (const npc of World.gameMap.getZone(zoneX, zoneZ, this.level).getAllNpcsSafe(true)) { |
| 342 | if (World.currentTick > this.tick) { |
| 343 | throw new Error('[NpcIterator] tried to use an old iterator. Create a new iterator instead.'); |
| 344 | } |
| 345 | if (CoordGrid.distanceToSW({ x: this.x, z: this.z }, npc) > this.distance) { |
| 346 | continue; |
| 347 | } |
| 348 | if (this.checkVis === HuntVis.LINEOFSIGHT && !isLineOfSight(this.level, this.x, this.z, npc.x, npc.z)) { |
| 349 | continue; |
| 350 | } |
| 351 | if (this.checkVis === HuntVis.LINEOFWALK && !isLineOfWalk(this.level, this.x, this.z, npc.x, npc.z)) { |
| 352 | continue; |
| 353 | } |
| 354 | if (this.npcType && NpcType.get(npc.type) !== this.npcType) { |
| 355 | continue; |
| 356 | } |
| 357 | yield npc; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | export class LocIterator extends ScriptIterator<Loc> { |
no test coverage detected