AdminMonsterRace.java 5.6 KB

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