From 38b9f59d7daa355ac1148aad2d124f66f0d4b21b Mon Sep 17 00:00:00 2001 From: Allan Martinez Date: Sat, 10 Feb 2024 00:50:03 -0800 Subject: [PATCH 1/3] Gumble.js -> Gumble.ts --- src/abilities/{Gumble.js => Gumble.ts} | 25 ++++++++++++++++--------- src/ability.ts | 5 ++++- 2 files changed, 20 insertions(+), 10 deletions(-) rename src/abilities/{Gumble.js => Gumble.ts} (94%) diff --git a/src/abilities/Gumble.js b/src/abilities/Gumble.ts similarity index 94% rename from src/abilities/Gumble.js rename to src/abilities/Gumble.ts index ea24cffeb..0ec32a9e0 100644 --- a/src/abilities/Gumble.js +++ b/src/abilities/Gumble.ts @@ -4,12 +4,14 @@ import { Team, isTeam } 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'; /** Creates the abilities * @param {Object} G the game object * @return {void} */ -export default (G) => { +export default (G: Game) => { G.abilities[14] = [ // First Ability: Gooey Body { @@ -49,8 +51,8 @@ export default (G) => { deleteTrigger: '', stackable: false, effectFn: () => { - if (bonus !== this.lastBonus) { - G.log('Effect ' + this.name + ' triggered'); + if (bonus !== this._lastBonus) { + G.log('Effect ' + this.title + ' triggered'); } }, }, @@ -87,7 +89,8 @@ export default (G) => { [1, 1], [1, 1, 1], [1, 1], - ]; + ] as matrices.AugmentedMatrix; + const dx = this.creature.y % 2 !== 0 ? -1 : 0; const dy = -1; const choices = [ @@ -102,13 +105,14 @@ export default (G) => { // This ensures that if a choice contains overlapping hexes only, that // choice won't be available for selection. choices.sort(function (choice1, choice2) { - return choice1.length < choice2.length; + return choice1.length - choice2.length; }); G.grid.queryChoice({ fnOnCancel: function () { G.activeCreature.queryMove(); }, fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, team: Team.Both, @@ -145,7 +149,8 @@ export default (G) => { damages = enemyDamages; } const dmg = new Damage(this.creature, damages, targets[i].hexesHit, [], G); - kills += targets[i].target.takeDamage(dmg).kill + 0; + // Increment kills if the target is killed + kills += targets[i].target.takeDamage(dmg).kill ? 1 : 0; } if (kills > 1) { this.creature.player.score.push({ @@ -179,6 +184,7 @@ export default (G) => { G.grid.queryHexes({ fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, size: creature.size, @@ -205,10 +211,10 @@ export default (G) => { { // Immunity to own trap type requireFn: function () { - const crea = this.trap.hex.creature; - return crea && crea.type !== this.owner.type; + const creaOnTrap = this.trap.hex.creature; + return creaOnTrap && creaOnTrap.type !== ability.creature.type; }, - effectFn: function (_, crea) { + effectFn: function (_, crea: Creature) { if (this.trap.turnLifetime === 0) { crea.remainingMove = 0; // Destroy the trap on the trapped creature's turn @@ -284,6 +290,7 @@ export default (G) => { G.grid.queryDirection({ fnOnConfirm: function () { + // eslint-disable-next-line ability.animation(...arguments); }, flipped: crea.player.flipped, diff --git a/src/ability.ts b/src/ability.ts index cac87ae86..cba6a548b 100644 --- a/src/ability.ts +++ b/src/ability.ts @@ -40,7 +40,8 @@ export type Trigger = | 'onEffectAttach' | 'onStartOfRound' | 'oncePerDamageChain' - | 'onCreatureMove onOtherCreatureMove'; + | 'onCreatureMove onOtherCreatureMove' + | 'onCreatureSummon onDamage onHeal'; // 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` @@ -94,6 +95,8 @@ export class Ability { movementType?: () => 'flying'; // Currently, this functon only exists in `Scavenger.js` triggeredThisChain?: boolean; + _lastBonus?: number; + _disableCooldowns: boolean; _energyNormal?: number; From 2f5a8f8197e81a9e4d3f8a860076c463631d7551 Mon Sep 17 00:00:00 2001 From: Allan Martinez Date: Sat, 10 Feb 2024 13:13:12 -0800 Subject: [PATCH 2/3] add type anotations, remove deprecated `hex.createTrap` --- src/abilities/Gumble.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/abilities/Gumble.ts b/src/abilities/Gumble.ts index 0ec32a9e0..d4e3a55f9 100644 --- a/src/abilities/Gumble.ts +++ b/src/abilities/Gumble.ts @@ -6,6 +6,8 @@ import * as arrayUtils from '../utility/arrayUtils'; import { Effect } from '../effect'; import { Creature } from '../creature'; import Game from '../game'; +import { Hex } from '../utility/hex'; +import { Trap } from '../utility/trap'; /** Creates the abilities * @param {Object} G the game object @@ -122,7 +124,7 @@ export default (G: Game) => { }); }, - activate: function (hexes) { + activate: function (hexes: Hex[]) { const ability = this; ability.end(); @@ -197,7 +199,7 @@ export default (G: Game) => { }, // activate() : - activate: function (hex) { + activate: function (hex: Hex) { this.end(); const ability = this; G.Phaser.camera.shake(0.01, 100, true, G.Phaser.camera.SHAKE_VERTICAL, true); @@ -233,10 +235,19 @@ export default (G: Game) => { G, ); - const trap = hex.createTrap('royal-seal', [effect], ability.creature.player, { - ownerCreature: ability.creature, - fullTurnLifetime: true, - }); + const trap = new Trap( + hex.x, + hex.y, + 'royal-seal', + [effect], + ability.creature.player, + { + ownerCreature: ability.creature, + fullTurnLifetime: true, + }, + G, + ); + trap.hide(); }; From b14555135174ffefdb780fca566abf0c2f200f12 Mon Sep 17 00:00:00 2001 From: Dread Knight Date: Sun, 11 Feb 2024 06:25:32 +0200 Subject: [PATCH 3/3] linting and typo fix --- src/abilities/Gumble.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/abilities/Gumble.ts b/src/abilities/Gumble.ts index d4e3a55f9..df0474a3c 100644 --- a/src/abilities/Gumble.ts +++ b/src/abilities/Gumble.ts @@ -15,7 +15,7 @@ import { Trap } from '../utility/trap'; */ export default (G: Game) => { G.abilities[14] = [ - // First Ability: Gooey Body + // First Ability: Gooey Body { // Update stat buffs whenever health changes trigger: 'onCreatureSummon onDamage onHeal', @@ -71,9 +71,9 @@ export default (G: Game) => { _lastBonus: 0, }, - // Second Ability: Gummy Mallet + // Second Ability: Gummy Mallet { - // Type : Can be "onQuery", "onStartPhase", "onDamage" + // Type : Can be "onQuery", "onStartPhase", "onDamage" trigger: 'onQuery', require: function () { @@ -81,7 +81,7 @@ export default (G: Game) => { return this.testRequirements(); }, - // query() : + // query() : query: function () { const ability = this; // Gummy Mallet can hit a 7-hexagon circular area in 6 directions, where the @@ -151,7 +151,7 @@ export default (G: Game) => { damages = enemyDamages; } const dmg = new Damage(this.creature, damages, targets[i].hexesHit, [], G); - // Increment kills if the target is killed + // Increment kills if the target is killed kills += targets[i].target.takeDamage(dmg).kill ? 1 : 0; } if (kills > 1) { @@ -163,17 +163,17 @@ export default (G: Game) => { }, }, - // Thirt Ability: Royal Seal + // Third Ability: Royal Seal { - // Type : Can be "onQuery", "onStartPhase", "onDamage" + // Type : Can be "onQuery", "onStartPhase", "onDamage" trigger: 'onQuery', - // require() : + // require() : require: function () { return this.testRequirements(); }, - // query() : + // query() : query: function () { const ability = this; const creature = this.creature; @@ -198,7 +198,7 @@ export default (G: Game) => { }); }, - // activate() : + // activate() : activate: function (hex: Hex) { this.end(); const ability = this; @@ -269,15 +269,15 @@ export default (G: Game) => { }, }, - // Fourth Ability: Boom Box + // Fourth Ability: Boom Box { - // Type : Can be "onQuery", "onStartPhase", "onDamage" + // Type : Can be "onQuery", "onStartPhase", "onDamage" trigger: 'onQuery', directions: [1, 1, 1, 1, 1, 1], _targetTeam: Team.Enemy, - // require() : + // require() : require: function () { if (!this.testRequirements()) { return false; @@ -294,7 +294,7 @@ export default (G: Game) => { return true; }, - // query() : + // query() : query: function () { const ability = this; const crea = this.creature; @@ -314,7 +314,7 @@ export default (G: Game) => { }); }, - // activate() : + // activate() : activate: function (path, args) { const ability = this; ability.end();