/**
   * Return True if a siege is in progress and the L2Character attacker isn't a Defender.
   *
   * @param attacker The L2Character that the L2SiegeGuardInstance try to attack
   */
  @Override
  public boolean isAutoAttackable(L2Character attacker) {
    // Attackable during siege by all except defenders
    if (!(attacker instanceof L2Playable)) {
      return false;
    }

    L2PcInstance player = attacker.getActingPlayer();

    // Check if siege is in progress
    if (((_fort != null) && _fort.getZone().isActive())
        || ((_castle != null) && _castle.getZone().isActive())
        || ((_hall != null) && _hall.getSiegeZone().isActive())) {
      int activeSiegeId =
          (_fort != null
              ? _fort.getResidenceId()
              : (_castle != null ? _castle.getResidenceId() : (_hall != null ? _hall.getId() : 0)));

      // Check if player is an enemy of this defender npc
      if ((player != null)
          && (((player.getSiegeState() == 2) && !player.isRegisteredOnThisSiegeField(activeSiegeId))
              || ((player.getSiegeState() == 1)
                  && !TerritoryWarManager.getInstance().isAllyField(player, activeSiegeId))
              || (player.getSiegeState() == 0))) {
        return true;
      }
    }
    return false;
  }
  @Override
  public void addDamageHate(L2Character attacker, int damage, int aggro) {
    if (attacker == null) {
      return;
    }

    if (!(attacker instanceof L2DefenderInstance)) {
      if ((damage == 0) && (aggro <= 1) && (attacker instanceof L2Playable)) {
        L2PcInstance player = attacker.getActingPlayer();
        // Check if siege is in progress
        if (((_fort != null) && _fort.getZone().isActive())
            || ((_castle != null) && _castle.getZone().isActive())
            || ((_hall != null) && _hall.getSiegeZone().isActive())) {
          int activeSiegeId =
              (_fort != null
                  ? _fort.getResidenceId()
                  : (_castle != null
                      ? _castle.getResidenceId()
                      : (_hall != null ? _hall.getId() : 0)));
          if ((player != null)
              && (((player.getSiegeState() == 2)
                      && player.isRegisteredOnThisSiegeField(activeSiegeId))
                  || ((player.getSiegeState() == 1)
                      && TerritoryWarManager.getInstance().isAllyField(player, activeSiegeId)))) {
            return;
          }
        }
      }
      super.addDamageHate(attacker, damage, aggro);
    }
  }
 private void showSiegeTimePage(L2PcInstance activeChar) {
   final NpcHtmlMessage adminReply = new NpcHtmlMessage();
   adminReply.setFile(activeChar.getHtmlPrefix(), "data/html/admin/territorywartime.htm");
   adminReply.replace(
       "%time%", TerritoryWarManager.getInstance().getTWStart().getTime().toString());
   activeChar.sendPacket(adminReply);
 }
 @Override
 public boolean doDie(L2Character killer) {
   if (!super.doDie(killer)) return false;
   if (_siege != null && _clan != null) {
     L2SiegeClan sc = _siege.getAttackerClan(_clan);
     if (sc != null) sc.removeFlag(this);
   } else if (_clan != null) TerritoryWarManager.getInstance().removeClanFlag(_clan);
   return true;
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = player.getQuestState(getName());
    if (st == null) {
      return htmltext;
    }

    switch (st.getState()) {
      case State.CREATED:
        htmltext = (player.getLevel() >= MIN_LEVEL) ? "36479-03.html" : "36479-02.html";
        break;
      case State.STARTED:
        if (TerritoryWarManager.getInstance().isTWInProgress()) {
          return "36479-05.html";
        }
        switch (st.getCond()) {
          case 1:
            htmltext = "36479-06.html";
            break;
          case 2:
            st.setCond(3, true);
            htmltext = "36479-07.html";
            break;
          case 3:
            htmltext = "36479-08.html";
            break;
          case 4:
            st.setCond(5, true);
            htmltext = "36479-09.html";
            break;
          case 5:
            htmltext = "36479-10.html";
            break;
          case 6:
            st.setCond(7, true);
            htmltext = "36479-11.html";
            break;
          case 7:
            htmltext = "36479-12.html";
            break;
          case 8:
            st.giveItems(CLOAK, 1);
            st.exitQuest(false, true);
            htmltext = "36479-13.html";
            break;
        }
        break;
      case State.COMPLETED:
        htmltext = "36479-01.html";
        break;
    }
    return htmltext;
  }
  public L2SiegeFlagInstance(
      L2PcInstance player,
      int objectId,
      L2NpcTemplate template,
      boolean advanced,
      boolean outPost) {
    super(objectId, template);
    setInstanceType(InstanceType.L2SiegeFlagInstance);

    if (TerritoryWarManager.getInstance().isTWInProgress()) {
      _clan = player.getClan();
      _player = player;
      _canTalk = false;
      if (_clan == null) deleteMe();
      if (outPost) {
        _isAdvanced = false;
        setIsInvul(true);
      } else {
        _isAdvanced = advanced;
        setIsInvul(false);
      }
      getStatus();
      return;
    }
    _clan = player.getClan();
    _player = player;
    _canTalk = true;
    _siege = SiegeManager.getInstance().getSiege(_player.getX(), _player.getY(), _player.getZ());
    if (_siege == null)
      _siege =
          FortSiegeManager.getInstance().getSiege(_player.getX(), _player.getY(), _player.getZ());
    if (_siege == null) _siege = CHSiegeManager.getInstance().getSiege(player);
    if (_clan == null || _siege == null) {
      throw new NullPointerException(getClass().getSimpleName() + ": Initialization failed.");
    }

    L2SiegeClan sc = _siege.getAttackerClan(_clan);
    if (sc == null)
      throw new NullPointerException(getClass().getSimpleName() + ": Cannot find siege clan.");

    sc.addFlag(this);
    _isAdvanced = advanced;
    getStatus();
    setIsInvul(false);
  }
