KF-MMO-Server/Classes/lobbyState.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-09-16 05:42:42 +08:00
import { physicsObject } from "../Classes/physicsObject";
import { playerData } from "../Classes/playerData";
2023-09-21 02:17:18 +08:00
import { levelState } from "./levelState";
import { userData } from "./userData";
2023-09-16 05:42:42 +08:00
export class lobbyState{
users : userData[] = [];
2023-09-16 05:42:42 +08:00
players : playerData[] = [];
2023-09-21 02:17:18 +08:00
rooms : levelState[] = []
2023-09-16 05:42:42 +08:00
copyLight(){
let lobby = Object.assign({}, this);
lobby.players = []
lobby.users = []
2023-09-16 05:42:42 +08:00
for (let i = 0; i < this.players.length; i++) {
2023-09-18 18:33:06 +08:00
lobby.players.push(this.players[i].copyLight());
2023-09-16 05:42:42 +08:00
}
2023-09-21 02:17:18 +08:00
lobby.rooms = this.rooms
2023-09-16 05:42:42 +08:00
return lobby
}
addUser(userData, playerData){
let uIdx = this.users.findIndex(u=>u.id == userData.id)
let pIdx = this.players.findIndex(u=>u.id == playerData.id)
if(uIdx != -1 || pIdx != -1){
console.log("User " + userData.login + " is already in the game!")
return false;
}
this.users.push(userData)
this.players.push(playerData)
return true
}
removeUser(id){
let idx = this.users.findIndex(u=>u.id == id)
if(idx != -1){
this.users.splice(idx, 1)
}
idx = this.players.findIndex(u=>u.id == id)
if(idx != -1){
this.players.splice(idx, 1)
}
}
findPlayer(id: number){
return this.players.find(p=>p.id == id)
}
2023-09-16 05:42:42 +08:00
}