@Override
    public void run() {
      if (this.main.getShell().isDisposed()) {
        return;
      }
      // タブを更新する
      CTabItem maintab = this.main.getTabFolder().getItem(0);
      maintab.setToolTipText(
          "装備:"
              + GlobalContext.getItemMap().size()
              + "/"
              + GlobalContext.maxSlotitem()
              + " 艦娘:"
              + GlobalContext.getShipMap().size()
              + "/"
              + GlobalContext.maxChara());

      boolean combinedFleetBadlyDamaed = false;
      if (GlobalContext.isCombined()) {
        combinedFleetBadlyDamaed =
            GlobalContext.getDock("1").isBadlyDamaged()
                || GlobalContext.getDock("2").isBadlyDamaged();
      }

      List<ShipDto> badlyDamaged = new ArrayList<>();

      FleetWindow[] fleetWindows = this.main.getFleetWindows();
      for (int i = 0; i < fleetWindows.length; i++) {
        fleetWindows[i].updateFleet(combinedFleetBadlyDamaed, badlyDamaged);
      }

      this.postFatal(badlyDamaged);
    }
Beispiel #2
0
  /**
   * 戦闘フェーズ結果を読み込む
   *
   * @param object 受け取ったJSON
   * @param kind 戦闘の種別
   * @return 作成されたPhaseオブジェクト
   */
  public Phase addPhase(JsonObject object, BattlePhaseKind kind) {
    if (this.phaseList.size() == 0) {
      // 最初のフェーズ
      String dockId;

      if (object.containsKey("api_dock_id")) {
        dockId = object.get("api_dock_id").toString();
      } else {
        dockId = object.get("api_deck_id").toString();
      }

      JsonArray nowhps = object.getJsonArray("api_nowhps");
      JsonArray maxhps = object.getJsonArray("api_maxhps");
      JsonArray nowhpsCombined = object.getJsonArray("api_nowhps_combined");
      JsonArray maxhpsCombined = object.getJsonArray("api_maxhps_combined");
      boolean isCombined = (nowhpsCombined != null);

      int numFships = 6;
      int numFshipsCombined = 0;

      for (int i = 1; i <= 6; ++i) {
        if (maxhps.getInt(i) == -1) {
          numFships = i - 1;
          break;
        }
      }
      if (object.containsKey("api_fParam_combined")) {
        numFshipsCombined = 6;
        for (int i = 1; i <= 6; ++i) {
          if (maxhpsCombined.getInt(i) == -1) {
            numFshipsCombined = i - 1;
            break;
          }
        }
      }

      if (this.friends.size() == 0) { // 再読み込みの場合はスキップ
        this.friends.add(GlobalContext.getDock(dockId));
        if (numFshipsCombined > 0) {
          this.friends.add(GlobalContext.getDock("2"));
        }
      }

      JsonArray shipKe = object.getJsonArray("api_ship_ke");
      JsonArray eSlots = object.getJsonArray("api_eSlot");
      JsonArray eParams = object.getJsonArray("api_eParam");
      JsonArray eLevel = object.getJsonArray("api_ship_lv");
      for (int i = 1; i < shipKe.size(); i++) {
        int id = shipKe.getInt(i);
        if (id != -1) {
          int[] slot = JsonUtils.toIntArray(eSlots.getJsonArray(i - 1));
          int[] param = JsonUtils.toIntArray(eParams.getJsonArray(i - 1));
          this.enemy.add(new EnemyShipDto(id, slot, param, eLevel.getInt(i)));
        }
      }
      int numEships = this.enemy.size();

      this.startFriendHp = new int[numFships];
      this.startEnemyHp = new int[numEships];
      this.maxFriendHp = new int[numFships];
      this.maxEnemyHp = new int[numEships];
      if (isCombined) {
        this.startFriendHpCombined = new int[numFshipsCombined];
        this.maxFriendHpCombined = new int[numFshipsCombined];
      } else {
        this.maxFriendHpCombined = null;
      }

      // 陣形
      if (object.containsKey("api_formation")) {
        JsonArray formation = object.getJsonArray("api_formation");
        for (int i = 0; i < 2; ++i) {
          switch (formation.get(i).getValueType()) {
            case NUMBER:
              this.formation[i] = toFormation(formation.getInt(i));
              break;
            default:
              this.formation[i] = toFormation(Integer.parseInt(formation.getString(i)));
          }
        }
        this.formationMatch = toMatch(formation.getInt(2));
      }

      // 索敵
      JsonArray jsonSearch = object.getJsonArray("api_search");
      if (jsonSearch != null) {
        this.sakuteki =
            new String[] {toSearch(jsonSearch.getInt(0)), toSearch(jsonSearch.getInt(1))};
      }

      // この戦闘の開始前HPを取得
      for (int i = 1; i < nowhps.size(); i++) {
        int hp = nowhps.getInt(i);
        int maxHp = maxhps.getInt(i);
        if (i <= 6) {
          if (i <= numFships) {
            this.maxFriendHp[i - 1] = maxHp;
            this.friendGaugeMax += this.startFriendHp[i - 1] = hp;
          }
        } else {
          if ((i - 6) <= numEships) {
            this.maxEnemyHp[i - 1 - 6] = maxHp;
            this.enemyGaugeMax += this.startEnemyHp[i - 1 - 6] = hp;
          }
        }
      }
      if (isCombined) {
        for (int i = 1; i < nowhpsCombined.size(); i++) {
          int hp = nowhpsCombined.getInt(i);
          int maxHp = maxhpsCombined.getInt(i);
          if (i <= numFshipsCombined) {
            this.maxFriendHpCombined[i - 1] = maxHp;
            this.friendGaugeMax += this.startFriendHpCombined[i - 1] = hp;
          }
        }

        // 退避
        this.escaped = new boolean[12];
        if (JsonUtils.hasKey(object, "api_escape_idx")) {
          for (JsonValue jsonShip : object.getJsonArray("api_escape_idx")) {
            this.escaped[((JsonNumber) jsonShip).intValue() - 1] = true;
          }
        }
        if (JsonUtils.hasKey(object, "api_escape_idx_combined")) {
          for (JsonValue jsonShip : object.getJsonArray("api_escape_idx_combined")) {
            this.escaped[(((JsonNumber) jsonShip).intValue() - 1) + 6] = true;
          }
        }
        for (int i = 0; i < 2; ++i) {
          this.friends.get(i).setEscaped(Arrays.copyOfRange(this.escaped, i * 6, (i + 1) * 6));
        }
      }
    }

    if (this.phaseList.size() > 0) {
      Phase phase = this.phaseList.get(0);
      this.completeDamageAndAddPhase(
          new Phase(
              this,
              object,
              kind,
              phase.getNowFriendHp(),
              phase.getNowFriendHpCombined(),
              phase.getNowEnemyHp()),
          kind);
    } else {
      this.completeDamageAndAddPhase(
          new Phase(
              this,
              object,
              kind,
              this.startFriendHp,
              this.startFriendHpCombined,
              this.startEnemyHp),
          kind);
    }
    return this.phaseList.get(this.phaseList.size() - 1);
  }
    /**
     * 遠征を更新する
     *
     * @param now
     * @param notice
     * @return
     */
    private void updateDeck() {
      BasicInfoDto basicDto = GlobalContext.getBasicInfo();
      if (AppConfig.get().isNameOnTitlebar() && (basicDto != null)) {
        String titlebarText = basicDto.getNickname() + " - 航海日誌";
        this.main.setTitleText(titlebarText);
      } else {
        this.main.setTitleText(AppConstants.TITLEBAR_TEXT);
      }

      Label[] deckNameLabels = {
        this.main.getDeck1name(), this.main.getDeck2name(),
        this.main.getDeck3name(), this.main.getDeck4name()
      };
      Text[] deckTimeTexts = {
        this.main.getDeck1time(), this.main.getDeck2time(),
        this.main.getDeck3time(), this.main.getDeck4time()
      };

      DeckMissionDto[] deckMissions = GlobalContext.getDeckMissions();
      Map<Integer, Date> ndockMap = GlobalContext.getNDockCompleteTimeMap();

      for (int i = 0; i < 4; i++) {
        String time = "";
        String dispname = "";
        String tooltip = null;
        Color backColor = SWTResourceManager.getColor(SWT.COLOR_WHITE);

        DockDto dock = GlobalContext.getDock(String.valueOf(i + 1));

        if (dock != null) {
          String dockName = dock.getName();
          if ((i >= 1) && (deckMissions[i - 1].getMission() != null)) {
            // 遠征中
            DeckMissionDto mission = deckMissions[i - 1];
            dispname = dockName + " (" + mission.getDisplayText("missioncheck_" + (i + 1)) + ")";

            if (mission.getTime() != null) {
              long rest = TimeLogic.getRest(this.now, mission.getTime());

              // ツールチップテキストで時刻を表示する
              tooltip = this.format.format(mission.getTime());

              // 20分前、10分前、5分前になったら背景色を変更する
              backColor = getBackgroundColor(rest);

              // 通知生成
              this.updateNoticeDeck(dispname, i - 1, rest);

              time = TimeLogic.toDateRestString(rest);
              if (time == null) {
                time = "まもなく帰投します";
              }
            }
          } else {
            // 遠征中でない
            // 疲労回復時刻を計算
            CondTiming condTiming = GlobalContext.getCondTiming();
            Date condClearTime = null;
            long condRest = -1;
            for (ShipDto ship : dock.getShips()) {
              Date clearTime =
                  ship.getCondClearTime(
                      condTiming, ndockMap.get(ship.getId()), AppConfig.get().getOkCond());
              if (clearTime != null) {
                if ((condClearTime == null) || condClearTime.before(clearTime)) {
                  condClearTime = clearTime;
                }
                condRest = Math.max(condRest, TimeLogic.getRest(this.now, clearTime));
              }
            }
            if (condClearTime != null) {
              // 疲労回復通知生成
              this.updateNoticeCond(dockName, i, condRest);
            }

            // 泊地修理タイマー更新
            AkashiTimer.RepairState repairState = TimerContext.get().getAkashiRepairState(i);
            if (repairState.isRepairing()) {
              // 泊地修理中
              dispname = dockName + " (泊地修理中)";
              time = TimeLogic.toDateRestString(repairState.getElapsed() / 1000, true);
              backColor = ColorManager.getColor(AppConstants.AKASHI_REPAIR_COLOR);

              // ツールチップで詳細表示
              for (AkashiTimer.ShipState state : repairState.get()) {
                if (state != null) {
                  ShipDto ship = state.getShip();
                  long rest = TimeLogic.getRest(this.now, state.getFinish());
                  String txt = ship.getFriendlyName();
                  String remainStr = TimeLogic.toDateRestString(rest);
                  if (remainStr == null) {
                    txt += ":まもなく修理完了します";
                  } else {
                    txt += ":残り" + remainStr + "(" + this.format.format(state.getFinish()) + ")";
                  }
                  if (tooltip == null) {
                    tooltip = txt;
                  } else {
                    tooltip += "\n" + txt;
                  }
                }
              }

              this.updateNoticeAkashi(dock, repairState);
            } else if (!GlobalContext.isSortie(dock.getId()) && (condClearTime != null)) {
              dispname = dockName + " (疲労回復中)";

              // ツールチップテキストで時刻を表示する
              tooltip = this.format.format(condClearTime);

              // 20分前、10分前、5分前になったら背景色を変更する
              backColor = getCondBackgroundColor(condRest);

              time = TimeLogic.toDateRestString(condRest);
              if (time == null) {
                time = "疲労回復しました";
              }
            }
          }
        }

        deckNameLabels[i].setText(dispname);
        deckNameLabels[i].setToolTipText(dispname);
        deckTimeTexts[i].setText(time);
        deckTimeTexts[i].setToolTipText(tooltip);
        deckTimeTexts[i].setBackground(backColor);
      }
    }