Пример #1
0
 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;
 }
Пример #2
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;
 }
Пример #3
0
 /**
  * @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;
 }
Пример #4
0
 /**
  * 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);
 }
  @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;
  }
Пример #6
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);
    }
  }
Пример #7
0
  public NpcInfo(L2Npc npc) {
    _npc = npc;
    _abnormalVisualEffects = npc.getCurrentAbnormalVisualEffects();

    addComponentType(
        NpcInfoType.ATTACKABLE,
        NpcInfoType.UNKNOWN1,
        NpcInfoType.ID,
        NpcInfoType.POSITION,
        NpcInfoType.ALIVE,
        NpcInfoType.RUNNING);

    if (npc.getHeading() > 0) {
      addComponentType(NpcInfoType.HEADING);
    }

    if ((npc.getStat().getPAtkSpd() > 0) || (npc.getStat().getMAtkSpd() > 0)) {
      addComponentType(NpcInfoType.ATK_CAST_SPEED);
    }

    if (npc.getRunSpeed() > 0) {
      addComponentType(NpcInfoType.SPEED_MULTIPLIER);
    }

    if ((npc.getLeftHandItem() > 0) || (npc.getRightHandItem() > 0)) {
      addComponentType(NpcInfoType.EQUIPPED);
    }

    if (npc.getTeam() != Team.NONE) {
      addComponentType(NpcInfoType.TEAM);
    }

    if (npc.getDisplayEffect() > 0) {
      addComponentType(NpcInfoType.DISPLAY_EFFECT);
    }

    if (npc.isInsideZone(ZoneId.WATER) || npc.isFlying()) {
      addComponentType(NpcInfoType.SWIM_OR_FLY);
    }

    if (npc.isFlying()) {
      addComponentType(NpcInfoType.FLYING);
    }

    if (npc.getMaxHp() > 0) {
      addComponentType(NpcInfoType.MAX_HP);
    }

    if (npc.getMaxMp() > 0) {
      addComponentType(NpcInfoType.MAX_MP);
    }

    if (npc.getCurrentHp() <= npc.getMaxHp()) {
      addComponentType(NpcInfoType.CURRENT_HP);
    }

    if (npc.getCurrentMp() <= npc.getMaxMp()) {
      addComponentType(NpcInfoType.CURRENT_MP);
    }

    if (npc.getTemplate().isUsingServerSideName()) {
      addComponentType(NpcInfoType.NAME);
    }

    if (npc.getTemplate().isUsingServerSideTitle()
        || (Config.SHOW_NPC_LVL && npc.isMonster())
        || npc.isChampion()) {
      addComponentType(NpcInfoType.TITLE);
    }

    if (!_abnormalVisualEffects.isEmpty()) {
      addComponentType(NpcInfoType.ABNORMALS);
    }

    if (npc.getEnchantEffect() > 0) {
      addComponentType(NpcInfoType.ENCHANT);
    }

    if ((npc.getTransformation() != null) && (npc.getTransformation().getId() > 0)) {
      addComponentType(NpcInfoType.TRANSFORMATION);
    }

    if (npc.isInsideZone(ZoneId.TOWN)
        && (npc.getCastle() != null)
        && (Config.SHOW_CREST_WITHOUT_QUEST || npc.getCastle().getShowNpcCrest())
        && (npc.getCastle().getOwnerId() != 0)) {
      int townId = TownManager.getTown(npc.getX(), npc.getY(), npc.getZ()).getTownId();
      if ((townId != 33) && (townId != 22)) {
        L2Clan clan = ClanTable.getInstance().getClan(npc.getCastle().getOwnerId());
        _clanId = clan.getId();
        _clanCrest = clan.getCrestId();
        _clanLargeCrest = clan.getCrestLargeId();
        _allyCrest = clan.getAllyCrestId();
        _allyId = clan.getAllyId();

        addComponentType(NpcInfoType.CLAN);
      }
    }

    addComponentType(NpcInfoType.UNKNOWN8);

    // TODO: Confirm me
    if (npc.isInCombat()) {
      _statusMask |= 0x01;
    }
    if (npc.isDead()) {
      _statusMask |= 0x02;
    }
    if (npc.isTargetable()) {
      _statusMask |= 0x04;
    }
    if (npc.isShowName()) {
      _statusMask |= 0x08;
    }

    if (_statusMask != 0) {
      addComponentType(NpcInfoType.VISUAL_STATE);
    }
  }
Пример #8
0
  @Override
  protected final void writeImpl() {
    writeC(0xcb);
    writeD(_castle.getResidenceId());
    writeD(0x00); // Unknown
    writeD(0x01); // Unknown
    writeD(0x00); // Unknown

    final int size =
        _castle.getSiege().getDefenderWaitingClans().size()
            + _castle.getSiege().getDefenderClans().size()
            + (_castle.getOwner() != null ? 1 : 0);

    writeD(size);
    writeD(size);

    // Add owners
    final L2Clan ownerClan = _castle.getOwner();
    if (ownerClan != null) {
      writeD(ownerClan.getId());
      writeS(ownerClan.getName());
      writeS(ownerClan.getLeaderName());
      writeD(ownerClan.getCrestId());
      writeD(0x00); // signed time (seconds) (not storated by L2J)
      writeD(SiegeClanType.OWNER.ordinal());
      writeD(ownerClan.getAllyId());
      writeS(ownerClan.getAllyName());
      writeS(""); // AllyLeaderName
      writeD(ownerClan.getAllyCrestId());
    }

    // List of confirmed defenders
    for (L2SiegeClan siegeClan : _castle.getSiege().getDefenderClans()) {
      final L2Clan defendingClan = ClanTable.getInstance().getClan(siegeClan.getClanId());
      if ((defendingClan == null) || (defendingClan == _castle.getOwner())) {
        continue;
      }

      writeD(defendingClan.getId());
      writeS(defendingClan.getName());
      writeS(defendingClan.getLeaderName());
      writeD(defendingClan.getCrestId());
      writeD(0x00); // signed time (seconds) (not storated by L2J)
      writeD(SiegeClanType.DEFENDER.ordinal());
      writeD(defendingClan.getAllyId());
      writeS(defendingClan.getAllyName());
      writeS(""); // AllyLeaderName
      writeD(defendingClan.getAllyCrestId());
    }

    // List of not confirmed defenders
    for (L2SiegeClan siegeClan : _castle.getSiege().getDefenderWaitingClans()) {
      final L2Clan defendingClan = ClanTable.getInstance().getClan(siegeClan.getClanId());
      if (defendingClan == null) {
        continue;
      }

      writeD(defendingClan.getId());
      writeS(defendingClan.getName());
      writeS(defendingClan.getLeaderName());
      writeD(defendingClan.getCrestId());
      writeD(0x00); // signed time (seconds) (not storated by L2J)
      writeD(SiegeClanType.DEFENDER_PENDING.ordinal());
      writeD(defendingClan.getAllyId());
      writeS(defendingClan.getAllyName());
      writeS(""); // AllyLeaderName
      writeD(defendingClan.getAllyCrestId());
    }
  }