Exemple #1
0
 @Override
 public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
   String htmltext = null;
   switch (event) {
     case "32557-01.html":
       {
         htmltext = event;
         break;
       }
     case "licence":
       {
         final L2Clan clan = player.getClan();
         if ((clan == null) || !player.isClanLeader() || (clan.getLevel() < MIN_CLAN_LV)) {
           htmltext = "32557-02.html";
         } else if (hasAtLeastOneQuestItem(player, LICENCE)) {
           htmltext = "32557-04.html";
         } else if (AirShipManager.getInstance().hasAirShipLicense(clan.getId())) {
           player.sendPacket(SystemMessageId.THE_AIRSHIP_SUMMON_LICENSE_ALREADY_ACQUIRED);
         } else if (getQuestItemsCount(player, STONE) >= STONE_COUNT) {
           takeItems(player, STONE, STONE_COUNT);
           giveItems(player, LICENCE, 1);
         } else {
           htmltext = "32557-03.html";
         }
         break;
       }
   }
   return htmltext;
 }
  @Override
  public boolean useBypass(String command, L2PcInstance activeChar, L2Character target) {
    if (!target.isNpc()) {
      return false;
    }

    final L2Npc npc = (L2Npc) target;
    final NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
    {
      if (npc.getCastle().getOwnerId() > 0) {
        html.setFile(activeChar.getHtmlPrefix(), "data/html/territorystatus.htm");
        L2Clan clan = ClanTable.getInstance().getClan(npc.getCastle().getOwnerId());
        html.replace("%clanname%", clan.getName());
        html.replace("%clanleadername%", clan.getLeaderName());
      } else {
        html.setFile(activeChar.getHtmlPrefix(), "data/html/territorynoclan.htm");
      }
    }
    html.replace("%castlename%", npc.getCastle().getName());
    html.replace("%taxpercent%", "" + npc.getCastle().getTaxPercent());
    html.replace("%objectId%", String.valueOf(npc.getObjectId()));
    {
      if (npc.getCastle().getResidenceId() > 6) {
        html.replace("%territory%", "The Kingdom of Elmore");
      } else {
        html.replace("%territory%", "The Kingdom of Aden");
      }
    }
    activeChar.sendPacket(html);
    return true;
  }
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    final L2Clan clan = activeChar.getClan();
    if (clan == null) {
      return;
    }

    if (!activeChar.hasClanPrivilege(ClanPrivilege.CL_MANAGE_RANKS)) {
      return;
    }

    final L2ClanMember member = clan.getClanMember(_member);
    if (member == null) {
      return;
    }

    if (member.getObjectId() == clan.getLeaderId()) {
      return;
    }

    if (member.getPledgeType() == L2Clan.SUBUNIT_ACADEMY) {
      // also checked from client side
      activeChar.sendMessage("You cannot change academy member grade");
      return;
    }

    member.setPowerGrade(_powerGrade);
    clan.broadcastClanStatus();
  }
