mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 00:10:37 +00:00
bugfix: don't use bigint for zod schema as it causes json parsing issues
This commit is contained in:
@@ -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
@@ -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({
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user