mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 14:45:05 +00:00
can change name after joining game
This commit is contained in:
@@ -6,6 +6,7 @@ import {SpawnExecution} from "./SpawnExecution";
|
||||
import {BotSpawner} from "./BotSpawner";
|
||||
import {BoatAttackExecution} from "./BoatAttackExecution";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {UpdateNameExecution} from "./UpdateNameExecution";
|
||||
|
||||
|
||||
export class Executor {
|
||||
@@ -40,6 +41,11 @@ export class Executor {
|
||||
new Cell(intent.x, intent.y),
|
||||
intent.troops
|
||||
)
|
||||
} else if (intent.type == "updateName") {
|
||||
return new UpdateNameExecution(
|
||||
intent.name,
|
||||
intent.clientID
|
||||
)
|
||||
} else {
|
||||
throw new Error(`intent type ${intent} not found`)
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export class SpawnExecution implements Execution {
|
||||
return
|
||||
}
|
||||
|
||||
const existing = this.mg.players().find(p => p.info().clientID != null && p.info().clientID == this.playerInfo.clientID)
|
||||
const existing = this.mg.players().find(p => p.clientID() != null && p.clientID() == this.playerInfo.clientID)
|
||||
if (existing) {
|
||||
existing.tiles().forEach(t => existing.relinquish(t))
|
||||
getSpawnCells(this.mg, this.cell).forEach(c => {
|
||||
@@ -42,7 +42,7 @@ export class SpawnExecution implements Execution {
|
||||
player.conquer(this.mg.tile(c))
|
||||
})
|
||||
this.mg.addExecution(new PlayerExecution(player.id()))
|
||||
if (player.info().isBot) {
|
||||
if (player.isBot()) {
|
||||
this.mg.addExecution(new BotExecution(player))
|
||||
}
|
||||
this.active = false
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import {Config, PlayerConfig} from "../configuration/Config"
|
||||
import {Execution, MutableGame, MutablePlayer, PlayerID} from "../Game"
|
||||
import {ClientID} from "../Schemas"
|
||||
|
||||
export class UpdateNameExecution implements Execution {
|
||||
|
||||
private active = true
|
||||
private mg: MutableGame
|
||||
|
||||
constructor(private newName: string, private clientID: ClientID) {
|
||||
}
|
||||
|
||||
init(mg: MutableGame, ticks: number) {
|
||||
this.mg = mg
|
||||
}
|
||||
|
||||
tick(ticks: number) {
|
||||
const player = this.mg.players().find(p => p.clientID() == this.clientID)
|
||||
if (player == null) {
|
||||
return
|
||||
}
|
||||
player.setName(this.newName)
|
||||
this.active = false
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user