Exemple #4
0
  /**
   * Claims the hero status for the given player.
   *
   * @param player the player to become hero
   */
  public void claimHero(L2PcInstance player) {
    _heroes.get(player.getObjectId()).set(CLAIMED, true);

    final L2Clan clan = player.getClan();
    if ((clan != null) && (clan.getLevel() >= 5)) {
      clan.addReputationScore(Config.HERO_POINTS, true);
      final SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId.CLAN_MEMBER_C1_BECAME_HERO_AND_GAINED_S2_REPUTATION_POINTS);
      sm.addString(CharNameTable.getInstance().getNameById(player.getObjectId()));
      sm.addInt(Config.HERO_POINTS);
      clan.broadcastToOnlineMembers(sm);
    }

    player.setHero(true);
    player.broadcastPacket(new SocialAction(player.getObjectId(), 20016)); // Hero Animation
    player.sendPacket(new UserInfo(player));
    player.sendPacket(new ExBrExtraUserInfo(player));
    player.broadcastUserInfo();
    // Set Gained hero and reload data
    setHeroGained(player.getObjectId());
    loadFights(player.getObjectId());
    loadDiary(player.getObjectId());
    _heroMessage.put(player.getObjectId(), "");

    updateHeroes(false);
  }
  private static final void changeClanLeader(L2PcInstance player, String target) {
    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }
    if (player.getName().equalsIgnoreCase(target)) return;
    /*
     * Until proper clan leader change support is done, this is a little
     * exploit fix (leader, while fliying wyvern changes clan leader and the new leader
     * can ride the wyvern too)
     * DrHouse
     */
    if (player.isFlying()) {
      player.sendMessage("Please, stop flying");
      return;
    }

    final L2Clan clan = player.getClan();

    final L2ClanMember member = clan.getClanMember(target);
    if (member == null) {
      SystemMessage sm = new SystemMessage(SystemMessageId.S1_DOES_NOT_EXIST);
      sm.addString(target);
      player.sendPacket(sm);
      sm = null;
      return;
    }
    if (!member.isOnline()) {
      player.sendPacket(new SystemMessage(SystemMessageId.INVITED_USER_NOT_ONLINE));
      return;
    }
    clan.setNewLeader(member);
  }
  private static final void renameSubPledge(
      L2PcInstance player, int pledgeType, String pledgeName) {
    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    final L2Clan clan = player.getClan();
    final SubPledge subPledge = player.getClan().getSubPledge(pledgeType);

    if (subPledge == null) {
      player.sendMessage("Pledge don't exists.");
      return;
    }
    if (!Util.isAlphaNumeric(pledgeName) || 2 > pledgeName.length()) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }
    if (pledgeName.length() > 16) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_TOO_LONG));
      return;
    }

    subPledge.setName(pledgeName);
    clan.updateSubPledgeInDB(subPledge.getId());
    clan.broadcastClanStatus();
    player.sendMessage("Pledge name changed.");
  }
Exemple #7
0
 public void updateClansReputation(L2Clan owner, boolean removePoints) {
   if (owner != null) {
     if (removePoints) {
       owner.takeReputationScore(Config.LOOSE_FORT_POINTS, true);
     } else {
       owner.addReputationScore(Config.TAKE_FORT_POINTS, true);
     }
   }
 }
  private static final void recoverClan(L2PcInstance player, int clanId) {
    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    final L2Clan clan = player.getClan();
    clan.setDissolvingExpiryTime(0);
    clan.updateClanInDB();
  }
Exemple #9
0
 @Override
 public void onStart(BuffInfo info) {
   if (info.getEffected().isPlayer()) {
     final L2Clan clan = info.getEffected().getActingPlayer().getClan();
     if (clan != null) {
       SystemMessage msg =
           SystemMessage.getSystemMessage(SystemMessageId.COURT_MAGICIAN_CREATED_PORTAL);
       clan.broadcastToOtherOnlineMembers(msg, info.getEffected().getActingPlayer());
     }
   }
 }
  private static final void dissolveClan(L2PcInstance player, int clanId) {
    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    final L2Clan clan = player.getClan();
    if (clan.getAllyId() != 0) {
      player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISPERSE_THE_CLANS_IN_ALLY));
      return;
    }
    if (clan.isAtWar()) {
      player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_WAR));
      return;
    }
    if (clan.getHasCastle() != 0 || clan.getHasHideout() != 0 || clan.getHasFort() != 0) {
      player.sendPacket(
          new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_OWNING_CLAN_HALL_OR_CASTLE));
      return;
    }

    for (Castle castle : CastleManager.getInstance().getCastles()) {
      if (SiegeManager.getInstance().checkIsRegistered(clan, castle.getCastleId())) {
        player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE));
        return;
      }
    }
    for (Fort fort : FortManager.getInstance().getForts()) {
      if (FortSiegeManager.getInstance().checkIsRegistered(clan, fort.getFortId())) {
        player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE));
        return;
      }
    }

    if (player.isInsideZone(L2PcInstance.ZONE_SIEGE)) {
      player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_WHILE_IN_SIEGE));
      return;
    }
    if (clan.getDissolvingExpiryTime() > System.currentTimeMillis()) {
      player.sendPacket(new SystemMessage(SystemMessageId.DISSOLUTION_IN_PROGRESS));
      return;
    }

    clan.setDissolvingExpiryTime(
        System.currentTimeMillis()
            + Config.ALT_CLAN_DISSOLVE_DAYS * 86400000L); // 24*60*60*1000 = 86400000
    clan.updateClanInDB();

    ClanTable.getInstance().scheduleRemoveClan(clan.getClanId());

    // The clan leader should take the XP penalty of a full death.
    player.deathPenalty(false, false, false);
  }
 public final ClanHall getAbstractHallByOwner(L2Clan clan) {
   // Separate loops to avoid iterating over free clan halls
   for (Map.Entry<Integer, AuctionableHall> ch : _clanHall.entrySet()) {
     if (clan.getId() == ch.getValue().getOwnerId()) {
       return ch.getValue();
     }
   }
   for (Map.Entry<Integer, SiegableHall> ch :
       CHSiegeManager.getInstance().getConquerableHalls().entrySet()) {
     if (clan.getId() == ch.getValue().getOwnerId()) {
       return ch.getValue();
     }
   }
   return null;
 }
 @Override
 protected final void writeImpl() {
   writeC(0x2A);
   writeD(_rank);
   writeD(_action);
   writeD(_clan.getRankPrivs(_rank).getBitmask());
 }
 /**
  * @param clan
  * @return Clan Hall by Owner
  */
 public final AuctionableHall getClanHallByOwner(L2Clan clan) {
   for (Map.Entry<Integer, AuctionableHall> ch : _clanHall.entrySet()) {
     if (clan.getId() == ch.getValue().getOwnerId()) {
       return ch.getValue();
     }
   }
   return null;
 }
