AdminMonsterRace.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import com.l2jserver.gameserver.MonsterRace;
  17. import com.l2jserver.gameserver.ThreadPoolManager;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.DeleteObject;
  22. import com.l2jserver.gameserver.network.serverpackets.MonRaceInfo;
  23. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. /**
  26. * This class handles following admin commands: - invul = turns invulnerability
  27. * on/off
  28. *
  29. * @version $Revision: 1.1.6.4 $ $Date: 2007/07/31 10:06:00 $
  30. */
  31. public class AdminMonsterRace implements IAdminCommandHandler
  32. {
  33. //private static Logger _log = Logger.getLogger(AdminMonsterRace.class.getName());
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_mons"
  37. };
  38. protected static int state = -1;
  39. @Override
  40. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  41. {
  42. if (command.equalsIgnoreCase("admin_mons"))
  43. {
  44. handleSendPacket(activeChar);
  45. }
  46. return true;
  47. }
  48. @Override
  49. public String[] getAdminCommandList()
  50. {
  51. return ADMIN_COMMANDS;
  52. }
  53. private void handleSendPacket(L2PcInstance activeChar)
  54. {
  55. /*
  56. * -1 0 to initialize the race
  57. * 0 15322 to start race
  58. * 13765 -1 in middle of race
  59. * -1 0 to end the race
  60. *
  61. * 8003 to 8027
  62. */
  63. int[][] codes =
  64. {
  65. {
  66. -1, 0
  67. },
  68. {
  69. 0, 15322
  70. },
  71. {
  72. 13765, -1
  73. },
  74. {
  75. -1, 0
  76. }
  77. };
  78. MonsterRace race = MonsterRace.getInstance();
  79. if (state == -1)
  80. {
  81. state++;
  82. race.newRace();
  83. race.newSpeeds();
  84. MonRaceInfo spk = new MonRaceInfo(codes[state][0], codes[state][1], race.getMonsters(), race.getSpeeds());
  85. activeChar.sendPacket(spk);
  86. activeChar.broadcastPacket(spk);
  87. }
  88. else if (state == 0)
  89. {
  90. state++;
  91. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.MONSRACE_RACE_START);
  92. sm.addNumber(0);
  93. activeChar.sendPacket(sm);
  94. PlaySound SRace = new PlaySound(1, "S_Race", 0, 0, 0, 0, 0);
  95. activeChar.sendPacket(SRace);
  96. activeChar.broadcastPacket(SRace);
  97. PlaySound SRace2 = new PlaySound(0, "ItemSound2.race_start", 1, 121209259, 12125, 182487, -3559);
  98. activeChar.sendPacket(SRace2);
  99. activeChar.broadcastPacket(SRace2);
  100. MonRaceInfo spk = new MonRaceInfo(codes[state][0], codes[state][1], race.getMonsters(), race.getSpeeds());
  101. activeChar.sendPacket(spk);
  102. activeChar.broadcastPacket(spk);
  103. ThreadPoolManager.getInstance().scheduleGeneral(new RunRace(codes, activeChar), 5000);
  104. }
  105. }
  106. class RunRace implements Runnable
  107. {
  108. private int[][] codes;
  109. private L2PcInstance activeChar;
  110. public RunRace(int[][] pCodes, L2PcInstance pActiveChar)
  111. {
  112. codes = pCodes;
  113. activeChar = pActiveChar;
  114. }
  115. @Override
  116. public void run()
  117. {
  118. //int[][] speeds1 = MonsterRace.getInstance().getSpeeds();
  119. //MonsterRace.getInstance().newSpeeds();
  120. //int[][] speeds2 = MonsterRace.getInstance().getSpeeds();
  121. /*
  122. int[] speed = new int[8];
  123. for (int i=0; i<8; i++)
  124. {
  125. for (int j=0; j<20; j++)
  126. {
  127. //_log.info("Adding "+speeds1[i][j] +" and "+ speeds2[i][j]);
  128. speed[i] += (speeds1[i][j]*1);// + (speeds2[i][j]*1);
  129. }
  130. _log.info("Total speed for "+(i+1)+" = "+speed[i]);
  131. }*/
  132. MonRaceInfo spk = new MonRaceInfo(codes[2][0], codes[2][1], MonsterRace.getInstance().getMonsters(), MonsterRace.getInstance().getSpeeds());
  133. activeChar.sendPacket(spk);
  134. activeChar.broadcastPacket(spk);
  135. ThreadPoolManager.getInstance().scheduleGeneral(new RunEnd(activeChar), 30000);
  136. }
  137. }
  138. private static class RunEnd implements Runnable
  139. {
  140. private L2PcInstance activeChar;
  141. public RunEnd(L2PcInstance pActiveChar)
  142. {
  143. activeChar = pActiveChar;
  144. }
  145. @Override
  146. public void run()
  147. {
  148. DeleteObject obj = null;
  149. for (int i = 0; i < 8; i++)
  150. {
  151. obj = new DeleteObject(MonsterRace.getInstance().getMonsters()[i]);
  152. activeChar.sendPacket(obj);
  153. activeChar.broadcastPacket(obj);
  154. }
  155. state = -1;
  156. }
  157. }
  158. }