- Show error, if got api request but api is disabled in cfg
- Various pokemon related calculations
- Extended candybag
This commit is contained in:
Felix 2016-09-04 14:15:52 +02:00
parent 034543036a
commit 5bc210b351
5 changed files with 263 additions and 10 deletions

View File

@ -15,6 +15,10 @@ export default class CandyBag {
}
/**
* @param {Number} dex
* @return {Object}
*/
getCandyByDexNumber(dex) {
let candies = this.candies;
@ -32,6 +36,35 @@ export default class CandyBag {
}
/**
* @param {Number} dex
* @return {Number}
*/
getCandy(dex) {
return (
this.getCandyByDexNumber(dex) || 0
);
}
/**
* @param {Number} dex
* @param {Number} amount
*/
addCandy(dex, amount) {
let candy = this.getCandyByDexNumber(dex);
candy.amount += amount << 0;
}
/**
* @param {Number} dex
* @param {Number} amount
*/
removeCandy(dex, amount) {
let candy = this.getCandyByDexNumber(dex);
candy.amount -= amount << 0;
if (candy.amount < 0) candy.amount = 0;
}
/**
* @param {String} str
*/

View File

@ -0,0 +1,91 @@
import Settings from "../../modes";
export function calcStats() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
let stats = pkmnTmpl.stats;
let minIV = Settings.PKMN_SETTINGS.MIN_IV;
let maxIV = Settings.PKMN_SETTINGS.MAX_IV;
this.attack = stats.base_attack;
this.defense = stats.base_defense;
this.stamina = stats.base_stamina;
this.ivAttack = (Math.random() * maxIV) << 0 + minIV;
this.ivDefense = (Math.random() * maxIV) << 0 + minIV;
this.ivStamina = (Math.random() * maxIV) << 0 + minIV;
this.height = pkmnTmpl.pokedex_height_m + ((Math.random() * pkmnTmpl.height_std_dev) + .1);
this.weight = pkmnTmpl.pokedex_weight_kg + ((Math.random() * pkmnTmpl.weight_std_dev) + .1);
}
export function calcMoves() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
let weakMoves = pkmnTmpl.quick_moves;
let strongMoves = pkmnTmpl.cinematic_moves;
this.move1 = weakMoves[(Math.random() * weakMoves.length) << 0 + 1];
this.move2 = strongMoves[(Math.random() * strongMoves.length) << 0 + 1];
}
/**
* @return {Number}
*/
export function calcCP() {
let ecpm = this.getEffectiveCpMultiplier();
let baseAtk = this.attack;
let baseDef = this.defense;
let baseSta = this.stamina;
let ivAtk = this.ivAttack;
let ivDef = this.ivDefense;
let ivSta = this.ivStamina;
return (
Math.floor(
(baseAtk + ivAtk) *
Math.pow(baseDef + ivDef, 0.5) *
Math.pow(baseSta + ivSta, 0.5) *
Math.pow(ecpm, 2) /
10
)
);
}
/**
* @return {Array}
*/
export function getCpMultipliers() {
return (
this.owner.info.getLevelSettings().cp_multiplier
);
}
/**
* @return {Number}
*/
export function getEffectiveCpMultiplier() {
if (!Number.isInteger(this.level / 2)) {
return (this.getHalfLevelCpMultiplier());
}
return (this.getCpMultipliers()[this.level / 2]);
}
/**
* @param {Number} lvl
* @return {Number}
*/
export function getHalfLevelCpMultiplier(lvl) {
let next = this.getCpMultipliers()[lvl + 1];
return (
Math.sqrt(Math.pow(lvl, 2) + ((Math.pow(next, 2) - Math.pow(lvl, 2)) / 2))
);
}

View File