Exemple #14
0
 public void removeOwner(boolean updateDB) {
   L2Clan clan = getOwnerClan();
   if (clan != null) {
     for (L2PcInstance member : clan.getOnlineMembers(0)) {
       removeResidentialSkills(member);
       member.sendSkillList();
     }
     clan.setFortId(0);
     clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
     setOwnerClan(null);
     setSupplyLvL(0);
     saveFortVariables();
     removeAllFunctions();
     if (updateDB) {
       updateOwnerInDB();
     }
   }
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    L2Clan clan = player.getClan();
    switch (st.getState()) {
      case State.CREATED:
        htmltext =
            ((clan == null) || !player.isClanLeader() || (clan.getLevel() < 5))
                ? "31331-0.htm"
                : "31331-1.htm";
        break;
      case State.STARTED:
        if ((clan == null) || !player.isClanLeader()) {
          st.exitQuest(true);
          return "31331-8.html";
        }

        if (!st.hasQuestItems(TYRANNOSAURUS_CLAW)) {
          htmltext = "31331-4.html";
        } else {
          int count = (int) st.getQuestItemsCount(TYRANNOSAURUS_CLAW);
          int reward = (count < 10) ? (30 * count) : (59 + (30 * count));
          st.playSound(QuestSound.ITEMSOUND_QUEST_FANFARE_1);
          st.takeItems(TYRANNOSAURUS_CLAW, -1);
          clan.addReputationScore(reward, true);
          player.sendPacket(
              SystemMessage.getSystemMessage(
                      SystemMessageId
                          .YOU_HAVE_SUCCESSFULLY_COMPLETED_A_CLAN_QUEST_S1_POINT_S_HAVE_BEEN_ADDED_TO_YOUR_CLAN_REPUTATION)
                  .addInt(reward));
          clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
          htmltext = "31331-7.html";
        }
        break;
      default:
        break;
    }
    return htmltext;
  }
  private static final void assignSubPledgeLeader(
      L2PcInstance player, String clanName, String leaderName) {
    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }
    if (leaderName.length() > 16) {
      player.sendPacket(new SystemMessage(SystemMessageId.NAMING_CHARNAME_UP_TO_16CHARS));
      return;
    }
    if (player.getName().equals(leaderName)) {
      player.sendPacket(
          new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));
      return;
    }

    final L2Clan clan = player.getClan();
    final SubPledge subPledge = player.getClan().getSubPledge(clanName);

    if (null == subPledge || subPledge.getId() == L2Clan.SUBUNIT_ACADEMY) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }
    if (clan.getClanMember(leaderName) == null
        || (clan.getClanMember(leaderName).getPledgeType() != 0)) {
      if (subPledge.getId() >= L2Clan.SUBUNIT_KNIGHT1)
        player.sendPacket(
            new SystemMessage(SystemMessageId.CAPTAIN_OF_ORDER_OF_KNIGHTS_CANNOT_BE_APPOINTED));
      else if (subPledge.getId() >= L2Clan.SUBUNIT_ROYAL1)
        player.sendPacket(
            new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));

      return;
    }

    subPledge.setLeaderId(clan.getClanMember(leaderName).getObjectId());
    clan.updateSubPledgeInDB(subPledge.getId());

    final L2ClanMember leaderSubPledge = clan.getClanMember(leaderName);
    final L2PcInstance leaderPlayer = leaderSubPledge.getPlayerInstance();
    if (leaderPlayer != null) {
      leaderPlayer.setPledgeClass(leaderSubPledge.calculatePledgeClass(leaderPlayer));
      leaderPlayer.sendPacket(new UserInfo(leaderPlayer));
      leaderPlayer.sendPacket(new ExBrExtraUserInfo(leaderPlayer));
    }

    clan.broadcastClanStatus();
    SystemMessage sm = new SystemMessage(SystemMessageId.C1_HAS_BEEN_SELECTED_AS_CAPTAIN_OF_S2);
    sm.addString(leaderName);
    sm.addString(clanName);
    clan.broadcastToOnlineMembers(sm);
    sm = null;
  }
 /**
  * Set ClanHallOwner
  *
  * @param chId
  * @param clan
  */
 public final synchronized void setOwner(int chId, L2Clan clan) {
   if (!_clanHall.containsKey(chId)) {
     _clanHall.put(chId, _freeClanHall.get(chId));
     _freeClanHall.remove(chId);
   } else {
     _clanHall.get(chId).free();
   }
   ClanTable.getInstance().getClan(clan.getId()).setHideoutId(chId);
   _clanHall.get(chId).setOwner(clan);
 }
