AdminGrandBoss.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Arrays;
  22. import java.util.StringTokenizer;
  23. import ai.individual.Antharas.Antharas;
  24. import ai.individual.Baium.Baium;
  25. import com.l2jserver.gameserver.cache.HtmCache;
  26. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  27. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  28. import com.l2jserver.gameserver.instancemanager.QuestManager;
  29. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.quest.Quest;
  33. import com.l2jserver.gameserver.model.zone.type.L2NoRestartZone;
  34. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  35. /**
  36. * @author St3eT
  37. */
  38. public class AdminGrandBoss implements IAdminCommandHandler
  39. {
  40. private static final int ANTHARAS = 29068; // Antharas
  41. private static final int ANTHARAS_ZONE = 70050; // Antharas Nest
  42. private static final int VALAKAS = 29028; // Valakas
  43. private static final int BAIUM = 29020; // Baium
  44. private static final int BAIUM_ZONE = 70051; // Baium Nest
  45. private static final int QUEENANT = 29001; // Queen Ant
  46. private static final int ORFEN = 29014; // Orfen
  47. private static final int CORE = 29006; // Core
  48. private static final String[] ADMIN_COMMANDS =
  49. {
  50. "admin_grandboss",
  51. "admin_grandboss_skip",
  52. "admin_grandboss_respawn",
  53. "admin_grandboss_minions",
  54. "admin_grandboss_abort",
  55. };
  56. @Override
  57. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  58. {
  59. final StringTokenizer st = new StringTokenizer(command, " ");
  60. final String actualCommand = st.nextToken();
  61. switch (actualCommand.toLowerCase())
  62. {
  63. case "admin_grandboss":
  64. {
  65. if (st.hasMoreTokens())
  66. {
  67. final int grandBossId = Integer.parseInt(st.nextToken());
  68. manageHtml(activeChar, grandBossId);
  69. }
  70. else
  71. {
  72. NpcHtmlMessage html = new NpcHtmlMessage(0, 1);
  73. html.setHtml(HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/grandboss.htm"));
  74. activeChar.sendPacket(html);
  75. }
  76. break;
  77. }
  78. case "admin_grandboss_skip":
  79. {
  80. if (st.hasMoreTokens())
  81. {
  82. final int grandBossId = Integer.parseInt(st.nextToken());
  83. if (grandBossId == ANTHARAS)
  84. {
  85. antharasAi().notifyEvent("SKIP_WAITING", null, activeChar);
  86. manageHtml(activeChar, grandBossId);
  87. }
  88. else
  89. {
  90. activeChar.sendMessage("Wrong ID!");
  91. }
  92. }
  93. else
  94. {
  95. activeChar.sendMessage("Usage: //grandboss_skip Id");
  96. }
  97. break;
  98. }
  99. case "admin_grandboss_respawn":
  100. {
  101. if (st.hasMoreTokens())
  102. {
  103. final int grandBossId = Integer.parseInt(st.nextToken());
  104. switch (grandBossId)
  105. {
  106. case ANTHARAS:
  107. {
  108. antharasAi().notifyEvent("RESPAWN_ANTHARAS", null, activeChar);
  109. manageHtml(activeChar, grandBossId);
  110. break;
  111. }
  112. case BAIUM:
  113. {
  114. baiumAi().notifyEvent("RESPAWN_BAIUM", null, activeChar);
  115. manageHtml(activeChar, grandBossId);
  116. break;
  117. }
  118. default:
  119. {
  120. activeChar.sendMessage("Wrong ID!");
  121. }
  122. }
  123. }
  124. else
  125. {
  126. activeChar.sendMessage("Usage: //grandboss_respawn Id");
  127. }
  128. break;
  129. }
  130. case "admin_grandboss_minions":
  131. {
  132. if (st.hasMoreTokens())
  133. {
  134. final int grandBossId = Integer.parseInt(st.nextToken());
  135. switch (grandBossId)
  136. {
  137. case ANTHARAS:
  138. {
  139. antharasAi().notifyEvent("DESPAWN_MINIONS", null, activeChar);
  140. break;
  141. }
  142. case BAIUM:
  143. {
  144. baiumAi().notifyEvent("DESPAWN_MINIONS", null, activeChar);
  145. break;
  146. }
  147. default:
  148. {
  149. activeChar.sendMessage("Wrong ID!");
  150. }
  151. }
  152. }
  153. else
  154. {
  155. activeChar.sendMessage("Usage: //grandboss_minions Id");
  156. }
  157. break;
  158. }
  159. case "admin_grandboss_abort":
  160. {
  161. if (st.hasMoreTokens())
  162. {
  163. final int grandBossId = Integer.parseInt(st.nextToken());
  164. switch (grandBossId)
  165. {
  166. case ANTHARAS:
  167. {
  168. antharasAi().notifyEvent("ABORT_FIGHT", null, activeChar);
  169. manageHtml(activeChar, grandBossId);
  170. break;
  171. }
  172. case BAIUM:
  173. {
  174. baiumAi().notifyEvent("ABORT_FIGHT", null, activeChar);
  175. manageHtml(activeChar, grandBossId);
  176. break;
  177. }
  178. default:
  179. {
  180. activeChar.sendMessage("Wrong ID!");
  181. }
  182. }
  183. }
  184. else
  185. {
  186. activeChar.sendMessage("Usage: //grandboss_abort Id");
  187. }
  188. }
  189. break;
  190. }
  191. return true;
  192. }
  193. private void manageHtml(L2PcInstance activeChar, int grandBossId)
  194. {
  195. if (Arrays.asList(ANTHARAS, VALAKAS, BAIUM, QUEENANT, ORFEN, CORE).contains(grandBossId))
  196. {
  197. final int bossStatus = GrandBossManager.getInstance().getBossStatus(grandBossId);
  198. L2NoRestartZone bossZone = null;
  199. String textColor = null;
  200. String text = null;
  201. String htmlPatch = null;
  202. int deadStatus = 0;
  203. switch (grandBossId)
  204. {
  205. case ANTHARAS:
  206. {
  207. bossZone = ZoneManager.getInstance().getZoneById(ANTHARAS_ZONE, L2NoRestartZone.class);
  208. htmlPatch = "data/html/admin/grandboss_antharas.htm";
  209. break;
  210. }
  211. case VALAKAS:
  212. {
  213. htmlPatch = "data/html/admin/grandboss_valakas.htm";
  214. break;
  215. }
  216. case BAIUM:
  217. {
  218. bossZone = ZoneManager.getInstance().getZoneById(BAIUM_ZONE, L2NoRestartZone.class);
  219. htmlPatch = "data/html/admin/grandboss_baium.htm";
  220. break;
  221. }
  222. case QUEENANT:
  223. {
  224. htmlPatch = "data/html/admin/grandboss_queenant.htm";
  225. break;
  226. }
  227. case ORFEN:
  228. {
  229. htmlPatch = "data/html/admin/grandboss_orfen.htm";
  230. break;
  231. }
  232. case CORE:
  233. {
  234. htmlPatch = "data/html/admin/grandboss_core.htm";
  235. break;
  236. }
  237. }
  238. if (Arrays.asList(ANTHARAS, VALAKAS, BAIUM).contains(grandBossId))
  239. {
  240. deadStatus = 3;
  241. switch (bossStatus)
  242. {
  243. case 0:
  244. {
  245. textColor = "00FF00"; // Green
  246. text = "Alive";
  247. break;
  248. }
  249. case 1:
  250. {
  251. textColor = "FFFF00"; // Yellow
  252. text = "Waiting";
  253. break;
  254. }
  255. case 2:
  256. {
  257. textColor = "FF9900"; // Orange
  258. text = "In Fight";
  259. break;
  260. }
  261. case 3:
  262. {
  263. textColor = "FF0000"; // Red
  264. text = "Dead";
  265. break;
  266. }
  267. }
  268. }
  269. else
  270. {
  271. deadStatus = 1;
  272. switch (bossStatus)
  273. {
  274. case 0:
  275. {
  276. textColor = "00FF00"; // Green
  277. text = "Alive";
  278. break;
  279. }
  280. case 1:
  281. {
  282. textColor = "FF0000"; // Red
  283. text = "Dead";
  284. break;
  285. }
  286. }
  287. }
  288. final StatsSet info = GrandBossManager.getInstance().getStatsSet(grandBossId);
  289. final String bossRespawn = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(info.getLong("respawn_time"));
  290. NpcHtmlMessage html = new NpcHtmlMessage(0, 1);
  291. html.setHtml(HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), htmlPatch));
  292. html.replace("%bossStatus%", text);
  293. html.replace("%bossColor%", textColor);
  294. html.replace("%respawnTime%", bossStatus == deadStatus ? bossRespawn : "Already respawned!");
  295. html.replace("%playersInside%", bossZone != null ? String.valueOf(bossZone.getPlayersInside().size()) : "Zone not found!");
  296. activeChar.sendPacket(html);
  297. }
  298. else
  299. {
  300. activeChar.sendMessage("Wrong ID!");
  301. }
  302. }
  303. private Quest antharasAi()
  304. {
  305. return QuestManager.getInstance().getQuest(Antharas.class.getSimpleName());
  306. }
  307. private Quest baiumAi()
  308. {
  309. return QuestManager.getInstance().getQuest(Baium.class.getSimpleName());
  310. }
  311. @Override
  312. public String[] getAdminCommandList()
  313. {
  314. return ADMIN_COMMANDS;
  315. }
  316. }