pokerogue/src/data/pokeball.ts
Greenlamp2 bac6c22973
ESLint - The Essential Linter and Formatter for JavaScript and TypeScript (#1224)
* eslint config + packages

* updated eslint config

* fix the issue eslint adding ;;;; at interfaces

* first round with eslint --fix .

* removed config for unused export

* Revert "first round with eslint --fix ."

This reverts commit 77a88e0895f7c3389cb223651b90d918af778fe9.

* removed config for camelCase

* for real this time, first round of eslint --fix .

* halfway to manual eslint fix

* eslint done

* added "how to setup" the hook to eslint --fix each new file before commit (if wanted)

* removed eslintrc config file duplicat

* fix human error + ignore build folder + merge overrides

* added curly brace style + eslint

* applied double quote linter rule

* added lefthook

* test precommit

* test precommit

* test precommit

* test precommit

* test precommit

* test precommit

* test precommit

* github action to run eslint

* added node_modules to ignore eslint

* different action for typescript

* no need for different glob (default src)

* node 20

* node 20

* removed no longer needed install file

* remove hooks part from README

* eslint fixes

---------

Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
2024-05-23 11:03:10 -04:00

126 lines
3.0 KiB
TypeScript

import BattleScene from "../battle-scene";
import i18next from "../plugins/i18n";
export enum PokeballType {
POKEBALL,
GREAT_BALL,
ULTRA_BALL,
ROGUE_BALL,
MASTER_BALL,
LUXURY_BALL
}
export function getPokeballAtlasKey(type: PokeballType): string {
switch (type) {
case PokeballType.POKEBALL:
return "pb";
case PokeballType.GREAT_BALL:
return "gb";
case PokeballType.ULTRA_BALL:
return "ub";
case PokeballType.ROGUE_BALL:
return "rb";
case PokeballType.MASTER_BALL:
return "mb";
case PokeballType.LUXURY_BALL:
return "lb";
}
}
export function getPokeballName(type: PokeballType): string {
let ret: string;
switch (type) {
case PokeballType.POKEBALL:
ret = i18next.t("pokeball:pokeBall");
break;
case PokeballType.GREAT_BALL:
ret = i18next.t("pokeball:greatBall");
break;
case PokeballType.ULTRA_BALL:
ret = i18next.t("pokeball:ultraBall");
break;
case PokeballType.ROGUE_BALL:
ret = i18next.t("pokeball:rogueBall");
break;
case PokeballType.MASTER_BALL:
ret = i18next.t("pokeball:masterBall");
break;
case PokeballType.LUXURY_BALL:
ret = i18next.t("pokeball:luxuryBall");
break;
}
return ret;
}
export function getPokeballCatchMultiplier(type: PokeballType): number {
switch (type) {
case PokeballType.POKEBALL:
return 1;
case PokeballType.GREAT_BALL:
return 1.5;
case PokeballType.ULTRA_BALL:
return 2;
case PokeballType.ROGUE_BALL:
return 3;
case PokeballType.MASTER_BALL:
return -1;
case PokeballType.LUXURY_BALL:
return 1;
}
}
export function getPokeballTintColor(type: PokeballType): number {
switch (type) {
case PokeballType.POKEBALL:
return 0xd52929;
case PokeballType.GREAT_BALL:
return 0x94b4de;
case PokeballType.ULTRA_BALL:
return 0xe6cd31;
case PokeballType.ROGUE_BALL:
return 0xd52929;
case PokeballType.MASTER_BALL:
return 0xa441bd;
case PokeballType.LUXURY_BALL:
return 0xffde6a;
}
}
export function doPokeballBounceAnim(scene: BattleScene, pokeball: Phaser.GameObjects.Sprite, y1: number, y2: number, baseBounceDuration: integer, callback: Function) {
let bouncePower = 1;
let bounceYOffset = y1;
let bounceY = y2;
const yd = y2 - y1;
const doBounce = () => {
scene.tweens.add({
targets: pokeball,
y: y2,
duration: bouncePower * baseBounceDuration,
ease: "Cubic.easeIn",
onComplete: () => {
scene.playSound("pb_bounce_1", { volume: bouncePower });
bouncePower = bouncePower > 0.01 ? bouncePower * 0.5 : 0;
if (bouncePower) {
bounceYOffset = yd * bouncePower;
bounceY = y2 - bounceYOffset;
scene.tweens.add({
targets: pokeball,
y: bounceY,
duration: bouncePower * baseBounceDuration,
ease: "Cubic.easeOut",
onComplete: () => doBounce()
});
} else if (callback) {
callback();
}
}
});
};
doBounce();
}