Exemple #18
0
  public void convertOldPedgeFiles() {
    File dir = new File(Config.DATAPACK_ROOT, "data/crests/");

    File[] files = dir.listFiles(new OldPledgeFilter());

    for (File file : files) {
      int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));

      _log.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);

      int newId = IdFactory.getInstance().getNextId();

      L2Clan clan = ClanTable.getInstance().getClan(clanId);

      if (clan != null) {
        removeOldPledgeCrest(clan.getCrestId());

        file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
        _log.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");

        Connection con = null;

        try {
          con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement statement =
              con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
          statement.setInt(1, newId);
          statement.setInt(2, clan.getClanId());
          statement.executeUpdate();
          statement.close();
        } catch (SQLException e) {
          _log.log(Level.WARNING, "Could not update the crest id:" + e.getMessage(), e);
        } finally {
          L2DatabaseFactory.close(con);
        }

        clan.setCrestId(newId);
      } else {
        _log.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
        file.delete();
      }
    }
  }
  @Override
  protected void runImpl() {
    final L2PcInstance activeChar = getClient().getActiveChar();

    if ((activeChar == null) || (activeChar.getClan() != null)) {
      return;
    }

    final L2Clan clan = ClanTable.getInstance().getClan(_clanId);

    if (clan == null) {
      return;
    }

    final PledgeApplicantInfo info =
        new PledgeApplicantInfo(
            activeChar.getObjectId(),
            activeChar.getName(),
            activeChar.getLevel(),
            _karma,
            _clanId,
            _message);

    if (ClanEntryManager.getInstance().addPlayerApplicationToClan(_clanId, info)) {
      activeChar.sendPacket(new ExPledgeRecruitApplyInfo(ClanEntryStatus.WAITING));

      final L2PcInstance clanLeader = L2World.getInstance().getPlayer(clan.getLeaderId());

      if (clanLeader != null) {
        clanLeader.sendPacket(ExPledgeWaitingListAlarm.STATIC_PACKET);
      }
    } else {
      final SystemMessage sm =
          SystemMessage.getSystemMessage(
              SystemMessageId
                  .YOU_MAY_APPLY_FOR_ENTRY_AFTER_S1_MINUTE_S_DUE_TO_CANCELLING_YOUR_APPLICATION);
      sm.addLong(ClanEntryManager.getInstance().getPlayerLockTime(activeChar.getObjectId()));
      activeChar.sendPacket(sm);
    }
  }
  @Override
  protected void runImpl() {
    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    L2PcInstance ob = L2World.getInstance().getPlayer(_id);

    if (ob == null) {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_INVITED_THE_WRONG_TARGET));
      return;
    }

    if (activeChar.getClan() == null) {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER));
      return;
    }

    L2PcInstance target = ob;
    L2Clan clan = activeChar.getClan();
    if (!clan.checkAllyJoinCondition(activeChar, target)) {
      return;
    }
    if (!activeChar.getRequest().setRequest(target, this)) {
      return;
    }

    SystemMessage sm =
        new SystemMessage(SystemMessageId.S2_ALLIANCE_LEADER_OF_S1_REQUESTED_ALLIANCE);
    sm.addString(activeChar.getClan().getAllyName());
    sm.addString(activeChar.getName());
    target.sendPacket(sm);
    sm = null;
    AskJoinAlly aja = new AskJoinAlly(activeChar.getObjectId(), activeChar.getClan().getAllyName());
    target.sendPacket(aja);
  }
 @Override
 public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill) {
   super.reduceCurrentHp(damage, attacker, skill);
   if (canTalk()) {
     if ((getCastle() != null && getCastle().getSiege().getIsInProgress())
         || (getFort() != null && getFort().getSiege().getIsInProgress())
         || (getConquerableHall() != null && getConquerableHall().isInSiege())) {
       if (_clan != null) {
         // send warning to owners of headquarters that theirs base is under attack
         _clan.broadcastToOnlineMembers(
             SystemMessage.getSystemMessage(SystemMessageId.BASE_UNDER_ATTACK));
         setCanTalk(false);
         ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleTalkTask(), 20000);
       }
     }
   }
 }
  @Override
  protected final void writeImpl() {
    writeC(0x2a);
    if (_action == 1) {
      _privs = _clan.getRankPrivs(_rank);
    } else {
      return;
      /*
               if (L2World.getInstance().findObject(_clanId) == null)
                   return;

      privs = ((L2PcInstance)L2World.getInstance().findObject(_clanId)).getClanPrivileges();
       */
    }

    writeD(0);
    writeD(0);
    writeD(_privs);
  }
