From 9ab35a04365f8381b20759a66417b4c366264caf Mon Sep 17 00:00:00 2001 From: evanpelle Date: Tue, 14 Oct 2025 19:05:53 -0700 Subject: [PATCH] bugfix: don't use bigint for zod schema as it causes json parsing issues --- src/client/Transport.ts | 2 +- src/core/Schemas.ts | 2 +- src/core/execution/DonateGoldExecution.ts | 8 ++++++-- tests/Donate.test.ts | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 3cb6c71c6..b5d9bf9b1 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -496,7 +496,7 @@ export class Transport { type: "donate_gold", clientID: this.lobbyConfig.clientID, recipient: event.recipient.id(), - gold: event.gold, + gold: event.gold ? Number(event.gold) : null, }); } diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index 270cc2297..b13f8ac17 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -278,7 +278,7 @@ export const EmbargoIntentSchema = BaseIntentSchema.extend({ export const DonateGoldIntentSchema = BaseIntentSchema.extend({ type: z.literal("donate_gold"), recipient: ID, - gold: z.bigint().nullable(), + gold: z.number().nullable(), }); export const DonateTroopIntentSchema = BaseIntentSchema.extend({ diff --git a/src/core/execution/DonateGoldExecution.ts b/src/core/execution/DonateGoldExecution.ts index 214c7e915..51b60ce0a 100644 --- a/src/core/execution/DonateGoldExecution.ts +++ b/src/core/execution/DonateGoldExecution.ts @@ -1,15 +1,19 @@ import { Execution, Game, Gold, Player, PlayerID } from "../game/Game"; +import { toInt } from "../Util"; export class DonateGoldExecution implements Execution { private recipient: Player; private active = true; + private gold: Gold; constructor( private sender: Player, private recipientID: PlayerID, - private gold: Gold | null, - ) {} + goldNum: number | null, + ) { + this.gold = toInt(goldNum ?? 0); + } init(mg: Game, ticks: number): void { if (!mg.hasPlayer(this.recipientID)) { diff --git a/tests/Donate.test.ts b/tests/Donate.test.ts index bbbccd4f9..966f9d493 100644 --- a/tests/Donate.test.ts +++ b/tests/Donate.test.ts @@ -120,7 +120,7 @@ describe("Donate gold to an ally", () => { donor.addGold(6000n); const donorGoldBefore = donor.gold(); const recipientGoldBefore = recipient.gold(); - game.addExecution(new DonateGoldExecution(donor, recipientInfo.id, 5000n)); + game.addExecution(new DonateGoldExecution(donor, recipientInfo.id, 5000)); for (let i = 0; i < 5; i++) { game.executeNextTick(); @@ -242,7 +242,7 @@ describe("Donate Gold to a non ally", () => { const donorGoldBefore = donor.gold(); const recipientGoldBefore = donor.gold(); - game.addExecution(new DonateGoldExecution(donor, recipientInfo.id, 5000n)); + game.addExecution(new DonateGoldExecution(donor, recipientInfo.id, 5000)); game.executeNextTick(); // Gold should not be donated since they are not allies