@ -4,11 +4,14 @@ import { GAME_MASTER } from "../../shared";
import {
_toCC,
inherit,
validName
} from "../../utils";
import print from "../../print";
import * as _calc from "./calc";
const pokename = require("pokename")();
/**
@ -30,19 +33,18 @@ export default class Pokemon extends MapObject {
this.owner = null;
this.level = 0;
this.capturedLevel = 0;
this.cp = 0;
this.cpMultiplier = 0;
this.addCpMultiplier = 0;
this.stamina = 0;
this.staminaMax = 0;
this.move1 = 0;
this.move2 = 0;
this.attack = 0;
this.defence = 0;
this.defense = 0;
this.stamina = 0;
this.height = 0;
this.weight = 0;
@ -51,6 +53,8 @@ export default class Pokemon extends MapObject {
this.ivDefense = 0;
this.ivStamina = 0;
this.staminaMax = 0;
this.nickname = null;
this.pokeball = null;
@ -59,7 +63,11 @@ export default class Pokemon extends MapObject {
this.init(obj);
this.evolvePkmn();
this.calcStats();
this.calcMoves();
this.powerUp();
this.evolve();
}
@ -108,11 +116,40 @@ export default class Pokemon extends MapObject {
);
}
evolvePkmn() {
/**
* @return {Boolean}
*/
hasEvolution() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
return (
pkmnTmpl.evolution_ids.length >= 1
);
}
/**
* @return {Number}
*/
getCandiesToEvolve() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
return (pkmnTmpl.candy_to_evolve << 0);
}
powerUp() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
let ownerStardust = this.owner.info.stardust;
let ownerPkmnCandies = this.owner.candyBag.getCandy(this.dexNumber);
let requiredCandies = this.getCandiesToEvolve();
let requiredStardust = this.xxx();
}
evolve() {
let pkmnTmpl = this.getPkmnTemplate(this.dexNumber);
let ownerPkmnCandies = this.owner.candyBag.getCandy(this.dexNumber);
if (ownerPkmnCandies < this.getCandiesToEvolve()) return void 0;
let evolutions = pkmnTmpl.evolution_ids;
if (evolutions.length <= 1) {
if (this.hasEvolution() && evolutions.length <= 1) {
this.evolveInto(evolutions[0]);
this.owner.candyBag.removeCandy(this.dexNumber, pkmnTmpl.candy_to_evolve);
}
else {
print(`Evolving this pokemon isnt supported yet!`, 31);
@ -127,7 +164,7 @@ export default class Pokemon extends MapObject {
let evId = pokename.getPokemonIdByName(evName);
if (evId <= 0) return print(`Failed at retrieving id for pokemon ${ev}`, 31);
let evTmpl = this.getPkmnTemplate(evId);
print(`${this.owner.username} successfully evolved ${this.getPkmnName()} to ${evName}`);
print(`${this.owner.username} successfully evolved ${this.getPkmnName()} into ${evName}`);
}
/**
@ -164,4 +201,6 @@ export default class Pokemon extends MapObject {
});
}
}
}
inherit(Pokemon, _calc);

View File

@ -27,5 +27,92 @@ export default {
base_eggs: 9
},
minimum_client_version: CFG.MINIMUM_CLIENT_VERSION
},
PKMN_SETTINGS: {
MIN_IV: 1,
MAX_IV: 15,
POWER_UP_PRICE: [
{
dust: 200,
candy: 1,
pkmnLevel: [1, 1.5, 2, 2.5]
}, {
dust: 400,
candy: 1,
pkmnLevel: [3, 3.5, 4, 4.5]
}, {
dust: 600,
candy: 1,
pkmnLevel: [5, 5.5, 6, 6.5]
}, {
dust: 800,
candy: 1,
pkmnLevel: [7, 7.5, 8, 8.5]
}, {
dust: 1000,
candy: 1,
pkmnLevel: [9, 9.5, 10, 10.5]
}, {
dust: 1300,
candy: 2,
pkmnLevel: [11, 11.5, 12, 12.5]
}, {
dust: 1600,
candy: 2,
pkmnLevel: [13, 13.5, 14, 14.5]
}, {
dust: 1900,
candy: 2,
pkmnLevel: [15, 15.5, 16, 16.5]
}, {
dust: 2200,
candy: 2,
pkmnLevel: [17, 17.5, 18, 18.5]
}, {
dust: 2500,
candy: 2,
pkmnLevel: [19, 19.5, 20, 20.5]
}, {
dust: 3000,
candy: 3,
pkmnLevel: [21, 21.5, 22, 22.5]
}, {
dust: 3500,
candy: 3,
pkmnLevel: [23, 23.5, 24, 24.5]
}, {
dust: 4000,
candy: 3,
pkmnLevel: [25, 25.5, 26, 26.5]
}, {
dust: 4500,
candy: 3,
pkmnLevel: [27, 27.5, 28, 28.5]
}, {
dust: 5000,
candy: 3,
pkmnLevel: [29, 29.5, 30, 30.5]
}, {
dust: 6000,
candy: 4,
pkmnLevel: [31, 31.5, 32, 32.5]
}, {
dust: 7000,
candy: 4,
pkmnLevel: [33, 33.5, 34, 34.5]
}, {
dust: 8000,
candy: 4,
pkmnLevel: [35, 35.5, 36, 36.5]
}, {
dust: 9000,
candy: 4,
pkmnLevel: [37, 37.5, 38, 38.5]
}, {
dust: 10000,
candy: 4,
pkmnLevel: [39, 39.5, 40, 40.5]
}
]
}
}

View File

@ -27,7 +27,10 @@ export function routeRequest(req, res) {
this.processModelRequest(req, res, route);
break;
case "api":
if (!CFG.ENABLE_API) return void 0;
if (!CFG.ENABLE_API) {
print(`API is disabled! Denied API access for ${host}!`, 31);
return void 0;
}
if (req.method === "POST") {
this.processApiCall(req, res, route);
}