From 2acbf9945ce975ed91d30456e854d679cb36db25 Mon Sep 17 00:00:00 2001 From: xeals Date: Thu, 27 Apr 2023 11:58:24 +1000 Subject: [PATCH] support tera --- bot.py | 2 +- calc.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 578d47b..8207622 100755 --- a/bot.py +++ b/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: diff --git a/calc.js b/calc.js index 3dcfdd2..6c4fcba 100644 --- a/calc.js +++ b/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 };