-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added load testing room and reorganized rooms as classes
- Loading branch information
Showing
7 changed files
with
119 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
import { makeBot } from "../../common/types/player"; | ||
import { makeRoom } from "../../common/types/room"; | ||
import { makeFlailWeapon } from "../../common/types/weapon"; | ||
import { world } from "../world"; | ||
import { makeBaseRoomController } from "./room-controller.base"; | ||
import { BaseRoomController } from "./room-controller.base"; | ||
|
||
export function makeBotsRoom() { | ||
const room = makeRoom(world.nextRoomId++); | ||
const base = makeBaseRoomController(room); | ||
export class BotsRoom extends BaseRoomController { | ||
constructor(botCount = 2) { | ||
const room = BaseRoomController.makeRoom(world.nextRoomId++); | ||
|
||
const botCount = 2; | ||
for (let i = 0; i < botCount; i++) { | ||
const botId = `_BOT_${i + 1}`; | ||
const botName = `BOT ${i + 1}`; | ||
const position = { | ||
x: (room.size.x / (botCount + 1)) * (i + 1), | ||
y: room.size.y / 2, | ||
}; | ||
for (let i = 0; i < botCount; i++) { | ||
const botId = `_BOT_${i + 1}`; | ||
const botName = `BOT ${i + 1}`; | ||
const position = { | ||
x: (room.size.x / (botCount + 1)) * (i + 1), | ||
y: room.size.y / 2, | ||
}; | ||
|
||
room.players[botId] = makeBot( | ||
botId, | ||
room.id, | ||
botName, | ||
position, | ||
makeFlailWeapon(position), | ||
); | ||
} | ||
room.players[botId] = makeBot( | ||
botId, | ||
room.id, | ||
botName, | ||
position, | ||
makeFlailWeapon(position), | ||
); | ||
} | ||
|
||
return { | ||
room, | ||
controller: base, | ||
}; | ||
super(room); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { makeBot, Player } from "../../common/types/player"; | ||
import { Room } from "../../common/types/room"; | ||
import { makeFlailWeapon } from "../../common/types/weapon"; | ||
import { world } from "../world"; | ||
import { BaseRoomController } from "./room-controller.base"; | ||
|
||
export class LoadTestRoom extends BaseRoomController { | ||
static BOT_ID_PREFIX = "_BOT_"; | ||
|
||
constructor(private botCount: number) { | ||
const room = { | ||
...BaseRoomController.makeRoom(world.nextRoomId++), | ||
maxPlayers: botCount + 1, | ||
size: { x: 1000 * botCount, y: 1000 }, | ||
}; | ||
|
||
for (let i = 1; i <= botCount; i++) { | ||
LoadTestRoom.addBot(i, botCount, room); | ||
} | ||
|
||
super(room); | ||
} | ||
|
||
disconnectPlayer(player: Player) { | ||
super.disconnectPlayer(player); | ||
|
||
const botIndex = Number(player.id.slice(LoadTestRoom.BOT_ID_PREFIX.length)); | ||
|
||
LoadTestRoom.addBot(botIndex, this.botCount, this.room); | ||
} | ||
|
||
static addBot(botNumber: number, botCount: number, room: Room) { | ||
const botId = `${LoadTestRoom.BOT_ID_PREFIX}${botNumber}`; | ||
const botName = `BOT ${botNumber}`; | ||
const position = { | ||
x: (room.size.x / (botCount + 1)) * botNumber, | ||
y: room.size.y / 2, | ||
}; | ||
|
||
room.players[botId] = makeBot( | ||
botId, | ||
room.id, | ||
botName, | ||
position, | ||
makeFlailWeapon(position), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import { makeRoom } from "../../common/types/room"; | ||
import { world } from "../world"; | ||
import { makeBaseRoomController } from "./room-controller.base"; | ||
import { BaseRoomController } from "./room-controller.base"; | ||
|
||
export function makeNormalRoom() { | ||
const room = makeRoom(world.nextRoomId++); | ||
const base = makeBaseRoomController(room); | ||
|
||
return { | ||
room, | ||
controller: base, | ||
}; | ||
export class NormalRoom extends BaseRoomController { | ||
constructor() { | ||
super(BaseRoomController.makeRoom(world.nextRoomId++)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters