Exemplo n.º 1
0
  /** 强制单元停止 */
  public void stop() {
    if (!running.isRunning()) return;

    // 强制同步移动
    this.running._pulse(this.getTime(), true);

    // 停止移动
    running._stop();

    // 发送消息
    SCStageMoveStop.Builder msgStop = SCStageMoveStop.newBuilder();
    msgStop.setObjId(id);
    msgStop.setPosEnd(posNow.toMsg());
    StageManager.inst().sendMsgToArea(msgStop, stageObj, posNow);
  }
Exemplo n.º 2
0
  /**
   * 地图单元移动
   *
   * @param posFrom
   * @param posTo
   */
  public void move(Vector3D posFrom, List<Vector3D> posTo, Vector3D dir, boolean fromClient) {
    if (!isInWorld()) return;
    if (!canMove) return;

    // 移动过于频繁,忽略这次消息
    // if (fromClient && !running.isTimeExpired()) {
    // return;
    // }
    //		if(posFrom.z == 0) {
    //			posFrom.z = 0;
    //		}
    // 修正起点
    //		if (isHumanObj()) {
    //			posFrom.set(running.correctPosFrom(posFrom));
    //		}

    // 修正所有点,如果连续两个点相同,则移出后一个
    Vector3D pos = new Vector3D();
    pos.set(posFrom);
    Iterator<Vector3D> it = posTo.iterator();
    while (it.hasNext()) {
      Vector3D posNext = it.next();
      if (pos.distance(posNext) < 0.01) {
        it.remove();
        continue;
      }
      pos.set(posNext);
    }

    // 目标点为空
    if (posTo.isEmpty()) return;

    if (this.isHumanObj()) {
      Event.fire(EventKey.HUMAN_MOVE_START_BEFORE, "humanObj", this);
      Event.fire(EventKey.HUMAN_ACTS_BEFORE, "humanObj", this);
    }

    // 移动
    running._move(posFrom, posTo, 1.0D * getUnit().getSpeed() / 100);

    // 发送消息给前端
    Msg.SCStageMove.Builder move = Msg.SCStageMove.newBuilder();
    move.setObjId(id);
    move.setPosBegin(posFrom.toMsg());
    move.addAllPosEnd(running.getRunPathMsg());
    move.setDir(dir.toMsg());
    StageManager.inst().sendMsgToArea(move, stageObj, posNow);

    // 抛出开始移动的事件
    Event.fire(EventKey.UNIT_MOVE_START, "unitObj", this);
    Event.fire(EventKey.UNIT_ACT, "unitObj", this);
    if (this.isHumanObj()) {
      Event.fire(EventKey.HUMAN_MOVE_START, "humanObj", this);
      Event.fire(EventKey.HUMAN_ACT, "humanObj", this);
    } else {
      Event.fire(EventKey.MONSTER_MOVE_START, "monsterObj", this);
      Event.fire(EventKey.MONSTER_ACT, "monsterObj", this);
    }

    // 记录日志
    if (this.isHumanObj()) {
      if (Log.stageMove.isInfoEnabled()) {
        //				Log.stageMove.info("角色({} {})开始移动,起始位置{},接下来的目标为{}。",
        //						this.name, this.id,posFrom.getPosStr(),
        //						running.getRunPathMsg());
      }
    } else {
      if (Log.stageMove.isInfoEnabled()) {
        //				Log.stageMove.info("地图单元({})开始移动,起始位置{},接下来的目标为{}。", this.name,
        //						posFrom.getPosStr(), running.getRunPathMsg());
      }
    }
  }
Exemplo n.º 3
0
 /**
  * 地图单元移动
  *
  * @param timeCurr 当前时间
  */
 public void pulseMove(long timeCurr) {
   if (!isInWorld()) return;
   if (!running.isRunning()) return;
   // 单元移动了
   running._pulse(timeCurr);
 }