Exemple #23
0
  private void updateOwnerInDB() {
    L2Clan clan = getOwnerClan();
    int clanId = 0;
    if (clan != null) {
      clanId = clan.getId();
      _lastOwnedTime.setTimeInMillis(System.currentTimeMillis());
    } else {
      _lastOwnedTime.setTimeInMillis(0);
    }

    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps =
            con.prepareStatement(
                "UPDATE fort SET owner=?,lastOwnedTime=?,state=?,castleId=? WHERE id = ?")) {
      ps.setInt(1, clanId);
      ps.setLong(2, _lastOwnedTime.getTimeInMillis());
      ps.setInt(3, 0);
      ps.setInt(4, 0);
      ps.setInt(5, getResidenceId());
      ps.execute();

      // Announce to clan members
      if (clan != null) {
        clan.setFortId(getResidenceId()); // Set has fort flag for new owner
        SystemMessage sm;
        sm =
            SystemMessage.getSystemMessage(
                SystemMessageId.S1_IS_VICTORIOUS_IN_THE_FORTRESS_BATTLE_OF_S2);
        sm.addString(clan.getName());
        sm.addCastleId(getResidenceId());
        L2World.getInstance().getPlayers().forEach(p -> p.sendPacket(sm));
        clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
        clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
        if (_FortUpdater[0] != null) {
          _FortUpdater[0].cancel(false);
        }
        if (_FortUpdater[1] != null) {
          _FortUpdater[1].cancel(false);
        }
        _FortUpdater[0] =
            ThreadPoolManager.getInstance()
                .scheduleGeneralAtFixedRate(
                    new FortUpdater(this, clan, 0, UpdaterType.PERIODIC_UPDATE),
                    Config.FS_UPDATE_FRQ * 60000L,
                    Config.FS_UPDATE_FRQ * 60000L); // Schedule owner tasks to start running
        if (Config.FS_MAX_OWN_TIME > 0) {
          _FortUpdater[1] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneralAtFixedRate(
                      new FortUpdater(this, clan, 0, UpdaterType.MAX_OWN_TIME),
                      3600000,
                      3600000); // Schedule owner tasks to remove owener
        }
      } else {
        if (_FortUpdater[0] != null) {
          _FortUpdater[0].cancel(false);
        }
        _FortUpdater[0] = null;
        if (_FortUpdater[1] != null) {
          _FortUpdater[1].cancel(false);
        }
        _FortUpdater[1] = null;
      }
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage(), e);
    }
  }
