Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: data/scripts/custom/BossRespawn/BossRespawn.java
- ===================================================================
- --- data/scripts/custom/BossRespawn/BossRespawn.java (revision 0)
- +++ data/scripts/custom/BossRespawn/BossRespawn.java (revision 0)
- @@ -0,0 +1,232 @@
- +/*
- + * This program is free software: you can redistribute it and/or modify it under
- + * the terms of the GNU General Public License as published by the Free Software
- + * Foundation, either version 3 of the License, or (at your option) any later
- + * version.
- + *
- + * This program is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- + * details.
- + *
- + * You should have received a copy of the GNU General Public License along with
- + * this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +
- +package custom.BossRespawn;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.text.SimpleDateFormat;
- +import java.util.Date;
- +import java.util.Map;
- +import java.util.logging.Level;
- +
- +import javolution.text.TextBuilder;
- +import javolution.util.FastMap;
- +
- +import com.l2jserver.L2DatabaseFactory;
- +import com.l2jserver.gameserver.ThreadPoolManager;
- +import com.l2jserver.gameserver.datatables.NpcTable;
- +import com.l2jserver.gameserver.instancemanager.GrandBossManager;
- +import com.l2jserver.gameserver.model.actor.L2Npc;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.model.quest.Quest;
- +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jserver.gameserver.templates.StatsSet;
- +
- +/**
- + *
- + * @author Dleogr
- + *
- + */
- +public class BossRespawn extends Quest
- +{
- + private static final int NPC_ID = 93000;
- + private static final boolean GM_ONLY = true;
- + private static Map<Integer, String> GRAND_BOSSES = new FastMap<Integer, String>();
- + private static Map<Integer, Integer> RAID_BOSSES = new FastMap<Integer, Integer>();
- + private static Map<Integer, Long> RAID_BOSSES_RESPAWN = new FastMap<Integer, Long>();
- + private static final int refreshTime = 30; // in minutes
- + private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
- +
- + public BossRespawn(int questid, String name, String descr)
- + {
- + super(questid, name, descr);
- + addFirstTalkId(NPC_ID);
- + addTalkId(NPC_ID);
- + addStartNpc(NPC_ID);
- +
- + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new reloadBosses(), 1000, (refreshTime * 60 * 60 * 1000));
- + }
- +
- + @Override
- + public String onFirstTalk(L2Npc npc, L2PcInstance player)
- + {
- + return "home.htm";
- + }
- +
- + @Override
- + public String onTalk(L2Npc npc, L2PcInstance player)
- + {
- + return "main.htm";
- + }
- +
- + @Override
- + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
- + {
- + if (event.equalsIgnoreCase("grandbosses"))
- + sendGrandBosses(player);
- + else if (event.equalsIgnoreCase("raidbosses"))
- + return "raidbosses.htm";
- + else if (event.startsWith("raidboss_"))
- + {
- + try
- + {
- + int level = Integer.parseInt(event.substring(9));
- + if (level != 20 && level != 40 && level != 60 && level != 80)
- + return "Are you fackin insain?";
- +
- + sendRaidBosses(player, level);
- + }
- + catch (NumberFormatException nfe) {}
- + }
- +
- + return null;
- + }
- +
- + private void sendRaidBosses(L2PcInstance player, int bosslevel)
- + {
- + TextBuilder tb = new TextBuilder();
- + tb.append("<html><title>Grand Boss Info</title><body><br><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><table width=260>");
- +
- + for (int bossId : RAID_BOSSES.keySet())
- + {
- + String name = NpcTable.getInstance().getTemplate(bossId).getName();
- + int level = RAID_BOSSES.get(bossId);
- + int min = bosslevel;
- + int max = min + 10;
- + if (level >= min && level <= max)
- + {
- + long delay = RAID_BOSSES_RESPAWN.get(bossId);
- + long currentTime = System.currentTimeMillis();
- +
- + if (delay <= currentTime)
- + tb.append("<tr><td><font color=\"00C3FF\">" + name + " (" + level + ")</color>:</td><td><font color=\"32C332\">Is Alive</color></td></tr>");
- +
- + else
- + tb.append("<tr><td><font color=\"00C3FF\">" + name + " (" + level + ")</color>:</td><td><font color=\"9CC300\">" + (player.isGM() && GM_ONLY ? sdf.format(new Date(delay)) : "Dead") + "</color></td></tr>");
- + }
- + }
- +
- + tb.append("</table><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br></center></body></html>");
- +
- + NpcHtmlMessage msg = new NpcHtmlMessage(NPC_ID);
- + msg.setHtml(tb.toString());
- + player.sendPacket(msg);
- + }
- +
- + private void sendGrandBosses(L2PcInstance player)
- + {
- + TextBuilder tb = new TextBuilder();
- + tb.append("<html><title>Grand Boss Info</title><body><br><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><table width=260>");
- +
- + for (int bossId : GRAND_BOSSES.keySet())
- + {
- + String name = GRAND_BOSSES.get(bossId);
- + StatsSet stats = GrandBossManager.getInstance().getStatsSet(bossId);
- + if (stats == null)
- + {
- + player.sendMessage("Stats for GrandBoss " + bossId + " not found!");
- + continue;
- + }
- +
- + long delay = stats.getLong("respawn_time");
- + long currentTime = System.currentTimeMillis();
- +
- + if (delay <= currentTime)
- + tb.append("<tr><td><font color=\"00C3FF\">" + name + "</color>:</td><td><font color=\"32C332\">Is Alive</color></td></tr>");
- +
- + else
- + tb.append("<tr><td><font color=\"00C3FF\">" + name + "</color>:</td><td><font color=\"9CC300\">" + (player.isGM() && GM_ONLY ? sdf.format(new Date(delay)) : "Dead") + "</color></td></tr>");
- + }
- +
- + tb.append("</table><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br></center></body></html>");
- +
- + NpcHtmlMessage msg = new NpcHtmlMessage(NPC_ID);
- + msg.setHtml(tb.toString());
- + player.sendPacket(msg);
- + }
- +
- + private class reloadBosses implements Runnable
- + {
- + public void run()
- + {
- +
- + RAID_BOSSES.clear();
- + RAID_BOSSES_RESPAWN.clear();
- + GRAND_BOSSES.clear();
- +
- + Connection con = null;
- +
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("SELECT `n`.`name`, `g`.`boss_id` FROM `npc` as `n` CROSS JOIN `grandboss_data` AS `g` ON `n`.`id` = `g`.`boss_id` GROUP BY `n`.`name` ORDER BY `g`.`respawn_time` DESC");
- +
- + ResultSet rset = statement.executeQuery();
- +
- + while (rset.next())
- + {
- + GRAND_BOSSES.put(rset.getInt("boss_id"), rset.getString("name"));
- + }
- +
- + rset.close();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, "Could not restore grand bosses: " + e.getMessage(), e);
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- +
- + try
- + {
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("SELECT `n`.`level`, `r`.`boss_id`, `r`.`respawn_time` FROM `npc` as `n` CROSS JOIN `raidboss_spawnlist` AS `r` ON `n`.`id` = `r`.`boss_id` ORDER BY `n`.`level`");
- +
- + ResultSet rset = statement.executeQuery();
- +
- + while (rset.next())
- + {
- + RAID_BOSSES.put(rset.getInt("boss_id"), rset.getInt("level"));
- + RAID_BOSSES_RESPAWN.put(rset.getInt("boss_id"), rset.getLong("respawn_time"));
- + }
- +
- + rset.close();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, "Could not restore raid bosses: " + e.getMessage(), e);
- + }
- + finally
- + {
- + L2DatabaseFactory.close(con);
- + }
- +
- + _log.info("Boss Respawn Loaded: " + GRAND_BOSSES.size() + " Grand Bosses");
- + _log.info("Boss Respawn Loaded: " + RAID_BOSSES.size() + " Raid Bosses");
- +
- + }
- + }
- +
- + public static void main(String[] args)
- + {
- + new BossRespawn(-1, "BossRespawn", "custom");
- + }
- +}
Advertisement
Add Comment
Please, Sign In to add comment