Enable Goldenrod City and its buildings, the department store with its elevator and rooftop, the Underground and its rooms, the Radio Tower floors and the Route 35 gate. Port what their scripts need: the herb shop, bargain shop, pharmacy and rooftop sale marts with ROM stock, prices and text; the Name Rater; the haircut brothers' happiness tables; the Lucky Number show over the party and boxes with its saved number and Friday countdown (RTC day timers with the 140-day wrap); coin and money balance boxes; Game Corner prize registration through NewPokedexEntry; gift Pokémon to the box when the party is full, with OT, nickname and MAIL (Kenya's 15-letter first line now stores). Saves gain hallOfFame, timers and luckyNumber, with defaults for older saves, and wUndergroundSwitchPositions joins the saved script bytes. The playthrough continues to the Bicycle, Whitney, the PLAINBADGE and the radio card. SlotMachine and CardFlip are still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
/** The RTC's day counter wraps every 20 weeks (FixDays keeps wCurDay below
|
|
* 140), and day differences wrap with it (_CalcDaysSince). */
|
|
export const RTC_DAYS = 20 * 7;
|
|
|
|
/** A day countdown (InitNDaysCountdown's two bytes): the days remaining
|
|
* and the wCurDay it was last checked on. */
|
|
export interface DayTimer {
|
|
remaining: number;
|
|
day: number;
|
|
}
|
|
|
|
/** wCurDay for a native day number. */
|
|
export const rtcDay = (day: number) => ((day % RTC_DAYS) + RTC_DAYS) % RTC_DAYS;
|
|
|
|
/** InitNDaysCountdown. */
|
|
export function initCountdown(days: number, today: number): DayTimer {
|
|
return { remaining: days, day: rtcDay(today) };
|
|
}
|
|
|
|
/** CheckDayDependentEventHL: CalcDaysSince (which also moves the stored
|
|
* day to today) and UpdateTimeRemaining. True (carry) once the countdown
|
|
* has run out; a timer never started (`undefined`, all zeros in the
|
|
* original) is already out. */
|
|
export function checkCountdown(timer: DayTimer | undefined, today: number) {
|
|
const current = rtcDay(today);
|
|
const start = timer ?? { remaining: 0, day: 0 };
|
|
const elapsed = (current - start.day + RTC_DAYS) % RTC_DAYS;
|
|
const remaining = Math.max(0, start.remaining - elapsed);
|
|
return { done: remaining === 0, timer: { remaining, day: current } };
|
|
}
|
|
|
|
/** The days until next Friday (RestartLuckyNumberCountdown's
|
|
* .GetDaysUntilNextFriday): 7 on Fridays and 6 on Saturdays. */
|
|
export function daysUntilNextFriday(weekday: number) {
|
|
const FRIDAY = 5;
|
|
const days = FRIDAY - weekday;
|
|
return days > 0 ? days : days + 7;
|
|
}
|
|
|
|
export function validDayTimer(value: unknown): value is DayTimer {
|
|
const timer = value as DayTimer;
|
|
return (
|
|
Boolean(timer) &&
|
|
typeof timer === "object" &&
|
|
Number.isInteger(timer.remaining) &&
|
|
timer.remaining >= 0 &&
|
|
timer.remaining <= 255 &&
|
|
Number.isInteger(timer.day) &&
|
|
timer.day >= 0 &&
|
|
timer.day < RTC_DAYS
|
|
);
|
|
}
|