Skip to content

Commit

Permalink
Headless.js -> Headless.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
allmtz committed Feb 11, 2024
1 parent 06c7ec3 commit a4edfc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/abilities/Headless.js → src/abilities/Headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ 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 +99,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 +121,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 +137,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 +249,7 @@ export default (G) => {

G.grid.queryDirection({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
team: this._targetTeam,
Expand Down Expand Up @@ -372,13 +376,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 +409,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 a4edfc9

Please sign in to comment.