Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swine-Thug.js -> Swine-Thug.ts #2463

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions src/abilities/Swine-Thug.js → src/abilities/Swine-Thug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Trigger>` 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
Expand All @@ -22,7 +36,7 @@ export default (G) => {
trigger: 'onCreatureMove',

// require() :
require: function (hex) {
require: function (hex: Hex) {
if (!this.testRequirements()) {
return false;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -123,6 +138,7 @@ export default (G) => {

G.grid.queryDirection({
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
flipped: swine.player.flipped,
Expand Down Expand Up @@ -177,8 +193,10 @@ export default (G) => {
// 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;
}
Expand Down Expand Up @@ -225,43 +243,37 @@ export default (G) => {
true,
true,
swine.id,
swine.team,
)
.concat(
arrayUtils.filterCreature(
G.grid.getHexMap(swine.x, swine.y, 0, false, straitrow),
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 (
Expand Down Expand Up @@ -300,12 +312,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,
});
},
Expand Down Expand Up @@ -395,6 +408,7 @@ export default (G) => {
G.activeCreature.queryMove();
},
fnOnConfirm: function () {
// eslint-disable-next-line
ability.animation(...arguments);
},
hexes: hexes,
Expand All @@ -403,7 +417,7 @@ export default (G) => {
},

// activate() :
activate: function (hex) {
activate: function (hex: Hex) {
const ability = this;
const swine = this.creature;

Expand Down Expand Up @@ -435,24 +449,27 @@ export default (G) => {
'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) {
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);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/utility/hexgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class HexGrid {
*
* @param o
*/
queryDirection(o: QueryOptions) {
queryDirection(o: Partial<QueryOptions>) {
o.isDirectionsQuery = true;
o = this.getDirectionChoices(o);
this.queryChoice(o);
Expand All @@ -263,7 +263,7 @@ export class HexGrid {
* @param o Options.
* @returns Altered options.
*/
getDirectionChoices(o: QueryOptions) {
getDirectionChoices(o: Partial<QueryOptions>) {
const defaultOpt = {
team: Team.Enemy,
requireCreature: true,
Expand Down
Loading