Skip to content

Commit 9512e48

Browse files
authored
Fix: Players don't auto-send emoji replies when donated to, unlike nations (openfrontio#2808)
## Description: The new (awesome) nation emoji updates had a small bug in them when I was playtesting with a friend where donating troops to them (a human player) would result in the player automatically sending an emoji reply. Sometimes these replies were negative-connotations like ❓ and 🥱, which could impact how other players perceive their donation attempt. This PR fixes that issue. ### Example of player nation sending emojis automatically https://github.com/user-attachments/assets/99689966-b784-4c3f-b43b-953a4a102e2d ### Donating to player after fix https://github.com/user-attachments/assets/ace0c1ee-3eb8-4240-9c78-167dd773cfb2 ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: bijx
1 parent 5d9b834 commit 9512e48

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

src/core/execution/DonateGoldExecution.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Gold,
66
Player,
77
PlayerID,
8+
PlayerType,
89
} from "../game/Game";
910
import { PseudoRandom } from "../PseudoRandom";
1011
import { assertNever, toInt } from "../Util";
@@ -60,21 +61,24 @@ export class DonateGoldExecution implements Execution {
6061
this.recipient.updateRelation(this.sender, relationUpdate);
6162
}
6263

63-
// Select emoji based on donation value
64-
const emoji =
65-
relationUpdate >= 50
66-
? EMOJI_LOVE
67-
: relationUpdate > 0
68-
? EMOJI_DONATION_OK
69-
: EMOJI_DONATION_TOO_SMALL;
64+
// Only AI nations auto-respond with emojis, human players should not
65+
if (this.recipient.type() === PlayerType.Nation) {
66+
// Select emoji based on donation value
67+
const emoji =
68+
relationUpdate >= 50
69+
? EMOJI_LOVE
70+
: relationUpdate > 0
71+
? EMOJI_DONATION_OK
72+
: EMOJI_DONATION_TOO_SMALL;
7073

71-
this.mg.addExecution(
72-
new EmojiExecution(
73-
this.recipient,
74-
this.sender.id(),
75-
this.random.randElement(emoji),
76-
),
77-
);
74+
this.mg.addExecution(
75+
new EmojiExecution(
76+
this.recipient,
77+
this.sender.id(),
78+
this.random.randElement(emoji),
79+
),
80+
);
81+
}
7882
} else {
7983
console.warn(
8084
`cannot send gold from ${this.sender.name()} to ${this.recipient.name()}`,

src/core/execution/DonateTroopExecution.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Difficulty, Execution, Game, Player, PlayerID } from "../game/Game";
1+
import {
2+
Difficulty,
3+
Execution,
4+
Game,
5+
Player,
6+
PlayerID,
7+
PlayerType,
8+
} from "../game/Game";
29
import { PseudoRandom } from "../PseudoRandom";
310
import { assertNever } from "../Util";
411
import { EmojiExecution } from "./EmojiExecution";
@@ -54,15 +61,18 @@ export class DonateTroopsExecution implements Execution {
5461
this.recipient.updateRelation(this.sender, 50);
5562
}
5663

57-
this.mg.addExecution(
58-
new EmojiExecution(
59-
this.recipient,
60-
this.sender.id(),
61-
this.random.randElement(
62-
this.troops >= minTroops ? EMOJI_LOVE : EMOJI_DONATION_TOO_SMALL,
64+
// Only AI nations auto-respond with emojis, human players should not
65+
if (this.recipient.type() === PlayerType.Nation) {
66+
this.mg.addExecution(
67+
new EmojiExecution(
68+
this.recipient,
69+
this.sender.id(),
70+
this.random.randElement(
71+
this.troops >= minTroops ? EMOJI_LOVE : EMOJI_DONATION_TOO_SMALL,
72+
),
6373
),
64-
),
65-
);
74+
);
75+
}
6676
} else {
6777
console.warn(
6878
`cannot send troops from ${this.sender} to ${this.recipient}`,

0 commit comments

Comments
 (0)