Guest User

Boss Respawn

a guest
Aug 16th, 2010
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.00 KB | None | 0 0
  1. Index: data/scripts/custom/BossRespawn/BossRespawn.java
  2. ===================================================================
  3. --- data/scripts/custom/BossRespawn/BossRespawn.java    (revision 0)
  4. +++ data/scripts/custom/BossRespawn/BossRespawn.java    (revision 0)
  5. @@ -0,0 +1,232 @@
  6. +/*
  7. + * This program is free software: you can redistribute it and/or modify it under
  8. + * the terms of the GNU General Public License as published by the Free Software
  9. + * Foundation, either version 3 of the License, or (at your option) any later
  10. + * version.
  11. + *
  12. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. + * details.
  16. + *
  17. + * You should have received a copy of the GNU General Public License along with
  18. + * this program. If not, see <http://www.gnu.org/licenses/>.
  19. + */
  20. +
  21. +package custom.BossRespawn;
  22. +
  23. +import java.sql.Connection;
  24. +import java.sql.PreparedStatement;
  25. +import java.sql.ResultSet;
  26. +import java.text.SimpleDateFormat;
  27. +import java.util.Date;
  28. +import java.util.Map;
  29. +import java.util.logging.Level;
  30. +
  31. +import javolution.text.TextBuilder;
  32. +import javolution.util.FastMap;
  33. +
  34. +import com.l2jserver.L2DatabaseFactory;
  35. +import com.l2jserver.gameserver.ThreadPoolManager;
  36. +import com.l2jserver.gameserver.datatables.NpcTable;
  37. +import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  38. +import com.l2jserver.gameserver.model.actor.L2Npc;
  39. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  40. +import com.l2jserver.gameserver.model.quest.Quest;
  41. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  42. +import com.l2jserver.gameserver.templates.StatsSet;
  43. +
  44. +/**
  45. + *
  46. + * @author Dleogr
  47. + *
  48. + */
  49. +public class BossRespawn extends Quest
  50. +{
  51. +   private static final int NPC_ID = 93000;
  52. +   private static final boolean GM_ONLY = true;
  53. +   private static Map<Integer, String> GRAND_BOSSES = new FastMap<Integer, String>();
  54. +   private static Map<Integer, Integer> RAID_BOSSES = new FastMap<Integer, Integer>();
  55. +   private static Map<Integer, Long> RAID_BOSSES_RESPAWN = new FastMap<Integer, Long>();
  56. +   private static final int refreshTime = 30; // in minutes
  57. +   private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
  58. +  
  59. +   public BossRespawn(int questid, String name, String descr)
  60. +   {
  61. +       super(questid, name, descr);
  62. +       addFirstTalkId(NPC_ID);
  63. +       addTalkId(NPC_ID);
  64. +       addStartNpc(NPC_ID);
  65. +      
  66. +       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new reloadBosses(), 1000, (refreshTime * 60 * 60 * 1000));
  67. +   }
  68. +  
  69. +   @Override
  70. +   public String onFirstTalk(L2Npc npc, L2PcInstance player)
  71. +   {
  72. +       return "home.htm";
  73. +   }
  74. +  
  75. +   @Override
  76. +   public String onTalk(L2Npc npc, L2PcInstance player)
  77. +   {  
  78. +       return "main.htm";
  79. +   }
  80. +  
  81. +   @Override
  82. +   public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  83. +   {
  84. +       if (event.equalsIgnoreCase("grandbosses"))
  85. +           sendGrandBosses(player);
  86. +       else if (event.equalsIgnoreCase("raidbosses"))
  87. +           return "raidbosses.htm";
  88. +       else if (event.startsWith("raidboss_"))
  89. +       {
  90. +           try
  91. +           {
  92. +               int level = Integer.parseInt(event.substring(9));
  93. +               if (level != 20 && level != 40 && level != 60 && level != 80)
  94. +                   return "Are you fackin insain?";
  95. +              
  96. +               sendRaidBosses(player, level);
  97. +           }
  98. +           catch (NumberFormatException nfe) {}
  99. +       }
  100. +      
  101. +       return null;
  102. +   }
  103. +  
  104. +   private void sendRaidBosses(L2PcInstance player, int bosslevel)
  105. +   {
  106. +       TextBuilder tb = new TextBuilder();
  107. +       tb.append("<html><title>Grand Boss Info</title><body><br><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><table width=260>");
  108. +      
  109. +       for (int bossId : RAID_BOSSES.keySet())
  110. +       {
  111. +           String name = NpcTable.getInstance().getTemplate(bossId).getName();
  112. +           int level = RAID_BOSSES.get(bossId);
  113. +           int min = bosslevel;
  114. +           int max = min + 10;
  115. +           if (level >= min && level <= max)
  116. +           {
  117. +               long delay = RAID_BOSSES_RESPAWN.get(bossId);
  118. +               long currentTime = System.currentTimeMillis();
  119. +              
  120. +               if (delay <= currentTime)
  121. +                   tb.append("<tr><td><font color=\"00C3FF\">" + name + " (" + level + ")</color>:</td><td><font color=\"32C332\">Is Alive</color></td></tr>");
  122. +              
  123. +               else
  124. +                   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>");
  125. +           }
  126. +       }
  127. +      
  128. +       tb.append("</table><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br></center></body></html>");
  129. +      
  130. +       NpcHtmlMessage msg = new NpcHtmlMessage(NPC_ID);
  131. +       msg.setHtml(tb.toString());
  132. +       player.sendPacket(msg);
  133. +   }
  134. +  
  135. +   private void sendGrandBosses(L2PcInstance player)
  136. +   {
  137. +       TextBuilder tb = new TextBuilder();
  138. +       tb.append("<html><title>Grand Boss Info</title><body><br><center><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><table width=260>");
  139. +      
  140. +       for (int bossId : GRAND_BOSSES.keySet())
  141. +       {
  142. +           String name = GRAND_BOSSES.get(bossId);
  143. +           StatsSet stats = GrandBossManager.getInstance().getStatsSet(bossId);
  144. +           if (stats == null)
  145. +           {
  146. +               player.sendMessage("Stats for GrandBoss " + bossId + " not found!");
  147. +               continue;
  148. +           }
  149. +          
  150. +           long delay = stats.getLong("respawn_time");
  151. +           long currentTime = System.currentTimeMillis();
  152. +          
  153. +           if (delay <= currentTime)
  154. +               tb.append("<tr><td><font color=\"00C3FF\">" + name + "</color>:</td><td><font color=\"32C332\">Is Alive</color></td></tr>");
  155. +          
  156. +           else
  157. +               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>");
  158. +       }
  159. +      
  160. +       tb.append("</table><img src=\"L2UI_CH3.herotower_deco\" width=256 height=32><br></center></body></html>");
  161. +      
  162. +       NpcHtmlMessage msg = new NpcHtmlMessage(NPC_ID);
  163. +       msg.setHtml(tb.toString());
  164. +       player.sendPacket(msg);
  165. +   }
  166. +  
  167. +   private class reloadBosses implements Runnable
  168. +   {
  169. +       public void run()
  170. +       {
  171. +
  172. +           RAID_BOSSES.clear();
  173. +           RAID_BOSSES_RESPAWN.clear();
  174. +           GRAND_BOSSES.clear();
  175. +          
  176. +           Connection con = null;
  177. +          
  178. +           try
  179. +           {
  180. +               con = L2DatabaseFactory.getInstance().getConnection();
  181. +               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");
  182. +              
  183. +               ResultSet rset = statement.executeQuery();
  184. +              
  185. +               while (rset.next())
  186. +               {
  187. +                   GRAND_BOSSES.put(rset.getInt("boss_id"), rset.getString("name"));
  188. +               }
  189. +              
  190. +               rset.close();
  191. +               statement.close();
  192. +           }
  193. +           catch (Exception e)
  194. +           {
  195. +               _log.log(Level.WARNING, "Could not restore grand bosses: " + e.getMessage(), e);
  196. +           }
  197. +           finally
  198. +           {
  199. +               L2DatabaseFactory.close(con);
  200. +           }
  201. +          
  202. +           try
  203. +           {
  204. +               con = L2DatabaseFactory.getInstance().getConnection();
  205. +               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`");
  206. +              
  207. +               ResultSet rset = statement.executeQuery();
  208. +              
  209. +               while (rset.next())
  210. +               {
  211. +                   RAID_BOSSES.put(rset.getInt("boss_id"), rset.getInt("level"));
  212. +                   RAID_BOSSES_RESPAWN.put(rset.getInt("boss_id"), rset.getLong("respawn_time"));
  213. +               }
  214. +              
  215. +               rset.close();
  216. +               statement.close();
  217. +           }
  218. +           catch (Exception e)
  219. +           {
  220. +               _log.log(Level.WARNING, "Could not restore raid bosses: " + e.getMessage(), e);
  221. +           }
  222. +           finally
  223. +           {
  224. +               L2DatabaseFactory.close(con);
  225. +           }
  226. +          
  227. +           _log.info("Boss Respawn Loaded: " + GRAND_BOSSES.size() + " Grand Bosses");
  228. +           _log.info("Boss Respawn Loaded: " + RAID_BOSSES.size() + " Raid Bosses");
  229. +          
  230. +       }
  231. +   }
  232. +  
  233. +   public static void main(String[] args)
  234. +   {
  235. +       new BossRespawn(-1, "BossRespawn", "custom");
  236. +   }
  237. +}
Advertisement
Add Comment
Please, Sign In to add comment