mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
format all files with prettier
This commit is contained in:
@@ -9,7 +9,7 @@ export class AttackImpl implements Attack {
|
||||
private _target: Player | TerraNullius,
|
||||
private _attacker: Player,
|
||||
private _troops: number,
|
||||
private _sourceTile: TileRef | null
|
||||
private _sourceTile: TileRef | null,
|
||||
) {}
|
||||
|
||||
sourceTile(): TileRef | null {
|
||||
|
||||
@@ -6,13 +6,16 @@ export class DefenseGrid {
|
||||
private grid: Set<Unit | UnitView>[][];
|
||||
private readonly cellSize = 100;
|
||||
|
||||
constructor(private gm: GameMap, private searchRange: number) {
|
||||
constructor(
|
||||
private gm: GameMap,
|
||||
private searchRange: number,
|
||||
) {
|
||||
this.grid = Array(Math.ceil(gm.height() / this.cellSize))
|
||||
.fill(null)
|
||||
.map(() =>
|
||||
Array(Math.ceil(gm.width() / this.cellSize))
|
||||
.fill(null)
|
||||
.map(() => new Set<Unit | UnitView>())
|
||||
.map(() => new Set<Unit | UnitView>()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ export class Nation {
|
||||
public readonly flag: string,
|
||||
public readonly name: string,
|
||||
public readonly cell: Cell,
|
||||
public readonly strength: number
|
||||
public readonly strength: number,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,10 @@ export class Cell {
|
||||
|
||||
private strRepr: string;
|
||||
|
||||
constructor(public readonly x, public readonly y) {
|
||||
constructor(
|
||||
public readonly x,
|
||||
public readonly y,
|
||||
) {
|
||||
this.strRepr = `Cell[${this.x},${this.y}]`;
|
||||
}
|
||||
|
||||
@@ -176,7 +179,7 @@ export class PlayerInfo {
|
||||
public readonly clientID: ClientID | null,
|
||||
// TODO: make player id the small id
|
||||
public readonly id: PlayerID,
|
||||
public readonly nation?: Nation | null
|
||||
public readonly nation?: Nation | null,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -302,7 +305,7 @@ export interface Player {
|
||||
createAttack(
|
||||
target: Player | TerraNullius,
|
||||
troops: number,
|
||||
sourceTile: TileRef
|
||||
sourceTile: TileRef,
|
||||
): Attack;
|
||||
outgoingAttacks(): Attack[];
|
||||
incomingAttacks(): Attack[];
|
||||
@@ -350,7 +353,7 @@ export interface Game extends GameMap {
|
||||
displayMessage(
|
||||
message: string,
|
||||
type: MessageType,
|
||||
playerID: PlayerID | null
|
||||
playerID: PlayerID | null,
|
||||
): void;
|
||||
|
||||
// Nations
|
||||
|
||||
+14
-14
@@ -35,7 +35,7 @@ export function createGame(
|
||||
gameMap: GameMap,
|
||||
miniGameMap: GameMap,
|
||||
nationMap: NationMap,
|
||||
config: Config
|
||||
config: Config,
|
||||
): Game {
|
||||
return new GameImpl(gameMap, miniGameMap, nationMap, config);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ export class GameImpl implements Game {
|
||||
private _map: GameMap,
|
||||
private miniGameMap: GameMap,
|
||||
nationMap: NationMap,
|
||||
private _config: Config
|
||||
private _config: Config,
|
||||
) {
|
||||
this._terraNullius = new TerraNulliusImpl();
|
||||
this._width = _map.width();
|
||||
@@ -81,12 +81,12 @@ export class GameImpl implements Game {
|
||||
n.flag || "",
|
||||
n.name,
|
||||
new Cell(n.coordinates[0], n.coordinates[1]),
|
||||
n.strength
|
||||
)
|
||||
n.strength,
|
||||
),
|
||||
);
|
||||
this.defenseGrid = new DefenseGrid(
|
||||
this._map,
|
||||
this._config.defensePostRange()
|
||||
this._config.defensePostRange(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -173,11 +173,11 @@ export class GameImpl implements Game {
|
||||
this,
|
||||
request.requestor() as PlayerImpl,
|
||||
request.recipient() as PlayerImpl,
|
||||
this._ticks
|
||||
this._ticks,
|
||||
);
|
||||
this.alliances_.push(alliance);
|
||||
(request.requestor() as PlayerImpl).pastOutgoingAllianceRequests.push(
|
||||
request
|
||||
request,
|
||||
);
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.AllianceRequestReply,
|
||||
@@ -189,7 +189,7 @@ export class GameImpl implements Game {
|
||||
rejectAllianceRequest(request: AllianceRequestImpl) {
|
||||
this.allianceRequests = this.allianceRequests.filter((ar) => ar != request);
|
||||
(request.requestor() as PlayerImpl).pastOutgoingAllianceRequests.push(
|
||||
request
|
||||
request,
|
||||
);
|
||||
this.addUpdate({
|
||||
type: GameUpdateType.AllianceRequestReply,
|
||||
@@ -296,7 +296,7 @@ export class GameImpl implements Game {
|
||||
removeExecution(exec: Execution) {
|
||||
this.execs = this.execs.filter((execution) => execution !== exec);
|
||||
this.unInitExecs = this.unInitExecs.filter(
|
||||
(execution) => execution !== exec
|
||||
(execution) => execution !== exec,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ export class GameImpl implements Game {
|
||||
}
|
||||
if (!breaker.isAlliedWith(other)) {
|
||||
throw new Error(
|
||||
`${breaker} not allied with ${other}, cannot break alliance`
|
||||
`${breaker} not allied with ${other}, cannot break alliance`,
|
||||
);
|
||||
}
|
||||
if (!other.isTraitor()) {
|
||||
@@ -459,7 +459,7 @@ export class GameImpl implements Game {
|
||||
const alliances = other.alliances().filter((a) => breakerSet.has(a));
|
||||
if (alliances.length != 1) {
|
||||
throw new Error(
|
||||
`must have exactly one alliance, have ${alliances.length}`
|
||||
`must have exactly one alliance, have ${alliances.length}`,
|
||||
);
|
||||
}
|
||||
this.alliances_ = this.alliances_.filter((a) => a != alliances[0]);
|
||||
@@ -478,7 +478,7 @@ export class GameImpl implements Game {
|
||||
.filter((a) => p1Set.has(a));
|
||||
if (alliances.length != 1) {
|
||||
throw new Error(
|
||||
`cannot expire alliance: must have exactly one alliance, have ${alliances.length}`
|
||||
`cannot expire alliance: must have exactly one alliance, have ${alliances.length}`,
|
||||
);
|
||||
}
|
||||
this.alliances_ = this.alliances_.filter((a) => a != alliances[0]);
|
||||
@@ -506,7 +506,7 @@ export class GameImpl implements Game {
|
||||
displayMessage(
|
||||
message: string,
|
||||
type: MessageType,
|
||||
playerID: PlayerID | null
|
||||
playerID: PlayerID | null,
|
||||
): void {
|
||||
let id = null;
|
||||
if (playerID != null) {
|
||||
@@ -614,7 +614,7 @@ export class GameImpl implements Game {
|
||||
}
|
||||
bfs(
|
||||
tile: TileRef,
|
||||
filter: (gm: GameMap, tile: TileRef) => boolean
|
||||
filter: (gm: GameMap, tile: TileRef) => boolean,
|
||||
): Set<TileRef> {
|
||||
return this._map.bfs(tile, filter);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export interface PlayerUpdate {
|
||||
type: GameUpdateType.Player;
|
||||
nameViewData?: NameViewData;
|
||||
clientID: ClientID;
|
||||
flag: string,
|
||||
flag: string;
|
||||
name: string;
|
||||
displayName: string;
|
||||
id: PlayerID;
|
||||
|
||||
+19
-10
@@ -36,7 +36,10 @@ export class UnitView {
|
||||
public _wasUpdated = true;
|
||||
public lastPos: MapPos[] = [];
|
||||
|
||||
constructor(private gameView: GameView, private data: UnitUpdate) {
|
||||
constructor(
|
||||
private gameView: GameView,
|
||||
private data: UnitUpdate,
|
||||
) {
|
||||
this.lastPos.push(data.pos);
|
||||
}
|
||||
|
||||
@@ -95,14 +98,14 @@ export class PlayerView {
|
||||
constructor(
|
||||
private game: GameView,
|
||||
public data: PlayerUpdate,
|
||||
public nameData: NameViewData
|
||||
public nameData: NameViewData,
|
||||
) {}
|
||||
|
||||
async actions(tile: TileRef): Promise<PlayerActions> {
|
||||
return this.game.worker.playerInteraction(
|
||||
this.id(),
|
||||
this.game.x(tile),
|
||||
this.game.y(tile)
|
||||
this.game.y(tile),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -156,12 +159,12 @@ export class PlayerView {
|
||||
}
|
||||
allies(): PlayerView[] {
|
||||
return this.data.allies.map(
|
||||
(a) => this.game.playerBySmallID(a) as PlayerView
|
||||
(a) => this.game.playerBySmallID(a) as PlayerView,
|
||||
);
|
||||
}
|
||||
targets(): PlayerView[] {
|
||||
return this.data.targets.map(
|
||||
(id) => this.game.playerBySmallID(id) as PlayerView
|
||||
(id) => this.game.playerBySmallID(id) as PlayerView,
|
||||
);
|
||||
}
|
||||
gold(): Gold {
|
||||
@@ -199,7 +202,13 @@ export class PlayerView {
|
||||
return this.data.outgoingEmojis;
|
||||
}
|
||||
info(): PlayerInfo {
|
||||
return new PlayerInfo(this.flag(), this.name(), this.type(), this.clientID(), this.id());
|
||||
return new PlayerInfo(
|
||||
this.flag(),
|
||||
this.name(),
|
||||
this.type(),
|
||||
this.clientID(),
|
||||
this.id(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +227,7 @@ export class GameView implements GameMap {
|
||||
public worker: WorkerClient,
|
||||
private _config: Config,
|
||||
private _map: GameMap,
|
||||
private _myClientID: ClientID
|
||||
private _myClientID: ClientID,
|
||||
) {
|
||||
this.lastUpdate = {
|
||||
tick: 0,
|
||||
@@ -250,7 +259,7 @@ export class GameView implements GameMap {
|
||||
} else {
|
||||
this._players.set(
|
||||
pu.id,
|
||||
new PlayerView(this, pu, gu.playerNameViewData[pu.id])
|
||||
new PlayerView(this, pu, gu.playerNameViewData[pu.id]),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -347,7 +356,7 @@ export class GameView implements GameMap {
|
||||
return Array.from(this._units.values()).filter((u) => u.isActive());
|
||||
}
|
||||
return Array.from(this._units.values()).filter(
|
||||
(u) => u.isActive() && types.includes(u.type())
|
||||
(u) => u.isActive() && types.includes(u.type()),
|
||||
);
|
||||
}
|
||||
unit(id: number): UnitView {
|
||||
@@ -443,7 +452,7 @@ export class GameView implements GameMap {
|
||||
}
|
||||
bfs(
|
||||
tile: TileRef,
|
||||
filter: (gm: GameMap, tile: TileRef) => boolean
|
||||
filter: (gm: GameMap, tile: TileRef) => boolean,
|
||||
): Set<TileRef> {
|
||||
return this._map.bfs(tile, filter);
|
||||
}
|
||||
|
||||
+31
-28
@@ -46,7 +46,10 @@ interface Target {
|
||||
}
|
||||
|
||||
class Donation {
|
||||
constructor(public readonly recipient: Player, public readonly tick: Tick) {}
|
||||
constructor(
|
||||
public readonly recipient: Player,
|
||||
public readonly tick: Tick,
|
||||
) {}
|
||||
}
|
||||
|
||||
export class PlayerImpl implements Player {
|
||||
@@ -85,7 +88,7 @@ export class PlayerImpl implements Player {
|
||||
private mg: GameImpl,
|
||||
private _smallID: number,
|
||||
private readonly playerInfo: PlayerInfo,
|
||||
startPopulation: number
|
||||
startPopulation: number,
|
||||
) {
|
||||
this._flag = playerInfo.flag;
|
||||
this._name = playerInfo.name;
|
||||
@@ -125,7 +128,7 @@ export class PlayerImpl implements Player {
|
||||
attackerID: a.attacker().smallID(),
|
||||
targetID: a.target().smallID(),
|
||||
troops: a.troops(),
|
||||
} as AttackUpdate)
|
||||
}) as AttackUpdate,
|
||||
),
|
||||
incomingAttacks: this._incomingAttacks.map(
|
||||
(a) =>
|
||||
@@ -133,7 +136,7 @@ export class PlayerImpl implements Player {
|
||||
attackerID: a.attacker().smallID(),
|
||||
targetID: a.target().smallID(),
|
||||
troops: a.troops(),
|
||||
} as AttackUpdate)
|
||||
}) as AttackUpdate,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -203,7 +206,7 @@ export class PlayerImpl implements Player {
|
||||
const owner = this.mg.map().ownerID(neighbor);
|
||||
if (owner != this.smallID()) {
|
||||
ns.add(
|
||||
this.mg.playerBySmallID(owner) as PlayerImpl | TerraNulliusImpl
|
||||
this.mg.playerBySmallID(owner) as PlayerImpl | TerraNulliusImpl,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -249,7 +252,7 @@ export class PlayerImpl implements Player {
|
||||
|
||||
alliances(): MutableAlliance[] {
|
||||
return this.mg.alliances_.filter(
|
||||
(a) => a.requestor() == this || a.recipient() == this
|
||||
(a) => a.requestor() == this || a.recipient() == this,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -269,7 +272,7 @@ export class PlayerImpl implements Player {
|
||||
return null;
|
||||
}
|
||||
return this.alliances().find(
|
||||
(a) => a.recipient() == other || a.requestor() == other
|
||||
(a) => a.recipient() == other || a.requestor() == other,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -398,7 +401,7 @@ export class PlayerImpl implements Player {
|
||||
targets(): PlayerImpl[] {
|
||||
return this.targets_
|
||||
.filter(
|
||||
(t) => this.mg.ticks() - t.tick < this.mg.config().targetDuration()
|
||||
(t) => this.mg.ticks() - t.tick < this.mg.config().targetDuration(),
|
||||
)
|
||||
.map((t) => t.target as PlayerImpl);
|
||||
}
|
||||
@@ -430,7 +433,7 @@ export class PlayerImpl implements Player {
|
||||
.filter(
|
||||
(e) =>
|
||||
this.mg.ticks() - e.createdAt <
|
||||
this.mg.config().emojiMessageDuration()
|
||||
this.mg.config().emojiMessageDuration(),
|
||||
)
|
||||
.sort((a, b) => b.createdAt - a.createdAt);
|
||||
}
|
||||
@@ -439,7 +442,7 @@ export class PlayerImpl implements Player {
|
||||
const recipientID =
|
||||
recipient == AllPlayers ? AllPlayers : recipient.smallID();
|
||||
const prevMsgs = this.outgoingEmojis_.filter(
|
||||
(msg) => msg.recipientID == recipientID
|
||||
(msg) => msg.recipientID == recipientID,
|
||||
);
|
||||
for (const msg of prevMsgs) {
|
||||
if (
|
||||
@@ -475,12 +478,12 @@ export class PlayerImpl implements Player {
|
||||
this.mg.displayMessage(
|
||||
`Sent ${renderTroops(troops)} troops to ${recipient.name()}`,
|
||||
MessageType.INFO,
|
||||
this.id()
|
||||
this.id(),
|
||||
);
|
||||
this.mg.displayMessage(
|
||||
`Recieved ${renderTroops(troops)} troops from ${this.name()}`,
|
||||
MessageType.SUCCESS,
|
||||
recipient.id()
|
||||
recipient.id(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -495,7 +498,7 @@ export class PlayerImpl implements Player {
|
||||
removeGold(toRemove: Gold): void {
|
||||
if (toRemove > this._gold) {
|
||||
throw Error(
|
||||
`Player ${this} does not enough gold (${toRemove} vs ${this._gold}))`
|
||||
`Player ${this} does not enough gold (${toRemove} vs ${this._gold}))`,
|
||||
);
|
||||
}
|
||||
this._gold -= toRemove;
|
||||
@@ -521,7 +524,7 @@ export class PlayerImpl implements Player {
|
||||
setTargetTroopRatio(target: number): void {
|
||||
if (target < 0 || target > 1) {
|
||||
throw new Error(
|
||||
`invalid targetTroopRatio ${target} set on player ${PlayerImpl}`
|
||||
`invalid targetTroopRatio ${target} set on player ${PlayerImpl}`,
|
||||
);
|
||||
}
|
||||
this._targetTroopRatio = target;
|
||||
@@ -553,7 +556,7 @@ export class PlayerImpl implements Player {
|
||||
}
|
||||
const prev = unit.owner();
|
||||
(prev as PlayerImpl)._units = (prev as PlayerImpl)._units.filter(
|
||||
(u) => u != unit
|
||||
(u) => u != unit,
|
||||
);
|
||||
(unit as UnitImpl)._owner = this;
|
||||
this._units.push(unit as UnitImpl);
|
||||
@@ -561,12 +564,12 @@ export class PlayerImpl implements Player {
|
||||
this.mg.displayMessage(
|
||||
`${unit.type()} captured by ${this.displayName()}`,
|
||||
MessageType.ERROR,
|
||||
prev.id()
|
||||
prev.id(),
|
||||
);
|
||||
this.mg.displayMessage(
|
||||
`Captured ${unit.type()} from ${prev.displayName()}`,
|
||||
MessageType.SUCCESS,
|
||||
this.id()
|
||||
this.id(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -578,7 +581,7 @@ export class PlayerImpl implements Player {
|
||||
spawnTile,
|
||||
troops,
|
||||
this.mg.nextUnitID(),
|
||||
this
|
||||
this,
|
||||
);
|
||||
this._units.push(b);
|
||||
this.removeGold(cost);
|
||||
@@ -641,7 +644,7 @@ export class PlayerImpl implements Player {
|
||||
.filter((t) => this.mg.owner(t) == this && this.mg.isOceanShore(t))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
this.mg.manhattanDist(a, tile) - this.mg.manhattanDist(b, tile)
|
||||
this.mg.manhattanDist(a, tile) - this.mg.manhattanDist(b, tile),
|
||||
);
|
||||
if (spawns.length == 0) {
|
||||
return false;
|
||||
@@ -657,12 +660,12 @@ export class PlayerImpl implements Player {
|
||||
.filter(
|
||||
(u) =>
|
||||
this.mg.manhattanDist(u.tile(), tile) <
|
||||
this.mg.config().boatMaxDistance()
|
||||
this.mg.config().boatMaxDistance(),
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
this.mg.manhattanDist(a.tile(), tile) -
|
||||
this.mg.manhattanDist(b.tile(), tile)
|
||||
this.mg.manhattanDist(b.tile(), tile),
|
||||
);
|
||||
if (spawns.length == 0) {
|
||||
return false;
|
||||
@@ -690,7 +693,7 @@ export class PlayerImpl implements Player {
|
||||
|
||||
tradeShipSpawn(targetTile: TileRef): TileRef | false {
|
||||
const spawns = this.units(UnitType.Port).filter(
|
||||
(u) => u.tile() == targetTile
|
||||
(u) => u.tile() == targetTile,
|
||||
);
|
||||
if (spawns.length == 0) {
|
||||
return false;
|
||||
@@ -721,7 +724,7 @@ export class PlayerImpl implements Player {
|
||||
this.allRelationsSorted().map(({ player, relation }) => [
|
||||
player.smallID(),
|
||||
relation,
|
||||
])
|
||||
]),
|
||||
),
|
||||
alliances: this.alliances().map((a) => a.other(this).smallID()),
|
||||
};
|
||||
@@ -765,8 +768,8 @@ export class PlayerImpl implements Player {
|
||||
tile,
|
||||
andFN(
|
||||
(gm, t) => gm.ownerID(t) == gm.ownerID(tile) && gm.isLand(t),
|
||||
manhattanDistFN(tile, 25)
|
||||
)
|
||||
manhattanDistFN(tile, 25),
|
||||
),
|
||||
)) {
|
||||
if (this.mg.isOceanShore(t)) {
|
||||
nearOcean = true;
|
||||
@@ -790,7 +793,7 @@ export class PlayerImpl implements Player {
|
||||
createAttack(
|
||||
target: Player | TerraNullius,
|
||||
troops: number,
|
||||
sourceTile: TileRef
|
||||
sourceTile: TileRef,
|
||||
): Attack {
|
||||
const attack = new AttackImpl(target, this, troops, sourceTile);
|
||||
this._outgoingAttacks.push(attack);
|
||||
@@ -835,8 +838,8 @@ export class PlayerImpl implements Player {
|
||||
tile,
|
||||
andFN(
|
||||
(gm, t) => !gm.hasOwner(t) && gm.isLand(t),
|
||||
manhattanDistFN(tile, 200)
|
||||
)
|
||||
manhattanDistFN(tile, 200),
|
||||
),
|
||||
)) {
|
||||
for (const n of this.mg.neighbors(t)) {
|
||||
if (this.mg.owner(n) == this) {
|
||||
|
||||
@@ -20,7 +20,7 @@ export class UnitImpl implements Unit {
|
||||
private _tile: TileRef,
|
||||
private _troops: number,
|
||||
private _id: number,
|
||||
public _owner: PlayerImpl
|
||||
public _owner: PlayerImpl,
|
||||
) {
|
||||
// default to half health (or 1 is no health specified)
|
||||
this._health = (this.mg.unitInfo(_type).maxHealth ?? 2) / 2;
|
||||
@@ -89,7 +89,7 @@ export class UnitImpl implements Unit {
|
||||
this.mg.displayMessage(
|
||||
`Your ${this.type()} was captured by ${newOwner.displayName()}`,
|
||||
MessageType.ERROR,
|
||||
oldOwner.id()
|
||||
oldOwner.id(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ export class UnitImpl implements Unit {
|
||||
this.mg.displayMessage(
|
||||
`Your ${this.type()} was destroyed`,
|
||||
MessageType.ERROR,
|
||||
this.owner().id()
|
||||
this.owner().id(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user