Exemple #24
0
  // This method loads fort
  @Override
  protected void load() {
    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM fort WHERE id = ?")) {
      ps.setInt(1, getResidenceId());
      int ownerId = 0;
      try (ResultSet rs = ps.executeQuery()) {
        while (rs.next()) {
          setName(rs.getString("name"));

          _siegeDate = Calendar.getInstance();
          _lastOwnedTime = Calendar.getInstance();
          _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
          _lastOwnedTime.setTimeInMillis(rs.getLong("lastOwnedTime"));
          ownerId = rs.getInt("owner");
          _fortType = rs.getInt("fortType");
          _state = rs.getInt("state");
          _castleId = rs.getInt("castleId");
          _supplyLvL = rs.getInt("supplyLvL");
        }
      }
      if (ownerId > 0) {
        L2Clan clan = ClanTable.getInstance().getClan(ownerId); // Try to find clan instance
        clan.setFortId(getResidenceId());
        setOwnerClan(clan);
        int runCount = getOwnedTime() / (Config.FS_UPDATE_FRQ * 60);
        long initial = System.currentTimeMillis() - _lastOwnedTime.getTimeInMillis();
        while (initial > (Config.FS_UPDATE_FRQ * 60000L)) {
          initial -= (Config.FS_UPDATE_FRQ * 60000L);
        }
        initial = (Config.FS_UPDATE_FRQ * 60000L) - initial;
        if ((Config.FS_MAX_OWN_TIME <= 0) || (getOwnedTime() < (Config.FS_MAX_OWN_TIME * 3600))) {
          _FortUpdater[0] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneralAtFixedRate(
                      new FortUpdater(this, clan, runCount, UpdaterType.PERIODIC_UPDATE),
                      initial,
                      Config.FS_UPDATE_FRQ * 60000L); // Schedule owner tasks to start running
          if (Config.FS_MAX_OWN_TIME > 0) {
            _FortUpdater[1] =
                ThreadPoolManager.getInstance()
                    .scheduleGeneralAtFixedRate(
                        new FortUpdater(this, clan, runCount, UpdaterType.MAX_OWN_TIME),
                        3600000,
                        3600000); // Schedule owner tasks to remove owener
          }
        } else {
          _FortUpdater[1] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneral(
                      new FortUpdater(this, clan, 0, UpdaterType.MAX_OWN_TIME),
                      60000); // Schedule owner tasks to remove owner
        }
      } else {
        setOwnerClan(null);
      }

    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: loadFortData(): " + e.getMessage(), e);
    }
  }
Exemple #25
0
  /**
   * This method will set owner for Fort
   *
   * @param clan
   * @param updateClansReputation
   * @return
   */
  public boolean setOwner(L2Clan clan, boolean updateClansReputation) {
    if (clan == null) {
      _log.warning(getClass().getSimpleName() + ": Updating Fort owner with null clan!!!");
      return false;
    }

    final SystemMessage sm =
        SystemMessage.getSystemMessage(SystemMessageId.THE_FORTRESS_BATTLE_OF_S1_HAS_FINISHED);
    sm.addCastleId(getResidenceId());
    getSiege().announceToPlayer(sm);

    final L2Clan oldowner = getOwnerClan();
    if ((oldowner != null) && (clan != oldowner)) {
      // Remove points from old owner
      updateClansReputation(oldowner, true);
      try {
        L2PcInstance oldleader = oldowner.getLeader().getPlayerInstance();
        if (oldleader != null) {
          if (oldleader.getMountType() == MountType.WYVERN) {
            oldleader.dismount();
          }
        }
      } catch (Exception e) {
        _log.log(Level.WARNING, "Exception in setOwner: " + e.getMessage(), e);
      }
      removeOwner(true);
    }
    setFortState(0, 0); // initialize fort state

    // if clan already have castle, don't store him in fortress
    if (clan.getCastleId() > 0) {
      getSiege()
          .announceToPlayer(
              SystemMessage.getSystemMessage(
                  SystemMessageId.THE_REBEL_ARMY_RECAPTURED_THE_FORTRESS));
      return false;
    }

    // Give points to new owner
    if (updateClansReputation) {
      updateClansReputation(clan, false);
    }

    spawnSpecialEnvoys();
    // if clan have already fortress, remove it
    if (clan.getFortId() > 0) {
      FortManager.getInstance().getFortByOwner(clan).removeOwner(true);
    }

    setSupplyLvL(0);
    setOwnerClan(clan);
    updateOwnerInDB(); // Update in database
    saveFortVariables();

    if (getSiege().isInProgress()) {
      getSiege().endSiege();
    }

    for (L2PcInstance member : clan.getOnlineMembers(0)) {
      giveResidentialSkills(member);
      member.sendSkillList();
    }
    return true;
  }
