MCPcopy
hub / github.com/FreezingMoon/AncientBeast / isWalkable

Method isWalkable

src/utility/hex.ts:509–545  ·  view source on GitHub ↗

* Can the ORIGIN (the right-most point) of the Creature with the passed ID * stand on this Hex without being out of bounds or overlapping an obstacle? * If `ignoreReachable` is false, also check the Hex's reachable value. * @param {number} size - Size of the creature. * @param {number} id -

(size: number, id: number, ignoreReachable = false, debug = false)

Source from the content-addressed store, hash-verified

507 * @returns True if this hex is walkable.
508 */
509 isWalkable(size: number, id: number, ignoreReachable = false, debug = false) {
510 // NOTE: If not in DEBUG mode, don't debug.
511 debug = DEBUG && debug;
512
513 let blocked = false;
514
515 for (let i = 0; i < size; i++) {
516 // For each Hex of the creature
517 if (this.x - i >= 0 && this.x - i < this.grid.hexes[this.y].length) {
518 //if hex exists
519 const hex = this.grid.hexes[this.y][this.x - i];
520 // Verify if blocked. If it's blocked by one attribute, OR statement will keep it status
521 blocked = blocked || hex.blocked;
522
523 if (!ignoreReachable) {
524 blocked = blocked || !hex.reachable;
525 }
526
527 let isNotMovingCreature;
528 if (hex.creature instanceof Creature) {
529 isNotMovingCreature = hex.creature.id !== id;
530 blocked = blocked || isNotMovingCreature; // Not blocked if this block contains the moving creature
531 }
532 if (debug) {
533 console.log({ isNotMovingCreature });
534 }
535 } else {
536 if (debug) {
537 console.log('BLOCKED BY GRID BOUNDARIES', this);
538 }
539 // Blocked by grid boundaries
540 blocked = true;
541 }
542 }
543
544 return !blocked; // It's walkable if it's NOT blocked
545 }
546
547 /**
548 * Change the appearance of the overlay hex

Callers 15

previewPositionMethod · 0.80
calcOffsetMethod · 0.80
knockbackFunction · 0.80
beginDestinationQueryFunction · 0.80
hurlFunction · 0.80
Snow-Bunny.tsFile · 0.80
Dark-Priest.tsFile · 0.80
getMeatSickleLandingFunction · 0.80
getKnuckleNibPushPathFunction · 0.80
Uncle-Fungus.tsFile · 0.80
Swine-Thug.tsFile · 0.80
Gumble.tsFile · 0.80

Calls 1

logMethod · 0.80

Tested by 1

_getHopHexFunction · 0.64