Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protosynthesis / Quark Drive Auto-Select & Override #546

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions calc/src/mechanics/gen789.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
isGrounded,
OF16, OF32,
pokeRound,
isQPActive,
} from './util';

export function calculateSMSSSV(
Expand Down Expand Up @@ -1266,14 +1267,10 @@ export function calculateAtModsSMSSSV(
}

if (
(attacker.hasAbility('Protosynthesis') &&
(field.hasWeather('Sun') || attacker.hasItem('Booster Energy'))) ||
(attacker.hasAbility('Quark Drive') &&
(field.hasTerrain('Electric') || attacker.hasItem('Booster Energy')))
(isQPActive(attacker, field))
) {
if (
(move.category === 'Physical' &&
getQPBoostedStat(attacker) === 'atk') ||
(move.category === 'Physical' && getQPBoostedStat(attacker) === 'atk') ||
(move.category === 'Special' && getQPBoostedStat(attacker) === 'spa')
) {
atMods.push(5325);
Expand Down Expand Up @@ -1421,10 +1418,7 @@ export function calculateDfModsSMSSSV(
}

if (
(defender.hasAbility('Protosynthesis') &&
(field.hasWeather('Sun') || attacker.hasItem('Booster Energy'))) ||
(defender.hasAbility('Quark Drive') &&
(field.hasTerrain('Electric') || attacker.hasItem('Booster Energy')))
(isQPActive(defender, field))
) {
if (
(hitsPhysical && getQPBoostedStat(defender) === 'def') ||
Expand Down
34 changes: 26 additions & 8 deletions calc/src/mechanics/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ export function getFinalSpeed(gen: Generation, pokemon: Pokemon, field: Field, s
speedMods.push(6144);
} else if (pokemon.hasAbility('Slow Start') && pokemon.abilityOn) {
speedMods.push(2048);
} else if (
getQPBoostedStat(pokemon, gen) === 'spe' &&
((pokemon.hasAbility('Protosynthesis') &&
(weather.includes('Sun') || pokemon.hasItem('Booster Energy'))) ||
(pokemon.hasAbility('Quark Drive') &&
(terrain === 'Electric' || pokemon.hasItem('Booster Energy'))))
) {
} else if (isQPActive(pokemon, field) && getQPBoostedStat(pokemon, gen) === 'spe') {
speedMods.push(6144);
}

Expand Down Expand Up @@ -413,7 +407,9 @@ export function getQPBoostedStat(
pokemon: Pokemon,
gen?: Generation
): StatID {
if (pokemon.boostedStat) return pokemon.boostedStat; // override.
if (pokemon.boostedStat && pokemon.boostedStat !== 'auto') {
return pokemon.boostedStat; // override.
}
let bestStat: StatID = 'atk';
for (const stat of ['def', 'spa', 'spd', 'spe'] as StatID[]) {
if (
Expand All @@ -427,6 +423,28 @@ export function getQPBoostedStat(
return bestStat;
}

export function isQPActive(
pokemon: Pokemon,
field: Field
): boolean {
if (!pokemon.boostedStat) {
return false;
}

const weather = field.weather || '';
const terrain = field.terrain;
if (
(pokemon.hasAbility('Protosynthesis') &&
(weather.includes('Sun') || pokemon.hasItem('Booster Energy'))) ||
(pokemon.hasAbility('Quark Drive') &&
(terrain === 'Electric' || pokemon.hasItem('Booster Energy'))) ||
(pokemon.boostedStat !== 'auto')
) {
return true;
}
return false;
}

export function getFinalDamage(
baseAmount: number,
i: number,
Expand Down
2 changes: 1 addition & 1 deletion calc/src/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Pokemon implements State.Pokemon {
dynamaxLevel?: number;
isSaltCure?: boolean;
alliesFainted?: number;
boostedStat?: I.StatIDExceptHP;
boostedStat?: I.StatIDExceptHP | 'auto';
item?: I.ItemName;
teraType?: I.TypeName;

Expand Down
2 changes: 1 addition & 1 deletion calc/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export namespace State {
dynamaxLevel?: number;
isSaltCure?: boolean;
alliesFainted?: number;
boostedStat?: I.StatIDExceptHP;
boostedStat?: I.StatIDExceptHP | 'auto';
item?: I.ItemName;
gender?: I.GenderName;
nature?: I.NatureName;
Expand Down
4 changes: 2 additions & 2 deletions calc/src/test/calc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,9 @@ describe('calc', () => {
});
function testQP(ability: string, field?: {weather?: Weather; terrain?: Terrain}) {
test(`${ability} should take into account boosted stats by default`, () => {
const attacker = Pokemon('Iron Leaves', {ability, boosts: {spa: 6}});
const attacker = Pokemon('Iron Leaves', {ability, boostedStat: 'auto', boosts: {spa: 6}});
// highest stat = defense
const defender = Pokemon('Iron Treads', {ability, boosts: {spd: 6}});
const defender = Pokemon('Iron Treads', {ability, boostedStat: 'auto', boosts: {spd: 6}});

let result = calculate(attacker, defender, Move('Leaf Storm'), Field(field)).rawDesc;
expect(result.attackerAbility).toBe(ability);
Expand Down
33 changes: 17 additions & 16 deletions src/honkalculate.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,23 @@
<label>Ability</label>
<select class="ability terrain-trigger"></select>
<input hidden type="checkbox" title= "Is this ability active?" class="abilityToggle">
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="">Auto-Select</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="auto">Auto-Select</option>
<option value="">Inactive</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>

</div>
<div class="gen-specific g2 g3 g4 g5 g6 g7 g8 g9">
Expand Down
66 changes: 34 additions & 32 deletions src/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -461,22 +461,23 @@
<label for="abilityL1">Ability</label>
<select class="ability terrain-trigger calc-trigger" id="abilityL1"></select>
<input hidden type="checkbox" title= "Is this ability active?" class="abilityToggle calc-trigger">
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="">Auto-Select</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="auto">Auto-Select</option>
<option value="">Inactive</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>
</div>
<div class="gen-specific g2 g3 g4 g5 g6 g7 g8 g9">
<label for="itemL1">Item</label>
Expand Down Expand Up @@ -1342,22 +1343,23 @@
<label for="abilityR1">Ability</label>
<select class="ability terrain-trigger calc-trigger" id="abilityR1"></select>
<input hidden type="checkbox" title= "Is this ability active?" class="abilityToggle calc-trigger">
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="">Auto-Select</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>
<select hidden aria-label="Allies fainted" class="alliesFainted calc-trigger">
<option value="0">Zero allies fainted</option>
<option value="1">One ally fainted</option>
<option value="2">Two allies fainted</option>
<option value="3">Three allies fainted</option>
<option value="4">Four allies fainted</option>
<option value="5">Five allies fainted</option>
</select>
<select hidden aria-label="Boosted Stat" title="What stat is boosted by this ability?" class="boostedStat calc-trigger">
<option value="auto">Auto-Select</option>
<option value="">Inactive</option>
<option value="atk">Attack</option>
<option value="def">Defense</option>
<option value="spa">Special Attack</option>
<option value="spd">Special Defense</option>
<option value="spe">Speed</option>
</select>
</div>
<div class="gen-specific g2 g3 g4 g5 g6 g7 g8 g9">
<label for="itemR1">Item</label>
Expand Down
44 changes: 41 additions & 3 deletions src/js/shared_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ $(".ability").bind("keyup change", function () {
} else {
$(this).closest(".poke-info").find(".abilityToggle").hide();
}

var boostedStat = $(this).closest(".poke-info").find(".boostedStat");
if (['Protosynthesis', 'Quark Drive'].indexOf(ability) >= 0) {

if (ability === "Protosynthesis" || ability === "Quark Drive") {
boostedStat.show();
autosetQP($(this).closest(".poke-info"));
} else {
boostedStat.hide();
}
Expand All @@ -267,9 +268,38 @@ $(".ability").bind("keyup change", function () {
}
});

function autosetQP(pokemon) {
var currentWeather = $("input:radio[name='weather']:checked").val();
var currentTerrain = $("input:checkbox[name='terrain']:checked").val() || "No terrain";

var item = pokemon.find(".item").val();
var ability = pokemon.find(".ability").val();
var boostedStat = pokemon.find(".boostedStat").val();

if (!boostedStat || boostedStat === "auto") {
if (
(item === "Booster Energy") ||
(ability === "Protosynthesis" && currentWeather === "Sun") ||
(ability === "Quark Drive" && currentTerrain === "Electric")
) {
pokemon.find(".boostedStat").val("auto");
} else {
pokemon.find(".boostedStat").val("");
}
}
}

$("#p1 .ability").bind("keyup change", function () {
autosetWeather($(this).val(), 0);
autosetTerrain($(this).val(), 0);
autosetQP($(this).closest(".poke-info"));
});

$("input[name='weather']").change(function () {
var allPokemon = $('.poke-info');
allPokemon.each(function () {
autosetQP($(this));
});
});

var lastManualWeather = "";
Expand Down Expand Up @@ -323,6 +353,13 @@ function autosetWeather(ability, i) {
}
}

$("input[name='terrain']").change(function () {
var allPokemon = $('.poke-info');
allPokemon.each(function () {
autosetQP($(this));
});
});

var lastManualTerrain = "";
var lastAutoTerrain = ["", ""];
function autosetTerrain(ability, i) {
Expand Down Expand Up @@ -475,6 +512,7 @@ $(".item").change(function () {
} else {
$metronomeControl.hide();
}
autosetQP($(this).closest(".poke-info"));
});

function smogonAnalysis(pokemonName) {
Expand All @@ -495,7 +533,7 @@ $(".set-selector").change(function () {
stickyMoves.clearStickyMove();
}
pokeObj.find(".teraToggle").prop("checked", isOgerponEmbody);
pokeObj.find(".boostedStat").val("Auto-Select");
pokeObj.find(".boostedStat").val("");
pokeObj.find(".analysis").attr("href", smogonAnalysis(pokemonName));
pokeObj.find(".type1").val(pokemon.types[0]);
pokeObj.find(".type2").val(pokemon.types[1]);
Expand Down
Loading