Skip to content

Commit

Permalink
balance pass 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ewei068 committed Dec 23, 2024
1 parent 1d62a20 commit a176758
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 166 deletions.
38 changes: 37 additions & 1 deletion src/battle/data/effects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-param-reassign */
const { effectTypes } = require("../../config/battleConfig");
const { effectIdEnum } = require("../../enums/battleEnums");
const { effectIdEnum, battleEventEnum } = require("../../enums/battleEnums");
const { getIsTargetPokemonCallback } = require("../engine/eventConditions");
const { getEffect } = require("./effectRegistry");

/**
* @template T
Expand Down Expand Up @@ -94,6 +96,40 @@ const effectsToRegister = Object.freeze({
battle.addToLog(`${target.name}'s shield was removed!`);
},
}),
[effectIdEnum.DEBUFF_IMMUNITY]: new Effect({
id: effectIdEnum.DEBUFF_IMMUNITY,
name: "Debuff Immunity",
description: "The target is immune to debuffs.",
type: effectTypes.BUFF,
dispellable: true,
/**
* @param {EffectAddBasicArgs & {initialArgs: any}} args
*/
effectAdd({ battle, target }) {
battle.addToLog(`${target.name} is immune to debuffs!`);
return {
listenerId: battle.registerListenerFunction({
eventName: battleEventEnum.BEFORE_EFFECT_ADD,
callback: (eventArgs) => {
const effect = getEffect(eventArgs.effectId);
if (effect.type !== effectTypes.DEBUFF) {
return;
}

eventArgs.canAdd = false;
battle.addToLog(
`${target.name} is immune to debuffs and cannot be affected by ${effect.name}!`
);
},
conditionCallback: getIsTargetPokemonCallback(target),
}),
};
},
effectRemove({ battle, target, properties }) {
battle.addToLog(`${target.name} is no longer immune to debuffs!`);
battle.unregisterListener(properties.listenerId);
},
}),
});

module.exports = {
Expand Down
18 changes: 16 additions & 2 deletions src/battle/engine/BattlePokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ class BattlePokemon {
}
break;
case statusConditions.SLEEP:
// sleep wakeup chance: 0 turns: 0%, 1 turn: 66%, 2 turns: 100%
const wakeupChance = this.status.turns * 0.66;
// sleep wakeup chance: 0 turns: 0%, 1 turn: 33%, 2 turns: 66%, 3 turns: 100%
const wakeupChance = this.status.turns * 0.33;
const wakeupRoll = Math.random();
if (wakeupRoll < wakeupChance) {
this.removeStatus();
Expand Down Expand Up @@ -1013,6 +1013,20 @@ class BattlePokemon {
if (freezeCheck) {
if (this.removeStatus()) {
damage = Math.floor(damage * 1.5);
this.battle.addToLog(
`${this.name} Took extra damage because it was frozen!`
);
}
}

// if sleep and hit with a move, wake up and deal 1.5x damage
const sleepCheck =
this.status.statusId === statusConditions.SLEEP &&
damageInfo.type === "move";
if (sleepCheck) {
if (this.removeStatus()) {
damage = Math.floor(damage * 1.5);
this.battle.addToLog(`${this.name} Took extra damage while sleeping!`);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/battle/engine/eventConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
const getIsActivePokemonCallback = (battle, pokemon) => () =>
battle.activePokemon === pokemon;

/**
* @param {BattlePokemon} pokemon
*/
const getIsTargetPokemonCallback = (pokemon) => (eventArgs) =>
eventArgs?.target === pokemon;

module.exports = {
getIsActivePokemonCallback,
getIsTargetPokemonCallback,
};
6 changes: 6 additions & 0 deletions src/battle/engine/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class BattleEventHandler {
listener.conditionCallback(fullArgs)
) {
listener.execute(fullArgs);
// updates args with new values
// TODO: do immutable event handling... someday
// Sorry for the hack folks this is too much for me to fix ATM
for (const key in args || {}) {
args[key] = fullArgs[key];
}
}
} else {
listener.execute(listener.initialArgs, args);
Expand Down
Loading

0 comments on commit a176758

Please sign in to comment.