|
1
|
|
|
import { SaveFileIterator } from './../SaveFileIterator'; |
|
2
|
|
|
import { SaveFileService } from './../../savefile.service'; |
|
3
|
|
|
import { PokemonBox } from './PokemonBox'; |
|
4
|
|
|
|
|
5
|
|
|
export class PokemonParty extends PokemonBox { |
|
6
|
|
|
constructor(saveFile?: SaveFileService, |
|
7
|
|
|
offset?: number, |
|
8
|
|
|
nicknameStartOffset?: number, |
|
9
|
|
|
otNameStartOffset?: number, |
|
10
|
|
|
index?: number) { |
|
11
|
|
|
|
|
12
|
|
|
// Due to an annoying attribute of typescript compiling variable |
|
13
|
|
|
// declarations below the super call thus resetting child class to default |
|
14
|
|
|
// after child and parent class have been initialized properly |
|
15
|
|
|
// we have to work around this annoyance by initiating a blank parent |
|
16
|
|
|
// and typescripts injected code for a blank child followed by the actual |
|
17
|
|
|
// loading process handled by the child and delegated manually to the parent |
|
18
|
|
|
// This annoyance took several hours to figure out why only the child |
|
19
|
|
|
// kept resetting to default values after loading properly |
|
20
|
|
|
super(); |
|
21
|
|
|
|
|
22
|
|
|
if (saveFile !== undefined) |
|
23
|
|
|
this.load(saveFile as SaveFileService, |
|
24
|
|
|
offset as number, |
|
25
|
|
|
nicknameStartOffset as number, |
|
26
|
|
|
otNameStartOffset as number, |
|
27
|
|
|
index as number) |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// Modifies a Pokemon Box to be a Pokemon Party and creates initial stats |
|
31
|
|
|
static convertToPokemonParty(pkmn: PokemonBox) { |
|
32
|
|
|
const _pkmn = pkmn as PokemonParty; |
|
33
|
|
|
Object.setPrototypeOf(_pkmn, PokemonParty.prototype); |
|
34
|
|
|
_pkmn.updateStats(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Modifies a Pokemon Party to be a Pokemon Box |
|
38
|
|
|
static convertToPokemonBox(pkmn: PokemonParty) { |
|
39
|
|
|
delete pkmn.maxHP; |
|
40
|
|
|
delete pkmn.attack; |
|
41
|
|
|
delete pkmn.defense; |
|
42
|
|
|
delete pkmn.speed; |
|
43
|
|
|
delete pkmn.special; |
|
44
|
|
|
Object.setPrototypeOf(pkmn, PokemonBox.prototype); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public load(saveFile: SaveFileService, |
|
48
|
|
|
offset: number, |
|
49
|
|
|
nicknameStartOffset: number, |
|
50
|
|
|
otNameStartOffset: number, |
|
51
|
|
|
index: number): SaveFileIterator { |
|
52
|
|
|
|
|
53
|
|
|
// Mark record size at end to the expanded size of 0x2C |
|
54
|
|
|
// Pokemon Party has expanded data |
|
55
|
|
|
const it: SaveFileIterator = super.load(saveFile, |
|
56
|
|
|
offset, |
|
57
|
|
|
nicknameStartOffset, |
|
58
|
|
|
otNameStartOffset, |
|
59
|
|
|
index, |
|
60
|
|
|
0x2C); |
|
61
|
|
|
|
|
62
|
|
|
this.level = it.getByte(); |
|
63
|
|
|
this.maxHP = it.getWord(); |
|
64
|
|
|
this.attack = it.getWord(); |
|
65
|
|
|
this.defense = it.getWord(); |
|
66
|
|
|
this.speed = it.getWord(); |
|
67
|
|
|
this.special = it.getWord(); |
|
68
|
|
|
|
|
69
|
|
|
return it; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public save(saveFile: SaveFileService, |
|
73
|
|
|
offset: number, |
|
74
|
|
|
speciesStartOffset: number | null, |
|
75
|
|
|
nicknameStartOffset: number, |
|
76
|
|
|
otNameStartOffset: number, |
|
77
|
|
|
index: number): SaveFileIterator { |
|
78
|
|
|
|
|
79
|
|
|
const it: SaveFileIterator = super.save(saveFile, |
|
80
|
|
|
offset, |
|
81
|
|
|
speciesStartOffset, |
|
82
|
|
|
nicknameStartOffset, |
|
83
|
|
|
otNameStartOffset, |
|
84
|
|
|
index, |
|
85
|
|
|
0x2C); |
|
86
|
|
|
|
|
87
|
|
|
it.setByte(this.level); |
|
88
|
|
|
it.setWord(this.maxHP); |
|
89
|
|
|
it.setWord(this.attack); |
|
90
|
|
|
it.setWord(this.defense); |
|
91
|
|
|
it.setWord(this.speed); |
|
92
|
|
|
it.setWord(this.special); |
|
93
|
|
|
|
|
94
|
|
|
return it; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public updateStats() { |
|
98
|
|
|
|
|
99
|
|
|
// Stop here if invalid Pokemon |
|
100
|
|
|
if(this.isValidPokemon === false) |
|
101
|
|
|
return; |
|
102
|
|
|
|
|
103
|
|
|
this.maxHP = this.hpStat; |
|
104
|
|
|
this.attack = this.attackStat; |
|
105
|
|
|
this.defense = this.defenseStat; |
|
106
|
|
|
this.speed = this.speedStat; |
|
107
|
|
|
this.special = this.specialStat; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public maxHP: number = 0; |
|
111
|
|
|
public attack: number = 0; |
|
112
|
|
|
public defense: number = 0; |
|
113
|
|
|
public speed: number = 0; |
|
114
|
|
|
public special: number = 0; |
|
115
|
|
|
} |
|
116
|
|
|
|