| Conditions | 17 |
| Total Lines | 88 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like MoreEventPokemon.genPokemonAndGive often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import { GameDataService } from './../../data/gameData.service'; |
||
| 176 | |||
| 177 | // Gives the Pokemon |
||
| 178 | genPokemonAndGive(entry: EventPokemon) { |
||
| 179 | // Get a blank Pokemon with random DV's and OT ID |
||
| 180 | const pkmn = this.pkmn; |
||
| 181 | |||
| 182 | // Get Pokemon Record |
||
| 183 | const nameRecord = this.findPokemonRecord(entry.pokemon); |
||
| 184 | if(nameRecord == null) |
||
| 185 | return; |
||
| 186 | |||
| 187 | // Assign Species Number |
||
| 188 | pkmn.species = nameRecord.ind; |
||
| 189 | |||
| 190 | if(nameRecord.catchRate !== undefined) |
||
| 191 | pkmn.catchRate = nameRecord.catchRate; |
||
| 192 | |||
| 193 | // Assign Types 1 & 2 |
||
| 194 | if(nameRecord.type1 === undefined || nameRecord.type2 === undefined) |
||
| 195 | return; |
||
| 196 | |||
| 197 | let typeX = this.getType(nameRecord.type1); |
||
| 198 | if(typeX === null) |
||
| 199 | return; |
||
| 200 | |||
| 201 | pkmn.type1 = typeX; |
||
| 202 | |||
| 203 | typeX = this.getType(nameRecord.type2); |
||
| 204 | if(typeX === null) |
||
| 205 | return; |
||
| 206 | |||
| 207 | pkmn.type2 = typeX; |
||
| 208 | |||
| 209 | if(pkmn.type1 == pkmn.type2) |
||
| 210 | pkmn.type2 = 0xFF; |
||
| 211 | |||
| 212 | // Assign OT Name |
||
| 213 | let otName = entry.otName; |
||
| 214 | if(Array.isArray(entry.otName)) |
||
| 215 | otName = otName[this.getRandomInt(0, otName.length - 1)]; |
||
| 216 | |||
| 217 | // Handled Above |
||
| 218 | // @ts-ignore |
||
| 219 | pkmn.otName = otName; |
||
| 220 | |||
| 221 | // OT ID if present, random otherwise |
||
| 222 | if(entry.otID !== undefined) |
||
| 223 | pkmn.otID = entry.otID; |
||
| 224 | |||
| 225 | if(entry.dv != undefined && entry.dv == "max") { |
||
| 226 | pkmn.dv.attack = 15; |
||
| 227 | pkmn.dv.defense = 15; |
||
| 228 | pkmn.dv.special = 15; |
||
| 229 | pkmn.dv.speed = 15; |
||
| 230 | } |
||
| 231 | else if(entry.dv != undefined && entry.dv.startsWith(":")) { |
||
| 232 | const dvs = entry.dv.split(":"); |
||
| 233 | dvs.shift(); |
||
| 234 | |||
| 235 | pkmn.dv.attack = parseInt(dvs[0]); |
||
| 236 | pkmn.dv.defense = parseInt(dvs[1]); |
||
| 237 | pkmn.dv.speed = parseInt(dvs[2]); |
||
| 238 | pkmn.dv.special = parseInt(dvs[3]); |
||
| 239 | } |
||
| 240 | |||
| 241 | // Assign Nickname |
||
| 242 | pkmn.nickname = nameRecord.name.toUpperCase(); |
||
| 243 | |||
| 244 | if(pkmn.nickname == "NIDORAN<M>") |
||
| 245 | pkmn.nickname = "NIDORAN<m>"; |
||
| 246 | else if(pkmn.nickname == "NIDORAN<F>") |
||
| 247 | pkmn.nickname = "NIDORAN<f>"; |
||
| 248 | |||
| 249 | // Assign Level |
||
| 250 | pkmn.level = (entry.level) ? entry.level : 5; |
||
| 251 | |||
| 252 | for(let i = 0; i < entry.moves.length; i++) { |
||
| 253 | const move = entry.moves[i]; |
||
| 254 | const moveData = this.getMove(move); |
||
| 255 | if(moveData == null) |
||
| 256 | return; |
||
| 257 | |||
| 258 | pkmn.moves[i].moveID = moveData.ind; |
||
| 259 | if(moveData.pp !== undefined) |
||
| 260 | pkmn.moves[i].pp = moveData.pp; |
||
| 261 | } |
||
| 262 | |||
| 263 | this.givePokemon(pkmn); |
||
| 264 | } |
||
| 266 |