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

Function hurl

src/abilities/Infernal.ts:346–408  ·  view source on GitHub ↗
(_path)

Source from the content-addressed store, hash-verified

344
345 // Movement
346 const hurl = (_path) => {
347 const target = arrayUtils.last(_path).creature;
348
349 const magmaHex = magmaSpawn.hexagons[args.direction === 4 ? magmaSpawn.size - 1 : 0];
350 arrayUtils.filterCreature(_path, false, false);
351 _path.unshift(magmaHex); // Prevent error on empty path
352
353 const offset = args.direction === 4 ? magmaSpawn.size - 1 : 0;
354 let destination;
355 for (let i = _path.length - 1; i >= 0; i--) {
356 const candidate = _path[i];
357 const x = candidate.x + offset;
358 const candidateHex = G.grid.hexes[candidate.y]?.[x];
359
360 if (candidateHex && candidateHex.isWalkable(magmaSpawn.size, magmaSpawn.id, true)) {
361 destination = candidateHex;
362 break;
363 }
364 }
365
366 if (!destination) {
367 finalizeHurl();
368 return;
369 }
370
371 magmaSpawn.moveTo(destination, {
372 ignoreMovementPoint: true,
373 ignorePath: true,
374 callback: function () {
375 // Destroy traps along path
376 _path.forEach(function (hex) {
377 if (!hex.trap) {
378 return;
379 }
380
381 hex.destroyTrap();
382 });
383
384 let targetKilled = false;
385 if (target !== undefined) {
386 const ret = target.takeDamage(damage, true);
387 targetKilled = ret.kill;
388 }
389
390 // If upgraded and target killed, keep going in the same direction and
391 // find the next target to move into
392 let continueHurl = false;
393 if (ability.isUpgraded() && targetKilled) {
394 const nextPath = G.grid.getHexLine(target.x, target.y, args.direction, false);
395 arrayUtils.filterCreature(nextPath, true, true, magmaSpawn.id);
396 const nextTarget = arrayUtils.last(nextPath).creature;
397 // Continue only if there's a next enemy creature
398 if (nextTarget && isTeam(magmaSpawn, nextTarget, ability._targetTeam)) {
399 continueHurl = true;
400 hurl(nextPath);
401 }
402 }
403 if (!continueHurl) {

Callers 1

Infernal.tsFile · 0.85

Calls 8

isTeamFunction · 0.90
finalizeHurlFunction · 0.85
isWalkableMethod · 0.80
destroyTrapMethod · 0.80
takeDamageMethod · 0.80
isUpgradedMethod · 0.80
getHexLineMethod · 0.80
moveToMethod · 0.45

Tested by

no test coverage detected