Exemple #1
0
  public PrimevalIsle() {
    super("ai/group");

    for (L2Spawn npc : SpawnTable.getInstance().getSpawnTable())
      if (Util.contains(MOBIDS, npc.getNpcId())
          && npc.getLastSpawn() != null
          && npc.getLastSpawn() instanceof L2Attackable)
        ((L2Attackable) npc.getLastSpawn()).seeThroughSilentMove(true);

    registerMobs(SPRIGANTS, EventType.ON_AGGRO, EventType.ON_KILL);
    addAttackId(ANCIENT_EGG);
    addSpawnId(MOBIDS);
  }
Exemple #2
0
  public void deleteSpawn(L2Spawn spawn, boolean updateDb) {
    if (!_spawntable.remove(spawn)) return;

    if (updateDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "DELETE FROM spawnlist WHERE locx=? AND locy=? AND locz=? AND npc_templateid=? AND heading=?");
        statement.setInt(1, spawn.getLocx());
        statement.setInt(2, spawn.getLocy());
        statement.setInt(3, spawn.getLocz());
        statement.setInt(4, spawn.getNpcId());
        statement.setInt(5, spawn.getHeading());
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with deleting spawn
        _log.warning("SpawnTable: Spawn " + spawn + " could not be removed from DB: " + e);
      }
    }
  }
  private void init() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * from raidboss_spawnlist ORDER BY boss_id");
      ResultSet rset = statement.executeQuery();

      while (rset.next()) {
        final L2NpcTemplate template = getValidTemplate(rset.getInt("boss_id"));
        if (template != null) {
          final L2Spawn spawnDat = new L2Spawn(template);
          spawnDat.setLocx(rset.getInt("loc_x"));
          spawnDat.setLocy(rset.getInt("loc_y"));
          spawnDat.setLocz(rset.getInt("loc_z"));
          spawnDat.setHeading(rset.getInt("heading"));
          spawnDat.setRespawnMinDelay(rset.getInt("spawn_time"));
          spawnDat.setRespawnMaxDelay(rset.getInt("random_time"));

          addNewSpawn(
              spawnDat,
              rset.getLong("respawn_time"),
              rset.getDouble("currentHP"),
              rset.getDouble("currentMP"),
              false);
        } else {
          _log.warning(
              "RaidBossSpawnManager: Could not load raidboss #"
                  + rset.getInt("boss_id")
                  + " from DB");
        }
      }

      _log.info("RaidBossSpawnManager: Loaded " + _bosses.size() + " instances.");
      _log.info("RaidBossSpawnManager: Scheduled " + _schedules.size() + " instances.");

      rset.close();
      statement.close();
    } catch (SQLException e) {
      _log.warning("RaidBossSpawnManager: Couldnt load raidboss_spawnlist table.");
    } catch (Exception e) {
      _log.log(
          Level.WARNING, "Error while initializing RaidBossSpawnManager: " + e.getMessage(), e);
    }
  }
  public void deleteSpawn(L2Spawn spawnDat, boolean updateDb) {
    if (spawnDat == null) return;

    final int bossId = spawnDat.getNpcId();
    if (!_spawns.containsKey(bossId)) return;

    SpawnTable.getInstance().deleteSpawn(spawnDat, false);
    _spawns.remove(bossId);

    if (_bosses.containsKey(bossId)) _bosses.remove(bossId);

    if (_schedules.containsKey(bossId)) {
      final ScheduledFuture<?> f = _schedules.remove(bossId);
      f.cancel(true);
    }

    if (_storedInfo.containsKey(bossId)) _storedInfo.remove(bossId);

    if (updateDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement("DELETE FROM raidboss_spawnlist WHERE boss_id=?");
        statement.setInt(1, bossId);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with deleting spawn
        _log.log(
            Level.WARNING,
            "RaidBossSpawnManager: Could not remove raidboss #"
                + bossId
                + " from DB: "
                + e.getMessage(),
            e);
      }
    }
  }
Exemple #5
0
  public void addNewSpawn(L2Spawn spawn, boolean storeInDb) {
    _spawntable.add(spawn);

    if (storeInDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "INSERT INTO spawnlist (npc_templateid,locx,locy,locz,heading,respawn_delay) values(?,?,?,?,?,?)");
        statement.setInt(1, spawn.getNpcId());
        statement.setInt(2, spawn.getLocx());
        statement.setInt(3, spawn.getLocy());
        statement.setInt(4, spawn.getLocz());
        statement.setInt(5, spawn.getHeading());
        statement.setInt(6, spawn.getRespawnDelay() / 1000);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with storing spawn
        _log.warning("SpawnTable: Could not store spawn in the DB:" + e);
      }
    }
  }
