Skip to content

Commit

Permalink
Merge pull request #2540 from allmtz/master
Browse files Browse the repository at this point in the history
Headless.js -> Headless.ts #1969
  • Loading branch information
DreadKnight authored Feb 17, 2024
2 parents 40af0bb + ed9c3c5 commit 5861211
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/abilities/Headless.js → src/abilities/Headless.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Damage } from '../damage';
import { Team } from '../utility/team';
import * as matrices from '../utility/matrices';
import * as arrayUtils from '../utility/arrayUtils';
import { Creature } from '../creature';
import { Effect } from '../effect';
import { Direction } from '../utility/hex';
import Game from '../game';

/** Creates the abilities
* @param {Object} G the game object
* @return {void}
*/
export default (G) => {
export default (G: Game) => {
G.abilities[39] = [
/**
* First Ability: Larva Infest
Expand Down Expand Up @@ -98,6 +96,7 @@ export default (G) => {
/* Headless position is the front hex of its two hexes, so we look for
an enemy unit two hexes back which will be the hex directly behind Headless. */
matrices.inlineback2hex,
false,
);
},
},
Expand All @@ -119,7 +118,7 @@ export default (G) => {

//At least one target
if (
!this.atLeastOneTarget(crea.getHexMap(matrices.frontnback2hex), {
!this.atLeastOneTarget(crea.getHexMap(matrices.frontnback2hex, false), {
team: this._targetTeam,
})
) {
Expand All @@ -135,12 +134,13 @@ export default (G) => {

G.grid.queryCreature({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
team: this._targetTeam,
id: crea.id,
flipped: crea.player.flipped,
hexes: crea.getHexMap(matrices.frontnback2hex),
hexes: crea.getHexMap(matrices.frontnback2hex, false),
});
},

Expand Down Expand Up @@ -246,6 +246,7 @@ export default (G) => {

G.grid.queryDirection({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
team: this._targetTeam,
Expand Down Expand Up @@ -291,7 +292,6 @@ export default (G) => {
destinationX = !isOnLeft ? target.x + 2 : target.x - 3;
}

let x;
let hex;

// Check if Headless will be moved.
Expand Down Expand Up @@ -372,13 +372,14 @@ export default (G) => {

G.grid.queryChoice({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
team: Team.Both,
requireCreature: 0,
id: crea.id,
flipped: crea.player.flipped,
choices: [crea.getHexMap(hexes), crea.getHexMap(hexes, true)],
choices: [crea.getHexMap(hexes, false), crea.getHexMap(hexes, true)],
});
},

Expand All @@ -404,6 +405,7 @@ export default (G) => {
damages, //Damage Type
[], //Effects
ability.getTargets(hexes), //Targets
false,
);
},
},
Expand Down
11 changes: 8 additions & 3 deletions src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export type Trigger =
| 'onStartOfRound'
| 'oncePerDamageChain'
| 'onCreatureMove onOtherCreatureMove'
| 'onCreatureSummon onDamage onHeal';
| 'onCreatureSummon onDamage onHeal'
| 'onStartPhase onEndPhase';

// Could get rid of the union and optionals by creating a separate (or conditional) type for Dark Priest's Cost
// This might narrow down the types in the constructor by checking `creature.name`
Expand Down Expand Up @@ -78,7 +79,7 @@ export class Ability {
upgraded: boolean;
title: string;

// TODO properly type all these unknowns
// TODO properly type all `unknown` types
// These properties come from extending a specific ability from `src/abilities`
requirements?: Requirement | undefined;
costs?: Cost | undefined;
Expand All @@ -89,11 +90,12 @@ export class Ability {
affectedByMatSickness?: boolean;
activate?: (target?: any, hex?: any, path?: Hex[]) => unknown;
getAnimationData?: (...args: unknown[]) => unknown;
damages?: CreatureMasteries & { pure?: number };
damages?: Partial<CreatureMasteries> & { pure?: number };
effects?: AbilityEffect[];
message?: string;
movementType?: () => 'flying'; // Currently, this functon only exists in `Scavenger.js`
triggeredThisChain?: boolean;
range?: { minimum?: number; regular: number; upgraded: number };

_lastBonus?: number;

Expand All @@ -108,6 +110,9 @@ export class Ability {
getAbilityName?: (name: string) => string;
getMovementBuff?: (buff: number) => number;
getOffenseBuff?: (buff: number) => number;
_getHexes?: () => any;
_getMaxDistance: () => number;
_directions?: Direction[];
_targetTeam: Team;

// Below methods exist in Snow-Bunny.ts
Expand Down
3 changes: 2 additions & 1 deletion src/utility/hexgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ interface QueryOptions {
*/
arg: any;

optTest: () => boolean;
optTest: (arg: Creature) => boolean;

/**
* Function applied when clicking on one of the available hexes.
Expand Down Expand Up @@ -579,6 +579,7 @@ export class HexGrid {
fillOnlyHoveredCreature: false,
};

// Overwrite any default options with options passed in through `o`
o = { ...defaultOpt, ...o };

let hexes = [];
Expand Down

0 comments on commit 5861211

Please sign in to comment.