Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. package com.dark.rs2.content.gambling;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import com.dark.core.util.Utility;
  7. import com.dark.rs2.content.dialogue.DialogueManager;
  8. import com.dark.rs2.content.io.PlayerSave.PlayerContainer;
  9. import com.dark.rs2.content.io.PlayerSaveUtil;
  10. import com.dark.rs2.entity.World;
  11. import com.dark.rs2.entity.item.Item;
  12. import com.dark.rs2.entity.player.Player;
  13. import com.dark.rs2.entity.player.net.out.impl.SendMessage;
  14. import com.dark.rs2.entity.player.net.out.impl.SendString;
  15.  
  16. /**
  17. * Handles the Lottery
  18. * @author Daniel
  19. *
  20. */
  21. public class Lottery {
  22.  
  23. /**
  24. * Players entered in the lottery
  25. */
  26. private static final List<Player> entries = new ArrayList<Player>();
  27.  
  28. /**
  29. * The lottery limit
  30. */
  31. private static final int LOTTERY_LIMIT = 1_000_000_000;
  32.  
  33. /**
  34. * The entry price of lottery
  35. */
  36. private static final int ENTRY_PRICE = 500_000_000;
  37.  
  38. /**
  39. * Current threshold of lottery
  40. */
  41. private static int CURRENT_POT = 0;
  42.  
  43. /**
  44. * The winner of lottery
  45. */
  46. private static Player winner = null;
  47.  
  48. /**
  49. * Handles player entering the lottery
  50. * @param player
  51. */
  52. public static void enterLotter(Player player) {
  53. if(player.isIron()){
  54. DialogueManager.sendStatement(player, "You may not enter the lottery.");
  55. return;
  56. }
  57.  
  58. if (hasEntered(player)) {
  59. DialogueManager.sendStatement(player, "You are already entered in the lottery!");
  60. return;
  61. }
  62.  
  63. if (CURRENT_POT >= LOTTERY_LIMIT) {
  64. DialogueManager.sendStatement(player, "The lottery is currently full.");
  65. return;
  66. }
  67.  
  68. if (!player.getInventory().hasItemAmount(995, ENTRY_PRICE)) {
  69. DialogueManager.sendStatement(player, "You need " + Utility.format(ENTRY_PRICE) + " coins to enter the lottery!");
  70. return;
  71. }
  72.  
  73. player.getInventory().remove(995, ENTRY_PRICE);
  74. CURRENT_POT += ENTRY_PRICE;
  75. entries.add(player);
  76. //World.sendGlobalMessage("[ @blu@Powerball @bla@]A new player has entered the lottery! @blu@" + Utility.format(CURRENT_POT) + " @bla@/ @blu@" + Utility.format(LOTTERY_LIMIT) + "@bla@.");
  77. player.send(new SendMessage("You have entered the lotto, use ::lotto command to see the current pot information!"));
  78.  
  79. if (CURRENT_POT == LOTTERY_LIMIT) {
  80. draw();
  81. }
  82.  
  83. }
  84.  
  85. /**
  86. * Draws the lottery
  87. */
  88. public static void draw() {
  89. if (entries.isEmpty()) {
  90. return;
  91. }
  92. winner = Utility.randomElement(entries);
  93.  
  94. if (winner== null) {
  95. winner = new Player();
  96. winner.setUsername(name);
  97. if (!PlayerContainer.loadDetails(winner)) {
  98. System.out.println("The player '" + name + "' could not be found.");
  99. return;
  100. }
  101. }
  102.  
  103. winner.send(new SendMessage("Congratulations! You have won the lottery.."));
  104. winner.getInventory().addOrCreateGroundItem(13204, + 900_000, true);
  105.  
  106.  
  107. return;
  108.  
  109. // World.sendGlobalMessage("<shad=0>[ @blu@Powerball @bla@] @blu@" + winner.getUsername() + "@bla@ has just won the Powerball!");
  110. // winner.send(new SendMessage("The Taxman takes 100k Platinum tokens... Taxation is theft!"));
  111. //reset();
  112. }
  113.  
  114. /**
  115. * Resets the lottery
  116. */
  117. public static void reset() {
  118. winner = null;
  119. CURRENT_POT = 0;
  120. entries.clear();
  121. }
  122.  
  123. /**
  124. * Does an announcement for lottery
  125. */
  126. public static void announce() {
  127. World.sendGlobalMessage("[ @blu@Powerball @bla] The current pot is at <col=C46423>" + Utility.format(CURRENT_POT) + " </col>/ <col=C46423>" + Utility.format(LOTTERY_LIMIT) + "</col>.");
  128. }
  129.  
  130. /**
  131. * Gets the current lottery pot
  132. * @return
  133. */
  134. public static int getPot() {
  135. return CURRENT_POT;
  136. }
  137.  
  138. /**
  139. * Gets the current lottery limit
  140. * @return
  141. */
  142. public static int getLimit() {
  143. return LOTTERY_LIMIT;
  144. }
  145.  
  146. /**
  147. * Gets the amount of players involved in lottery
  148. * @return
  149. */
  150. public static int getPlayers() {
  151. return entries.size();
  152. }
  153.  
  154. /**
  155. * Checks if player has entered the lotter
  156. * @param player
  157. * @return
  158. */
  159. public static boolean hasEntered(Player player) {
  160. if (entries.contains(player)) {
  161. return true;
  162. }
  163. return false;
  164. }
  165.  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement