From 60c2613acf1ca8182f69946303427495b89072b6 Mon Sep 17 00:00:00 2001 From: Allan Martinez Date: Tue, 1 Aug 2023 15:39:36 -0700 Subject: [PATCH 1/3] adjust type definitions --- src/ability.ts | 2 +- src/utility/hexgrid.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ability.ts b/src/ability.ts index cd910db06..7a8bf65a5 100644 --- a/src/ability.ts +++ b/src/ability.ts @@ -81,7 +81,7 @@ export class Ability { costs?: Cost | undefined; trigger?: Trigger; triggerFunc?: () => Trigger; - require?: (damage?: Damage, hex?: Hex) => boolean; + require?: (req?: Damage | Hex) => boolean; query?: () => unknown; affectedByMatSickness?: boolean; activate?: (target?: any, hex?: any, path?: any) => unknown; diff --git a/src/utility/hexgrid.ts b/src/utility/hexgrid.ts index 5a091d976..c0e54a0d8 100644 --- a/src/utility/hexgrid.ts +++ b/src/utility/hexgrid.ts @@ -251,7 +251,7 @@ export class HexGrid { * * @param o */ - queryDirection(o: QueryOptions) { + queryDirection(o: Partial) { o.isDirectionsQuery = true; o = this.getDirectionChoices(o); this.queryChoice(o); @@ -263,7 +263,7 @@ export class HexGrid { * @param o Options. * @returns Altered options. */ - getDirectionChoices(o: QueryOptions) { + getDirectionChoices(o: Partial) { const defaultOpt = { team: Team.Enemy, requireCreature: true, From d24b8505320e8b7368e04300c8438435f3007590 Mon Sep 17 00:00:00 2001 From: Allan Martinez Date: Tue, 1 Aug 2023 15:49:17 -0700 Subject: [PATCH 2/3] Swine-Thug.js -> Swine-Thug.ts also refactored some deprecated code --- .../{Swine-Thug.js => Swine-Thug.ts} | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) rename src/abilities/{Swine-Thug.js => Swine-Thug.ts} (90%) diff --git a/src/abilities/Swine-Thug.js b/src/abilities/Swine-Thug.ts similarity index 90% rename from src/abilities/Swine-Thug.js rename to src/abilities/Swine-Thug.ts index 7bd63fec2..ae71633ca 100644 --- a/src/abilities/Swine-Thug.js +++ b/src/abilities/Swine-Thug.ts @@ -4,12 +4,26 @@ import { Team } from '../utility/team'; import * as matrices from '../utility/matrices'; import * as arrayUtils from '../utility/arrayUtils'; import { Effect } from '../effect'; +import { Creature } from '../creature'; +import Game from '../game'; +import { Hex } from '../utility/hex'; +import { getPointFacade } from '../utility/pointfacade'; +import { Trap } from '../utility/trap'; + +/* + *TODO + * + * Fix ts-error 2554: Need to properly type the `on` functions in `game.ts`. + * This can be done once all the `abilities` files are converted to TS. + * + * Fix eslint prefer rest params error + */ /** Creates the abilities * @param {Object} G the game object * @return {void} */ -export default (G) => { +export default (G: Game) => { /* * * Swine Thug abilities @@ -22,7 +36,7 @@ export default (G) => { trigger: 'onCreatureMove', // require() : - require: function (hex) { + require: function (hex: Hex) { if (!this.testRequirements()) { return false; } @@ -32,8 +46,9 @@ export default (G) => { } this.message = ''; - if (hex.trap) { - if (hex.trap.type == 'mud-bath') { + if (hex) { + const trapsOnHex = getPointFacade().getTrapsAt(hex.x, hex.y); + if (trapsOnHex.length > 0 && trapsOnHex.some((trap) => trap.type === 'mud-bath')) { G.UI.abilitiesButtons[0].changeState('noclick'); return true; } @@ -123,6 +138,7 @@ export default (G) => { G.grid.queryDirection({ fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, flipped: swine.player.flipped, @@ -225,7 +241,6 @@ export default (G) => { true, true, swine.id, - swine.team, ) .concat( arrayUtils.filterCreature( @@ -233,35 +248,30 @@ export default (G) => { true, true, swine.id, - swine.team, ), arrayUtils.filterCreature( G.grid.getHexMap(swine.x, swine.y, 0, false, bellowrow), true, true, swine.id, - swine.team, ), arrayUtils.filterCreature( G.grid.getHexMap(swine.x, swine.y - 2, 0, true, bellowrow), true, true, swine.id, - swine.team, ), arrayUtils.filterCreature( G.grid.getHexMap(swine.x, swine.y, 0, true, straitrow), true, true, swine.id, - swine.team, ), arrayUtils.filterCreature( G.grid.getHexMap(swine.x, swine.y, 0, true, bellowrow), true, true, swine.id, - swine.team, ), ); if ( @@ -300,12 +310,13 @@ export default (G) => { G.grid.queryChoice({ fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, // fnOnConfirm team: this._targetTeam, requireCreature: 1, id: swine.id, - flipped: swine.flipped, + flipped: swine.player.flipped, choices: choices, }); }, @@ -395,6 +406,7 @@ export default (G) => { G.activeCreature.queryMove(); }, fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, hexes: hexes, @@ -403,7 +415,7 @@ export default (G) => { }, // activate() : - activate: function (hex) { + activate: function (hex: Hex) { const ability = this; const swine = this.creature; @@ -440,19 +452,21 @@ export default (G) => { } return this.trap.hex.creature.type != 'A1'; }, - effectFn: function (effect, crea) { - crea.remainingMove--; + effectFn: function (effect, crea: Creature) { + if (crea) { + crea.remainingMove--; + } }, }, G, ), ]; - - hex.createTrap('mud-bath', effects, ability.creature.player); + new Trap(hex.x, hex.y, 'mud-bath', effects, ability.creature.player, {}, G); G.soundsys.playSFX('sounds/mudbath'); // Trigger trap immediately if on self if (isSelf) { // onCreatureMove is Spa Goggles' trigger event + // @ts-expect-error 2554 G.onCreatureMove(swine, hex); } }, From 93abae79695956d01dc7930a0b838c1ad66137e6 Mon Sep 17 00:00:00 2001 From: Allan Martinez Date: Tue, 1 Aug 2023 16:08:01 -0700 Subject: [PATCH 3/3] refactor deprecated code --- src/abilities/Swine-Thug.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/abilities/Swine-Thug.ts b/src/abilities/Swine-Thug.ts index ae71633ca..1918f0f73 100644 --- a/src/abilities/Swine-Thug.ts +++ b/src/abilities/Swine-Thug.ts @@ -193,8 +193,10 @@ export default (G: Game) => { // The target must be completely over mud baths to keep sliding let mudSlide = true; for (let j = 0; j < target.size; j++) { - const mudHex = G.grid.hexes[hex.y][hex.x - j]; - if (!mudHex.trap || mudHex.trap.type !== 'mud-bath') { + const hexToCheck = G.grid.hexes[hex.y][hex.x - j]; + const trapsOnHex = getPointFacade().getTrapsAt(hexToCheck.x, hexToCheck.y); + + if (trapsOnHex.length === 0 || !trapsOnHex.some((trap) => trap.type === 'mud-bath')) { mudSlide = false; break; } @@ -447,10 +449,11 @@ export default (G: Game) => { 'onStepIn', { requireFn: function () { - if (!this.trap.hex.creature) { + const creaturesOnHex = getPointFacade().getCreaturesAt(hex.x, hex.y); + if (creaturesOnHex.length === 0) { return false; } - return this.trap.hex.creature.type != 'A1'; + return creaturesOnHex[0].type != 'A1'; }, effectFn: function (effect, crea: Creature) { if (crea) {