private void spawnMonster( L2PcInstance activeChar, String monsterId, int respawnTime, int mobCount, boolean permanent) { L2Object target = activeChar.getTarget(); if (target == null) { target = activeChar; } L2NpcTemplate template1; if (monsterId.matches("[0-9]*")) { // First parameter was an ID number int monsterTemplate = Integer.parseInt(monsterId); template1 = NpcData.getInstance().getTemplate(monsterTemplate); } else { // First parameter wasn't just numbers so go by name not ID monsterId = monsterId.replace('_', ' '); template1 = NpcData.getInstance().getTemplateByName(monsterId); } try { L2Spawn spawn = new L2Spawn(template1); if (Config.SAVE_GMSPAWN_ON_CUSTOM) { spawn.setCustom(true); } spawn.setX(target.getX()); spawn.setY(target.getY()); spawn.setZ(target.getZ()); spawn.setAmount(mobCount); spawn.setHeading(activeChar.getHeading()); spawn.setRespawnDelay(respawnTime); if (activeChar.getInstanceId() > 0) { spawn.setInstanceId(activeChar.getInstanceId()); permanent = false; } else { spawn.setInstanceId(0); } // TODO add checks for GrandBossSpawnManager if (RaidBossSpawnManager.getInstance().isDefined(spawn.getId())) { activeChar.sendMessage("You cannot spawn another instance of " + template1.getName() + "."); } else { if (RaidBossSpawnManager.getInstance().getValidTemplate(spawn.getId()) != null) { spawn.setRespawnMinDelay(43200); spawn.setRespawnMaxDelay(129600); RaidBossSpawnManager.getInstance() .addNewSpawn(spawn, 0, template1.getBaseHpMax(), template1.getBaseMpMax(), permanent); } else { SpawnTable.getInstance().addNewSpawn(spawn, permanent); spawn.init(); } if (!permanent) { spawn.stopRespawn(); } activeChar.sendMessage("Created " + template1.getName() + " on " + target.getObjectId()); } } catch (Exception e) { activeChar.sendPacket(SystemMessageId.TARGET_CANT_FOUND); } }
public void newRace() { int random = 0; for (int i = 0; i < 8; i++) { int id = 31003; random = Rnd.get(24); while (true) { for (int j = i - 1; j >= 0; j--) { if (_monsters[j].getTemplate().getId() == (id + random)) { random = Rnd.get(24); continue; } } break; } try { L2NpcTemplate template = NpcData.getInstance().getTemplate(id + random); _constructor = Class.forName( "com.l2jserver.gameserver.model.actor.instance." + template.getType() + "Instance") .getConstructors()[0]; int objectId = IdFactory.getInstance().getNextId(); _monsters[i] = (L2Npc) _constructor.newInstance(objectId, template); } catch (Exception e) { _log.log(Level.WARNING, "", e); } // _log.info("Monster "+i+" is id: "+(id+random)); } newSpeeds(); }
private RangeGuard() { super(RangeGuard.class.getSimpleName(), "ai/group_template"); final List<L2NpcTemplate> monsters = NpcData.getInstance().getAllNpcOfClassType("L2Monster"); for (L2NpcTemplate template : monsters) { if (template.hasParameters() && (template.getParameters().getInt("LongRangeGuardRate", -1) > 0)) { addAttackId(template.getId()); } } }
public void loadDiary(int charId) { final List<StatsSet> _diary = new FastList<>(); int diaryentries = 0; try (Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT * FROM heroes_diary WHERE charId=? ORDER BY time ASC")) { statement.setInt(1, charId); try (ResultSet rset = statement.executeQuery()) { while (rset.next()) { StatsSet _diaryentry = new StatsSet(); long time = rset.getLong("time"); int action = rset.getInt("action"); int param = rset.getInt("param"); String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time)); _diaryentry.set("date", date); if (action == ACTION_RAID_KILLED) { L2NpcTemplate template = NpcData.getInstance().getTemplate(param); if (template != null) { _diaryentry.set("action", template.getName() + " was defeated"); } } else if (action == ACTION_HERO_GAINED) { _diaryentry.set("action", "Gained Hero status"); } else if (action == ACTION_CASTLE_TAKEN) { Castle castle = CastleManager.getInstance().getCastleById(param); if (castle != null) { _diaryentry.set("action", castle.getName() + " Castle was successfuly taken"); } } _diary.add(_diaryentry); diaryentries++; } } _herodiary.put(charId, _diary); _log.info( "Hero System: Loaded " + diaryentries + " diary entries for Hero: " + CharNameTable.getInstance().getNameById(charId)); } catch (SQLException e) { _log.log(Level.WARNING, "Hero System: Couldnt load Hero Diary for CharId: " + charId, e); } }
public void setRBkilled(int charId, int npcId) { setDiaryData(charId, ACTION_RAID_KILLED, npcId); L2NpcTemplate template = NpcData.getInstance().getTemplate(npcId); if (_herodiary.containsKey(charId) && (template != null)) { // Get Data List<StatsSet> _list = _herodiary.get(charId); // Clear old data _herodiary.remove(charId); // Prepare new data StatsSet _diaryentry = new StatsSet(); String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis())); _diaryentry.set("date", date); _diaryentry.set("action", template.getName() + " was defeated"); // Add to old list _list.add(_diaryentry); // Put new list into diary _herodiary.put(charId, _list); } }
private void showNpcs(L2PcInstance activeChar, String starting, int from) { final List<L2NpcTemplate> mobs = NpcData.getInstance().getAllNpcStartingWith(starting); final int mobsCount = mobs.size(); final StringBuilder tb = StringUtil.startAppend( 500 + (mobsCount * 80), "<html><title>Spawn Monster:</title><body><p> There are ", Integer.toString(mobsCount), " Npcs whose name starts with ", starting, ":<br>"); // Loop int i = from; for (int j = 0; (i < mobsCount) && (j < 50); i++, j++) { StringUtil.append( tb, "<a action=\"bypass -h admin_spawn_monster ", Integer.toString(mobs.get(i).getId()), "\">", mobs.get(i).getName(), "</a><br1>"); } if (i == mobsCount) { tb.append( "<br><center><button value=\"Back\" action=\"bypass -h admin_show_npcs\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>"); } else { StringUtil.append( tb, "<br><center><button value=\"Next\" action=\"bypass -h admin_npc_index ", starting, " ", Integer.toString(i), "\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"Back\" action=\"bypass -h admin_show_npcs\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>"); } activeChar.sendPacket(new NpcHtmlMessage(tb.toString())); }
@Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (command.equals("admin_show_spawns")) { AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } else if (command.equalsIgnoreCase("admin_spawn_debug_menu")) { AdminHtml.showAdminHtml(activeChar, "spawns_debug.htm"); } else if (command.startsWith("admin_spawn_debug_print")) { StringTokenizer st = new StringTokenizer(command, " "); L2Object target = activeChar.getTarget(); if (target instanceof L2Npc) { try { st.nextToken(); int type = Integer.parseInt(st.nextToken()); printSpawn((L2Npc) target, type); if (command.contains("_menu")) { AdminHtml.showAdminHtml(activeChar, "spawns_debug.htm"); } } catch (Exception e) { } } else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); } } else if (command.startsWith("admin_spawn_index")) { StringTokenizer st = new StringTokenizer(command, " "); try { st.nextToken(); int level = Integer.parseInt(st.nextToken()); int from = 0; try { from = Integer.parseInt(st.nextToken()); } catch (NoSuchElementException nsee) { } showMonsters(activeChar, level, from); } catch (Exception e) { AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } else if (command.equals("admin_show_npcs")) { AdminHtml.showAdminHtml(activeChar, "npcs.htm"); } else if (command.startsWith("admin_npc_index")) { StringTokenizer st = new StringTokenizer(command, " "); try { st.nextToken(); String letter = st.nextToken(); int from = 0; try { from = Integer.parseInt(st.nextToken()); } catch (NoSuchElementException nsee) { } showNpcs(activeChar, letter, from); } catch (Exception e) { AdminHtml.showAdminHtml(activeChar, "npcs.htm"); } } else if (command.startsWith("admin_instance_spawns")) { StringTokenizer st = new StringTokenizer(command, " "); try { st.nextToken(); int instance = Integer.parseInt(st.nextToken()); if (instance >= 300000) { final StringBuilder html = StringUtil.startAppend( 500 + 1000, "<html><table width=\"100%\"><tr><td width=45><button value=\"Main\" action=\"bypass -h admin_admin\" width=45 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td width=180><center>", "<font color=\"LEVEL\">Spawns for " + String.valueOf(instance) + "</font>", "</td><td width=45><button value=\"Back\" action=\"bypass -h admin_current_player\" width=45 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table><br>", "<table width=\"100%\"><tr><td width=200>NpcName</td><td width=70>Action</td></tr>"); int counter = 0; int skiped = 0; Instance inst = InstanceManager.getInstance().getInstance(instance); if (inst != null) { for (L2Npc npc : inst.getNpcs()) { if (!npc.isDead()) { // Only 50 because of client html limitation if (counter < 50) { StringUtil.append( html, "<tr><td>" + npc.getName() + "</td><td>", "<a action=\"bypass -h admin_move_to " + npc.getX() + " " + npc.getY() + " " + npc.getZ() + "\">Go</a>", "</td></tr>"); counter++; } else { skiped++; } } } StringUtil.append( html, "<tr><td>Skipped:</td><td>" + String.valueOf(skiped) + "</td></tr></table></body></html>"); final NpcHtmlMessage ms = new NpcHtmlMessage(); ms.setHtml(html.toString()); activeChar.sendPacket(ms); } else { activeChar.sendMessage("Cannot find instance " + instance); } } else { activeChar.sendMessage("Invalid instance number."); } } catch (Exception e) { activeChar.sendMessage("Usage //instance_spawns <instance_number>"); } } else if (command.startsWith("admin_unspawnall")) { Broadcast.toAllOnlinePlayers( SystemMessage.getSystemMessage(SystemMessageId.NPC_SERVER_NOT_OPERATING)); RaidBossSpawnManager.getInstance().cleanUp(); DayNightSpawnManager.getInstance().cleanUp(); L2World.getInstance().deleteVisibleNpcSpawns(); AdminTable.getInstance().broadcastMessageToGMs("NPC Unspawn completed!"); } else if (command.startsWith("admin_spawnday")) { DayNightSpawnManager.getInstance().spawnDayCreatures(); } else if (command.startsWith("admin_spawnnight")) { DayNightSpawnManager.getInstance().spawnNightCreatures(); } else if (command.startsWith("admin_respawnall") || command.startsWith("admin_spawn_reload")) { // make sure all spawns are deleted RaidBossSpawnManager.getInstance().cleanUp(); DayNightSpawnManager.getInstance().cleanUp(); L2World.getInstance().deleteVisibleNpcSpawns(); // now respawn all NpcData.getInstance().load(); SpawnTable.getInstance().load(); RaidBossSpawnManager.getInstance().load(); AutoSpawnHandler.getInstance().reload(); SevenSigns.getInstance().spawnSevenSignsNPC(); QuestManager.getInstance().reloadAllScripts(); AdminTable.getInstance().broadcastMessageToGMs("NPC Respawn completed!"); } else if (command.startsWith("admin_spawn_monster") || command.startsWith("admin_spawn")) { StringTokenizer st = new StringTokenizer(command, " "); try { String cmd = st.nextToken(); String id = st.nextToken(); int respawnTime = 0; int mobCount = 1; if (st.hasMoreTokens()) { mobCount = Integer.parseInt(st.nextToken()); } if (st.hasMoreTokens()) { respawnTime = Integer.parseInt(st.nextToken()); } if (cmd.equalsIgnoreCase("admin_spawn_once")) { spawnMonster(activeChar, id, respawnTime, mobCount, false); } else { spawnMonster(activeChar, id, respawnTime, mobCount, true); } } catch (Exception e) { // Case of wrong or missing monster data AdminHtml.showAdminHtml(activeChar, "spawns.htm"); } } else if (command.startsWith("admin_list_spawns") || command.startsWith("admin_list_positions")) { int npcId = 0; int teleportIndex = -1; try { // admin_list_spawns x[xxxx] x[xx] String[] params = command.split(" "); Pattern pattern = Pattern.compile("[0-9]*"); Matcher regexp = pattern.matcher(params[1]); if (regexp.matches()) { npcId = Integer.parseInt(params[1]); } else { params[1] = params[1].replace('_', ' '); npcId = NpcData.getInstance().getTemplateByName(params[1]).getId(); } if (params.length > 2) { teleportIndex = Integer.parseInt(params[2]); } } catch (Exception e) { activeChar.sendMessage("Command format is //list_spawns <npcId|npc_name> [tele_index]"); } if (command.startsWith("admin_list_positions")) { findNPCInstances(activeChar, npcId, teleportIndex, true); } else { findNPCInstances(activeChar, npcId, teleportIndex, false); } } return true; }