Exemple #7
0
  @Override
  protected final void writeImpl() {
    writeC(0x00);
    writeD(_charObjId);
    writeD(_canTeleport ? 0x01 : 0);
    if (_canTeleport && (_clan != null) && !_isJailed) {
      boolean isInCastleDefense = false;
      boolean isInFortDefense = false;

      L2SiegeClan siegeClan = null;
      Castle castle = CastleManager.getInstance().getCastle(_activeChar);
      Fort fort = FortManager.getInstance().getFort(_activeChar);
      SiegableHall hall = CHSiegeManager.getInstance().getNearbyClanHall(_activeChar);
      if ((castle != null) && castle.getSiege().getIsInProgress()) {
        // siege in progress
        siegeClan = castle.getSiege().getAttackerClan(_clan);
        if ((siegeClan == null) && castle.getSiege().checkIsDefender(_clan)) {
          isInCastleDefense = true;
        }
      } else if ((fort != null) && fort.getSiege().getIsInProgress()) {
        // siege in progress
        siegeClan = fort.getSiege().getAttackerClan(_clan);
        if ((siegeClan == null) && fort.getSiege().checkIsDefender(_clan)) {
          isInFortDefense = true;
        }
      }

      writeD(_clan.getHideoutId() > 0 ? 0x01 : 0x00); // 6d 01 00 00 00 - to hide away
      writeD(
          (_clan.getCastleId() > 0) || isInCastleDefense
              ? 0x01
              : 0x00); // 6d 02 00 00 00 - to castle
      writeD(
          (TerritoryWarManager.getInstance().getFlagForClan(_clan) != null)
                  || ((siegeClan != null)
                      && !isInCastleDefense
                      && !isInFortDefense
                      && !siegeClan.getFlag().isEmpty())
                  || ((hall != null) && hall.getSiege().checkIsAttacker(_clan))
              ? 0x01
              : 0x00); // 6d 03 00 00 00 - to siege HQ
      writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
      writeD(_access.allowFixedRes() ? 0x01 : 0x00); // 6d 04 00 00 00 - to FIXED
      writeD(
          (_clan.getFortId() > 0) || isInFortDefense ? 0x01 : 0x00); // 6d 05 00 00 00 - to fortress
    } else {
      writeD(0x00); // 6d 01 00 00 00 - to hide away
      writeD(0x00); // 6d 02 00 00 00 - to castle
      writeD(0x00); // 6d 03 00 00 00 - to siege HQ
      writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
      writeD(_access.allowFixedRes() ? 0x01 : 0x00); // 6d 04 00 00 00 - to FIXED
      writeD(0x00); // 6d 05 00 00 00 - to fortress
    }
    // TODO: protocol 152
    // @formatter:off
    /*
     * writeC(0); //show die animation
     * writeD(0); //agathion ress button
     * writeD(0); //additional free space
     */
    // @formatter:on
  }
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    StringTokenizer st = new StringTokenizer(command);
    command = st.nextToken();

    if (command.equals("admin_territory_war")) {
      showMainPage(activeChar);
    } else if (command.equalsIgnoreCase("admin_territory_war_time")) {
      if (st.hasMoreTokens()) {
        final Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(TerritoryWarManager.getInstance().getTWStartTimeInMillis());

        final String val = st.nextToken();
        if ("month".equals(val)) {
          int month = cal.get(Calendar.MONTH) + Integer.parseInt(st.nextToken());
          if ((cal.getActualMinimum(Calendar.MONTH) > month)
              || (cal.getActualMaximum(Calendar.MONTH) < month)) {
            activeChar.sendMessage(
                "Unable to change Siege Date - Incorrect month value only "
                    + cal.getActualMinimum(Calendar.MONTH)
                    + "-"
                    + cal.getActualMaximum(Calendar.MONTH)
                    + " is accepted!");
            return false;
          }
          cal.set(Calendar.MONTH, month);
        } else if ("day".equals(val)) {
          int day = Integer.parseInt(st.nextToken());
          if ((cal.getActualMinimum(Calendar.DAY_OF_MONTH) > day)
              || (cal.getActualMaximum(Calendar.DAY_OF_MONTH) < day)) {
            activeChar.sendMessage(
                "Unable to change Siege Date - Incorrect day value only "
                    + cal.getActualMinimum(Calendar.DAY_OF_MONTH)
                    + "-"
                    + cal.getActualMaximum(Calendar.DAY_OF_MONTH)
                    + " is accepted!");
            return false;
          }
          cal.set(Calendar.DAY_OF_MONTH, day);
        } else if ("hour".equals(val)) {
          int hour = Integer.parseInt(st.nextToken());
          if ((cal.getActualMinimum(Calendar.HOUR_OF_DAY) > hour)
              || (cal.getActualMaximum(Calendar.HOUR_OF_DAY) < hour)) {
            activeChar.sendMessage(
                "Unable to change Siege Date - Incorrect hour value only "
                    + cal.getActualMinimum(Calendar.HOUR_OF_DAY)
                    + "-"
                    + cal.getActualMaximum(Calendar.HOUR_OF_DAY)
                    + " is accepted!");
            return false;
          }
          cal.set(Calendar.HOUR_OF_DAY, hour);
        } else if ("min".equals(val)) {
          int min = Integer.parseInt(st.nextToken());
          if ((cal.getActualMinimum(Calendar.MINUTE) > min)
              || (cal.getActualMaximum(Calendar.MINUTE) < min)) {
            activeChar.sendMessage(
                "Unable to change Siege Date - Incorrect minute value only "
                    + cal.getActualMinimum(Calendar.MINUTE)
                    + "-"
                    + cal.getActualMaximum(Calendar.MINUTE)
                    + " is accepted!");
            return false;
          }
          cal.set(Calendar.MINUTE, min);
        }

        if (cal.getTimeInMillis() < Calendar.getInstance().getTimeInMillis()) {
          activeChar.sendMessage("Unable to change TW Date!");
        } else if (cal.getTimeInMillis()
            != TerritoryWarManager.getInstance().getTWStartTimeInMillis()) {
          TerritoryWarManager.getInstance().setTWStartTimeInMillis(cal.getTimeInMillis());
          GlobalVariablesManager.getInstance()
              .set(TerritoryWarManager.GLOBAL_VARIABLE, cal.getTimeInMillis());
        }
      }
      showSiegeTimePage(activeChar);
    } else if (command.equalsIgnoreCase("admin_territory_war_start")) {
      TerritoryWarManager.getInstance().setTWStartTimeInMillis(System.currentTimeMillis());
    } else if (command.equalsIgnoreCase("admin_territory_war_end")) {
      TerritoryWarManager.getInstance()
          .setTWStartTimeInMillis(System.currentTimeMillis() - TerritoryWarManager.WARLENGTH);
    } else if (command.equalsIgnoreCase("admin_territory_wards_list")) {
      // build beginning of html page
      final NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0, 1);
      StringBuilder sb = new StringBuilder();
      sb.append(
          "<html><title>Territory War</title><body><br><center><font color=\"LEVEL\">Active Wards List:</font></center>");

      // get,build & send current Wards list
      if (TerritoryWarManager.getInstance().isTWInProgress()) {
        List<TerritoryWard> territoryWardList =
            TerritoryWarManager.getInstance().getAllTerritoryWards();
        for (TerritoryWard ward : territoryWardList) {
          if (ward.getNpc() != null) {
            sb.append("<table width=270><tr>");
            sb.append("<td width=135 ALIGN=\"LEFT\">" + ward.getNpc().getName() + "</td>");
            sb.append(
                "<td width=135 ALIGN=\"RIGHT\"><button value=\"TeleTo\" action=\"bypass -h admin_move_to "
                    + ward.getNpc().getX()
                    + " "
                    + ward.getNpc().getY()
                    + " "
                    + ward.getNpc().getZ()
                    + "\" width=50 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></td>");
            sb.append("</tr></table>");
          } else if (ward.getPlayer() != null) {
            sb.append("<table width=270><tr>");
            sb.append(
                "<td width=135 ALIGN=\"LEFT\">"
                    + ward.getPlayer().getActiveWeaponInstance().getItemName()
                    + " - "
                    + ward.getPlayer().getName()
                    + "</td>");
            sb.append(
                "<td width=135 ALIGN=\"RIGHT\"><button value=\"TeleTo\" action=\"bypass -h admin_move_to "
                    + ward.getPlayer().getX()
                    + " "
                    + ward.getPlayer().getY()
                    + " "
                    + ward.getPlayer().getZ()
                    + "\" width=50 height=20 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></td>");
            sb.append("</tr></table>");
          }
        }
        sb.append(
            "<br><center><button value=\"Back\" action=\"bypass -h admin_territory_war\" width=50 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
        npcHtmlMessage.setHtml(sb.toString());
        activeChar.sendPacket(npcHtmlMessage);
      } else {
        sb.append("<br><br><center>The Ward List is empty!<br>TW has probably NOT started!");
        sb.append(
            "<br><button value=\"Back\" action=\"bypass -h admin_territory_war\" width=50 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
        npcHtmlMessage.setHtml(sb.toString());
        activeChar.sendPacket(npcHtmlMessage);
      }
    }
    return true;
  }