Skip to content

Commit

Permalink
Merge pull request #108 from mini-game-world/#107_fix_hit_count
Browse files Browse the repository at this point in the history
#107 fix hit count
  • Loading branch information
jayjayppark authored Jul 9, 2024
2 parents 2c8e229 + d8009ba commit d4a10d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/redis/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class RedisService {
private readonly client: Redis.Redis; // Explicitly type the client property
constructor() {
this.client = new Redis.default({
// REDIS_HOST=127.0.0.1
// REDIS_PORT=6379
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT), // Ensure the port is a number
});
Expand Down
40 changes: 18 additions & 22 deletions src/status/status.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,27 @@ async handleAttackPosition(channel: any, data: playerAttackPositionDTO) {

this.logger.log(`Client ${channel.id} attacked position x: ${data.x}, y: ${data.y}`);

// 같은 방의 다른 클라이언트들의 위치와 비교하여 히트된 유저들의 아이디만 추출
const hitResults = Array.from(this.statusService.bombGameRoomPosition.entries())
.filter(([playerId]) => playerId !== channel.id)
.filter(([playerId]) => {
// Exclude users in bombUserList
return (
!this.statusService.getBombUserList().includes(playerId) ||
!this.statusService.checkIsNotPlayer(playerId)
);
})
.filter(([_, pos]) => {

const bombUserList = new Set(this.statusService.getBombUserList());

const hitResults = this.statusService.getPlayGameUserList()
.filter(playerId => playerId !== channel.id)
.filter(playerId => !bombUserList.has(playerId))
.filter(playerId => {
const pos = this.statusService.bombGameRoomPosition.get(playerId);
if (pos) {
const distance = Math.sqrt(
Math.pow(data.x - pos.x, 2) + Math.pow(data.y - pos.y, 2),
Math.pow(data.x - pos.x, 2) + Math.pow(data.y - pos.y, 2)
);
return distance <= this.HITRADIUS;
})
.filter(([playerId]) => {
// Check if the player is not stunned
const playerData =
this.statusService.bombGameRoomPosition.get(playerId);
return playerData && playerData.isStun !== 1;
})
.map(([playerId]) => playerId);

// 히트된 유저들에게 개별적으로 히트 여부 알림
}
return false; // 위치 정보가 없는 경우 제외
})
.filter(playerId => {
const playerData = this.statusService.bombGameRoomPosition.get(playerId);
return playerData && playerData.isStun !== 1; // 스턴 상태가 아닌 경우만 필터링
});

hitResults.forEach(async (playerId) => {
const clientPosition = this.statusService.bombGameRoomPosition.get(playerId);
if (clientPosition) {
Expand Down

0 comments on commit d4a10d7

Please sign in to comment.