Skip to content

Commit

Permalink
Uncle-Fungus.js -> Uncle-Fungus.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
allmtz committed Mar 6, 2024
1 parent c7ac52a commit 90feb8f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
34 changes: 19 additions & 15 deletions src/abilities/Uncle-Fungus.js → src/abilities/Uncle-Fungus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as matrices from '../utility/matrices';
import * as arrayUtils from '../utility/arrayUtils';
import { Effect } from '../effect';
import { getDirectionFromDelta } from '../utility/position';
import Game from '../game';

/** Creates the abilities
* @param {Object} G the game object
* @return {void}
*/
export default (G) => {
export default (G: Game) => {
G.abilities[3] = [
// First Ability: Toxic Spores
{
Expand All @@ -30,7 +31,7 @@ export default (G) => {
}

// Check that attack is melee from actual creature, not from trap
if (damage && damage.melee !== undefined) {
if (damage instanceof Damage && damage.melee !== undefined) {
return damage.melee && !damage.isFromTrap;
}
// Always return true so that ability is highlighted in UI
Expand Down Expand Up @@ -93,7 +94,7 @@ export default (G) => {

// At least one target
if (
!this.atLeastOneTarget(this.creature.getHexMap(matrices.frontnback2hex), {
!this.atLeastOneTarget(this.creature.getHexMap(matrices.frontnback2hex, false), {
team: this._targetTeam,
})
) {
Expand All @@ -114,7 +115,7 @@ export default (G) => {
team: this._targetTeam,
id: uncle.id,
flipped: uncle.player.flipped,
hexes: uncle.getHexMap(matrices.frontnback2hex),
hexes: uncle.getHexMap(matrices.frontnback2hex, false),
});
},

Expand Down Expand Up @@ -194,14 +195,6 @@ export default (G) => {
return this.testRequirements() && this.creature.stats.moveable;
},

fnOnSelect: function (hex) {
this.creature.tracePosition({
x: hex.x,
y: hex.y,
overlayClass: 'creature moveto selected player' + this.creature.team,
});
},

// query() :
query: function () {
const ability = this;
Expand All @@ -213,8 +206,19 @@ export default (G) => {
const hexes = this._getHexRange(stopOnCreature);

G.grid.queryHexes({
fnOnSelect: function () {
ability.fnOnSelect(...arguments);
fnOnSelect: function (...args) {
const hex = args[0];

if (hex) {
// Uncle Fungus is 2 hexes wide, but the selected hex is only 1 hex wide.
// `tracePosition` ensures that both hexes are highlighted when hovering over the selected hex.
uncle.tracePosition({
x: hex.x,
y: hex.y,
overlayClass: 'creature moveto selected player' + uncle.team,
});
hex.game.activeCreature.faceHex(hex);
}
},
fnOnConfirm: function () {
if (arguments[0].x == ability.creature.x && arguments[0].y == ability.creature.y) {
Expand Down Expand Up @@ -263,7 +267,7 @@ export default (G) => {
// Shake the screen upon landing to simulate the jump
G.Phaser.camera.shake(0.03, 90, true, G.Phaser.camera.SHAKE_VERTICAL, true);

G.onStepIn(ability.creature, ability.creature.hexagons[0]);
G.onStepIn(ability.creature, ability.creature.hexagons[0], false);

const interval = setInterval(function () {
if (!G.freezedInput) {
Expand Down
7 changes: 6 additions & 1 deletion src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export type Trigger =
| 'onCreatureSummon onDamage onHeal'
| 'onStartPhase onEndPhase'
| 'onDamage onStartPhase'
| 'onStartPhase onDamage';
| 'onStartPhase onDamage'
| 'onUnderAttack onAttack'
| 'onUnderAttack';

// 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 @@ -134,6 +136,9 @@ export class Ability {
_damage: (target: Creature, runPath: Hex[]) => void;
_pushTarget: (target: Creature, pushPath: Hex[], args: any) => void;

_isSecondLowJump: () => boolean;
_getHexRange: (stopOnCreature: boolean) => Hex[];

_defenseBuff: number;
_maxDefenseBuff: number;
_damageTaken: boolean;
Expand Down

0 comments on commit 90feb8f

Please sign in to comment.