Пример #1
0
  private void generateAttack() {
    Attack a = (Attack) jAttack.getSelectedItem();
    if (a == null) {
      System.err.println("No attack selected");
      return;
    }
    SimpleDateFormat f;
    if (!ServerSettings.getSingleton().isMillisArrival()) {
      f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format"));
    } else {
      f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format.ms"));
    }
    StringBuilder b = new StringBuilder();

    b.append(PluginManager.getSingleton().getVariableValue("sos.source"))
        .append(" ")
        .append(a.getSource().toString())
        .append("\n");
    b.append("Ziel: ").append(a.getTarget().toString()).append("\n");
    b.append(PluginManager.getSingleton().getVariableValue("attack.arrive.time"))
        .append(" ")
        .append(f.format(a.getArriveTime()))
        .append("\n");

    sendToClipboard(b.toString());
  }
Пример #2
0
  private void generateSOS() {
    String plan = (String) jAttackPlan.getSelectedItem();
    int amount = Math.min(UIHelper.parseIntFromField(jAmount, 1), jAttack.getItemCount());
    SOSRequest sos = null;
    Tribe t = null;
    for (int i = 0; i < amount; i++) {
      Attack a = AttackManager.getSingleton().getManagedElement(plan, i);
      if (sos == null) {
        sos = new SOSRequest(a.getTarget().getTribe());
        t = a.getTarget().getTribe();
      }

      if (t != null && a.getTarget().getTribe().getId() == t.getId()) {
        TargetInformation info = sos.addTarget(a.getTarget());
        if (info.getTroops().isEmpty()) {
          Hashtable<UnitHolder, Integer> troops = getDefendingTroops();

          Enumeration<UnitHolder> keys = troops.keys();
          while (keys.hasMoreElements()) {
            UnitHolder key = keys.nextElement();
            info.addTroopInformation(key, troops.get(key));
          }
          info.setWallLevel(20);
        }
        if (jIncludeTypes.isSelected()) {
          info.addAttack(
              a.getSource(),
              a.getArriveTime(),
              a.getUnit(),
              a.getType() == Attack.FAKE_TYPE,
              a.getUnit().getPlainName().equals("snob"));
        } else {
          info.addAttack(a.getSource(), a.getArriveTime());
        }
      } else {
        System.err.println(
            "Tribe "
                + a.getTarget().getTribe()
                + "does not fit request tribe "
                + sos.getDefender());
      }
    }

    /**
     * [b]Dorf:[/b] [coord]112|87[/coord] [b]Wallstufe:[/b] 20 [b]Verteidiger:[/b] 23011 22928 0 266
     * 0 814 0 0 0
     *
     * <p>bäääng! [coord]282|306[/coord] --> Ankunftszeit: 11.10.11 14:37:57
     * [player]MrBlue76[/player]
     *
     * <p>[b]Dorf:[/b] [coord]114|84[/coord] [b]Wallstufe:[/b] 20 [b]Verteidiger:[/b] 9079 9080 0
     * 100 0 300 0 0 0
     *
     * <p>bäääng! [coord]318|272[/coord] --> Ankunftszeit: 11.10.11 14:42:49
     * [player]MrBlue76[/player] bäääng! [coord]211|345[/coord] --> Ankunftszeit: 11.10.11 16:45:37
     * [player]MrBlue76[/player]
     */
    Enumeration<Village> targets = sos.getTargets();
    StringBuilder b = new StringBuilder();
    SimpleDateFormat df;
    if (de.tor.tribes.util.ServerSettings.getSingleton().isMillisArrival()) {
      df = new SimpleDateFormat("dd.MM.yy HH:mm:ss:SSS");
    } else {
      df = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    }
    while (targets.hasMoreElements()) {
      Village target = targets.nextElement();
      b.append("[b]Dorf:[/b] ").append(target.toBBCode()).append("\n");
      TargetInformation ti = sos.getTargetInformation(target);
      b.append("[b]Wallstufe:[/b] ").append(ti.getWallLevel()).append("\n");
      b.append("[b]Verteidiger:[/b] ");
      for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        b.append(ti.getTroops().get(unit)).append(" ");
      }
      b.append("\n\n");
      for (TimedAttack a : ti.getAttacks()) {
        if (jIncludeTypes.isSelected()) {
          if (a.isPossibleFake()) {
            b.append("Fake, ");
          } else {
            if (a.getUnit() != null) {
              if (a.getUnit().getPlainName().equals("axe")) {
                b.append("Axt, ");
              } else if (a.getUnit().getPlainName().equals("light")) {
                b.append("LKAV, ");
              } else if (a.getUnit().getPlainName().equals("snob")) {
                b.append("AG, ");
              } else if (a.getUnit().getPlainName().equals("heavy")) {
                b.append("SKAV, ");
              } else if (a.getUnit().getPlainName().equals("sword")) {
                b.append("Schwert, ");
              } else if (a.getUnit().getPlainName().equals("catapult")) {
                b.append("Kata, ");
              }
            }
          }
        }
        b.append(a.getSource().getName())
            .append(" ")
            .append(a.getSource().toBBCode())
            .append(" --> Ankunftszeit: ")
            .append(df.format(new Date(a.getlArriveTime())))
            .append(" ")
            .append(a.getSource().getTribe().toBBCode())
            .append("\n");
      }
      b.append("\n");
    }
    sendToClipboard(b.toString());
  }
  public static void doExport(File pHtmlFile, String pPlanName, List<Attack> pAttacks) {
    if (TEMPLATE_ERROR) {
      logger.warn("Skip writing HTML file due to TEMPLATE_ERROR flag");
      return;
    }
    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    StringBuffer result = new StringBuffer();
    // append header
    result.append(replaceHeadFootVariables(HEADER, pPlanName, pAttacks));

    int cnt = 0;
    for (Attack a : pAttacks) {
      String b = BLOCK;
      // <editor-fold defaultstate="collapsed" desc="Replace DIV-IDs">
      if (cnt % 2 == 0) {
        b = b.replaceAll(DIV_CLASS, "odd_div");
      } else {
        b = b.replaceAll(DIV_CLASS, "even_div");
      }
      b = b.replaceAll(ID, Integer.toString(cnt));
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace Unit Icons">
      UnitHolder unit = a.getUnit();
      b =
          b.replaceAll(
              UNIT,
              "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/"
                  + unit.getPlainName()
                  + ".png\">");

      switch (a.getType()) {
        case Attack.CLEAN_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/att.png\">");
            break;
          }
        case Attack.SNOB_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/snob.png\">");
            break;
          }
        case Attack.FAKE_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/fake.png\">");
            break;
          }
        case Attack.FAKE_DEFF_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE,
                    "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/def_fake.png\">");
            break;
          }
        case Attack.SUPPORT_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/ally.png\">");
            break;
          }
        default:
          {
            b = b.replaceAll(TYPE, "-");
            break;
          }
      }
      // </editor-fold>

      String baseURL = ServerManager.getServerURL(GlobalOptions.getSelectedServer()) + "/";

      // <editor-fold defaultstate="collapsed" desc=" replace source tribe and ally">
      Tribe sourceTribe = a.getSource().getTribe();
      String sourceTribeName = "";
      String sourceTribeLink = "";
      String sourceAllyName = "";
      String sourceAllyTag = "";
      String sourceAllyLink = "";
      String sourceVillageName = "";
      String sourceVillageCoord = "";
      String sourceVillageLink = "";

      if (sourceTribe == null) {
        // tribe is null, so it is a barbarian village
        sourceTribeName = "Barbaren";
        sourceAllyName = "Barbaren";
      } else {
        sourceTribeLink = baseURL;
        sourceTribeLink += "guest.php?screen=info_player&id=" + sourceTribe.getId();
        sourceTribeName = sourceTribe.getName();

        // replace source tribe
        Ally sourceAlly = sourceTribe.getAlly();
        if (sourceAlly == null) {
          // tribe has no ally
          sourceAllyName = "Kein Stamm";
        } else {
          // ally valid
          sourceAllyName = sourceAlly.getName();
          sourceAllyTag = sourceAlly.getTag();
          sourceAllyLink = baseURL;
          sourceAllyLink += "guest.php?screen=info_ally&id=" + sourceAlly.getId();
        }
      }
      // replace source village
      sourceVillageLink = baseURL;
      sourceVillageLink += "guest.php?screen=info_village&id=" + a.getSource().getId();
      sourceVillageName = a.getSource().getFullName();
      sourceVillageCoord = a.getSource().getCoordAsString();

      // replace values
      b = b.replaceAll(SOURCE_PLAYER_NAME, Matcher.quoteReplacement(sourceTribeName));
      b = b.replaceAll(SOURCE_PLAYER_LINK, sourceTribeLink);
      b = b.replaceAll(SOURCE_ALLY_NAME, Matcher.quoteReplacement(sourceAllyName));
      b = b.replaceAll(SOURCE_ALLY_TAG, Matcher.quoteReplacement(sourceAllyTag));
      b = b.replaceAll(SOURCE_ALLY_LINK, sourceAllyLink);
      b = b.replaceAll(SOURCE_VILLAGE_NAME, Matcher.quoteReplacement(sourceVillageName));
      b = b.replaceAll(SOURCE_VILLAGE_COORD, sourceVillageCoord);
      b = b.replaceAll(SOURCE_VILLAGE_LINK, sourceVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" replace target tribe and ally">
      Tribe targetTribe = a.getTarget().getTribe();
      String targetTribeName = "";
      String targetTribeLink = "";
      String targetAllyName = "";
      String targetAllyTag = "";
      String targetAllyLink = "";
      String targetVillageName = "";
      String targetVillageCoord = "";
      String targetVillageLink = "";

      if (targetTribe == null) {
        // tribe is null, so it is a barbarian village
        targetTribeName = "Barbaren";
        targetAllyName = "Barbaren";
      } else {
        targetTribeLink = baseURL;
        targetTribeLink += "guest.php?screen=info_player&id=" + targetTribe.getId();
        targetTribeName = targetTribe.getName();

        // replace source tribe
        Ally targetAlly = targetTribe.getAlly();
        if (targetAlly == null) {
          // tribe has no ally
          targetAllyName = "Kein Stamm";
        } else {
          // ally valid
          targetAllyName = targetAlly.getName();
          targetAllyTag = targetAlly.getTag();
          targetAllyLink = baseURL;
          targetAllyLink += "guest.php?screen=info_ally&id=" + targetAlly.getId();
        }
      }
      // replace source village
      targetVillageLink = baseURL;
      targetVillageLink += "guest.php?screen=info_village&id=" + a.getTarget().getId();
      targetVillageName = a.getTarget().getFullName();
      targetVillageCoord = a.getTarget().getCoordAsString();

      // replace values
      b = b.replaceAll(TARGET_PLAYER_NAME, Matcher.quoteReplacement(targetTribeName));
      b = b.replaceAll(TARGET_PLAYER_LINK, targetTribeLink);
      b = b.replaceAll(TARGET_ALLY_NAME, Matcher.quoteReplacement(targetAllyName));
      b = b.replaceAll(TARGET_ALLY_TAG, Matcher.quoteReplacement(targetAllyTag));
      b = b.replaceAll(TARGET_ALLY_LINK, targetAllyLink);
      b = b.replaceAll(TARGET_VILLAGE_NAME, Matcher.quoteReplacement(targetVillageName));
      b = b.replaceAll(TARGET_VILLAGE_COORD, targetVillageCoord);
      b = b.replaceAll(TARGET_VILLAGE_LINK, targetVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace times and place URL">
      // replace arrive time
      String arrive = f.format(a.getArriveTime());
      b = b.replaceAll(ARRIVE_TIME, arrive);
      // replace send time
      long send =
          a.getArriveTime().getTime()
              - ((long)
                      DSCalculator.calculateMoveTimeInSeconds(
                          a.getSource(), a.getTarget(), a.getUnit().getSpeed())
                  * 1000);
      b = b.replaceAll(SEND_TIME, f.format(new Date(send)));
      // replace place link
      String placeURL = baseURL + "game.php?village=";
      int uvID = GlobalOptions.getSelectedProfile().getUVId();
      if (uvID >= 0) {
        placeURL = baseURL + "game.php?t=" + uvID + "&village=";
      }
      placeURL +=
          a.getSource().getId() + "&screen=place&mode=command&target=" + a.getTarget().getId();

      placeURL += "&type=0";

      StandardAttack stdAttack = StandardAttackManager.getSingleton().getElementByIcon(a.getType());
      for (UnitHolder u : DataHolder.getSingleton().getUnits()) {
        int amount = 0;
        if (stdAttack != null) {
          amount = stdAttack.getAmountForUnit(u, a.getSource());
        }
        placeURL += "&" + u.getPlainName() + "=" + amount;
      }

      b = b.replaceAll(PLACE, placeURL);
      // </editor-fold>

      result.append(b);
      cnt++;
    }

    // append footer
    result.append(replaceHeadFootVariables(FOOTER, pPlanName, pAttacks));
    try {
      FileWriter w = new FileWriter(pHtmlFile);
      w.write(result.toString());
      w.flush();
      w.close();
    } catch (Exception e) {
      logger.error("Failed writing HTML file", e);
    }
  }