support tera
This commit is contained in:
parent
6aa1cac328
commit
2acbf9945c
2
bot.py
2
bot.py
@ -93,7 +93,7 @@ class BotClient(discord.Client):
|
||||
"Run Showdown damage calculations.\n"
|
||||
"Example format:\n"
|
||||
"` %calc -2 8 SpA Choice Specs Torkoal Overheat vs. 252 HP / 4+ SpD Assault Vest Abomasnow in Sun through Light Screen`\n"
|
||||
"Supported: attacker/defender boosts, EVs, item, species; attacker ability; weather/terrain; screens."
|
||||
"Supported: attacker/defender boosts, EVs, tera, item, species; attacker ability; weather/terrain; screens."
|
||||
)
|
||||
|
||||
async def _calculate(self, args: list[str]) -> str:
|
||||
|
25
calc.js
25
calc.js
@ -74,6 +74,19 @@ function buildLexer() {
|
||||
pattern: /vs\.?/,
|
||||
});
|
||||
|
||||
const teraEnter = createToken({
|
||||
name: "teraEnter",
|
||||
pattern: "Tera",
|
||||
push_mode: "tera_mode",
|
||||
});
|
||||
const Tera = createToken({
|
||||
name: "Tera",
|
||||
pattern: new RegExp(
|
||||
[...gen.types].map((t) => escapeRegExp(t.name)).join("|")
|
||||
),
|
||||
pop_mode: true,
|
||||
});
|
||||
|
||||
const terrainEnter = createToken({
|
||||
name: "terrainEnter",
|
||||
pattern: "in",
|
||||
@ -109,9 +122,11 @@ function buildLexer() {
|
||||
Ability,
|
||||
Pokemon,
|
||||
Move,
|
||||
teraEnter,
|
||||
terrainEnter,
|
||||
screenEnter,
|
||||
],
|
||||
tera_mode: [whitespace, Tera],
|
||||
terrain_mode: [whitespace, Weather, Terrain],
|
||||
screen_mode: [whitespace, Move],
|
||||
},
|
||||
@ -229,8 +244,6 @@ function parseAndCalculate(line) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Stat":
|
||||
throw Error("Impossible state: bare Stat");
|
||||
case "Item":
|
||||
opts().item = unwrapToken("Item", item);
|
||||
break;
|
||||
@ -247,6 +260,9 @@ function parseAndCalculate(line) {
|
||||
case "Move":
|
||||
move = unwrapToken("Move", item);
|
||||
break;
|
||||
case "teraEnter":
|
||||
opts().teraType = unwrapToken("Tera", it.next().value);
|
||||
break;
|
||||
case "terrainEnter":
|
||||
{
|
||||
let next = it.next().value;
|
||||
@ -302,7 +318,7 @@ function parseAndCalculate(line) {
|
||||
function test() {
|
||||
const text =
|
||||
"-2 8 SpA Choice Specs Torkoal Overheat vs. 252 HP / 4+ SpD Assault Vest Abomasnow in Sun through Light Screen";
|
||||
const res = parseAndCalculate(text);
|
||||
var res = parseAndCalculate(text);
|
||||
|
||||
assert(res.attacker.boosts.spa === -2, "should have -2 SpA");
|
||||
assert(res.attacker.evs.spa === 8, "should have 8 SpA EVs");
|
||||
@ -317,6 +333,9 @@ function test() {
|
||||
res.desc().replace(/:.*/, "") === text,
|
||||
"non-damage text should be equivalent to input"
|
||||
);
|
||||
|
||||
res = parseAndCalculate("Tera Electric Iron Hands Wild Charge vs Basculin");
|
||||
assert(res.attacker.teraType === "Electric", "should parse tera type");
|
||||
}
|
||||
|
||||
export { parseAndCalculate, test };
|
||||
|
Loading…
Reference in New Issue
Block a user