mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 17:53:29 +00:00
have client create player id
This commit is contained in:
@@ -122,6 +122,7 @@ class Client {
|
|||||||
this.game = createClientGame(
|
this.game = createClientGame(
|
||||||
getUsername(),
|
getUsername(),
|
||||||
uuidv4(),
|
uuidv4(),
|
||||||
|
uuidv4(),
|
||||||
clientIP,
|
clientIP,
|
||||||
lobby.id,
|
lobby.id,
|
||||||
getConfig(),
|
getConfig(),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {TerrainRenderer} from "./graphics/TerrainRenderer";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function createClientGame(name: string, clientID: ClientID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame {
|
export function createClientGame(name: string, clientID: ClientID, playerID: PlayerID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame {
|
||||||
let eventBus = new EventBus()
|
let eventBus = new EventBus()
|
||||||
let game = createGame(terrainMap, eventBus, config)
|
let game = createGame(terrainMap, eventBus, config)
|
||||||
let terrainRenderer = new TerrainRenderer(game)
|
let terrainRenderer = new TerrainRenderer(game)
|
||||||
@@ -21,6 +21,7 @@ export function createClientGame(name: string, clientID: ClientID, ip: string |
|
|||||||
return new ClientGame(
|
return new ClientGame(
|
||||||
name,
|
name,
|
||||||
clientID,
|
clientID,
|
||||||
|
playerID,
|
||||||
ip,
|
ip,
|
||||||
gameID,
|
gameID,
|
||||||
eventBus,
|
eventBus,
|
||||||
@@ -45,9 +46,11 @@ export class ClientGame {
|
|||||||
|
|
||||||
private isProcessingTurn = false
|
private isProcessingTurn = false
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public playerName: string,
|
public playerName: string,
|
||||||
private id: ClientID,
|
private id: ClientID,
|
||||||
|
private playerID: PlayerID,
|
||||||
private clientIP: string | null,
|
private clientIP: string | null,
|
||||||
private gameID: GameID,
|
private gameID: GameID,
|
||||||
private eventBus: EventBus,
|
private eventBus: EventBus,
|
||||||
@@ -88,13 +91,11 @@ export class ClientGame {
|
|||||||
if (!this.isActive) {
|
if (!this.isActive) {
|
||||||
this.start()
|
this.start()
|
||||||
}
|
}
|
||||||
this.sendIntent(
|
this.sendIntent({
|
||||||
{
|
type: "updateName",
|
||||||
type: "updateName",
|
name: this.playerName,
|
||||||
name: this.playerName,
|
clientID: this.id
|
||||||
clientID: this.id
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (message.type == "turn") {
|
if (message.type == "turn") {
|
||||||
this.addTurn(message.turn)
|
this.addTurn(message.turn)
|
||||||
@@ -279,6 +280,7 @@ export class ClientGame {
|
|||||||
this.sendIntent({
|
this.sendIntent({
|
||||||
type: "spawn",
|
type: "spawn",
|
||||||
clientID: this.id,
|
clientID: this.id,
|
||||||
|
playerID: this.playerID,
|
||||||
name: this.playerName,
|
name: this.playerName,
|
||||||
playerType: PlayerType.Human,
|
playerType: PlayerType.Human,
|
||||||
x: cell.x,
|
x: cell.x,
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
|
|||||||
|
|
||||||
export const SpawnIntentSchema = BaseIntentSchema.extend({
|
export const SpawnIntentSchema = BaseIntentSchema.extend({
|
||||||
type: z.literal('spawn'),
|
type: z.literal('spawn'),
|
||||||
|
playerID: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
playerType: PlayerTypeSchema,
|
playerType: PlayerTypeSchema,
|
||||||
x: z.number(),
|
x: z.number(),
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export class BotSpawner {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: 'spawn',
|
type: 'spawn',
|
||||||
|
playerID: this.random.nextID(),
|
||||||
name: botName,
|
name: botName,
|
||||||
playerType: PlayerType.Bot,
|
playerType: PlayerType.Bot,
|
||||||
x: tile.cell().x,
|
x: tile.cell().x,
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class Executor {
|
|||||||
)
|
)
|
||||||
} else if (intent.type == "spawn") {
|
} else if (intent.type == "spawn") {
|
||||||
return new SpawnExecution(
|
return new SpawnExecution(
|
||||||
new PlayerInfo(intent.name, intent.playerType, intent.clientID, this.random.nextID()),
|
new PlayerInfo(intent.name, intent.playerType, intent.clientID, intent.playerID),
|
||||||
new Cell(intent.x, intent.y)
|
new Cell(intent.x, intent.y)
|
||||||
)
|
)
|
||||||
} else if (intent.type == "boat") {
|
} else if (intent.type == "boat") {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class SpawnExecution implements Execution {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const existing = this.mg.players().find(p => p.clientID() != null && p.clientID() == this.playerInfo.clientID)
|
const existing = this.mg.players().find(p => p.id() == this.playerInfo.id)
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing.tiles().forEach(t => existing.relinquish(t))
|
existing.tiles().forEach(t => existing.relinquish(t))
|
||||||
getSpawnCells(this.mg, this.cell).forEach(c => {
|
getSpawnCells(this.mg, this.cell).forEach(c => {
|
||||||
|
|||||||
Reference in New Issue
Block a user