diff --git a/src/models/Player/PokeDex/index.js b/src/models/Player/PokeDex/index.js index 01c7930..a7bbcdd 100644 --- a/src/models/Player/PokeDex/index.js +++ b/src/models/Player/PokeDex/index.js @@ -21,16 +21,39 @@ export default class PokeDex { /** * @param {Number} dex + * @return {Boolean} */ - addEntry(dex) { + entryExists(dex) { + return ( + this.pkmns.hasOwnProperty(dex) + ); + } + /** + * @param {Number} dex + * @param {Number} capture + * @param {Number} encounter + */ + addEntry(dex, capture, encounter) { + if (this.entryExists(dex)) { + this.pkmns[dex].captured += capture << 0; + this.pkmns[dex].encountered += encounter << 0; + } else { + this.pkmns[dex] = { + captured: 0, + encountered: 0 + }; + this.addEntry(dex, capture, encounter); + } } /** * @param {Number} dex */ removeEntry(dex) { - + if (this.entryExists(dex)) { + delete this.pkmns[dex]; + } } /** @@ -45,8 +68,8 @@ export default class PokeDex { inventory_item_data: { pokedex_entry: { pokemon_id: key, - times_encountered: 1, - times_captured: 1 + times_captured: this.pkmns[key].captured, + times_encountered: this.pkmns[key].encountered } } }); diff --git a/src/models/Player/index.js b/src/models/Player/index.js index a33502d..276fcb5 100644 --- a/src/models/Player/index.js +++ b/src/models/Player/index.js @@ -316,6 +316,8 @@ export default class Player extends MapObject { let cp = pkmn.getSeenCp(this); pkmn.isOwned = false; pkmn = this.party.addPkmn(pkmn); + pkmn.isWild = false; + pkmn.isOwned = true; pkmn.cp = cp; pkmn.uid = insertId; pkmn.addCandies(3); diff --git a/src/models/Pokemon/WildPokemon/index.js b/src/models/Pokemon/WildPokemon/index.js index d30569c..4677867 100644 --- a/src/models/Pokemon/WildPokemon/index.js +++ b/src/models/Pokemon/WildPokemon/index.js @@ -22,12 +22,14 @@ export default class WildPokemon extends Pokemon { this.encounterId = this.getEncounterId(); + this.isDespawned = false; + this.minExpire = obj.minExpire; this.maxExpire = obj.maxExpire; this.creation = +new Date(); - this.expiration = ~~(Math.random() * this.maxExpire) + this.minExpire; + this.expiration = (Math.floor((Math.random() * this.maxExpire) + this.minExpire) * 1e3); // players who already caught this pkmn this.hasCatched = []; @@ -98,7 +100,7 @@ export default class WildPokemon extends Pokemon { */ isExpired() { return ( - ((this.creation + this.expiration) - +new Date()) <= 0 + +new Date() - this.creation >= this.expiration ); } @@ -124,7 +126,7 @@ export default class WildPokemon extends Pokemon { serializeWild() { return ({ encounter_id: this.encounterId, - last_modified_timestamp_ms: +new Date(), + last_modified_timestamp_ms: this.creation, latitude: this.latitude, longitude: this.longitude, spawn_point_id: this.spawnPointId, diff --git a/src/models/Pokemon/index.js b/src/models/Pokemon/index.js index 0fac159..e9fb321 100644 --- a/src/models/Pokemon/index.js +++ b/src/models/Pokemon/index.js @@ -40,7 +40,7 @@ export default class Pokemon extends MapObject { this.capturedLevel = 0; this.cp = 0; - this.cpMultiplier = Math.random(); + this.cpMultiplier = Math.random() + 1.0; this.addCpMultiplier = 0; this.move1 = 0; @@ -277,7 +277,7 @@ export default class Pokemon extends MapObject { cp_multiplier: this.cpMultiplier, pokeball: "ITEM_POKE_BALL", captured_cell_id: "1337", - creation_time_ms: +new Date() - 1e3, + creation_time_ms: +new Date(), favorite: this.favorite, nickname: this.nickname }); diff --git a/src/models/World/Cell/index.js b/src/models/World/Cell/index.js index 9705ad4..524f370 100644 --- a/src/models/World/Cell/index.js +++ b/src/models/World/Cell/index.js @@ -253,7 +253,10 @@ export default class Cell extends MapObject { fort = this.forts[ii]; if (!(fort.isSpawn === true)) continue; fort.activeSpawns.map((encounter) => { - if (!encounter.alreadyCatchedBy(player)) { + if ( + !encounter.alreadyCatchedBy(player) && + !encounter.isDespawned + ) { out.wild.push(encounter.serializeWild()); out.nearby.push(encounter.serializeNearby()); out.catchable.push(encounter.serializeCatchable()); diff --git a/src/models/World/SpawnPoint/index.js b/src/models/World/SpawnPoint/index.js index d52ae35..abb0001 100644 --- a/src/models/World/SpawnPoint/index.js +++ b/src/models/World/SpawnPoint/index.js @@ -6,8 +6,12 @@ import WildPokemon from "../../Pokemon/WildPokemon"; import print from "../../../print"; import CFG from "../../../../cfg"; +import Settings from "../../../modes"; + const pokename = require("pokename")(); +const MAP_REFRESH_RATE = Settings.GAME_SETTINGS.map_settings.get_map_objects_max_refresh_seconds; + /** * @class SpawnPoint */ @@ -27,8 +31,8 @@ export default class SpawnPoint extends MapObject { this.spawns = JSON.parse(obj.encounters); - this.minExpire = ((obj.min_spawn_expire * 1e3) * 60) << 0; - this.maxExpire = ((obj.max_spawn_expire * 1e3) * 60) << 0; + this.minExpire = ((obj.min_spawn_expire) * 60) << 0; + this.maxExpire = ((obj.max_spawn_expire) * 60) << 0; this.isSpawn = true; @@ -54,7 +58,12 @@ export default class SpawnPoint extends MapObject { refresh() { this.activeSpawns.map((pkmn) => { - if (pkmn.isExpired()) this.despawnPkmn(pkmn); + if (pkmn.isExpired() && !pkmn.isDespawned) { + pkmn.isDespawned = true; + setTimeout(() => { + this.despawnPkmn(pkmn); + }, (MAP_REFRESH_RATE * 1e3) * 2); + } }); } @@ -85,7 +94,7 @@ export default class SpawnPoint extends MapObject { maxExpire: this.maxExpire }); this.activeSpawns.push(pkmn); - print(`Spawned ${pkmn.getPkmnName()}:${pkmn.uid} at ${this.cellId}`); + print(`Spawned 1x ${pkmn.getPkmnName()}:${pkmn.uid} at ${this.cellId}`); } /** @@ -95,7 +104,7 @@ export default class SpawnPoint extends MapObject { let index = 0; this.activeSpawns.map((encounter) => { if (encounter.uid === pkmn.uid) { - print(`Killed 1x ${pkmn.getPkmnName()} at ${this.cellId}`, 33); + print(`Killed 1x ${pkmn.getPkmnName()}:${pkmn.uid} at ${this.cellId}`, 33); this.activeSpawns.splice(index, 1); } index++; diff --git a/src/models/World/players.js b/src/models/World/players.js index 406327b..edd2f92 100644 --- a/src/models/World/players.js +++ b/src/models/World/players.js @@ -102,7 +102,8 @@ export function validPlayerName(name) { name === null || name === void 0 || typeof name === "string" && - name.length <= 1 + name.length <= 3 || + name.length > 16 ); } @@ -123,7 +124,7 @@ export function playerIsRegistered(email) { */ export function registerPlayer(player) { return new Promise((resolve) => { - this.db.query(`INSERT INTO ${CFG.MYSQL_USERS_TABLE} SET email=? `, [player.email], (e, res) => { + this.db.query(`INSERT INTO ${CFG.MYSQL_USERS_TABLE} SET email=?, username=? `, [player.email, player.username], (e, res) => { if (e) return this.print(e, 31); resolve(); });