1 분 소요

오늘 작업

  1. 몬스터의 인식을 담당하는 로직을 수정함. 기존에는 플레이어의 추적 시간을 계산했으나 그 부분을 삭제하고 대신 시작 위치에서 거리가 벌어지면 처리하도록 합.

    이후 계획으로 맵이 타일화 될 때 추가 수정이 될 것으로 보여짐.

  lostPlayer() {
    if (this.targetPlayer === null) {
      return true;
    }

    const playerPos = this.targetPlayer.getPlayerPos();
    const distance = Math.sqrt(
      Math.pow(playerPos.x - this.x, 2) + Math.pow(playerPos.y - this.y, 2),
    );

    const distanceFromStartPoint = Math.sqrt(
      Math.pow(playerPos.x - this.startPoint_x, 2) + Math.pow(playerPos.y - this.startPoint_y, 2),
    );

    /** 몬스터가 플레이어를 잃는 조건 */
    //1. 몬스터와 플레이어 간의 거리가 인식 범위를 넘어갔을 때
    //2. 타겟 플레이어의 hp가 0이 되었을 때 
    //3. 시작 위치에서 일정 이상의 거리를 벗어나게 되었을 때
    const targetHp = this.targetPlayer.getPlayerHp();
    if (distance > this.awakeRange + 5|| targetHp <= 0 || distanceFromStartPoint > 10 + this.awakeRange) {
      this.distanceBetweenPlayer = Infinity;
      this.targetPlayer = null;
      return true;
    } else {
      this.distanceBetweenPlayer = distance;
      return false;
    }
  }
  1. game 클래스, monster 클래스 내부에서 중복되는 기능들 삭제(아래 코드는 플레이어 바로 할당 방식으로 바꾸고 game 클래스에서 적합 조건 체크)
  setTargetPlayerByDistance(player) {
    if (this.priorityPlayer === null) {
      const playerPos = player.getPlayerPos();
      const distance = Math.sqrt(
        Math.pow(this.x - playerPos.x, 2) + Math.pow(this.y - playerPos.y, 2),
      );
      if (distance <= this.awakeRange) {
        this.distanceBetweenPlayer = distance;
        this.priorityPlayer = player;
        //패킷을 보내
      }
    } else {
      if (player !== this.priorityPlayer) {
        const playerPos = this.priorityPlayer.getPlayerPos();
        const distance = Math.sqrt(
          Math.pow(this.x - playerPos.x, 2) + Math.pow(this.y - playerPos.y, 2),
        );
        if (this.distanceBetweenPlayer > distance) {
          this.priorityPlayer = player;
        }
        this.calculateBetweenDistance();
      }
    }
  }

태그:

카테고리:

업데이트: