AdminMonsterRace.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import net.sf.l2j.gameserver.MonsterRace;
  17. import net.sf.l2j.gameserver.ThreadPoolManager;
  18. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.network.serverpackets.DeleteObject;
  22. import net.sf.l2j.gameserver.network.serverpackets.MonRaceInfo;
  23. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  24. import net.sf.l2j.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. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. if (command.equalsIgnoreCase("admin_mons"))
  42. {
  43. handleSendPacket(activeChar);
  44. }
  45. return true;
  46. }
  47. public String[] getAdminCommandList()
  48. {
  49. return ADMIN_COMMANDS;
  50. }
  51. private void handleSendPacket(L2PcInstance activeChar)
  52. {
  53. /*
  54. * -1 0 to initialize the race
  55. * 0 15322 to start race
  56. * 13765 -1 in middle of race
  57. * -1 0 to end the race
  58. *
  59. * 8003 to 8027
  60. */
  61. int[][] codes =
  62. {
  63. {
  64. -1, 0
  65. },
  66. {
  67. 0, 15322
  68. },
  69. {
  70. 13765, -1
  71. },
  72. {
  73. -1, 0
  74. }
  75. };
  76. MonsterRace race = MonsterRace.getInstance();
  77. if (state == -1)
  78. {
  79. state++;
  80. race.newRace();
  81. race.newSpeeds();
  82. MonRaceInfo spk = new MonRaceInfo(codes[state][0], codes[state][1], race.getMonsters(), race.getSpeeds());
  83. activeChar.sendPacket(spk);
  84. activeChar.broadcastPacket(spk);
  85. }
  86. else if (state == 0)
  87. {
  88. state++;
  89. SystemMessage sm = new SystemMessage(SystemMessageId.MONSRACE_RACE_START);
  90. sm.addNumber(0);
  91. activeChar.sendPacket(sm);
  92. PlaySound SRace = new PlaySound(1, "S_Race", 0, 0, 0, 0, 0);
  93. activeChar.sendPacket(SRace);
  94. activeChar.broadcastPacket(SRace);
  95. PlaySound SRace2 = new PlaySound(0, "ItemSound2.race_start", 1, 121209259, 12125, 182487, -3559);
  96. activeChar.sendPacket(SRace2);
  97. activeChar.broadcastPacket(SRace2);
  98. MonRaceInfo spk = new MonRaceInfo(codes[state][0], codes[state][1], race.getMonsters(), race.getSpeeds());
  99. activeChar.sendPacket(spk);
  100. activeChar.broadcastPacket(spk);
  101. ThreadPoolManager.getInstance().scheduleGeneral(new RunRace(codes, activeChar), 5000);
  102. }
  103. }
  104. class RunRace implements Runnable
  105. {
  106. private int[][] codes;
  107. private L2PcInstance activeChar;
  108. public RunRace(int[][] pCodes, L2PcInstance pActiveChar)
  109. {
  110. codes = pCodes;
  111. activeChar = pActiveChar;
  112. }
  113. public void run()
  114. {
  115. //int[][] speeds1 = MonsterRace.getInstance().getSpeeds();
  116. //MonsterRace.getInstance().newSpeeds();
  117. //int[][] speeds2 = MonsterRace.getInstance().getSpeeds();
  118. /*
  119. int[] speed = new int[8];
  120. for (int i=0; i<8; i++)
  121. {
  122. for (int j=0; j<20; j++)
  123. {
  124. //_log.info("Adding "+speeds1[i][j] +" and "+ speeds2[i][j]);
  125. speed[i] += (speeds1[i][j]*1);// + (speeds2[i][j]*1);
  126. }
  127. _log.info("Total speed for "+(i+1)+" = "+speed[i]);
  128. }*/
  129. MonRaceInfo spk = new MonRaceInfo(codes[2][0], codes[2][1], MonsterRace.getInstance().getMonsters(), MonsterRace.getInstance().getSpeeds());
  130. activeChar.sendPacket(spk);
  131. activeChar.broadcastPacket(spk);
  132. ThreadPoolManager.getInstance().scheduleGeneral(new RunEnd(activeChar), 30000);
  133. }
  134. }
  135. class RunEnd implements Runnable
  136. {
  137. private L2PcInstance activeChar;
  138. public RunEnd(L2PcInstance pActiveChar)
  139. {
  140. activeChar = pActiveChar;
  141. }
  142. public void run()
  143. {
  144. DeleteObject obj = null;
  145. for (int i = 0; i < 8; i++)
  146. {
  147. obj = new DeleteObject(MonsterRace.getInstance().getMonsters()[i]);
  148. activeChar.sendPacket(obj);
  149. activeChar.broadcastPacket(obj);
  150. }
  151. state = -1;
  152. }
  153. }
  154. }