Exemple #6
0
  private void fillSpawnTable() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement = con.prepareStatement("SELECT * FROM spawnlist");
      ResultSet rset = statement.executeQuery();

      L2Spawn spawnDat;
      L2NpcTemplate template1;

      while (rset.next()) {
        template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
        if (template1 != null) {
          if (template1.isType("L2SiegeGuard")) {
            // Don't spawn guards, they're spawned during castle sieges.
          } else if (template1.isType("L2RaidBoss")) {
            // Don't spawn raidbosses ; raidbosses are supposed to be loaded in another table !
            _log.warning(
                "SpawnTable: RB ("
                    + template1.getIdTemplate()
                    + ") is in regular spawnlist, move it in raidboss_spawnlist.");
          } else if (!Config.ALLOW_CLASS_MASTERS && template1.isType("L2ClassMaster")) {
            // Dont' spawn class masters (if config is setuped to false).
          } else if (!Config.WYVERN_ALLOW_UPGRADER && template1.isType("L2WyvernManager")) {
            // Dont' spawn wyvern managers (if config is setuped to false).
          } else {
            spawnDat = new L2Spawn(template1);
            spawnDat.setLocx(rset.getInt("locx"));
            spawnDat.setLocy(rset.getInt("locy"));
            spawnDat.setLocz(rset.getInt("locz"));
            spawnDat.setHeading(rset.getInt("heading"));
            spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));

            switch (rset.getInt("periodOfDay")) {
              case 0: // default
                spawnDat.init();
                _npcSpawnCount++;
                break;
              case 1: // Day
                DayNightSpawnManager.getInstance().addDayCreature(spawnDat);
                _npcSpawnCount++;
                break;
              case 2: // Night
                DayNightSpawnManager.getInstance().addNightCreature(spawnDat);
                _npcSpawnCount++;
                break;
            }

            _spawntable.add(spawnDat);
          }
        } else {
          _log.warning(
              "SpawnTable: Data missing in NPC table for ID: "
                  + rset.getInt("npc_templateid")
                  + ".");
        }
      }
      rset.close();
      statement.close();
    } catch (Exception e) {
      // problem with initializing spawn, go to next one
      _log.warning("SpawnTable: Spawn could not be initialized: " + e);
    }

    _log.config("SpawnTable: Loaded " + _spawntable.size() + " Npc Spawn Locations.");

    if (Config.DEBUG)
      _log.fine(
          "SpawnTable: Spawning completed, total number of NPCs in the world: " + _npcSpawnCount);
  }
  public void addNewSpawn(
      L2Spawn spawnDat, long respawnTime, double currentHP, double currentMP, boolean storeInDb) {
    if (spawnDat == null) return;

    final int bossId = spawnDat.getNpcId();
    if (_spawns.containsKey(bossId)) return;

    final long time = Calendar.getInstance().getTimeInMillis();

    SpawnTable.getInstance().addNewSpawn(spawnDat, false);

    if (respawnTime == 0L || (time > respawnTime)) {
      L2RaidBossInstance raidboss = null;

      if (bossId == 25328) raidboss = DayNightSpawnManager.getInstance().handleBoss(spawnDat);
      else raidboss = (L2RaidBossInstance) spawnDat.doSpawn();

      if (raidboss != null) {
        currentHP = (currentHP == 0) ? raidboss.getMaxHp() : currentHP;
        currentMP = (currentMP == 0) ? raidboss.getMaxMp() : currentMP;

        raidboss.setCurrentHp(currentHP);
        raidboss.setCurrentMp(currentMP);
        raidboss.setRaidStatus(StatusEnum.ALIVE);

        _bosses.put(bossId, raidboss);

        final StatsSet info = new StatsSet();
        info.set("currentHP", currentHP);
        info.set("currentMP", currentMP);
        info.set("respawnTime", 0L);

        _storedInfo.put(bossId, info);
      }
    } else {
      long spawnTime = respawnTime - Calendar.getInstance().getTimeInMillis();
      _schedules.put(
          bossId,
          ThreadPoolManager.getInstance().scheduleGeneral(new spawnSchedule(bossId), spawnTime));
    }

    _spawns.put(bossId, spawnDat);

    if (storeInDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "INSERT INTO raidboss_spawnlist (boss_id,loc_x,loc_y,loc_z,heading,respawn_time,currentHp,currentMp) values(?,?,?,?,?,?,?,?)");
        statement.setInt(1, spawnDat.getNpcId());
        statement.setInt(2, spawnDat.getLocx());
        statement.setInt(3, spawnDat.getLocy());
        statement.setInt(4, spawnDat.getLocz());
        statement.setInt(5, spawnDat.getHeading());
        statement.setLong(6, respawnTime);
        statement.setDouble(7, currentHP);
        statement.setDouble(8, currentMP);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with storing spawn
        _log.log(
            Level.WARNING,
            "RaidBossSpawnManager: Could not store raidboss #"
                + bossId
                + " in the DB:"
                + e.getMessage(),
            e);
      }
    }
  }