bugfix: don't use bigint for zod schema as it causes json parsing issues

This commit is contained in:
evanpelle
2025-10-14 19:05:53 -07:00
parent 5579fcf91b
commit 9ab35a0436
4 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -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,
});
}
+1 -1
View File
@@ -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({
+6 -2
View File
@@ -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)) {
+2 -2
View File
@@ -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