-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpokemon_red_blue.js
147 lines (132 loc) · 6.21 KB
/
pokemon_red_blue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import {
copyProperties,
getValue,
setProperty,
setValue,
} from "../common/index.js";
import { hpIv } from "../common/pokemon.js";
const PARTY_SIZE = 6;
function getGamestate() {
// FSM FOR GAMESTATE TRACKING
// MAIN GAMESTATE: This tracks the three basic states the game can be in.
// 1. "No Pokemon": cartridge reset; player has not received a Pokemon
// 2. "Overworld": Pokemon in party, but not in battle
// 3. "To Battle": Battle has started but player hasn't sent their Pokemon in yet
// 4. "From Battle": Battle result has been decided but the battle has not transition to the overworld yet
// 5. "Battle": In battle
const team_0_level = getValue('player.team.0.level')
const outcome_flags = getValue('battle.other.outcome_flags')
const battle_start = getValue('battle.other.battle_start')
const battle_mode = getValue('battle.mode')
const low_health_alarm = getValue('battle.other.low_health_alarm')
if (team_0_level == 0) {
return 'No Pokemon'
}
else if (battle_mode == null) {
return 'Overworld'
}
else if (battle_start == 0) {
return 'To Battle'
}
else if (low_health_alarm == "Disabled" || outcome_flags > 0) {
return 'From Battle'
}
else {
return 'Battle'
}
}
function getBattleOutcome() {
const outcome_flags = getValue('battle.other.outcome_flags')
const state = getGamestate()
switch (state) {
case 'From Battle':
switch (outcome_flags) {
case 0:
return 'Win'
case 1:
return 'Lose'
case 2:
return 'Flee'
default:
return null
}
}
return null
}
function getPlayerPartyPosition() {
const state = getGamestate()
switch (state) {
case 'Battle':
return getValue('battle.player.party_position')
case 'From Battle':
return getValue('battle.player.party_position')
default: {
const team = [0, 1, 2, 3, 4, 5]
for (let i = 0; i < team.length; i++) {
if (getValue(`player.team.${i}.stats.hp`) > 0) {
return i
}
}
return 0
}
}
}
export function postprocessor() {
const gamestate = getGamestate()
setValue('meta.state', gamestate)
setValue('battle.outcome', getBattleOutcome())
setValue('player.party_position', getPlayerPartyPosition())
//Set player.active_pokemon properties
const party_position_overworld = getPlayerPartyPosition()
const party_position_battle = getValue('battle.player.party_position')
if (gamestate === 'Battle') {
copyProperties(`player.team.${party_position_battle}`, 'player.active_pokemon')
copyProperties('battle.player.active_pokemon', 'player.active_pokemon')
} else {
setProperty('player.active_pokemon.modifiers.attack', { address: null, value: 0 })
setProperty('player.active_pokemon.modifiers.defense', { address: null, value: 0 })
setProperty('player.active_pokemon.modifiers.speed', { address: null, value: 0 })
setProperty('player.active_pokemon.modifiers.special', { address: null, value: 0 })
setProperty('player.active_pokemon.modifiers.accuracy', { address: null, value: 0 })
setProperty('player.active_pokemon.modifiers.evasion', { address: null, value: 0 })
setProperty('player.active_pokemon.volatile_status_conditions.confusion', { address: null, value: false })
setProperty('player.active_pokemon.volatile_status_conditions.toxic', { address: null, value: false })
setProperty('player.active_pokemon.volatile_status_conditions.leech_seed', { address: null, value: false })
setProperty('player.active_pokemon.effects.bide', { address: null, value: false })
setProperty('player.active_pokemon.effects.thrash', { address: null, value: false })
setProperty('player.active_pokemon.effects.multi_hit', { address: null, value: false })
setProperty('player.active_pokemon.effects.flinch', { address: null, value: false })
setProperty('player.active_pokemon.effects.charging', { address: null, value: false })
setProperty('player.active_pokemon.effects.multi_turn', { address: null, value: false })
setProperty('player.active_pokemon.effects.invulnerable', { address: null, value: false })
setProperty('player.active_pokemon.effects.bypass_accuracy', { address: null, value: false })
setProperty('player.active_pokemon.effects.mist', { address: null, value: false })
setProperty('player.active_pokemon.effects.focus_energy', { address: null, value: false })
setProperty('player.active_pokemon.effects.substitute', { address: null, value: false })
setProperty('player.active_pokemon.effects.recharge', { address: null, value: false })
setProperty('player.active_pokemon.effects.rage', { address: null, value: false })
setProperty('player.active_pokemon.effects.lightscreen', { address: null, value: false })
setProperty('player.active_pokemon.effects.reflect', { address: null, value: false })
setProperty('player.active_pokemon.effects.transformed', { address: null, value: false })
setProperty('player.active_pokemon.counters.multi_hit', { address: null, value: 0 })
setProperty('player.active_pokemon.counters.confusion', { address: null, value: 0 })
setProperty('player.active_pokemon.counters.toxic', { address: null, value: 0 })
setProperty('player.active_pokemon.counters.disable', { address: null, value: 0 })
setProperty('player.active_pokemon.last_move.move', { address: null, value: null })
setProperty('player.active_pokemon.last_move.effect', { address: null, value: 0 })
setProperty('player.active_pokemon.last_move.power', { address: null, value: 0 })
setProperty('player.active_pokemon.last_move.type', { address: null, value: null })
setProperty('player.active_pokemon.last_move.accuracy', { address: null, value: 0 })
setProperty('player.active_pokemon.last_move.pp_max', { address: null, value: 0 })
copyProperties(`player.team.${party_position_overworld}`, 'player.active_pokemon')
}
for (let index = 0; index < PARTY_SIZE; index++) {
const ivs = {
attack: getValue(`player.team.${index}.ivs.attack`),
defense: getValue(`player.team.${index}.ivs.defense`),
special: getValue(`player.team.${index}.ivs.special`),
speed: getValue(`player.team.${index}.ivs.speed`),
};
setValue(`player.team.${index}.ivs.hp`, hpIv(ivs));
}
}