Use bigint for gold (#1000)

## Description:

- Switch gold to bigint.
- Remove unused or untrusted values from event payloads.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-06-02 12:48:24 -07:00
committed by GitHub
co-authored by Scott Anderson coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
parent df0d99e212
commit 73a6853fd7
19 changed files with 125 additions and 100 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ import { consolex } from "../Consolex";
import {
Execution,
Game,
Gold,
Player,
PlayerID,
Tick,
@@ -26,7 +27,7 @@ export class ConstructionExecution implements Execution {
private ticksUntilComplete: Tick;
private cost: number;
private cost: Gold;
constructor(
private ownerId: PlayerID,
+7 -5
View File
@@ -1,5 +1,5 @@
import { consolex } from "../Consolex";
import { Execution, Game, Player, PlayerID } from "../game/Game";
import { Execution, Game, Gold, Player, PlayerID } from "../game/Game";
export class DonateGoldExecution implements Execution {
private sender: Player;
@@ -10,7 +10,7 @@ export class DonateGoldExecution implements Execution {
constructor(
private senderID: PlayerID,
private recipientID: PlayerID,
private gold: number | null,
private gold: Gold | null,
) {}
init(mg: Game, ticks: number): void {
@@ -28,14 +28,16 @@ export class DonateGoldExecution implements Execution {
this.sender = mg.player(this.senderID);
this.recipient = mg.player(this.recipientID);
if (this.gold === null) {
this.gold = Math.round(this.sender.gold() / 3);
this.gold = this.sender.gold() / 3n;
}
}
tick(ticks: number): void {
if (this.gold === null) throw new Error("not initialized");
if (this.sender.canDonate(this.recipient)) {
this.sender.donateGold(this.recipient, this.gold);
if (
this.sender.canDonate(this.recipient) &&
this.sender.donateGold(this.recipient, this.gold)
) {
this.recipient.updateRelation(this.sender, 50);
} else {
consolex.warn(
+4 -2
View File
@@ -34,8 +34,10 @@ export class DonateTroopsExecution implements Execution {
tick(ticks: number): void {
if (this.troops === null) throw new Error("not initialized");
if (this.sender.canDonate(this.recipient)) {
this.sender.donateTroops(this.recipient, this.troops);
if (
this.sender.canDonate(this.recipient) &&
this.sender.donateTroops(this.recipient, this.troops)
) {
this.recipient.updateRelation(this.sender, 50);
} else {
consolex.warn(
+2 -1
View File
@@ -4,6 +4,7 @@ import {
Difficulty,
Execution,
Game,
Gold,
Nation,
Player,
PlayerID,
@@ -543,7 +544,7 @@ export class FakeHumanExecution implements Execution {
return null;
}
private cost(type: UnitType): number {
private cost(type: UnitType): Gold {
if (this.player === null) throw new Error("not initialized");
return this.mg.unitInfo(type).cost(this.player);
}