Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. package server.model.minigames;
  2.  
  3. import server.model.players.Client;
  4. import server.Server;
  5. import server.model.npcs.*;
  6. import server.model.players.*;
  7.  
  8. /**
  9. * @author Slick
  10. */
  11.  
  12. public class PestControl {
  13.  
  14. public PestControl() {
  15.  
  16. }
  17.  
  18. public final int GAME_TIMER = 40; //5 minutes
  19. public final int WAIT_TIMER = 7;
  20.  
  21. public int gameTimer = -1;
  22. public int waitTimer = 15;
  23. public int properTimer = 0;
  24.  
  25. public void process() {
  26. setInterface();
  27. if (properTimer > 0) {
  28. properTimer--;
  29. return;
  30. } else {
  31. properTimer = 4;
  32. }
  33. if (waitTimer > 0)
  34. waitTimer--;
  35. else if (waitTimer == 0)
  36. startGame();
  37. if (gameTimer > 0) {
  38. gameTimer--;
  39. if (allPortalsDead()) {
  40. endGame(true);
  41. }
  42. } else if (gameTimer == 0)
  43. endGame(false);
  44. }
  45.  
  46. public void startGame() {
  47. if (playersInBoat() > 2) {
  48. gameTimer = GAME_TIMER;
  49. waitTimer = -1;
  50. //spawn npcs
  51. spawnNpcs();
  52. setInterface();
  53. //move players into game
  54. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  55. if (Server.playerHandler.players[j] != null) {
  56. if (Server.playerHandler.players[j].inPcBoat()) {
  57. movePlayer(j);
  58. }
  59. }
  60. }
  61. } else {
  62. waitTimer = WAIT_TIMER;
  63. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  64. if (Server.playerHandler.players[j] != null) {
  65. if (Server.playerHandler.players[j].inPcBoat()) {
  66. Client c = (Client)Server.playerHandler.players[j];
  67. c.sendMessage("There need to be at least 3 players to start a game of pest control.");
  68. }
  69. }
  70. }
  71. }
  72. }
  73.  
  74. public int playersInBoat() {
  75. int count = 0;
  76. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  77. if (Server.playerHandler.players[j] != null) {
  78. if (Server.playerHandler.players[j].inPcBoat()) {
  79. count++;
  80. }
  81. }
  82. }
  83. return count;
  84. }
  85.  
  86. public void endGame(boolean won) {
  87. gameTimer = -1;
  88. waitTimer = WAIT_TIMER;
  89. for (int j = 0; j < Server.playerHandler.players.length; j++) {
  90. if (Server.playerHandler.players[j] != null) {
  91. if (Server.playerHandler.players[j].inPcGame()) {
  92. Client c = (Client)Server.playerHandler.players[j];
  93. c.getPA().movePlayer(2657, 2639, 0);
  94. if (won && c.pcDamage > 4) {
  95. c.sendMessage("You have won the pest control game and have been awarded 4 pest control points.");
  96. c.pcPoints += 4;
  97. c.playerLevel[3] = c.getLevelForXP(c.playerXP[3]);
  98. c.playerLevel[5] = c.getLevelForXP(c.playerXP[5]);
  99. c.specAmount = 10;
  100. c.getItems().addItem(995, c.combatLevel * 50);
  101. c.getPA().refreshSkill(3);
  102. c.getPA().refreshSkill(5);
  103. } else if (won) {
  104. c.sendMessage("The void knights notice your lack of zeal.");
  105. } else {
  106. c.sendMessage("You failed to kill all the portals in 5 minutes and have not been awarded any points.");
  107. }
  108. c.pcDamage = 0;
  109. c.getItems().addSpecialBar(c.playerEquipment[c.playerWeapon]);
  110. c.getCombat().resetPrayers();
  111. }
  112. }
  113. }
  114.  
  115. for (int j = 0; j < Server.npcHandler.npcs.length; j++) {
  116. if (Server.npcHandler.npcs[j] != null) {
  117. if (Server.npcHandler.npcs[j].npcType > 6144 && Server.npcHandler.npcs[j].npcType < 6146)
  118. Server.npcHandler.npcs[j] = null;
  119. }
  120. }
  121. }
  122. public void setInterface() {
  123. for (int j = 0; j < PlayerHandler.players.length; j++) {
  124. if (PlayerHandler.players[j] != null) {
  125. if (PlayerHandler.players[j].inPcBoat()) {
  126. Client c = (Client) PlayerHandler.players[j];
  127. c.getPA().sendFrame126("Next Departure: "+waitTimer+"", 21006);
  128. c.getPA().sendFrame126("Players Ready: "+playersInBoat()+"", 21007);
  129. c.getPA().sendFrame126("(Need 3 to 25 players)", 21008);
  130. c.getPA().sendFrame126("Points: "+c.pcPoints+"", 21009);
  131. c.getPA().walkableInterface(21005);
  132. }
  133. if (PlayerHandler.players[j].inPcGame()) {
  134. Client c = (Client) PlayerHandler.players[j];
  135. for (j = 0; j < NPCHandler.npcs.length; j++) {
  136. if (NPCHandler.npcs[j] != null) {
  137. if (NPCHandler.npcs[j].npcType == 6145)
  138. c.getPA().sendFrame126("" + NPCHandler.npcs[j].HP + "", 21114);
  139. }
  140. }
  141.  
  142. c.getPA().sendFrame126("PORTAL", 21110);
  143. c.getPA().sendFrame126(""+c.pcDamage+"", 21115);
  144. c.getPA().sendFrame126("500", 21116);
  145. c.getPA().sendFrame126("Time remaining: "+gameTimer+"", 21117);
  146. c.getPA().walkableInterface(21100);
  147. }
  148. }
  149. }
  150. }
  151.  
  152. public boolean allPortalsDead() {
  153. int count = 0;
  154. for (int j = 0; j < Server.npcHandler.npcs.length; j++) {
  155. if (Server.npcHandler.npcs[j] != null) {
  156. if (Server.npcHandler.npcs[j].npcType > 6144 && Server.npcHandler.npcs[j].npcType < 6146)
  157. if (Server.npcHandler.npcs[j].needRespawn)
  158. count++;
  159. }
  160. }
  161. return count >= 1;
  162. }
  163.  
  164. public void movePlayer(int index) {
  165. Client c = (Client)Server.playerHandler.players[index];
  166. if (c.combatLevel < 10) {
  167. c.sendMessage("You must be at least 10 combat level to enter this boat.");
  168. return;
  169. }
  170. c.getPA().movePlayer(2658,2611,0);
  171. }
  172.  
  173. public void spawnNpcs() {
  174. Server.npcHandler.spawnNpc2(6145,2656,2592,0,0,1200,0,0,100);
  175.  
  176. }
  177.  
  178.  
  179. }
Add Comment
Please, Sign In to add comment