Skip to content

Commit 90dff31

Browse files
committed
Add coderabbit recommendation
1 parent 1ce1eae commit 90dff31

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/core/execution/DonateGoldExecution.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ export class DonateGoldExecution implements Execution {
4848
this.sender.donateGold(this.recipient, this.gold)
4949
) {
5050
// Give relation points based on how much gold was donated
51-
const relationUpdate = this.calculateRelationUpdate(Number(this.gold));
52-
this.recipient.updateRelation(this.sender, relationUpdate);
51+
const relationUpdate = this.calculateRelationUpdate(this.gold);
52+
if (relationUpdate > 0) {
53+
this.recipient.updateRelation(this.sender, relationUpdate);
54+
}
5355
} else {
5456
console.warn(
5557
`cannot send gold from ${this.sender.name()} to ${this.recipient.name()}`,
@@ -58,26 +60,27 @@ export class DonateGoldExecution implements Execution {
5860
this.active = false;
5961
}
6062

61-
getGoldChunkSize(): number {
63+
getGoldChunkSize(): Gold {
6264
const { difficulty } = this.mg.config().gameConfig();
6365
switch (difficulty) {
6466
case Difficulty.Easy:
65-
return this.random.nextInt(1, 2_500);
67+
return BigInt(this.random.nextInt(1, 2_500));
6668
case Difficulty.Medium:
67-
return this.random.nextInt(2_500, 5_000);
69+
return BigInt(this.random.nextInt(2_500, 5_000));
6870
case Difficulty.Hard:
69-
return this.random.nextInt(5_000, 12_500);
71+
return BigInt(this.random.nextInt(5_000, 12_500));
7072
case Difficulty.Impossible:
71-
return this.random.nextInt(12_500, 25_000);
73+
return BigInt(this.random.nextInt(12_500, 25_000));
7274
default:
73-
return 2_500;
75+
return 2_500n;
7476
}
7577
}
7678

77-
calculateRelationUpdate(goldSent: number): number {
79+
calculateRelationUpdate(goldSent: Gold): number {
7880
const chunkSize = this.getGoldChunkSize();
7981
// Calculate how many complete chunks were donated
80-
const chunks = Math.floor(goldSent / chunkSize);
82+
// BigInt division automatically truncates (integer division)
83+
const chunks = Number(goldSent / chunkSize);
8184
// Each chunk gives 5 relation points
8285
const relationUpdate = chunks * 5;
8386
// Cap at 100 relation points

src/core/execution/DonateTroopExecution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class DonateTroopsExecution implements Execution {
8484
recipientMaxTroops / 5,
8585
);
8686
default:
87-
return 0;
87+
return recipientMaxTroops / 11;
8888
}
8989
}
9090

0 commit comments

Comments
 (0)