mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 17:24:36 +00:00
Disconnected player giveaway for team mode
This commit is contained in:
@@ -4,6 +4,7 @@ import { consolex } from "../Consolex";
|
||||
import {
|
||||
Execution,
|
||||
Game,
|
||||
GameMode,
|
||||
MessageType,
|
||||
Player,
|
||||
PlayerID,
|
||||
@@ -75,6 +76,17 @@ export class PlayerExecution implements Execution {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.player.isDisconnected() &&
|
||||
this.config.gameConfig().gameMode === GameMode.Team
|
||||
) {
|
||||
const closestAlly = this.getMoreSharedBorderAlly();
|
||||
if (closestAlly) {
|
||||
this.giveaway(closestAlly);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const popInc = this.config.populationIncreaseRate(this.player);
|
||||
this.player.addWorkers(popInc * (1 - this.player.targetTroopRatio()));
|
||||
this.player.addTroops(popInc * this.player.targetTroopRatio());
|
||||
@@ -252,6 +264,45 @@ export class PlayerExecution implements Execution {
|
||||
}
|
||||
}
|
||||
|
||||
private getMoreSharedBorderAlly(): Player | null {
|
||||
if (!this.player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const neighbours = this.player!.neighborsBordersSurface().filter((p) =>
|
||||
p[0].isOnSameTeam(this.player!),
|
||||
);
|
||||
|
||||
if (!neighbours.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return neighbours[0][0];
|
||||
}
|
||||
|
||||
private giveaway(other: Player) {
|
||||
if (this.mg === null || this.player === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const tile of this.player.tiles()) {
|
||||
other.conquer(tile);
|
||||
}
|
||||
|
||||
other.addGold(this.player.gold());
|
||||
this.player.removeGold(this.player.gold());
|
||||
|
||||
other.addTroops(this.player.troops());
|
||||
this.player.removeTroops(this.player.troops());
|
||||
|
||||
other.addWorkers(this.player.workers());
|
||||
this.player.removeWorkers(this.player.workers());
|
||||
|
||||
for (const unit of this.player.units()) {
|
||||
other.captureUnit(unit);
|
||||
}
|
||||
}
|
||||
|
||||
private getCapturingPlayer(cluster: Set<TileRef>): Player | null {
|
||||
if (this.mg === null || this.player === null) {
|
||||
throw new Error("Not initialized");
|
||||
|
||||
Reference in New Issue
Block a user