mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-19 13:59:27 +02:00
[Beta][Bug] Fixing Ribbons that do not work because of integer overflow (#6288)
Change ribbondata number to bigint Co-authored-by: Jimmybald1 <147992650+IBBCalc@users.noreply.github.com>
This commit is contained in:
parent
2ff9bd4652
commit
74136a9c2b
@ -49,7 +49,7 @@ export abstract class Challenge {
|
|||||||
* @defaultValue 0
|
* @defaultValue 0
|
||||||
*/
|
*/
|
||||||
public get ribbonAwarded(): RibbonFlag {
|
public get ribbonAwarded(): RibbonFlag {
|
||||||
return 0 as RibbonFlag;
|
return 0n as RibbonFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -436,7 +436,7 @@ export class SingleGenerationChallenge extends Challenge {
|
|||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
// NOTE: This logic will not work for the eventual mono gen 10 ribbon, as
|
// NOTE: This logic will not work for the eventual mono gen 10 ribbon, as
|
||||||
// as its flag will not be in sequence with the other mono gen ribbons.
|
// as its flag will not be in sequence with the other mono gen ribbons.
|
||||||
return this.value ? ((RibbonData.MONO_GEN_1 << (this.value - 1)) as RibbonFlag) : 0;
|
return this.value ? ((RibbonData.MONO_GEN_1 << (BigInt(this.value) - 1n)) as RibbonFlag) : 0n;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -706,7 +706,7 @@ export class SingleTypeChallenge extends Challenge {
|
|||||||
// `this.value` represents the 1-based index of pokemon type
|
// `this.value` represents the 1-based index of pokemon type
|
||||||
// `RibbonData.MONO_NORMAL` starts the flag position for the types,
|
// `RibbonData.MONO_NORMAL` starts the flag position for the types,
|
||||||
// and we shift it by 1 for the specific type.
|
// and we shift it by 1 for the specific type.
|
||||||
return this.value ? ((RibbonData.MONO_NORMAL << (this.value - 1)) as RibbonFlag) : 0;
|
return this.value ? ((RibbonData.MONO_NORMAL << (BigInt(this.value) - 1n)) as RibbonFlag) : 0n;
|
||||||
}
|
}
|
||||||
private static TYPE_OVERRIDES: monotypeOverride[] = [
|
private static TYPE_OVERRIDES: monotypeOverride[] = [
|
||||||
{ species: SpeciesId.CASTFORM, type: PokemonType.NORMAL, fusion: false },
|
{ species: SpeciesId.CASTFORM, type: PokemonType.NORMAL, fusion: false },
|
||||||
@ -778,7 +778,7 @@ export class SingleTypeChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class FreshStartChallenge extends Challenge {
|
export class FreshStartChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? RibbonData.FRESH_START : 0;
|
return this.value ? RibbonData.FRESH_START : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.FRESH_START, 2);
|
super(Challenges.FRESH_START, 2);
|
||||||
@ -854,7 +854,7 @@ export class FreshStartChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class InverseBattleChallenge extends Challenge {
|
export class InverseBattleChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? RibbonData.INVERSE : 0;
|
return this.value ? RibbonData.INVERSE : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.INVERSE_BATTLE, 1);
|
super(Challenges.INVERSE_BATTLE, 1);
|
||||||
@ -890,7 +890,7 @@ export class InverseBattleChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class FlipStatChallenge extends Challenge {
|
export class FlipStatChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? RibbonData.FLIP_STATS : 0;
|
return this.value ? RibbonData.FLIP_STATS : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.FLIP_STAT, 1);
|
super(Challenges.FLIP_STAT, 1);
|
||||||
@ -973,7 +973,7 @@ export class LowerStarterPointsChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class LimitedSupportChallenge extends Challenge {
|
export class LimitedSupportChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? ((RibbonData.NO_HEAL << (this.value - 1)) as RibbonFlag) : 0;
|
return this.value ? ((RibbonData.NO_HEAL << (BigInt(this.value) - 1n)) as RibbonFlag) : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.LIMITED_SUPPORT, 3);
|
super(Challenges.LIMITED_SUPPORT, 3);
|
||||||
@ -1008,7 +1008,7 @@ export class LimitedSupportChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class LimitedCatchChallenge extends Challenge {
|
export class LimitedCatchChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? RibbonData.LIMITED_CATCH : 0;
|
return this.value ? RibbonData.LIMITED_CATCH : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.LIMITED_CATCH, 1);
|
super(Challenges.LIMITED_CATCH, 1);
|
||||||
@ -1035,7 +1035,7 @@ export class LimitedCatchChallenge extends Challenge {
|
|||||||
*/
|
*/
|
||||||
export class HardcoreChallenge extends Challenge {
|
export class HardcoreChallenge extends Challenge {
|
||||||
public override get ribbonAwarded(): RibbonFlag {
|
public override get ribbonAwarded(): RibbonFlag {
|
||||||
return this.value ? RibbonData.HARDCORE : 0;
|
return this.value ? RibbonData.HARDCORE : 0n;
|
||||||
}
|
}
|
||||||
constructor() {
|
constructor() {
|
||||||
super(Challenges.HARDCORE, 1);
|
super(Challenges.HARDCORE, 1);
|
||||||
|
@ -119,7 +119,7 @@ export class GameOverPhase extends BattlePhase {
|
|||||||
* game mode and challenges.
|
* game mode and challenges.
|
||||||
*/
|
*/
|
||||||
private awardRibbons(): void {
|
private awardRibbons(): void {
|
||||||
let ribbonFlags = 0;
|
let ribbonFlags = 0n;
|
||||||
if (globalScene.gameMode.isClassic) {
|
if (globalScene.gameMode.isClassic) {
|
||||||
ribbonFlags |= RibbonData.CLASSIC;
|
ribbonFlags |= RibbonData.CLASSIC;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { Brander } from "#types/type-helpers";
|
import type { Brander } from "#types/type-helpers";
|
||||||
|
|
||||||
export type RibbonFlag = (number & Brander<"RibbonFlag">) | 0;
|
export type RibbonFlag = (bigint & Brander<"RibbonFlag">) | 0n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for ribbon data management. Usually constructed via the {@linkcode fromJSON} method.
|
* Class for ribbon data management. Usually constructed via the {@linkcode fromJSON} method.
|
||||||
@ -10,91 +10,91 @@ export type RibbonFlag = (number & Brander<"RibbonFlag">) | 0;
|
|||||||
*/
|
*/
|
||||||
export class RibbonData {
|
export class RibbonData {
|
||||||
/** Internal bitfield storing the unlock state for each ribbon */
|
/** Internal bitfield storing the unlock state for each ribbon */
|
||||||
private payload: number;
|
private payload: bigint;
|
||||||
|
|
||||||
//#region Ribbons
|
//#region Ribbons
|
||||||
//#region Monotype challenge ribbons
|
//#region Monotype challenge ribbons
|
||||||
/** Ribbon for winning the normal monotype challenge */
|
/** Ribbon for winning the normal monotype challenge */
|
||||||
public static readonly MONO_NORMAL = 0x1 as RibbonFlag;
|
public static readonly MONO_NORMAL = 0x1n as RibbonFlag;
|
||||||
/** Ribbon for winning the fighting monotype challenge */
|
/** Ribbon for winning the fighting monotype challenge */
|
||||||
public static readonly MONO_FIGHTING = 0x2 as RibbonFlag;
|
public static readonly MONO_FIGHTING = 0x2n as RibbonFlag;
|
||||||
/** Ribbon for winning the flying monotype challenge */
|
/** Ribbon for winning the flying monotype challenge */
|
||||||
public static readonly MONO_FLYING = 0x4 as RibbonFlag;
|
public static readonly MONO_FLYING = 0x4n as RibbonFlag;
|
||||||
/** Ribbon for winning the poision monotype challenge */
|
/** Ribbon for winning the poision monotype challenge */
|
||||||
public static readonly MONO_POISON = 0x8 as RibbonFlag;
|
public static readonly MONO_POISON = 0x8n as RibbonFlag;
|
||||||
/** Ribbon for winning the ground monotype challenge */
|
/** Ribbon for winning the ground monotype challenge */
|
||||||
public static readonly MONO_GROUND = 0x10 as RibbonFlag;
|
public static readonly MONO_GROUND = 0x10n as RibbonFlag;
|
||||||
/** Ribbon for winning the rock monotype challenge */
|
/** Ribbon for winning the rock monotype challenge */
|
||||||
public static readonly MONO_ROCK = 0x20 as RibbonFlag;
|
public static readonly MONO_ROCK = 0x20n as RibbonFlag;
|
||||||
/** Ribbon for winning the bug monotype challenge */
|
/** Ribbon for winning the bug monotype challenge */
|
||||||
public static readonly MONO_BUG = 0x40 as RibbonFlag;
|
public static readonly MONO_BUG = 0x40n as RibbonFlag;
|
||||||
/** Ribbon for winning the ghost monotype challenge */
|
/** Ribbon for winning the ghost monotype challenge */
|
||||||
public static readonly MONO_GHOST = 0x80 as RibbonFlag;
|
public static readonly MONO_GHOST = 0x80n as RibbonFlag;
|
||||||
/** Ribbon for winning the steel monotype challenge */
|
/** Ribbon for winning the steel monotype challenge */
|
||||||
public static readonly MONO_STEEL = 0x100 as RibbonFlag;
|
public static readonly MONO_STEEL = 0x100n as RibbonFlag;
|
||||||
/** Ribbon for winning the fire monotype challenge */
|
/** Ribbon for winning the fire monotype challenge */
|
||||||
public static readonly MONO_FIRE = 0x200 as RibbonFlag;
|
public static readonly MONO_FIRE = 0x200n as RibbonFlag;
|
||||||
/** Ribbon for winning the water monotype challenge */
|
/** Ribbon for winning the water monotype challenge */
|
||||||
public static readonly MONO_WATER = 0x400 as RibbonFlag;
|
public static readonly MONO_WATER = 0x400n as RibbonFlag;
|
||||||
/** Ribbon for winning the grass monotype challenge */
|
/** Ribbon for winning the grass monotype challenge */
|
||||||
public static readonly MONO_GRASS = 0x800 as RibbonFlag;
|
public static readonly MONO_GRASS = 0x800n as RibbonFlag;
|
||||||
/** Ribbon for winning the electric monotype challenge */
|
/** Ribbon for winning the electric monotype challenge */
|
||||||
public static readonly MONO_ELECTRIC = 0x1000 as RibbonFlag;
|
public static readonly MONO_ELECTRIC = 0x1000n as RibbonFlag;
|
||||||
/** Ribbon for winning the psychic monotype challenge */
|
/** Ribbon for winning the psychic monotype challenge */
|
||||||
public static readonly MONO_PSYCHIC = 0x2000 as RibbonFlag;
|
public static readonly MONO_PSYCHIC = 0x2000n as RibbonFlag;
|
||||||
/** Ribbon for winning the ice monotype challenge */
|
/** Ribbon for winning the ice monotype challenge */
|
||||||
public static readonly MONO_ICE = 0x4000 as RibbonFlag;
|
public static readonly MONO_ICE = 0x4000n as RibbonFlag;
|
||||||
/** Ribbon for winning the dragon monotype challenge */
|
/** Ribbon for winning the dragon monotype challenge */
|
||||||
public static readonly MONO_DRAGON = 0x8000 as RibbonFlag;
|
public static readonly MONO_DRAGON = 0x8000n as RibbonFlag;
|
||||||
/** Ribbon for winning the dark monotype challenge */
|
/** Ribbon for winning the dark monotype challenge */
|
||||||
public static readonly MONO_DARK = 0x10000 as RibbonFlag;
|
public static readonly MONO_DARK = 0x10000n as RibbonFlag;
|
||||||
/** Ribbon for winning the fairy monotype challenge */
|
/** Ribbon for winning the fairy monotype challenge */
|
||||||
public static readonly MONO_FAIRY = 0x20000 as RibbonFlag;
|
public static readonly MONO_FAIRY = 0x20000n as RibbonFlag;
|
||||||
//#endregion Monotype ribbons
|
//#endregion Monotype ribbons
|
||||||
|
|
||||||
//#region Monogen ribbons
|
//#region Monogen ribbons
|
||||||
/** Ribbon for winning the the mono gen 1 challenge */
|
/** Ribbon for winning the the mono gen 1 challenge */
|
||||||
public static readonly MONO_GEN_1 = 0x40000 as RibbonFlag;
|
public static readonly MONO_GEN_1 = 0x40000n as RibbonFlag;
|
||||||
/** Ribbon for winning the the mono gen 2 challenge */
|
/** Ribbon for winning the the mono gen 2 challenge */
|
||||||
public static readonly MONO_GEN_2 = 0x80000 as RibbonFlag;
|
public static readonly MONO_GEN_2 = 0x80000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 3 challenge */
|
/** Ribbon for winning the mono gen 3 challenge */
|
||||||
public static readonly MONO_GEN_3 = 0x100000 as RibbonFlag;
|
public static readonly MONO_GEN_3 = 0x100000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 4 challenge */
|
/** Ribbon for winning the mono gen 4 challenge */
|
||||||
public static readonly MONO_GEN_4 = 0x200000 as RibbonFlag;
|
public static readonly MONO_GEN_4 = 0x200000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 5 challenge */
|
/** Ribbon for winning the mono gen 5 challenge */
|
||||||
public static readonly MONO_GEN_5 = 0x400000 as RibbonFlag;
|
public static readonly MONO_GEN_5 = 0x400000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 6 challenge */
|
/** Ribbon for winning the mono gen 6 challenge */
|
||||||
public static readonly MONO_GEN_6 = 0x800000 as RibbonFlag;
|
public static readonly MONO_GEN_6 = 0x800000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 7 challenge */
|
/** Ribbon for winning the mono gen 7 challenge */
|
||||||
public static readonly MONO_GEN_7 = 0x1000000 as RibbonFlag;
|
public static readonly MONO_GEN_7 = 0x1000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 8 challenge */
|
/** Ribbon for winning the mono gen 8 challenge */
|
||||||
public static readonly MONO_GEN_8 = 0x2000000 as RibbonFlag;
|
public static readonly MONO_GEN_8 = 0x2000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the mono gen 9 challenge */
|
/** Ribbon for winning the mono gen 9 challenge */
|
||||||
public static readonly MONO_GEN_9 = 0x4000000 as RibbonFlag;
|
public static readonly MONO_GEN_9 = 0x4000000n as RibbonFlag;
|
||||||
//#endregion Monogen ribbons
|
//#endregion Monogen ribbons
|
||||||
|
|
||||||
/** Ribbon for winning classic */
|
/** Ribbon for winning classic */
|
||||||
public static readonly CLASSIC = 0x8000000 as RibbonFlag;
|
public static readonly CLASSIC = 0x8000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the nuzzlocke challenge */
|
/** Ribbon for winning the nuzzlocke challenge */
|
||||||
public static readonly NUZLOCKE = 0x10000000 as RibbonFlag;
|
public static readonly NUZLOCKE = 0x10000000n as RibbonFlag;
|
||||||
/** Ribbon for reaching max friendship */
|
/** Ribbon for reaching max friendship */
|
||||||
public static readonly FRIENDSHIP = 0x20000000 as RibbonFlag;
|
public static readonly FRIENDSHIP = 0x20000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the flip stats challenge */
|
/** Ribbon for winning the flip stats challenge */
|
||||||
public static readonly FLIP_STATS = 0x40000000 as RibbonFlag;
|
public static readonly FLIP_STATS = 0x40000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the inverse challenge */
|
/** Ribbon for winning the inverse challenge */
|
||||||
public static readonly INVERSE = 0x80000000 as RibbonFlag;
|
public static readonly INVERSE = 0x80000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the fresh start challenge */
|
/** Ribbon for winning the fresh start challenge */
|
||||||
public static readonly FRESH_START = 0x100000000 as RibbonFlag;
|
public static readonly FRESH_START = 0x100000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the hardcore challenge */
|
/** Ribbon for winning the hardcore challenge */
|
||||||
public static readonly HARDCORE = 0x200000000 as RibbonFlag;
|
public static readonly HARDCORE = 0x200000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the limited catch challenge */
|
/** Ribbon for winning the limited catch challenge */
|
||||||
public static readonly LIMITED_CATCH = 0x400000000 as RibbonFlag;
|
public static readonly LIMITED_CATCH = 0x400000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the limited support challenge set to no heal */
|
/** Ribbon for winning the limited support challenge set to no heal */
|
||||||
public static readonly NO_HEAL = 0x800000000 as RibbonFlag;
|
public static readonly NO_HEAL = 0x800000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the limited uspport challenge set to no shop */
|
/** Ribbon for winning the limited uspport challenge set to no shop */
|
||||||
public static readonly NO_SHOP = 0x1000000000 as RibbonFlag;
|
public static readonly NO_SHOP = 0x1000000000n as RibbonFlag;
|
||||||
/** Ribbon for winning the limited support challenge set to both*/
|
/** Ribbon for winning the limited support challenge set to both*/
|
||||||
public static readonly NO_SUPPORT = 0x2000000000 as RibbonFlag;
|
public static readonly NO_SUPPORT = 0x2000000000n as RibbonFlag;
|
||||||
|
|
||||||
// NOTE: max possible ribbon flag is 0x20000000000000 (53 total ribbons)
|
// NOTE: max possible ribbon flag is 0x20000000000000 (53 total ribbons)
|
||||||
// Once this is exceeded, bitfield needs to be changed to a bigint or even a uint array
|
// Once this is exceeded, bitfield needs to be changed to a bigint or even a uint array
|
||||||
@ -104,7 +104,7 @@ export class RibbonData {
|
|||||||
|
|
||||||
/** Create a new instance of RibbonData. Generally, {@linkcode fromJSON} is used instead. */
|
/** Create a new instance of RibbonData. Generally, {@linkcode fromJSON} is used instead. */
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
this.payload = value;
|
this.payload = BigInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Serialize the bitfield payload as a hex encoded string */
|
/** Serialize the bitfield payload as a hex encoded string */
|
||||||
|
Loading…
Reference in New Issue
Block a user