MCPcopy Create free account
hub / github.com/MaxBittker/rs-sdk / generator

Method generator

server/engine/src/engine/script/ScriptIterators.ts:328–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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
365export class LocIterator extends ScriptIterator<Loc> {

Callers 1

constructorFunction · 0.45

Calls 5

isLineOfSightFunction · 0.85
isLineOfWalkFunction · 0.85
getAllNpcsSafeMethod · 0.80
getZoneMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected