Now for something that 95% of Smogon's users won't care at all about but maybe some of my fellow sweaty nerds in this forum will appreciate!
tl;dr There is an API for Pokemon damage calculations at
https://calc-api.herokuapp.com/calc-api
The Backstory
Basically, TheFenderStory and I have been working on various technical projects which required damage calculations run and we realized that we were kind of writing the same tedious code over and over again, and that often running such a complicated group of checks and calculations over and over was probably suboptimal. We realized that an efficient way to solve the problem was an external API for Pokemon damage calculation.
What it is
This API allows you to post a request which contains two Pokemon's movesets and a move (in the format given below), and it will run the damage calculation and return some information about how much damage the move will do. The code is basically just a modified, condensed version of the Pokemon Showdown! Damage Calculator which we all know and love, so most of the credit should go to Austin and the other contributors.
How to use it
Easy! Just make a post method to the URL below. Example implementation with JQuery (obviously this request can be made in all sorts of ways):
Both attacker and defender object should look something like this:
The response comes in two parts. The first is data, which will be in an object like this:
The second part is the status, which will either be "success", or an error code (404, 502, etc).
What is missing
There's a few things that I would love to add that don't really work at the moment
What this means
I hope that some of you will try and use this calculator api for code projects. Some general ideas that could use it:
This is my first attempt (and to my knowledge, Fender's too) at making something like this, so please let me know if there are any issues, or anything you'd like to see added!
tl;dr There is an API for Pokemon damage calculations at
https://calc-api.herokuapp.com/calc-api
The Backstory
Basically, TheFenderStory and I have been working on various technical projects which required damage calculations run and we realized that we were kind of writing the same tedious code over and over again, and that often running such a complicated group of checks and calculations over and over was probably suboptimal. We realized that an efficient way to solve the problem was an external API for Pokemon damage calculation.
What it is
This API allows you to post a request which contains two Pokemon's movesets and a move (in the format given below), and it will run the damage calculation and return some information about how much damage the move will do. The code is basically just a modified, condensed version of the Pokemon Showdown! Damage Calculator which we all know and love, so most of the credit should go to Austin and the other contributors.
How to use it
Easy! Just make a post method to the URL below. Example implementation with JQuery (obviously this request can be made in all sorts of ways):
Code:
$.post("https://calc-api.herokuapp.com/calc-api", {
attacker: attackerObject,
defender: defenderObject,
move: "Leaf Storm",
},
function (data, status) {
//Do something with the data
});
Code:
attackerObject = {
"species": "Serperior", //species name AS IT IS IN THE POKEDEX [REQUIRED]
"ability": "Contrary", //ability [REQUIRED]
"item": "Leftovers", //item [REQUIRED]
"level": 100, //level [REQUIRED], must be a number
"nature": "Modest", //not required, defaults to serious
"evs": {"spa": 252, "spe": 252}, //not required, defaults to 0 in all stats. Valid stats are "hp", "atk", "spa", "def", "spd", "spe"
"ivs": {"atk": 0} //not required, defaults to 31 in any stat not specified
}
Code:
{
"damage": Array[16], //All 16 possible damage rolls, in exact HP numbers
"description": String, //the description of the calc, e.g. '0+ SpA Serperior Leaf Storm vs. 116 HP / 76 SpD Eviolite Vullaby'
"kochance": String, //the calculated KO chance as a string, e.g. 'guaranteed 3HKO'
"min": Number, //minimum damage percentage as a number, e.g. '16.4'
"max": Number //maximum damage percentage as a number, e.g. '31.2'
}
What is missing
There's a few things that I would love to add that don't really work at the moment
- Multi-hit moves are more complicated, and at the moment just assume a single hit or else don't return any damage at all, which is obviously suboptimal
- Z-moves don't work
- Open-source: at the moment this code is not open-source. I will work on cleaning it up to the point where we can release it publicly someday (tm).
What this means
I hope that some of you will try and use this calculator api for code projects. Some general ideas that could use it:
- Damage calculator bot as a quick way to calc damages in game
- bRMT bot that can rate teams by pushing lots of requests through the api to calculate how a team fares against various metagame threats
- Something that analyzes EV spreads for whether they are optimal...?
This is my first attempt (and to my knowledge, Fender's too) at making something like this, so please let me know if there are any issues, or anything you'd like to see added!