Guest User

Count Down engine

a guest
Aug 16th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.88 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Server
  3. Index: java/com/l2jserver/gameserver/network/serverpackets/ExShowScreenMessage.java
  4. ===================================================================
  5. --- java/com/l2jserver/gameserver/network/serverpackets/ExShowScreenMessage.java    (revision 5563)
  6. +++ java/com/l2jserver/gameserver/network/serverpackets/ExShowScreenMessage.java    (working copy)
  7. @@ -100,7 +100,10 @@
  8.         _time = time;
  9.         _size = size;
  10.         _effect = showEffect;
  11. -       _npcString = npcString.getId();
  12. +       if (npcString != null)
  13. +           _npcString = npcString.getId();
  14. +       else
  15. +           _npcString = -1;
  16.     }
  17.    
  18.     /**
  19. Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  20. ===================================================================
  21. --- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (revision 5563)
  22. +++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
  23. @@ -222,6 +222,7 @@
  24.  import com.l2jserver.gameserver.network.serverpackets.ExOlympiadMode;
  25.  import com.l2jserver.gameserver.network.serverpackets.ExPrivateStoreSetWholeMsg;
  26.  import com.l2jserver.gameserver.network.serverpackets.ExSetCompassZoneCode;
  27. +import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  28.  import com.l2jserver.gameserver.network.serverpackets.ExSpawnEmitter;
  29.  import com.l2jserver.gameserver.network.serverpackets.ExStartScenePlayer;
  30.  import com.l2jserver.gameserver.network.serverpackets.ExStorageMaxCount;
  31. @@ -15471,4 +15472,95 @@
  32.     {
  33.         globalProfessionChangeListeners.remove(listener);
  34.     }
  35. +  
  36. +   long timeForCountDown = 0;
  37. +   ScheduledFuture<?> countDown = null;
  38. +  
  39. +   public enum Position {
  40. +       None,
  41. +       UpperLeft,
  42. +       UpperCenter,
  43. +       UpperRight,
  44. +       MiddleLeft,
  45. +       MiddleCenter,
  46. +       MiddleRight,
  47. +       LowerCenter,
  48. +       LowerRight;
  49. +   }
  50. +   /**
  51. +    * text can be replaced with %s (seconds), %S (seconds, with zero in the front if lower than 9), %m (minutes), %M (minutes, with zero in the front if lower than 9), %h (hours), %H (hours, with zero in the front if lower than 9)
  52. +    * @param time
  53. +    * @param text
  54. +    * @param position
  55. +    * @param textIsSmall
  56. +    */
  57. +   public void startCountDown(long time, String text, Position position, boolean textIsSmall) {
  58. +       stopCountDown();
  59. +       timeForCountDown = time;
  60. +       long seconds = timeForCountDown % 60;
  61. +       long minutes = timeForCountDown / 60 % 60;
  62. +       long hours = timeForCountDown / 60 / 60 % 24;
  63. +       String replacedText = text;
  64. +       if (text.contains("%s"))
  65. +           replacedText = replacedText.replace("%s", seconds + "");
  66. +       if (text.contains("%S"))
  67. +           replacedText = replacedText.replace("%S", seconds > 9 ? seconds + "" : "0" + seconds);
  68. +       if (text.contains("%m"))
  69. +           replacedText = replacedText.replace("%m", minutes + "");
  70. +       if (text.contains("%M"))
  71. +           replacedText = replacedText.replace("%M", minutes > 9 ? minutes + "" : "0" + minutes);
  72. +       if (text.contains("%h"))
  73. +           replacedText = replacedText.replace("%h", hours + "");
  74. +       if (text.contains("%H"))
  75. +           replacedText = replacedText.replace("%H", hours > 9 ? hours + "" : "0" + hours);
  76. +       sendPacket(new ExShowScreenMessage(1, 0, position.ordinal(), 0, (textIsSmall ? 1 : 0), 0, 0, false, 1000, true, replacedText, null));
  77. +       timeForCountDown--;
  78. +       countDown = ThreadPoolManager.getInstance().scheduleGeneral(new CountDown(this, text, position.ordinal(), (textIsSmall ? 1 : 0)), 1000);
  79. +   }
  80. +  
  81. +   class CountDown implements Runnable {
  82. +       L2PcInstance player;
  83. +       String text;
  84. +       int position;
  85. +       int textIsSmall;
  86. +       public CountDown(L2PcInstance _player, String _text, int _position, int _textIsSmall) {
  87. +           player = _player;
  88. +           text = _text;
  89. +           position = _position;
  90. +           textIsSmall = _textIsSmall;
  91. +       }
  92. +
  93. +       @Override
  94. +       public void run() {
  95. +           if (player == null || timeForCountDown <= 0) {
  96. +               return;
  97. +           }
  98. +           long seconds = timeForCountDown % 60;
  99. +           long minutes = timeForCountDown / 60 % 60;
  100. +           long hours = timeForCountDown / 60 / 60 % 24;
  101. +           String replacedText = text;
  102. +           if (text.contains("%s"))
  103. +               replacedText = replacedText.replace("%s", seconds + "");
  104. +           if (text.contains("%S"))
  105. +               replacedText = replacedText.replace("%S", seconds > 9 ? seconds + "" : "0" + seconds);
  106. +           if (text.contains("%m"))
  107. +               replacedText = replacedText.replace("%m", minutes + "");
  108. +           if (text.contains("%M"))
  109. +               replacedText = replacedText.replace("%M", minutes > 9 ? minutes + "" : "0" + minutes);
  110. +           if (text.contains("%h"))
  111. +               replacedText = replacedText.replace("%h", hours + "");
  112. +           if (text.contains("%H"))
  113. +               replacedText = replacedText.replace("%H", hours > 9 ? hours + "" : "0" + hours);
  114. +           player.sendPacket(new ExShowScreenMessage(1, 0, position, 0, textIsSmall, 0, 0, false, 1000, true, replacedText, null));
  115. +           timeForCountDown--;
  116. +           countDown = ThreadPoolManager.getInstance().scheduleGeneral(new CountDown(player, text, position, textIsSmall), 1000);
  117. +       }
  118. +   }
  119. +
  120. +   public void stopCountDown() {
  121. +       timeForCountDown = 0;
  122. +       if (countDown != null)
  123. +           countDown.cancel(true);
  124. +       countDown = null;
  125. +   }
  126.  }
  127. \ No newline at end of file
  128. #P L2J_DataPack
  129. Index: dist/game/data/scripts/handlers/admincommandhandlers/AdminTest.java
  130. ===================================================================
  131. --- dist/game/data/scripts/handlers/admincommandhandlers/AdminTest.java (revision 9067)
  132. +++ dist/game/data/scripts/handlers/admincommandhandlers/AdminTest.java (working copy)
  133. @@ -24,6 +24,7 @@
  134.  import com.l2jserver.gameserver.model.L2Object;
  135.  import com.l2jserver.gameserver.model.actor.L2Character;
  136.  import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  137. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance.Position;
  138.  import com.l2jserver.gameserver.model.skills.L2Skill;
  139.  import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  140.  
  141. @@ -36,7 +37,8 @@
  142.     {
  143.         "admin_stats",
  144.         "admin_skill_test",
  145. -       "admin_known"
  146. +       "admin_known",
  147. +       "admin_test_countdown"
  148.     };
  149.    
  150.     @Override
  151. @@ -82,6 +84,14 @@
  152.         {
  153.             Config.CHECK_KNOWN = false;
  154.         }
  155. +       else if (command.toLowerCase().startsWith("admin_test_countdown")) {
  156. +           int start = 0;
  157. +           start = command.length() > 20 ? Integer.parseInt(command.substring(21)) : 1;
  158. +           if (start == 1)
  159. +               activeChar.startCountDown(35, "The test Count Down is turned on for %s seconds!", Position.MiddleCenter, false);
  160. +           else
  161. +               activeChar.stopCountDown();
  162. +       }
  163.         return true;
  164.     }
  165.    
  166. Index: dist/game/config/adminCommands.xml
  167. ===================================================================
  168. --- dist/game/config/adminCommands.xml  (revision 9067)
  169. +++ dist/game/config/adminCommands.xml  (working copy)
  170. @@ -602,6 +602,7 @@
  171.     <admin command="admin_stats" accessLevel="7" />
  172.     <admin command="admin_skill_test" accessLevel="7" />
  173.     <admin command="admin_known" accessLevel="7" />
  174. +   <admin command="admin_test_countdown" accessLevel="7" />
  175.  
  176.     <!-- ADMIN TVT EVENT -->
  177.     <admin command="admin_tvt_add" accessLevel="7" />
Advertisement
Add Comment
Please, Sign In to add comment