mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-04-03 15:55:09 -05:00
Update
- Added pokemon family enums - Stable candy bag - Pokemon candy support - Release pokemons, even from database and award candies
This commit is contained in:
parent
380f5d6f87
commit
f9832072ce
|
|
@ -6,6 +6,7 @@ export default {
|
|||
GENDER: proto.Enums.Gender,
|
||||
TUTORIAL: proto.Enums.TutorialState,
|
||||
POKEMON_IDS: proto.Enums.PokemonId,
|
||||
POKEMON_FAMILY: proto.Enums.PokemonFamilyId,
|
||||
getNameById: (emu, id) => {
|
||||
id <<= 0;
|
||||
for (let key in emu) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import { GAME_MASTER } from "../../../shared";
|
||||
|
||||
import ENUM from "../../../enum";
|
||||
|
||||
/**
|
||||
* @class CandyBag
|
||||
*/
|
||||
|
|
@ -19,12 +23,48 @@ export default class CandyBag {
|
|||
* @param {Number} dex
|
||||
* @return {Object}
|
||||
*/
|
||||
getCandyByDexNumber(dex) {
|
||||
getPkmnTemplate(dex) {
|
||||
let tmpl = GAME_MASTER.getPokemonTmplByDex(dex);
|
||||
return (tmpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} dex
|
||||
* @return {String}
|
||||
*/
|
||||
getPkmnFamily(dex) {
|
||||
return (
|
||||
this.candies[dex << 0] || null
|
||||
this.getPkmnTemplate(dex).family_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} dex
|
||||
* @return {Object}
|
||||
*/
|
||||
createCandy(dex) {
|
||||
let id = ENUM.getIdByName(ENUM.POKEMON_FAMILY, this.getPkmnFamily(dex << 0));
|
||||
let candy = {
|
||||
amount: 0
|
||||
};
|
||||
this.candies[id] = candy;
|
||||
return (candy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} dex
|
||||
* @return {Object}
|
||||
*/
|
||||
getCandyByDexNumber(dex) {
|
||||
let id = ENUM.getIdByName(ENUM.POKEMON_FAMILY, this.getPkmnFamily(dex << 0));
|
||||
if (this.candies[id] !== void 0) {
|
||||
return (this.candies[id]);
|
||||
}
|
||||
else {
|
||||
return (this.createCandy(id) || null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} dex
|
||||
* @return {Number}
|
||||
|
|
@ -41,7 +81,7 @@ export default class CandyBag {
|
|||
*/
|
||||
addCandy(dex, amount) {
|
||||
let candy = this.getCandyByDexNumber(dex);
|
||||
candy.amount += amount << 0;
|
||||
candy.amount += parseInt(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -50,24 +90,39 @@ export default class CandyBag {
|
|||
*/
|
||||
removeCandy(dex, amount) {
|
||||
let candy = this.getCandyByDexNumber(dex);
|
||||
candy.amount -= amount << 0;
|
||||
candy.amount -= parseInt(amount);
|
||||
if (candy.amount < 0) candy.amount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
* @return {Array}
|
||||
*/
|
||||
serialize() {
|
||||
return (
|
||||
JSON.stringify(this.candies)
|
||||
);
|
||||
let out = [];
|
||||
for (let key in this.candies) {
|
||||
let candy = this.candies[key];
|
||||
if (!(candy.amount > 0)) continue;
|
||||
out.push({
|
||||
modified_timestamp_ms: +new Date() - 1e3,
|
||||
inventory_item_data: {
|
||||
candy: {
|
||||
family_id: this.getPkmnFamily(key << 0),
|
||||
candy: candy.amount
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
return (out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} str
|
||||
*/
|
||||
parseJSON(str) {
|
||||
this.candies = JSON.parse(str);
|
||||
let candies = JSON.parse(str);
|
||||
for (let candy in candies) {
|
||||
this.createCandy(candy).amount = parseInt(candies[candy]);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -133,7 +133,9 @@ export default class Player extends MapObject {
|
|||
resolve(this.LevelUpRewards(msg));
|
||||
break;
|
||||
case "RELEASE_POKEMON":
|
||||
resolve(this.ReleasePokemon(msg));
|
||||
this.ReleasePokemon(msg).then((result) => {
|
||||
resolve(result);
|
||||
});
|
||||
break;
|
||||
case "GET_PLAYER_PROFILE":
|
||||
resolve(this.GetPlayerProfile(msg));
|
||||
|
|
@ -264,26 +266,26 @@ export default class Player extends MapObject {
|
|||
/**
|
||||
* @param {WildPokemon} pkmn
|
||||
* @param {String} ball
|
||||
* @return {Object}
|
||||
*/
|
||||
catchPkmn(pkmn, ball) {
|
||||
this.info.exp += 100;
|
||||
this.info.stardust += 100;
|
||||
this.info.pkmnCaptured += 1;
|
||||
this.currentEncounter = null;
|
||||
pkmn.owner = this;
|
||||
pkmn.calcStats();
|
||||
pkmn.catchedBy(this);
|
||||
pkmn.pokeball = ball;
|
||||
return new Promise((resolve) => {
|
||||
pkmn.owner = this;
|
||||
pkmn.calcStats();
|
||||
pkmn.insertIntoDatabase().then((insertId) => {
|
||||
print(insertId, 36);
|
||||
pkmn.uid = pkmn.insertId;
|
||||
let partyPkmn = this.party.addPkmn(pkmn);
|
||||
pkmn = this.party.addPkmn(pkmn);
|
||||
pkmn.owner = this;
|
||||
pkmn.uid = insertId;
|
||||
pkmn.addCandies(3);
|
||||
print(`${this.username} catched a wild ${pkmn.getPkmnName()}!`);
|
||||
resolve({
|
||||
status: "CATCH_SUCCESS",
|
||||
captured_pokemon_id: partyPkmn.uid,
|
||||
captured_pokemon_id: pkmn.uid,
|
||||
capture_award: {
|
||||
activity_type: ["ACTIVITY_CATCH_POKEMON"],
|
||||
xp: [100],
|
||||
|
|
@ -295,6 +297,19 @@ export default class Player extends MapObject {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {WildPokemon} pkmn
|
||||
*/
|
||||
releasePkmn(pkmn) {
|
||||
pkmn.addCandies(3);
|
||||
this.party.deletePkmn(pkmn.uid);
|
||||
return new Promise((resolve) => {
|
||||
pkmn.deleteFromDatabase().then(() => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inherit(Player, _packets);
|
||||
|
|
@ -9,12 +9,18 @@ export default function GetInventory(msg) {
|
|||
let items = this.bag.serialize();
|
||||
let stats = this.info.serialize();
|
||||
let party = this.party.serialize();
|
||||
let candies = this.candyBag.serialize();
|
||||
let currencies = this.currency.serialize();
|
||||
//let pokedex = this.pokedex.serialize();
|
||||
|
||||
items.push(stats);
|
||||
items.push(candies);
|
||||
items.push(currencies);
|
||||
|
||||
candies.map((candy) => {
|
||||
items.push(candy);
|
||||
});
|
||||
|
||||
party.map((pkmn) => {
|
||||
items.push(pkmn);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,22 +7,25 @@ import POGOProtos from "pokemongo-protobuf";
|
|||
export default function ReleasePokemon(msg) {
|
||||
|
||||
let buffer = null;
|
||||
let schema = "POGOProtos.Networking.Responses.ReleasePokemonResponse";
|
||||
|
||||
let pkmn = this.party.getPkmnById(msg.pokemon_id);
|
||||
|
||||
if (pkmn) {
|
||||
this.party.deletePkmn(pkmn.uid);
|
||||
buffer = {
|
||||
result: "SUCCESS",
|
||||
candy_awarded: 0
|
||||
};
|
||||
} else {
|
||||
buffer = {
|
||||
result: "FAILED"
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
POGOProtos.serialize(buffer, "POGOProtos.Networking.Responses.ReleasePokemonResponse")
|
||||
);
|
||||
return new Promise((resolve) => {
|
||||
if (pkmn) {
|
||||
this.releasePkmn(pkmn).then((result) => {
|
||||
buffer = {
|
||||
result: "SUCCESS",
|
||||
candy_awarded: 3
|
||||
};
|
||||
resolve(POGOProtos.serialize(buffer, schema));
|
||||
});
|
||||
} else {
|
||||
buffer = {
|
||||
result: "FAILED"
|
||||
};
|
||||
resolve(POGOProtos.serialize(buffer, schema));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import {
|
|||
import print from "../../print";
|
||||
|
||||
import CFG from "../../../cfg";
|
||||
import ENUM from "../../enum";
|
||||
|
||||
import * as _calc from "./calc";
|
||||
import * as _actions from "./action";
|
||||
|
|
@ -150,6 +151,25 @@ export default class Pokemon extends MapObject {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} dex
|
||||
* @return {String}
|
||||
*/
|
||||
getPkmnFamily(dex) {
|
||||
return (
|
||||
this.getPkmnTemplate(dex).family_id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} amount
|
||||
*/
|
||||
addCandies(amount) {
|
||||
let family = this.getPkmnFamily(this.dexNumber);
|
||||
let id = ENUM.getIdByName(ENUM.POKEMON_FAMILY, family) << 0;
|
||||
if (this.owner) this.owner.candyBag.addCandy(id, parseInt(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
|
@ -220,6 +240,16 @@ export default class Pokemon extends MapObject {
|
|||
});
|
||||
}
|
||||
|
||||
deleteFromDatabase() {
|
||||
let query = `DELETE FROM ${CFG.MYSQL_OWNED_PKMN_TABLE} WHERE id=? AND owner_id=? LIMIT 1`;
|
||||
return new Promise((resolve) => {
|
||||
this.owner.world.db.query(query, [this.uid, this.owner.uid], (e, res) => {
|
||||
if (e) return print(e, 31);
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Object}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ export default function CatchPokemon(msg) {
|
|||
player.bag[ball] -= 1;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
// Invalid pkmn
|
||||
if (!pkmn) {
|
||||
player.currentEncounter = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user