can change name after joining game

This commit is contained in:
evanpelle
2024-08-26 15:03:50 -07:00
parent da6f0a89e7
commit 480cfba8e0
13 changed files with 130 additions and 19 deletions
@@ -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`)
}
+2 -2
View File
@@ -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
+36
View File
@@ -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
}
}