Skip to content

Commit

Permalink
feat: effects
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelVanhoutte committed Feb 7, 2024
1 parent 57ac166 commit 712b47d
Show file tree
Hide file tree
Showing 11 changed files with 707 additions and 93 deletions.
20 changes: 10 additions & 10 deletions dist/openmon.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/openmon.js

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion src/assets/data/checkDex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pokedex from './final/pokedex.json' assert {type: "json"};
import pokedex from './final/pokedexBW-animated2.json' assert {type: 'json'};
import fs from "fs";

/*
console.log(pokedex.length);
let idx = 0;
Expand All @@ -8,3 +10,50 @@ console.log(pokedex[idx]);
pokedex[2].moves.forEach((move) => {
console.log(move.name, move.level );
});
*/
let movesImpl = [1, 2, 3, 4, 5, 6, 7, 11, 12, 14, 17, 19, 20, 21, 24];
let toImpl = {};

pokedex.forEach((pokemon) => {
pokemon.moves.filter((move) => !movesImpl.includes(move.effect?.move_effect_id)).map((move) => {
/*console.log(move.name, move.level);*/
if (toImpl[move.effect?.move_effect_id + ' : ' + move.effect?.short_effect] === undefined) {
toImpl[move.effect?.move_effect_id + ' : ' + move.effect?.short_effect] = [];
}
toImpl[move.effect?.move_effect_id + ' : ' + move.effect?.short_effect].push(pokemon.name);
});
});


//console.log(toImpl);

/*Object.keys(toImpl).forEach((key) => {
if(toImpl[key].length < 5) {
console.log('---------------------');
console.log(key);
}
});*/

// sort toImpl by lengths
let sortable = [];
for (let key in toImpl) {
sortable.push([key, toImpl[key]]);
}

sortable.sort((a, b) => {
return b[1].length - a[1].length;
});
console.log(sortable.filter((item) => item[1].length >= 5).map((item) => item[0] + ' : ' + item[1].length)) ;


fs.writeFile("./moves-impl-order.json", JSON.stringify(sortable.map((item) => 'id : ' + item[0].split(':')[0] + ', nb poke : ' + item[1].length + ', effect : ' + item[0].split(':')[1])), (error) => {
// throwing the error
// in case of a writing problem
if (error) {
// logging the error
console.error(error);

throw error;
}
});
259 changes: 259 additions & 0 deletions src/assets/data/moves-impl-order.json

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions src/lib/js/battle/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BattleState {
public selectAction(action: Action) {
this.isPlayerTurnV = false;

if (action instanceof Attack && this.playerCurrentMonster.currentStats.speed > this.opponentCurrentMonster.currentStats.speed
if (action instanceof Attack && this.playerCurrentMonster.battleStats.speed > this.opponentCurrentMonster.battleStats.speed
|| action instanceof RunAway
|| action instanceof ChangePokemon
|| action instanceof BagObject) {
Expand Down Expand Up @@ -155,7 +155,7 @@ export class BattleState {
// randomized based on opponent speed
this.escapeAttempts++;
const random = Math.random() * 255;
const f = Math.floor((this.opponentCurrentMonster.currentStats.speed * 128) / this.playerCurrentMonster.currentStats.speed) + 30 * this.escapeAttempts * random;
const f = Math.floor((this.opponentCurrentMonster.battleStats.speed * 128) / this.playerCurrentMonster.battleStats.speed) + 30 * this.escapeAttempts * random;

if (f > 255) {
this.turnStack = [];
Expand All @@ -174,9 +174,9 @@ export class BattleState {
const attacker = action.initiator;
const target = action.target === 'opponent' ? this.opponentCurrentMonster : this.playerCurrentMonster;

// start turn effects (sleep, paralysis..)
// start turn statuses (sleep, paralysis..)
if (attacker.status?.when === 'start-turn') {
let effect = attacker.status.playEffect(attacker);
let effect = attacker.status.playEffect(attacker, target);

if (effect?.message) {
this.addToStack(new Message(effect.message, attacker), true);
Expand All @@ -186,6 +186,7 @@ export class BattleState {
}
}


const actionsToPush: Action[] = [];
const success = this.accuracyApplies(action.move);

Expand All @@ -196,9 +197,14 @@ export class BattleState {
if (success) {

const result = this.calculateDamage(attacker, target, action.move);
let effect = MOVE_EFFECT_APPLIER.findEffect(action.move.effect);

console.log({result})

if (effect.when === 'before-move' && this.effectApplies(action.move)) {
actionsToPush.push(new ApplyEffect(action.move, action.target, action.initiator))
}

if (result.immune) {
actionsToPush.push(new Message('It doesn\'t affect ' + target.name + '...', action.initiator));
} else if (result.notVeryEffective) {
Expand All @@ -212,9 +218,11 @@ export class BattleState {

actionsToPush.push(new RemoveHP(result.damages, action.target, action.initiator));

// Apply attack effect
if (!result.immune && this.effectApplies(action.move)) {
actionsToPush.push(new ApplyEffect(action.move, action.target, action.initiator))
}

} else {
actionsToPush.push(new Message('But it failed!', action.initiator));
}
Expand Down Expand Up @@ -266,8 +274,8 @@ export class BattleState {
result.critical = critical > 1;

if (move.category !== 'no-damage' && move.power > 0) {
const attack = move.category === 'physical' ? attacker.currentStats.attack : attacker.currentStats.specialAttack;
const defense = move.category === 'physical' ? defender.currentStats.defense : defender.currentStats.specialDefense;
const attack = move.category === 'physical' ? attacker.battleStats.attack : attacker.battleStats.specialAttack;
const defense = move.category === 'physical' ? defender.battleStats.defense : defender.battleStats.specialDefense;

const random = Math.random() * (1 - 0.85) + 0.85;
const stab = this.calculateStab(attacker, move);
Expand Down Expand Up @@ -328,22 +336,23 @@ export class BattleState {

// end turn effects (burn, poison..)
if (this.playerCurrentMonster.status && this.playerCurrentMonster.status.when === 'end-turn') {
let effect = this.playerCurrentMonster.status.playEffect(this.playerCurrentMonster);
let effect = this.playerCurrentMonster.status.playEffect(this.playerCurrentMonster, this.opponentCurrentMonster);
if (effect?.message) {
this.addToStack(new Message(effect.message, this.playerCurrentMonster), true);
}
}
if (this.opponentCurrentMonster.status && this.opponentCurrentMonster.status.when === 'end-turn') {
let effect = this.opponentCurrentMonster.status.playEffect(this.opponentCurrentMonster);
let effect = this.opponentCurrentMonster.status.playEffect(this.opponentCurrentMonster, this.playerCurrentMonster);
if (effect?.message) {
this.addToStack(new Message(effect.message, this.opponentCurrentMonster), true);
}
}

this.addToStack(new Message(`What should ${this.playerCurrentMonster.name} do ?`, action.initiator));
this.isPlayerTurnV = true;
this.currentMessageV = `What should ${this.playerCurrentMonster.name} do ?`;

}
this.playerCurrentMonster.resetBattleStats();
BATTLE_STATE.set(new BattleContext(this));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/js/mapping/maps/test-map.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {OpenMap} from "../maps";
import {Position} from "../../sprites/drawers";

//const monsters = Array.from({length: 251}, (v, k) => k + 1);
const monsters = [122];
const monsters = Array.from({length: 251}, (v, k) => k + 1);
//const monsters = [122];
const collisions = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 806, 806, 806, 806, 806, 806, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
Loading

0 comments on commit 712b47d

Please sign in to comment.