Guest User

Untitled

a guest
Jul 7th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2004-2013 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.  
  20. package l2dc.CastleBattle;
  21.  
  22. import java.util.Calendar;
  23. import java.util.Map;
  24. import java.util.logging.Logger;
  25.  
  26. import javolution.util.FastMap;
  27.  
  28. import com.l2jserver.gameserver.Announcements;
  29. import com.l2jserver.gameserver.ThreadPoolManager;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  32.  
  33. /**
  34. * @author HyperByter
  35. * @version Beta
  36. * @build 8.7.2013
  37. */
  38.  
  39. public class CastleBattle
  40. {
  41. protected static CastleBattle instance = null;
  42. public static CastleBattleLoop _task = new CastleBattleLoop();
  43.  
  44. private static final Logger _log = Logger.getLogger("CastleBattle");
  45.  
  46. private final String htm_path = "data/scripts/l2dc/CastleBattle/";
  47. /**
  48. * <ul>
  49. * <li>0 - Disabled</li>
  50. * <li>1 - Not in progress</li>
  51. * <li>2 - Participation</li>
  52. * <li>3 - Event Started</li>
  53. * <li>5 - Event Ended
  54. * </ul>
  55. */
  56. private int CB_State;
  57. private final Map<Integer, L2PcInstance> _participatedPlayers = new FastMap<>();
  58.  
  59. private CastleBattle()
  60. {
  61. CB_Init();
  62. }
  63.  
  64. public static synchronized CastleBattle getInstance()
  65. {
  66. if (instance == null)
  67. {
  68. instance = new CastleBattle();
  69. }
  70. return instance;
  71. }
  72.  
  73. // Initialize Engine
  74. private void CB_Init()
  75. {
  76. CBState_Set(1); // 1 - ON, 2 - OFF
  77. if (CBState_Get() == 1)
  78. {
  79. SetStartTime();
  80. }
  81. }
  82.  
  83. public int CBState_Get()
  84. {
  85. return CB_State;
  86. }
  87.  
  88. public void CBState_Set(int _state)
  89. {
  90. CB_State = _state;
  91. }
  92.  
  93. public void SetStartTime()
  94. {
  95. Calendar _nextTime = Calendar.getInstance();
  96. int _m = _nextTime.get(Calendar.MINUTE);
  97. int x = 1;
  98. while (_m > 5)
  99. {
  100. _m -= 5;
  101. x++;
  102. }
  103. _nextTime.set(Calendar.MINUTE, x * 5);
  104. ThreadPoolManager.getInstance().scheduleGeneral(_task, _nextTime.getTimeInMillis() - System.currentTimeMillis());
  105. }
  106.  
  107. public void StartParticipation()
  108. {
  109. CBState_Set(2);
  110. Announcements.getInstance().announceToAll("Castle Battle participation has started.");
  111. _log.info("Castle Battle participation has started.");
  112. }
  113.  
  114. private void CB_AddPlayer(L2PcInstance _player)
  115. {
  116. _participatedPlayers.put(_player.getObjectId(), _player);
  117. }
  118.  
  119. private int CB_GetPlayerCount()
  120. {
  121. int _pCount = _participatedPlayers.size();
  122. return _pCount;
  123. }
  124.  
  125. // HTML Chat Handler
  126. public void CB_bypass(String _cmd, L2PcInstance _player)
  127. {
  128. final NpcHtmlMessage _html = new NpcHtmlMessage(0);
  129. if (_cmd.startsWith("InitHtmlRequest"))
  130. {
  131. switch (CBState_Get())
  132. {
  133. case 0:
  134. _html.setFile(null, htm_path + "CB_Disabled.htm");
  135. _player.sendPacket(_html);
  136. break;
  137. case 1:
  138. _html.setFile(null, htm_path + "CB_NotRunning.htm");
  139. _player.sendPacket(_html);
  140. break;
  141. case 2:
  142. _html.setFile(null, htm_path + "CB_Participate.htm");
  143. _html.replace("%_pCount%", "" + CB_GetPlayerCount());
  144. _player.sendPacket(_html);
  145. break;
  146. }
  147. }
  148. if (_cmd.startsWith("CB_Participate"))
  149. {
  150. if (_participatedPlayers.containsKey(_player.getObjectId()))
  151. {
  152. _html.setFile("", htm_path + "CB_No_AlreadyJoined.htm");
  153. _player.sendPacket(_html);
  154. }
  155. else if (_player.isInOlympiadMode())
  156. {
  157. _html.setFile("", htm_path + "CB_No_Olympiad.htm");
  158. _player.sendPacket(_html);
  159. }
  160. else
  161. {
  162. CB_AddPlayer(_player);
  163. _html.setFile("", htm_path + "CB_ParticipateSuccess.htm");
  164. _player.sendPacket(_html);
  165. }
  166. }
  167. }
  168.  
  169. public static void main(String[] args)
  170. {
  171. _log.info("# Castle Battle Engine #");
  172. _log.info("Author : HyperByter");
  173. _log.info("Version : Beta");
  174. _log.info("Build : 8.7.2013");
  175. }
  176. }
  177.  
  178. class CastleBattleLoop implements Runnable
  179. {
  180. @Override
  181. public void run()
  182. {
  183. if (CastleBattle.getInstance().CBState_Get() == 1)
  184. {
  185. CastleBattle.getInstance().StartParticipation();
  186. }
  187. }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment