mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 07:14:36 +00:00
240690c574
## Description: ### `NationAllianceBehavior` - `isAlliancePartnerSimilarlyStrong()` now also checks for `numTilesOwned`, should make it a bit easier to get alliances. The troop calculation now also uses the players `outgoingAttacks` to make it feel less random. OF-Discord-Humans complained. - Rebalanced `checkAlreadyEnoughAlliances()` a bit ### `NationNukeBehavior` - Don't save up for MIRV if they are disabled - Don't try to throw atom bombs / hydros if they are disabled - Hydro-Nations are allowed to throw atom bombs if they are under heavy attack - Rebalance `isUnderHeavyAttack()` a bit - Increased perceived cost ### `NationEmojiBehavior` - Fix multiple nations congratulated the winner instead of one - Don't brag with our crown if the game is already over ### `DonateGoldExecution` & `DonateTroopExecution` - Added `canSendEmoji` checks ## 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
129 lines
3.4 KiB
TypeScript
129 lines
3.4 KiB
TypeScript
import {
|
|
Difficulty,
|
|
Execution,
|
|
Game,
|
|
Player,
|
|
PlayerID,
|
|
PlayerType,
|
|
} from "../game/Game";
|
|
import { PseudoRandom } from "../PseudoRandom";
|
|
import { assertNever } from "../Util";
|
|
import { EmojiExecution } from "./EmojiExecution";
|
|
import {
|
|
EMOJI_DONATION_TOO_SMALL,
|
|
EMOJI_LOVE,
|
|
} from "./nation/NationEmojiBehavior";
|
|
|
|
export class DonateTroopsExecution implements Execution {
|
|
private recipient: Player;
|
|
|
|
private random: PseudoRandom;
|
|
private mg: Game;
|
|
|
|
private active = true;
|
|
|
|
constructor(
|
|
private sender: Player,
|
|
private recipientID: PlayerID,
|
|
private troops: number | null,
|
|
) {}
|
|
|
|
init(mg: Game, ticks: number): void {
|
|
this.mg = mg;
|
|
this.random = new PseudoRandom(mg.ticks());
|
|
|
|
if (!mg.hasPlayer(this.recipientID)) {
|
|
console.warn(
|
|
`DonateTroopExecution recipient ${this.recipientID} not found`,
|
|
);
|
|
this.active = false;
|
|
return;
|
|
}
|
|
|
|
this.recipient = mg.player(this.recipientID);
|
|
this.troops ??= mg.config().defaultDonationAmount(this.sender);
|
|
const maxDonation =
|
|
mg.config().maxTroops(this.recipient) - this.recipient.troops();
|
|
this.troops = Math.min(this.troops, maxDonation);
|
|
}
|
|
|
|
tick(ticks: number): void {
|
|
if (this.troops === null) throw new Error("not initialized");
|
|
|
|
const minTroops = this.getMinTroopsForRelationUpdate();
|
|
|
|
if (
|
|
this.sender.canDonateTroops(this.recipient) &&
|
|
this.sender.donateTroops(this.recipient, this.troops)
|
|
) {
|
|
// Prevent players from just buying a good relation by sending 1% troops. Instead, a minimum is needed, and it's random.
|
|
if (this.troops >= minTroops) {
|
|
this.recipient.updateRelation(this.sender, 50);
|
|
}
|
|
|
|
// Only AI nations auto-respond with emojis, human players should not
|
|
if (
|
|
this.recipient.type() === PlayerType.Nation &&
|
|
this.recipient.canSendEmoji(this.sender)
|
|
) {
|
|
this.mg.addExecution(
|
|
new EmojiExecution(
|
|
this.recipient,
|
|
this.sender.id(),
|
|
this.random.randElement(
|
|
this.troops >= minTroops ? EMOJI_LOVE : EMOJI_DONATION_TOO_SMALL,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} else {
|
|
console.warn(
|
|
`cannot send troops from ${this.sender} to ${this.recipient}`,
|
|
);
|
|
}
|
|
this.active = false;
|
|
}
|
|
|
|
private getMinTroopsForRelationUpdate(): number {
|
|
const { difficulty } = this.mg.config().gameConfig();
|
|
const recipientMaxTroops = this.mg.config().maxTroops(this.recipient);
|
|
|
|
switch (difficulty) {
|
|
// ~7.7k - ~9.1k troops (for 100k troops)
|
|
case Difficulty.Easy:
|
|
return this.random.nextInt(
|
|
recipientMaxTroops / 13,
|
|
recipientMaxTroops / 11,
|
|
);
|
|
// ~9.1k - ~11.1k troops (for 100k troops)
|
|
case Difficulty.Medium:
|
|
return this.random.nextInt(
|
|
recipientMaxTroops / 11,
|
|
recipientMaxTroops / 9,
|
|
);
|
|
// ~11.1k - ~14.3k troops (for 100k troops)
|
|
case Difficulty.Hard:
|
|
return this.random.nextInt(
|
|
recipientMaxTroops / 9,
|
|
recipientMaxTroops / 7,
|
|
);
|
|
// ~14.3k - ~20k troops (for 100k troops)
|
|
case Difficulty.Impossible:
|
|
return this.random.nextInt(
|
|
recipientMaxTroops / 7,
|
|
recipientMaxTroops / 5,
|
|
);
|
|
default:
|
|
assertNever(difficulty);
|
|
}
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.active;
|
|
}
|
|
|
|
activeDuringSpawnPhase(): boolean {
|
|
return false;
|
|
}
|
|
}
|