Skip to content

Commit

Permalink
"fix" stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisXV committed Jan 5, 2023
1 parent 7d8e97d commit bacfa1f
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 102 deletions.
8 changes: 5 additions & 3 deletions calc/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const exports = {};
`;
bundled += bundler.read('util.js', 3, 1);
const species = bundler.read('data/species.js').split('\n');
bundled += species.slice(1, 64).join('\n'); // generator + iterator + spreadArray polyfill
bundled += species.slice(1, 39).join('\n'); // generator + iterator polyfill
bundled += '\nvar e_1, _a, e_2, _b;\nvar util_1 = exports;\n';
bundled += species.slice(68, -2).join('\n');
bundled += species.slice(43, -2).join('\n');

const types = bundler.read('data/types.js').split('\n');
bundled += types.slice(1, 12).join('\n'); // __assign polyfill
Expand All @@ -25,7 +25,9 @@ bundled += natures.slice(28, 44).join('\n'); // __read polyfill
bundled += natures.slice(47, -2).join('\n');
bundled += bundler.read('data/abilities.js', 43, 1);
bundled += bundler.read('data/moves.js', 43, 1);
bundled += bundler.read('data/items.js', 68, 1);
const items = bundler.read('data/items.js').split('\n');
bundled += items.slice(44, 53).join('\n'); // __spreadArray polyfill
bundled += items.slice(68, -2).join('\n');
bundled += `
var abilities_1 = exports;
var items_1 = exports;
Expand Down
1 change: 1 addition & 0 deletions calc/src/data/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export interface Specie extends Data<SpeciesName> {
readonly nfe?: boolean;
readonly gender?: GenderName;
readonly otherFormes?: SpeciesName[];
readonly canGigantamax?: MoveName;
readonly baseSpecies?: SpeciesName;
readonly abilities?: {0: AbilityName | ''};
}
Expand Down
4 changes: 4 additions & 0 deletions calc/src/data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4750,6 +4750,10 @@ const SV_PATCH: {[name: string]: DeepPartial<MoveData>} = {

const SV: {[name: string]: MoveData} = extend(true, {}, SS, SV_PATCH);

for (const moveName in SV) {
if (moveName.startsWith('G-Max')) delete SV[moveName];
}

export const MOVES = [{}, RBY, GSC, ADV, DPP, BW, XY, SM, SS, SV];

export class Moves implements I.Moves {
Expand Down
26 changes: 16 additions & 10 deletions calc/src/data/species.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7513,6 +7513,7 @@ const SS_PATCH: {[name: string]: DeepPartial<SpeciesData>} = {
Kingler: {canGigantamax: "G-Max Foam Burst"},
Lapras: {canGigantamax: "G-Max Resonance"},
Linoone: {otherFormes: ['Linoone-Galar']},
Machamp: {canGigantamax: "G-Max Chi-Strike"},
Magearna: {otherFormes: ["Magearna-Original"]},
Melmetal: {canGigantamax: "G-Max Meltdown"},
Meowth: {canGigantamax: "G-Max Gold Rush", otherFormes: ['Meowth-Alola', 'Meowth-Galar']},
Expand Down Expand Up @@ -8511,6 +8512,12 @@ const SS_PATCH: {[name: string]: DeepPartial<SpeciesData>} = {

const SS: {[name: string]: SpeciesData} = extend(true, {}, SM, SS_PATCH);

for (const speciesName in SS) {
if (SS[speciesName].canGigantamax) {
SS[speciesName + '-Gmax'] = SS[speciesName];
}
}

delete SS['Pikachu-Starter'];
delete SS['Eevee-Starter'];

Expand Down Expand Up @@ -9520,6 +9527,13 @@ const SV_PATCH: {[name: string]: DeepPartial<SpeciesData>} = {

const SV: {[name: string]: SpeciesData} = extend(true, {}, SS, SV_PATCH, PLA_PATCH);

for (const speciesName in SV) {
if (SV[speciesName].canGigantamax) {
// @ts-ignore readonly
delete SV[speciesName].canGigantamax;
}
}

export const SPECIES = [{}, RBY, GSC, ADV, DPP, BW, XY, SM, SS, SV];

export class Species implements I.Species {
Expand Down Expand Up @@ -9550,10 +9564,11 @@ class Specie implements I.Specie {
readonly nfe?: boolean;
readonly gender?: I.GenderName;
readonly otherFormes?: I.SpeciesName[];
readonly canGigantamax?: I.MoveName;
readonly baseSpecies?: I.SpeciesName;
readonly abilities?: {0: I.AbilityName}; // ability

private static readonly EXCLUDE = new Set(['bs', 'otherFormes']);
private static readonly EXCLUDE = new Set(['bs']);

constructor(name: string, data: SpeciesData) {
this.kind = 'Species';
Expand All @@ -9568,15 +9583,6 @@ class Specie implements I.Specie {
baseStats.spd = gen >= 2 ? data.bs.sd : data.bs.sl;
baseStats.spe = data.bs.sp;
this.baseStats = baseStats as I.StatsTable;
// Hack for getting Gmax pokemon out of existence in Gen 9+
if (data.otherFormes) {
this.otherFormes = data.otherFormes as I.SpeciesName[];
if (gen >= 9 && !['toxtricity', 'urshifu'].includes(this.id)) {
this.otherFormes = this.otherFormes.filter(f => !f.endsWith('-Gmax'));
if (!this.otherFormes.length) this.otherFormes = undefined;
if (this.otherFormes) this.otherFormes = [...new Set(this.otherFormes)];
}
}

assignWithout(this, data, Specie.EXCLUDE);
}
Expand Down
9 changes: 3 additions & 6 deletions calc/src/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Move implements State.Move {
item?: I.ItemName;
species?: I.SpeciesName;
useZ?: boolean;
useMax?: boolean;
useMax?: 'gmax' | boolean;
isGmax?: boolean;
overrides?: Partial<I.Move>;

Expand Down Expand Up @@ -64,7 +64,7 @@ export class Move implements State.Move {
options.species,
!!(data.category === 'Status'),
options.ability,
options.isGmax
!!(options.useMax === 'gmax')
);
const maxMove = gen.moves.get(toID(maxMoveName));
const maxPower = () => {
Expand Down Expand Up @@ -112,7 +112,6 @@ export class Move implements State.Move {
this.item = options.item;
this.useZ = options.useZ;
this.useMax = options.useMax;
this.isGmax = options.useMax;
this.overrides = options.overrides;
this.species = options.species;

Expand Down Expand Up @@ -178,7 +177,6 @@ export class Move implements State.Move {
species: this.species,
useZ: this.useZ,
useMax: this.useMax,
isGmax: this.isGmax,
isCrit: this.isCrit,
hits: this.hits,
timesUsed: this.timesUsed,
Expand Down Expand Up @@ -272,8 +270,7 @@ export function getMaxMoveName(
}
if (moveType === 'Electric') {
if (pokemonSpecies === 'Pikachu' && isGmax) return 'G-Max Volt Crash';
if (pokemonSpecies?.startsWith('Toxtricity') &&
pokemonSpecies?.endsWith('Gmax')) return 'G-Max Stun Shock';
if (pokemonSpecies?.startsWith('Toxtricity') && isGmax) return 'G-Max Stun Shock';
}
if (moveType === 'Grass') {
if (pokemonSpecies === 'Appletun' && isGmax) return 'G-Max Sweetness';
Expand Down
8 changes: 1 addition & 7 deletions calc/src/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export class Pokemon implements State.Pokemon {
this.gen = gen;
this.name = options.name || name as I.SpeciesName;
this.types = this.species.types;
this.weightkg = this.species.weightkg;

this.level = options.level || 100;
this.gender = options.gender || this.species.gender || 'M';
this.ability = options.ability || this.species.abilities?.[0] || undefined;
this.abilityOn = !!options.abilityOn;

this.isDynamaxed = !!options.isDynamaxed;
this.weightkg = this.isDynamaxed ? 0 : this.species.weightkg;
this.isSaltCure = !!options.isSaltCure;
this.alliesFainted = options.alliesFainted;
this.teraType = options.teraType;
Expand All @@ -70,12 +70,6 @@ export class Pokemon implements State.Pokemon {
this.evs = Pokemon.withDefault(gen, options.evs, gen.num >= 3 ? 0 : 252);
this.boosts = Pokemon.withDefault(gen, options.boosts, 0, false);

// Gigantamax 'forms' inherit weight from their base species when not dynamaxed
// TODO: clean this up with proper Gigantamax support
if (this.weightkg === 0 && !this.isDynamaxed && this.species.baseSpecies) {
this.weightkg = gen.species.get(toID(this.species.baseSpecies))!.weightkg;
}

if (gen.num < 3) {
this.ivs.hp = Stats.DVToIV(
Stats.getHPDV({
Expand Down
3 changes: 1 addition & 2 deletions calc/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export namespace State {
export interface Move {
name: I.MoveName;
useZ?: boolean;
useMax?: boolean;
isGmax?: boolean;
useMax?: 'gmax' | boolean;
isCrit?: boolean;
hits?: number;
timesUsed?: number;
Expand Down
2 changes: 2 additions & 0 deletions calc/src/test/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class Specie implements I.Specie {
readonly weightkg: number;
readonly nfe?: boolean;
readonly gender?: I.GenderName;
readonly canGigantamax?: I.MoveName;
readonly otherFormes?: I.SpeciesName[];
readonly baseSpecies?: I.SpeciesName;
readonly abilities?: {0: I.AbilityName};
Expand Down Expand Up @@ -329,6 +330,7 @@ class Specie implements I.Specie {
} else if (species.baseSpecies !== this.name) {
this.baseSpecies = species.baseSpecies as I.SpeciesName;
}
if (species.canGigantamax) this.canGigantamax = species.canGigantamax;

if (dex.gen > 2) this.abilities = {0: species.abilities[0] as I.AbilityName};
}
Expand Down
23 changes: 14 additions & 9 deletions src/honkalculate.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,20 @@
<label>Current HP</label>
<input class="current-hp" value="341" />/<span class="max-hp">341</span> (
<input class="percent-hp" value="100" />%)
<<<<<<< HEAD
<input class="max calc-trigger btn-input" type="checkbox" id="maxL" /><label class="btn btn-wide gen-specific g8 g9" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
=======
<br />
<input class="max calc-trigger btn-input" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
<input class="gmax calc-trigger btn-input" type="checkbox" id="gmaxL" />
<label class="btn btn-xwide gen-specific g8" for="gmaxL" title="Use the G-Max forme instead?">Gigantamax</label>
>>>>>>> Implement Gigantamaxing properly
<div class="dynamaxOnly">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8 hide" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
</div>
<div class="dynamaxAndGigantamax">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8 hide" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
<input class="gmax calc-trigger" type="checkbox" id="gmaxL" />
<label class="gen-specific g8 hide" for="gmaxL" title="Use the G-Max forme instead?">Gigantamax</label>
</div>
<br />
<br />
Health <div class="hpbar"></div>
Expand Down
54 changes: 28 additions & 26 deletions src/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,20 @@
<label for="currentHpL1">Current HP</label>
<input class="current-hp calc-trigger" id="currentHpL1" value="341" />/<span class="max-hp">341</span> (
<input class="percent-hp calc-trigger" value="100" />%)
<<<<<<< HEAD
<input class="visually-hidden max calc-trigger btn-input" type="checkbox" id="maxL" />
<label class="btn btn-xwide gen-specific g8 hide" for="maxL"
title="Use the corresponding Max Move?">Dynamax</label>
<br />
=======
<br />
<input class="visually-hidden max calc-trigger btn-input" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
<input class="visually-hidden gmax calc-trigger btn-input" type="checkbox" id="gmaxL" />
<label class="btn btn-xwide gen-specific g8" for="gmaxL" title="Use the G-Max forme instead?">Gigantamax</label>
<br />
>>>>>>> Implement Gigantamaxing properly
<div class="dynamaxOnly">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8 hide" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
</div>
<div class="dynamaxAndGigantamax">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxL" />
<label class="btn btn-wide gen-specific g8 hide" for="maxL" title="Use the corresponding Max Move?">Dynamax</label>
<input class="gmax calc-trigger" type="checkbox" id="gmaxL" />
<label class="gen-specific g8 hide" for="gmaxL" title="Use the G-Max forme instead?">Gigantamax</label>
</div>
<br />
Health <div class="hpbar"></div>
</div>
Expand Down Expand Up @@ -1389,19 +1390,20 @@
<label for="currentHpR1">Current HP</label>
<input class="current-hp calc-trigger" id="currentHpR1" value="341" />/<span class="max-hp">341</span> (
<input class="percent-hp calc-trigger" value="100" />%)
<<<<<<< HEAD
<input class="visually-hidden max calc-trigger btn-input" type="checkbox" id="maxR" />
<label class="btn btn-xwide gen-specific g8 hide" for="maxR"
title="Use the corresponding Max Move?">Dynamax</label>
<br />
=======
<br />
<input class="visually-hidden max calc-trigger btn-input" type="checkbox" id="maxR" />
<label class="btn btn-wide gen-specific g8" for="maxR" title="Use the corresponding Max Move?">Dynamax</label>
<input class="visually-hidden gmax calc-trigger btn-input" type="checkbox" id="gmaxR" />
<label class="btn btn-xwide gen-specific g8" for="gmaxR" title="Use the G-Max forme instead?">Gigantamax</label>
<br />
>>>>>>> Implement Gigantamaxing properly
<div class="dynamaxOnly">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxR" />
<label class="btn btn-wide gen-specific g8 hide" for="maxR" title="Use the corresponding Max Move?">Dynamax</label>
</div>
<div class="dynamaxAndGigantamax">
<br />
<br />
<input class="visually-hidden max calc-trigger" type="checkbox" id="maxR" />
<label class="btn btn-wide gen-specific g8 hide" for="maxR" title="Use the corresponding Max Move?">Dynamax</label>
<input class="gmax calc-trigger" type="checkbox" id="gmaxR" />
<label class="gen-specific g8 hide" for="gmaxR" title="Use the G-Max forme instead?">Gigantamax</label>
</div>
<br />
Health <div class="hpbar"></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/js/moveset_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function ExportPokemon(pokeInfo) {
finalText += pokemon.nature && gen > 2 ? pokemon.nature + " Nature" + "\n" : "";
finalText += pokemon.teraType && gen > 8 ? "Tera Type: " + pokemon.teraType : "";
finalText += pokemon.ability ? "Ability: " + pokemon.ability + "\n" : "";
finalText += pokemon.isGigantamaxed ? "Gigantamax: Yes\n" : "";
finalText += pokemon.isDynamaxed === 'gmax' ? "Gigantamax: Yes\n" : "";
if (gen > 2) {
var EVs_Array = [];
for (var stat in pokemon.evs) {
Expand Down
38 changes: 26 additions & 12 deletions src/js/shared_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ $(".set-selector").change(function () {
} else {
formeObj.hide();
}
if (gen === 8) {
if (pokemon.canGigantamax) {
$(this).closest('.poke-info').find('.dynamaxOnly').hide();
$(this).closest('.poke-info').find('.dynamaxAndGigantamax').show();
} else {
$(this).closest('.poke-info').find('.dynamaxOnly').show();
$(this).closest('.poke-info').find('.dynamaxAndGigantamax').hide();
}
} else {
$(this).closest('.poke-info').find('.dynamaxOnly').hide();
$(this).closest('.poke-info').find('.dynamaxAndGigantamax').hide();
}
calcHP(pokeObj);
calcStats(pokeObj);
abilityObj.change();
Expand Down Expand Up @@ -838,15 +850,17 @@ function createPokemon(pokeInfo) {
var ability = pokeInfo.find(".ability").val();
var item = pokeInfo.find(".item").val();
var isDynamaxed = pokeInfo.find(".max").prop("checked");
var isGigantamaxed = isDynamaxed && pokeInfo.find(".gmax").prop("checked");
var isGigantamaxed = pokeInfo.find(".gmax").prop("checked");
if (isGigantamaxed) {
pokeInfo.find(".max").prop("checked", true);
isDynamaxed = pokeInfo.find(".max").prop("checked");
}
var teraType = pokeInfo.find(".teraToggle").is(":checked") ? pokeInfo.find(".teraType").val() : undefined;
pokeInfo.isDynamaxed = isDynamaxed;
pokeInfo.isGigantamaxed = isGigantamaxed;
if (pokeInfo.isGigantamaxed) pokeInfo.isDynamaxed = true;
pokeInfo.isDynamaxed = isGigantamaxed ? 'gmax' : !!isDynamaxed;
calcHP(pokeInfo);
var curHP = ~~pokeInfo.find(".current-hp").val();
// FIXME the Pokemon constructor expects non-dynamaxed HP
if (isDynamaxed || isGigantamaxed) curHP = Math.floor(curHP / 2);
if (pokeInfo.isDynamaxed) curHP = Math.floor(curHP / 2);
var types = [pokeInfo.find(".type1").val(), pokeInfo.find(".type2").val()];
return new calc.Pokemon(gen, name, {
level: ~~pokeInfo.find(".level").val(),
Expand All @@ -866,10 +880,10 @@ function createPokemon(pokeInfo) {
status: CALC_STATUS[pokeInfo.find(".status").val()],
toxicCounter: status === 'Badly Poisoned' ? ~~pokeInfo.find(".toxic-counter").val() : 0,
moves: [
getMoveDetails(pokeInfo.find(".move1"), name, ability, item, isDynamaxed, isGigantamaxed),
getMoveDetails(pokeInfo.find(".move2"), name, ability, item, isDynamaxed, isGigantamaxed),
getMoveDetails(pokeInfo.find(".move3"), name, ability, item, isDynamaxed, isGigantamaxed),
getMoveDetails(pokeInfo.find(".move4"), name, ability, item, isDynamaxed, isGigantamaxed)
getMoveDetails(pokeInfo.find(".move1"), name, ability, item, isDynamaxed),
getMoveDetails(pokeInfo.find(".move2"), name, ability, item, isDynamaxed),
getMoveDetails(pokeInfo.find(".move3"), name, ability, item, isDynamaxed),
getMoveDetails(pokeInfo.find(".move4"), name, ability, item, isDynamaxed)
],
overrides: {
baseStats: baseStats,
Expand All @@ -885,7 +899,7 @@ function getGender(gender) {
return 'F';
}

function getMoveDetails(moveInfo, species, ability, item, useMax, isGmax) {
function getMoveDetails(moveInfo, species, ability, item, useMax) {
var moveName = moveInfo.find("select.move-selector").val();
var isZMove = gen > 6 && moveInfo.find("input.move-z").prop("checked");
var isCrit = moveInfo.find(".move-crit").prop("checked");
Expand All @@ -899,7 +913,7 @@ function getMoveDetails(moveInfo, species, ability, item, useMax, isGmax) {
if (gen >= 4) overrides.category = moveInfo.find(".move-cat").val();
return new calc.Move(gen, moveName, {
ability: ability, item: item, useZ: isZMove, species: species, isCrit: isCrit, hits: hits, timesUsed: timesUsed,
timesUsedWithMetronome: timesUsedWithMetronome, overrides: overrides, useMax: useMax, isGmax: isGmax
timesUsedWithMetronome: timesUsedWithMetronome, overrides: overrides, useMax: useMax,
});
}

Expand Down Expand Up @@ -996,7 +1010,7 @@ function calcStat(poke, StatID) {
}
// Shedinja still has 1 max HP during the effect even if its Dynamax Level is maxed (DaWoblefet)
var total = calc.calcStat(gen, legacyStatToStat(StatID), base, ivs, evs, level, nature);
if (gen > 7 && StatID === "hp" && (poke.isDynamaxed || poke.isGigantamaxed) && total !== 1) {
if (gen > 7 && StatID === "hp" && poke.isDynamaxed && total !== 1) {
total *= 2;
}
stat.find(".total").text(total);
Expand Down
Loading

0 comments on commit bacfa1f

Please sign in to comment.