Skip to content

Commit

Permalink
Refactor Decision -> Action
Browse files Browse the repository at this point in the history
"Decision" and "Choice" were always kind of unclear, so Decision is now
Action. It should now be a lot clearer.

Actions are also now strongly typed.
  • Loading branch information
Zarel committed Dec 2, 2017
1 parent dc7c46b commit f3dbfbe
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 326 deletions.
2 changes: 1 addition & 1 deletion PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ In addition to room messages, battles have their own messages.

`|request|REQUEST`

> Gives a JSON object containing a request for a decision (to move or
> Gives a JSON object containing a request for a choice (to move or
> switch). To assist in your decision, `REQUEST.active` has information
> about your active Pokémon, and `REQUEST.side` has information about your
> your team as a whole.
Expand Down
6 changes: 3 additions & 3 deletions data/abilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ exports.BattleAbilities = {

if (target.side.active.length === 2 && target.position === 1) {
// Curse Glitch
const decision = this.willMove(target);
if (decision && decision.move.id === 'curse') {
decision.targetLoc = -1;
const action = this.willMove(target);
if (action && action.move.id === 'curse') {
action.targetLoc = -1;
}
}
}
Expand Down
74 changes: 37 additions & 37 deletions data/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ exports.BattleMovedex = {
flags: {authentic: 1, mystery: 1},
onHit: function (target) {
if (target.side.active.length < 2) return false; // fails in singles
let decision = this.willMove(target);
if (decision) {
let action = this.willMove(target);
if (action) {
this.cancelMove(target);
this.queue.unshift(decision);
this.queue.unshift(action);
this.add('-activate', target, 'move: After You');
} else {
return false;
Expand Down Expand Up @@ -4415,7 +4415,7 @@ exports.BattleMovedex = {
this.effectData.duration++;
}
},
onOverrideDecision: function (pokemon, target, move) {
onOverrideAction: function (pokemon, target, move) {
if (move.id !== this.effectData.move) return this.effectData.move;
},
onResidualOrder: 13,
Expand Down Expand Up @@ -5045,11 +5045,11 @@ exports.BattleMovedex = {
flags: {protect: 1, mirror: 1, nonsky: 1},
onPrepareHit: function (target, source, move) {
for (let i = 0; i < this.queue.length; i++) {
let decision = this.queue[i];
if (!decision.move || !decision.pokemon || !decision.pokemon.isActive || decision.pokemon.fainted) continue;
if (decision.pokemon.side === source.side && ['grasspledge', 'waterpledge'].includes(decision.move.id)) {
this.prioritizeQueue(decision);
this.add('-waiting', source, decision.pokemon);
let action = this.queue[i];
if (!action.move || !action.pokemon || !action.pokemon.isActive || action.pokemon.fainted) continue;
if (action.pokemon.side === source.side && ['grasspledge', 'waterpledge'].includes(action.move.id)) {
this.prioritizeAction(action);
this.add('-waiting', source, action.pokemon);
return null;
}
}
Expand Down Expand Up @@ -6461,11 +6461,11 @@ exports.BattleMovedex = {
flags: {protect: 1, mirror: 1, nonsky: 1},
onPrepareHit: function (target, source, move) {
for (let i = 0; i < this.queue.length; i++) {
let decision = this.queue[i];
if (!decision.move || !decision.pokemon || !decision.pokemon.isActive || decision.pokemon.fainted) continue;
if (decision.pokemon.side === source.side && ['waterpledge', 'firepledge'].includes(decision.move.id)) {
this.prioritizeQueue(decision);
this.add('-waiting', source, decision.pokemon);
let action = this.queue[i];
if (!action.move || !action.pokemon || !action.pokemon.isActive || action.pokemon.fainted) continue;
if (action.pokemon.side === source.side && ['waterpledge', 'firepledge'].includes(action.move.id)) {
this.prioritizeAction(action);
this.add('-waiting', source, action.pokemon);
return null;
}
}
Expand Down Expand Up @@ -9926,12 +9926,12 @@ exports.BattleMovedex = {
priority: 0,
flags: {protect: 1, authentic: 1},
onTryHit: function (target, pokemon) {
let decision = this.willMove(target);
if (decision) {
let action = this.willMove(target);
if (action) {
let noMeFirst = [
'chatter', 'counter', 'covet', 'focuspunch', 'mefirst', 'metalburst', 'mirrorcoat', 'struggle', 'thief',
];
let move = this.getMoveCopy(decision.move.id);
let move = this.getMoveCopy(action.move.id);
if (move.category !== 'Status' && !noMeFirst.includes(move)) {
pokemon.addVolatile('mefirst');
this.useMove(move, pokemon, target);
Expand Down Expand Up @@ -12749,7 +12749,7 @@ exports.BattleMovedex = {
this.add('-activate', pokemon, 'move: Pursuit');
alreadyAdded = true;
}
// Run through each decision in queue to check if the Pursuit user is supposed to Mega Evolve this turn.
// Run through each action in queue to check if the Pursuit user is supposed to Mega Evolve this turn.
// If it is, then Mega Evolve before moving.
if (source.canMegaEvo || source.canUltraBurst) {
for (const [actionIndex, action] of this.queue.entries()) {
Expand Down Expand Up @@ -12784,13 +12784,13 @@ exports.BattleMovedex = {
flags: {protect: 1, mirror: 1},
onHit: function (target) {
if (target.side.active.length < 2) return false; // fails in singles
let decision = this.willMove(target);
if (decision) {
decision.priority = -7.1;
let action = this.willMove(target);
if (action) {
action.priority = -7.1;
this.cancelMove(target);
for (let i = this.queue.length - 1; i >= 0; i--) {
if (this.queue[i].choice === 'residual') {
this.queue.splice(i, 0, decision);
this.queue.splice(i, 0, action);
break;
}
}
Expand Down Expand Up @@ -13842,10 +13842,10 @@ exports.BattleMovedex = {
flags: {protect: 1, mirror: 1, sound: 1, authentic: 1},
onTry: function () {
for (let i = 0; i < this.queue.length; i++) {
let decision = this.queue[i];
if (!decision.pokemon || !decision.move) continue;
if (decision.move.id === 'round') {
this.prioritizeQueue(decision);
let action = this.queue[i];
if (!action.pokemon || !action.move) continue;
if (action.move.id === 'round') {
this.prioritizeAction(action);
return;
}
}
Expand Down Expand Up @@ -16573,8 +16573,8 @@ exports.BattleMovedex = {
priority: 1,
flags: {contact: 1, protect: 1, mirror: 1},
onTry: function (source, target) {
let decision = this.willMove(target);
if (!decision || decision.choice !== 'move' || (decision.move.category === 'Status' && decision.move.id !== 'mefirst') || target.volatiles.mustrecharge) {
let action = this.willMove(target);
if (!action || action.choice !== 'move' || (action.move.category === 'Status' && action.move.id !== 'mefirst') || target.volatiles.mustrecharge) {
this.attrLastMove('[still]');
this.add('-fail', source);
return null;
Expand Down Expand Up @@ -17884,9 +17884,9 @@ exports.BattleMovedex = {

if (target.side.active.length === 2 && target.position === 1) {
// Curse Glitch
const decision = this.willMove(target);
if (decision && decision.move.id === 'curse') {
decision.targetLoc = -1;
const action = this.willMove(target);
if (action && action.move.id === 'curse') {
action.targetLoc = -1;
}
}
},
Expand Down Expand Up @@ -17926,7 +17926,7 @@ exports.BattleMovedex = {
onStart: function (target, source) {
this.add('-fieldstart', 'move: Trick Room', '[of] ' + source);
},
// Speed modification is changed in Pokemon.getDecisionSpeed() in sim/pokemon.js
// Speed modification is changed in Pokemon.getActionSpeed() in sim/pokemon.js
onResidualOrder: 23,
onEnd: function () {
this.add('-fieldend', 'move: Trick Room');
Expand Down Expand Up @@ -18413,11 +18413,11 @@ exports.BattleMovedex = {
flags: {protect: 1, mirror: 1, nonsky: 1},
onPrepareHit: function (target, source, move) {
for (let i = 0; i < this.queue.length; i++) {
let decision = this.queue[i];
if (!decision.move || !decision.pokemon || !decision.pokemon.isActive || decision.pokemon.fainted) continue;
if (decision.pokemon.side === source.side && ['firepledge', 'grasspledge'].includes(decision.move.id)) {
this.prioritizeQueue(decision);
this.add('-waiting', source, decision.pokemon);
let action = this.queue[i];
if (!action.move || !action.pokemon || !action.pokemon.isActive || action.pokemon.fainted) continue;
if (action.pokemon.side === source.side && ['firepledge', 'grasspledge'].includes(action.move.id)) {
this.prioritizeAction(action);
this.add('-waiting', source, action.pokemon);
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.BattleScripts = {
runMove: function (move, pokemon, targetLoc, sourceEffect, zMove, externalMove) {
let target = this.getTarget(pokemon, zMove || move, targetLoc);
if (!sourceEffect && toId(move) !== 'struggle' && !zMove) {
let changedMove = this.runEvent('OverrideDecision', pokemon, target, move);
let changedMove = this.runEvent('OverrideAction', pokemon, target, move);
if (changedMove && changedMove !== true) {
move = changedMove;
target = null;
Expand Down
2 changes: 1 addition & 1 deletion mods/gen2/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ exports.BattleMovedex = {
this.effectData.duration++;
}
},
onOverrideDecision: function (pokemon) {
onOverrideAction: function (pokemon) {
return this.effectData.move;
},
onResidualOrder: 13,
Expand Down
2 changes: 1 addition & 1 deletion mods/gen2/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.BattleScripts = {
runMove: function (move, pokemon, targetLoc, sourceEffect) {
let target = this.getTarget(pokemon, move, targetLoc);
if (!sourceEffect && toId(move) !== 'struggle') {
let changedMove = this.runEvent('OverrideDecision', pokemon, target, move);
let changedMove = this.runEvent('OverrideAction', pokemon, target, move);
if (changedMove && changedMove !== true) {
move = changedMove;
target = null;
Expand Down
2 changes: 1 addition & 1 deletion mods/gen2/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ exports.BattleStatuses = {
let move = this.getMove(this.effectData.move);
if (move.id) {
this.debug('Forcing into ' + move.id);
this.changeDecision(pokemon, {move: move.id});
this.changeAction(pokemon, {move: move.id});
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion mods/gen3/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exports.BattleMovedex = {
this.effectData.duration++;
}
},
onOverrideDecision: function (pokemon) {
onOverrideAction: function (pokemon) {
return this.effectData.move;
},
onResidualOrder: 13,
Expand Down
28 changes: 14 additions & 14 deletions mods/gen4/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ exports.BattleItems = {
onModifyPriority: function () {},
onBeforeTurn: function (pokemon) {
if (pokemon.hp <= pokemon.maxhp / 4 || (pokemon.hp <= pokemon.maxhp / 2 && pokemon.ability === 'gluttony')) {
let decision = this.willMove(pokemon);
if (!decision) return;
let action = this.willMove(pokemon);
if (!action) return;
this.insertQueue({
choice: 'event',
event: 'Custap',
priority: decision.priority + 0.1,
pokemon: decision.pokemon,
move: decision.move,
target: decision.target,
priority: action.priority + 0.1,
pokemon: action.pokemon,
move: action.move,
target: action.target,
});
}
},
onCustap: function (pokemon) {
let decision = this.willMove(pokemon);
this.debug('custap decision: ' + decision);
if (decision) {
let action = this.willMove(pokemon);
this.debug('custap action: ' + action);
if (action) {
pokemon.eatItem();
}
},
onEat: function (pokemon) {
let decision = this.willMove(pokemon);
this.debug('custap eaten: ' + decision);
if (decision) {
this.cancelDecision(pokemon);
let action = this.willMove(pokemon);
this.debug('custap eaten: ' + action);
if (action) {
this.cancelAction(pokemon);
this.add('-message', "Custap Berry activated.");
this.runDecision(decision);
this.runAction(action);
}
},
},
Expand Down
6 changes: 3 additions & 3 deletions mods/gen4/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ exports.BattleMovedex = {
this.effectData.duration++;
}
},
onOverrideDecision: function (pokemon) {
onOverrideAction: function (pokemon) {
return this.effectData.move;
},
onResidualOrder: 13,
Expand Down Expand Up @@ -1094,8 +1094,8 @@ exports.BattleMovedex = {
inherit: true,
desc: "Fails if the target did not select a physical or special attack for use this turn, or if the target moves before the user.",
onTry: function (source, target) {
let decision = this.willMove(target);
if (!decision || decision.choice !== 'move' || decision.move.category === 'Status' || target.volatiles.mustrecharge) {
let action = this.willMove(target);
if (!action || action.choice !== 'move' || action.move.category === 'Status' || target.volatiles.mustrecharge) {
this.add('-fail', source);
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion mods/gen6/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ exports.BattleMovedex = {
this.effectData.duration++;
}
},
onOverrideDecision: function (pokemon, target, move) {
onOverrideAction: function (pokemon, target, move) {
if (move.id !== this.effectData.move) return this.effectData.move;
},
onResidualOrder: 13,
Expand Down
Loading

0 comments on commit f3dbfbe

Please sign in to comment.