Skip to content

Commit

Permalink
Merge pull request #2532 from allmtz/master
Browse files Browse the repository at this point in the history
Gumble.js -> Gumble.ts #1696
  • Loading branch information
DreadKnight authored Feb 11, 2024
2 parents 3a3823d + b145551 commit 1a3efef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
76 changes: 47 additions & 29 deletions src/abilities/Gumble.js → src/abilities/Gumble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ 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';
import { Hex } from '../utility/hex';
import { Trap } from '../utility/trap';

/** 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
// First Ability: Gooey Body
{
// Update stat buffs whenever health changes
trigger: 'onCreatureSummon onDamage onHeal',
Expand Down Expand Up @@ -49,8 +53,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');
}
},
},
Expand All @@ -67,17 +71,17 @@ export default (G) => {
_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 () {
// Always usable, even if no targets
return this.testRequirements();
},

// query() :
// query() :
query: function () {
const ability = this;
// Gummy Mallet can hit a 7-hexagon circular area in 6 directions, where the
Expand All @@ -87,7 +91,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 = [
Expand All @@ -102,13 +107,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,
Expand All @@ -118,7 +124,7 @@ export default (G) => {
});
},

activate: function (hexes) {
activate: function (hexes: Hex[]) {
const ability = this;
ability.end();

Expand All @@ -145,7 +151,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({
Expand All @@ -156,17 +163,17 @@ export default (G) => {
},
},

// 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;
Expand All @@ -179,6 +186,7 @@ export default (G) => {

G.grid.queryHexes({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
size: creature.size,
Expand All @@ -190,8 +198,8 @@ export default (G) => {
});
},

// activate() :
activate: function (hex) {
// activate() :
activate: function (hex: Hex) {
this.end();
const ability = this;
G.Phaser.camera.shake(0.01, 100, true, G.Phaser.camera.SHAKE_VERTICAL, true);
Expand All @@ -205,10 +213,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
Expand All @@ -227,10 +235,19 @@ export default (G) => {
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();
};

Expand All @@ -252,15 +269,15 @@ export default (G) => {
},
},

// 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;
Expand All @@ -277,13 +294,14 @@ export default (G) => {
return true;
},

// query() :
// query() :
query: function () {
const ability = this;
const crea = this.creature;

G.grid.queryDirection({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
flipped: crea.player.flipped,
Expand All @@ -296,7 +314,7 @@ export default (G) => {
});
},

// activate() :
// activate() :
activate: function (path, args) {
const ability = this;
ability.end();
Expand Down
5 changes: 4 additions & 1 deletion src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1a3efef

Please sign in to comment.