@@ -3,6 +3,7 @@ import { DataService } from '../services/data.service';
3
3
4
4
export class PokemonModel {
5
5
private _species : number ;
6
+ private _form : string ;
6
7
public name : string ;
7
8
public type1 : string ;
8
9
public type2 : string ;
@@ -24,8 +25,8 @@ export class PokemonModel {
24
25
public isRemovable : boolean ;
25
26
public canSelectMoves : boolean ;
26
27
27
- constructor ( species : number , private dataService : DataService , internalId ?: string , internalTitle ?: string , isRemovable ?: boolean , canSelectMoves ?: boolean ) {
28
- this . species = species ;
28
+ constructor ( species : number , form : string , private dataService : DataService , internalId ?: string , internalTitle ?: string , isRemovable ?: boolean , canSelectMoves ?: boolean ) {
29
+ this . changeSpecies ( species , form ) ;
29
30
this . level = 30 ;
30
31
this . attackIv = 15 ;
31
32
this . defenseIv = 15 ;
@@ -39,15 +40,48 @@ export class PokemonModel {
39
40
this . canSelectMoves = canSelectMoves || false ;
40
41
}
41
42
42
- set species ( species : number ) {
43
+ get species ( ) : number {
44
+ return this . _species ;
45
+ }
46
+
47
+ get form ( ) : string {
48
+ return this . _form ;
49
+ }
50
+
51
+ get levelMultiplier ( ) : number {
52
+ return this . dataService . getLevelMultiplier ( this . level ) ;
53
+ }
54
+
55
+ get attack ( ) : number {
56
+ return ( this . attackBase + this . attackIv ) * this . levelMultiplier ;
57
+ }
58
+
59
+ get defense ( ) : number {
60
+ return ( this . defenseBase + this . defenseIv ) * this . levelMultiplier ;
61
+ }
62
+
63
+ get stamina ( ) : number {
64
+ return ( this . staminaBase + this . staminaIv ) * this . levelMultiplier ;
65
+ }
66
+
67
+ get cp ( ) : number {
68
+ return Math . floor ( Math . max ( ( this . attack * Math . pow ( this . defense , 0.5 ) * Math . pow ( this . stamina , 0.5 ) * Math . pow ( this . levelMultiplier , 2 ) ) / 10 , 10 ) ) ;
69
+ }
70
+
71
+ get paddedNumber ( ) : string {
72
+ return ( this . species < 10 ? '00' + this . species : ( this . species < 100 ) ? '0' + this . species : '' + this . species ) ;
73
+ }
74
+
75
+ public changeSpecies ( species : number , form : string ) {
43
76
this . _species = species ;
44
- let pokedexData = this . dataService . getPokemon ( species ) ;
77
+ this . _form = form ;
78
+ let pokedexData = this . dataService . getPokemon ( species , form ) ;
45
79
this . name = pokedexData [ 0 ] ;
46
- this . type1 = pokedexData [ 2 ] ;
47
- this . type2 = ( pokedexData [ 3 ] && pokedexData [ 3 ] != 'N/A' ) ? pokedexData [ 3 ] : null ;
48
- this . attackBase = parseInt ( pokedexData [ 4 ] ) ;
49
- this . defenseBase = parseInt ( pokedexData [ 5 ] ) ;
50
- this . staminaBase = parseInt ( pokedexData [ 6 ] ) ;
80
+ this . type1 = pokedexData [ 3 ] ;
81
+ this . type2 = ( pokedexData [ 4 ] && pokedexData [ 4 ] != 'N/A' ) ? pokedexData [ 4 ] : null ;
82
+ this . attackBase = parseInt ( pokedexData [ 5 ] ) ;
83
+ this . defenseBase = parseInt ( pokedexData [ 6 ] ) ;
84
+ this . staminaBase = parseInt ( pokedexData [ 7 ] ) ;
51
85
52
86
if ( this . _species == 151 ) { // darn you mew. y u break all the things.
53
87
const mewQuick = [ "c" ,
@@ -98,41 +132,15 @@ export class PokemonModel {
98
132
this . parseMoves ( mewCharge , false ) ; // parse charge moves
99
133
}
100
134
else {
101
- this . parseMoves ( pokedexData . slice ( 7 , 21 ) , true ) ; // parse quick moves
102
- this . parseMoves ( pokedexData . slice ( 21 , 37 ) , false ) ; // parse charge moves
135
+ this . parseMoves ( pokedexData . slice ( 8 , 22 ) , true ) ; // parse quick moves
136
+ this . parseMoves ( pokedexData . slice ( 22 , 38 ) , false ) ; // parse charge moves
103
137
}
104
138
}
105
- get species ( ) : number {
106
- return this . _species ;
107
- }
108
-
109
- get levelMultiplier ( ) : number {
110
- return this . dataService . getLevelMultiplier ( this . level ) ;
111
- }
112
-
113
- get attack ( ) : number {
114
- return ( this . attackBase + this . attackIv ) * this . levelMultiplier ;
115
- }
116
-
117
- get defense ( ) : number {
118
- return ( this . defenseBase + this . defenseIv ) * this . levelMultiplier ;
119
- }
120
-
121
- get stamina ( ) : number {
122
- return ( this . staminaBase + this . staminaIv ) * this . levelMultiplier ;
123
- }
124
-
125
- get cp ( ) : number {
126
- return Math . floor ( Math . max ( ( this . attack * Math . pow ( this . defense , 0.5 ) * Math . pow ( this . stamina , 0.5 ) * Math . pow ( this . levelMultiplier , 2 ) ) / 10 , 10 ) ) ;
127
- }
128
-
129
- get paddedNumber ( ) : string {
130
- return ( this . species < 10 ? '00' + this . species : ( this . species < 100 ) ? '0' + this . species : '' + this . species ) ;
131
- }
132
139
133
140
public serialize ( ) {
134
141
return JSON . stringify ( {
135
142
species : this . species ,
143
+ form : this . form ,
136
144
level : this . level ,
137
145
attackIv : this . attackIv ,
138
146
defenseIv : this . defenseIv ,
@@ -149,7 +157,9 @@ export class PokemonModel {
149
157
150
158
public deserialize ( source : string ) {
151
159
const sourceObj : any = JSON . parse ( source ) ;
152
- if ( sourceObj . species ) this . species = sourceObj . species ;
160
+ if ( sourceObj . species ) {
161
+ this . changeSpecies ( sourceObj . species , sourceObj . form ) ;
162
+ }
153
163
if ( sourceObj . level ) this . level = sourceObj . level ;
154
164
if ( sourceObj . attackIv ) this . attackIv = sourceObj . attackIv ;
155
165
if ( sourceObj . defenseIv ) this . defenseIv = sourceObj . defenseIv ;
0 commit comments