Exemple #26
0
  @Override
  protected final void writeImpl() {
    writeC(0x96);
    writeS(_activeChar.getName());
    writeD(_clan.getClanId());
    writeD(0x00);
    writeS(_clan.getName());
    writeS(_clan.getLeaderName());
    writeD(_clan.getCrestId()); // -> no, it's no longer used (nuocnam) fix by game
    writeD(_clan.getLevel());
    writeD(_clan.getCastleId());
    writeD(_clan.getHideoutId());
    writeD(_clan.getFortId());
    writeD(_clan.getRank());
    writeD(_clan.getReputationScore());
    writeD(0x00);
    writeD(0x00);

    writeD(_clan.getAllyId()); // c2
    writeS(_clan.getAllyName()); // c2
    writeD(_clan.getAllyCrestId()); // c2
    writeD(_clan.isAtWar() ? 1 : 0); // c3
    writeD(0x00); // T3 Unknown
    writeD(_clan.getMembers().length);

    for (L2ClanMember member : _clan.getMembers()) {
      if (member != null) {
        writeS(member.getName());
        writeD(member.getLevel());
        writeD(member.getClassId());
        writeD(member.getSex() ? 1 : 0);
        writeD(member.getRaceOrdinal());
        writeD(member.isOnline() ? member.getObjectId() : 0);
        writeD(member.getSponsor() != 0 ? 1 : 0);
      }
    }
  }
 @Override
 public void unregister() {
   L2Clan.removeClanCreationListener(this);
 }
 @Override
 public void register() {
   L2Clan.addClanCreationListener(this);
 }
  @Override
  public boolean useUserCommand(int id, L2PcInstance activeChar) {
    if ((id != COMMAND_IDS[0]) && (id != COMMAND_IDS[1]) && (id != COMMAND_IDS[2])) {
      return false;
    }

    final L2Clan clan = activeChar.getClan();
    if (clan == null) {
      activeChar.sendPacket(SystemMessageId.NOT_JOINED_IN_ANY_CLAN);
      return false;
    }

    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      String query;
      // Attack List
      if (id == 88) {
        activeChar.sendPacket(SystemMessageId.CLANS_YOU_DECLARED_WAR_ON);
        query = ATTACK_LIST;
      }
      // Under Attack List
      else if (id == 89) {
        activeChar.sendPacket(SystemMessageId.CLANS_THAT_HAVE_DECLARED_WAR_ON_YOU);
        query = UNDER_ATTACK_LIST;
      }
      // War List
      else {
        activeChar.sendPacket(SystemMessageId.WAR_LIST);
        query = WAR_LIST;
      }

      try (PreparedStatement ps = con.prepareStatement(query)) {
        ps.setInt(1, clan.getId());
        ps.setInt(2, clan.getId());

        SystemMessage sm;
        try (ResultSet rs = ps.executeQuery()) {
          String clanName;
          int ally_id;
          while (rs.next()) {
            clanName = rs.getString("clan_name");
            ally_id = rs.getInt("ally_id");
            if (ally_id > 0) {
              // Target With Ally
              sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2_ALLIANCE);
              sm.addString(clanName);
              sm.addString(rs.getString("ally_name"));
            } else {
              // Target Without Ally
              sm = SystemMessage.getSystemMessage(SystemMessageId.S1_NO_ALLI_EXISTS);
              sm.addString(clanName);
            }
            activeChar.sendPacket(sm);
          }
        }
      }
      activeChar.sendPacket(SystemMessageId.FRIEND_LIST_FOOTER);
    } catch (Exception e) {
      _log.log(Level.WARNING, "", e);
    }
    return true;
  }
Exemple #30
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
  }