Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escort service ability when target is of size three #2614

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions src/abilities/Scavenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ import * as matrices from '../utility/matrices';
import * as arrayUtils from '../utility/arrayUtils';
import { Effect } from '../effect';

function getEscortUsableHexes(G, crea, trg) {
const trgIsInfront =
G.grid.getHexMap(
crea.x - matrices.inlinefront2hex.origin[0],
crea.y - matrices.inlinefront2hex.origin[1],
0,
false,
matrices.inlinefront2hex,
)[0].creature == trg;

const distance = crea.remainingMove;
const size = crea.size + trg.size;
const x = trgIsInfront ? crea.x + trg.size : crea.x;

const usableHexes = G.grid
.getFlyingRange(x, crea.y, distance, size, [crea.id, trg.id])
.filter(function (item) {
return (
crea.y == item.y && (trgIsInfront ? item.x < x : item.x > x - crea.size - trg.size + 1)
);
});

return { size, trgIsInfront, usableHexes };
}

/** Creates the abilities
* @param {Object} G the game object
* @return {void}
Expand Down Expand Up @@ -165,8 +190,9 @@ export default (G) => {
return false;
}

if (crea.remainingMove < trg.size) {
// Unit too tired
const { usableHexes } = getEscortUsableHexes(G, crea, trg);

if (!usableHexes.length) {
this.message = 'Not enough movement points.';
return false;
}
Expand All @@ -181,17 +207,7 @@ export default (G) => {
const hexes = crea.getHexMap(matrices.inlinefrontnback2hex);
const trg = hexes[0].creature || hexes[1].creature;

const distance = Math.floor(crea.remainingMove / trg.size);
const size = crea.size + trg.size;

const trgIsInfront =
G.grid.getHexMap(
crea.x - matrices.inlinefront2hex.origin[0],
crea.y - matrices.inlinefront2hex.origin[1],
0,
false,
matrices.inlinefront2hex,
)[0].creature == trg;
const { size, trgIsInfront, usableHexes } = getEscortUsableHexes(G, crea, trg);

const select = (hex) => {
for (let i = 0; i < trg.hexagons.length; i++) {
Expand Down Expand Up @@ -229,8 +245,6 @@ export default (G) => {
}
};

const x = trgIsInfront ? crea.x + trg.size : crea.x;

G.grid.queryHexes({
fnOnConfirm: function () {
G.grid.fadeOutTempCreature();
Expand All @@ -242,14 +256,7 @@ export default (G) => {
id: [crea.id, trg.id],
size: size,
flipped: crea.player.flipped,
hexes: G.grid
.getFlyingRange(x, crea.y, distance, size, [crea.id, trg.id])
.filter(function (item) {
return (
crea.y == item.y &&
(trgIsInfront ? item.x < x : item.x > x - crea.size - trg.size + 1)
);
}),
hexes: usableHexes,
args: {
trg: trg.id,
trgIsInfront: trgIsInfront,
Expand Down
Loading