Skip to content

Commit

Permalink
chore: trees size fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 committed Dec 30, 2024
1 parent 25fb1cb commit b01d95e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions apps/website/server/core/rooms/wagon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export class WagonRoom extends BaseRoom {
}

this.objects = this.objects.filter((o) => o.id !== id)

this.updateChunksInStorage()
}

createNewChunks() {
Expand Down Expand Up @@ -278,6 +280,8 @@ export class WagonRoom extends BaseRoom {
}

this.chunks = this.chunks.filter((c) => c !== chunk)

this.updateChunksInStorage()
}
}

Expand Down
6 changes: 4 additions & 2 deletions apps/website/server/core/rooms/wagon/chunk/forestChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ export class ForestChunk extends BaseChunk {
const treesAmount = this.width / 50
for (let i = 0; i < treesAmount; i++) {
const x = getRandomInRange(this.startX, this.endX)
const size = getRandomInRange(100, 175)

this.objects.push({
type: 'TREE',
id: createId(),
x,
state: 'IDLE',
health: 100,
speedPerSecond: 0,
size: 75,
maxSize: getRandomInRange(100, 175),
size,
maxSize: size,
zIndex: getRandomInRange(-10, 1),
variant: this.variant,
treeType: this.getRandomTreeType(),
Expand Down
6 changes: 4 additions & 2 deletions packages/game/src/lib/objects/treeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class TreeObject extends BaseObject implements GameObjectTree {

switch (this.state) {
case 'IDLE':
this.grow()
// this.grow()
break
case 'CHOPPING':
this.handleChoppingState()
Expand Down Expand Up @@ -108,7 +108,9 @@ export class TreeObject extends BaseObject implements GameObjectTree {
return
}

this.visible = true
if (!this.visible) {
this.visible = true
}
}

shakeAnimation() {
Expand Down
14 changes: 5 additions & 9 deletions packages/game/src/lib/services/baseWebSocketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BaseWebSocketService implements WebSocketService {
this.addon.playerService.createPlayer({ id: obj.id, telegramId: obj.telegramId, x: obj.x, character: obj.character })
}
} else if (obj.type === 'TREE') {
this.addon.treeService.create({ id: obj.id, x: obj.x, zIndex: obj.zIndex, treeType: obj.treeType, variant: obj.variant, size: 75, maxSize: obj.maxSize })
this.addon.treeService.create({ id: obj.id, x: obj.x, zIndex: obj.zIndex, treeType: obj.treeType, variant: obj.variant, size: obj.size, maxSize: obj.maxSize })
} else {
this.addon.createObject({ type: obj.type, id: obj.id, x: obj.x, zIndex: obj?.zIndex })
}
Expand All @@ -78,8 +78,7 @@ export class BaseWebSocketService implements WebSocketService {
}
}
if (message.type === 'DISCONNECTED_FROM_WAGON_ROOM') {
const { id } = message.data
this.addon.playerService.removePlayer(id)
this.addon.playerService.removePlayer(message.data.id)
}

if (this.addon.client === 'TELEGRAM_CLIENT') {
Expand All @@ -99,17 +98,14 @@ export class BaseWebSocketService implements WebSocketService {
}

if (message.type === 'NEW_WAGON_TARGET') {
const { x } = message.data
this.addon.wagon?.createFlagAndMove(x)
this.addon.wagon?.createFlagAndMove(message.data.x)
}

if (message.type === 'NEW_TREE') {
const { id, x, zIndex, treeType, variant, maxSize } = message.data
this.addon.treeService.create({ id, x, zIndex, treeType, variant, size: 8, maxSize })
this.addon.treeService.create({ ...message.data })
}
if (message.type === 'DESTROY_TREE') {
const { id } = message.data
this.addon.removeObject(id)
this.addon.removeObject(message.data.id)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/lib/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export interface WebSocketNewTree {
zIndex: number
treeType: GameObjectTree['treeType']
variant: GameObjectTree['variant']
size: number
maxSize: number
}
}
Expand Down

0 comments on commit b01d95e

Please sign in to comment.