Skip to content

Commit a427cd2

Browse files
committed
prohibit placing oob in map editor
1 parent 7daa382 commit a427cd2

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

client/src/playback/Bodies.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ export default class Bodies {
9999

100100
return body
101101
}
102+
102103
checkBodyCollisionAtLocation(type: schema.RobotType, pos: Vector): boolean {
103-
const bodyClass = BODY_DEFINITIONS[type] ?? assert.fail(`Body type ${type} not found in BODY_DEFINITIONS`)
104-
const tempBody = new bodyClass(this.game, pos, this.game.getTeamByID(1), 0)
105-
const bodySize = tempBody.size
106104
const occupiedSpaces: Vector[] = []
107105

108106
for (const otherBody of this.bodies.values()) {
@@ -154,6 +152,34 @@ export default class Bodies {
154152
return false
155153
}
156154

155+
checkBodyOutofBoundsAtLocation(type: schema.RobotType, pos: Vector): boolean {
156+
const map = this.game.currentMatch?.map
157+
if(!map) return false
158+
159+
const dimension = map.dimension
160+
const occupiedSpaces: Vector[] = []
161+
162+
if (type == schema.RobotType.RAT) {
163+
if(!map.inBounds(pos.x, pos.y)) return false
164+
}
165+
if (type == schema.RobotType.CAT) {
166+
for (let xoff = 0; xoff <= 1; xoff++) {
167+
for (let yoff = 0; yoff <= 1; yoff++) {
168+
if(!map.inBounds(pos.x+xoff, pos.y+yoff)) return false
169+
}
170+
}
171+
}
172+
if (type == schema.RobotType.RAT_KING) {
173+
for (let xoff = -1; xoff <= 1; xoff++) {
174+
for (let yoff = -1; yoff <= 1; yoff++) {
175+
if(!map.inBounds(pos.x+xoff, pos.y+yoff)) return false
176+
}
177+
}
178+
}
179+
180+
return true
181+
}
182+
157183
markBodyAsDead(id: number): void {
158184
const body = this.getById(id)
159185
body.dead = true

client/src/playback/Brushes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
546546
const add = (x: number, y: number, team: Team) => {
547547
const pos = { x, y }
548548

549-
if (this.bodies.checkBodyCollisionAtLocation(schema.RobotType.CAT, pos)) return null
549+
if (
550+
this.bodies.checkBodyCollisionAtLocation(schema.RobotType.CAT, pos)||
551+
!this.bodies.checkBodyOutofBoundsAtLocation(schema.RobotType.CAT, pos)
552+
) {
553+
return null
554+
}
550555

551556
const id = this.bodies.getNextID()
552557
this.bodies.spawnBodyFromValues(id, schema.RobotType.CAT, team, pos, 0, robotOne ? 0 : 1)
@@ -650,7 +655,8 @@ export class RatKingBrush extends SymmetricMapEditorBrush<StaticMap> {
650655
const pos = { x, y }
651656
if (
652657
this.bodies.getBodyAtLocation(x, y) ||
653-
this.bodies.checkBodyCollisionAtLocation(schema.RobotType.RAT_KING, pos)
658+
this.bodies.checkBodyCollisionAtLocation(schema.RobotType.RAT_KING, pos) ||
659+
!this.bodies.checkBodyOutofBoundsAtLocation(schema.RobotType.RAT_KING, pos)
654660
) {
655661
return null
656662
}

0 commit comments

Comments
 (0)