mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 13:52:45 +00:00
5d52f73278
## Description: Previously, nations just spammed these two rather toxic emojis: 🤡😡 They now send fewer emojis while attacking, and the clown emoji is reserved for special cases. They got the ability to send emojis in much more cases: - Human didn't donate enough for relation update - Human did donate an ok amount - Human did donate a lot - Responding to emojis that they get sent from a human - Nuke sent - MIRV sent - Retaliation warship sent - Traitor tries to ally - Threat asks for / accepts an alliance request - Disliked human tries to ally - Friendly human tries to ally - They are getting attacked by very much troops - They are getting attacked by very little troops - Congratulating the winner - Bragging with their crown - Charming their allies - Clown-Emoting traitors - Easteregg: Sending a rat emoji to very small humans ## 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: FloPinguin --------- Co-authored-by: iamlewis <lewismmmm@gmail.com>
127 lines
3.3 KiB
TypeScript
127 lines
3.3 KiB
TypeScript
import {
|
|
Difficulty,
|
|
Execution,
|
|
Game,
|
|
Gold,
|
|
Player,
|
|
PlayerID,
|
|
} from "../game/Game";
|
|
import { PseudoRandom } from "../PseudoRandom";
|
|
import { assertNever, toInt } from "../Util";
|
|
import { EmojiExecution } from "./EmojiExecution";
|
|
import {
|
|
EMOJI_DONATION_OK,
|
|
EMOJI_DONATION_TOO_SMALL,
|
|
EMOJI_LOVE,
|
|
} from "./nation/NationEmojiBehavior";
|
|
|
|
export class DonateGoldExecution implements Execution {
|
|
private recipient: Player;
|
|
private gold: Gold;
|
|
|
|
private mg: Game;
|
|
private random: PseudoRandom;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private sender: Player,
|
|
private recipientID: PlayerID,
|
|
goldNum: number | null,
|
|
) {
|
|
this.gold = toInt(goldNum ?? 0);
|
|
}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
this.random = new PseudoRandom(mg.ticks());
|
|
|
|
if (!mg.hasPlayer(this.recipientID)) {
|
|
console.warn(
|
|
`DonateGoldExecution recipient ${this.recipientID} not found`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.recipient = mg.player(this.recipientID);
|
|
this.gold ??= this.sender.gold() / 3n;
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.gold === null) throw new Error("not initialized");
|
|
if (
|
|
this.sender.canDonateGold(this.recipient) &&
|
|
this.sender.donateGold(this.recipient, this.gold)
|
|
) {
|
|
// Give relation points based on how much gold was donated
|
|
const relationUpdate = this.calculateRelationUpdate(this.gold, ticks);
|
|
if (relationUpdate > 0) {
|
|
this.recipient.updateRelation(this.sender, relationUpdate);
|
|
}
|
|
|
|
// Select emoji based on donation value
|
|
const emoji =
|
|
relationUpdate >= 50
|
|
? EMOJI_LOVE
|
|
: relationUpdate > 0
|
|
? EMOJI_DONATION_OK
|
|
: EMOJI_DONATION_TOO_SMALL;
|
|
|
|
this.mg.addExecution(
|
|
new EmojiExecution(
|
|
this.recipient,
|
|
this.sender.id(),
|
|
this.random.randElement(emoji),
|
|
),
|
|
);
|
|
} else {
|
|
console.warn(
|
|
`cannot send gold from ${this.sender.name()} to ${this.recipient.name()}`,
|
|
);
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
private getGoldChunkSize(): number {
|
|
const { difficulty } = this.mg.config().gameConfig();
|
|
switch (difficulty) {
|
|
case Difficulty.Easy:
|
|
return 2_500;
|
|
case Difficulty.Medium:
|
|
return 5_000;
|
|
case Difficulty.Hard:
|
|
return 12_500;
|
|
case Difficulty.Impossible:
|
|
return 25_000;
|
|
default:
|
|
assertNever(difficulty);
|
|
}
|
|
}
|
|
|
|
private calculateRelationUpdate(goldSent: Gold, ticks: number): number {
|
|
const chunkSize = this.getGoldChunkSize();
|
|
// For every 5 minutes that pass, multiply the chunk size to scale with game progression
|
|
const chunkSizeMultiplier =
|
|
ticks / (3000 + this.mg.config().numSpawnPhaseTurns());
|
|
const adjustedChunkSize = BigInt(
|
|
Math.round(chunkSize + chunkSize * chunkSizeMultiplier),
|
|
);
|
|
// Calculate how many complete chunks were donated
|
|
const chunks = Number(goldSent / adjustedChunkSize);
|
|
// Each chunk gives 5 relation points
|
|
const relationUpdate = chunks * 5;
|
|
// Cap at 100 relation points
|
|
if (relationUpdate > 100) return 100;
|
|
return relationUpdate;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|