Advertisement
Guest User

wildernessboss

a guest
Jan 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package org.brutality.model.npcs.boss;
  2.  
  3. import java.util.Arrays;
  4. import java.util.EnumSet;
  5. import java.util.Objects;
  6. import java.util.Optional;
  7. import java.util.Set;
  8. import java.util.concurrent.ThreadLocalRandom;
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. import org.brutality.model.content.teleport.Position;
  12. import org.brutality.model.npcs.NPCHandler;
  13. import org.brutality.model.players.Player;
  14. import org.brutality.model.players.PlayerHandler;
  15. /**
  16. * Represents a random {@lin NPC} spawned within the Wilderness location on a regular basis
  17. * @author Rene
  18. *
  19. */
  20. public final class NewWildernessBoss {
  21.  
  22. public enum Location {
  23. EXAMPLE(new Position(3222, 3222, 0)),
  24. ANOTHER_EXAMPLE(new Position(3100, 3100, 0)), //TESTING, now you can add as much locations as yo uwant
  25. //it is complete
  26. //can add that 1hour thing +5mins and rare item drop i can add more items
  27.  
  28. ;
  29.  
  30. private final Position pos;
  31.  
  32. Location(Position pos) {
  33. this.pos = pos;
  34. }
  35.  
  36. public static final Set<Location> SET = EnumSet.allOf(Location.class);
  37.  
  38. public static Location random() {
  39. int size = SET.size();
  40. int random = ThreadLocalRandom.current().nextInt(size);
  41. int index = 0;
  42. for (Location loc : SET) {
  43. if (index == random) {
  44. return loc;
  45. }
  46. index++;
  47. }
  48. throw new AssertionError("Won't be reached");
  49. }
  50.  
  51. public int getX() {
  52. return pos.getX();
  53. }
  54.  
  55. public int getY() {
  56. return pos.getY();
  57. }
  58.  
  59. public int getHeight() {
  60. return pos.getZ();
  61. }
  62.  
  63. public Position getPos() {
  64. return pos;
  65. }
  66. }
  67.  
  68. /** Configuration **/
  69. public static final int NPC_ID = 5; //TODO
  70. private static final int NOTIF_COUNTDOWN = (int) TimeUnit.MINUTES.toSeconds(5) *2;
  71. private static final int COUNTDOWN = (int) TimeUnit.HOURS.toSeconds(1) * 2;
  72.  
  73. /** Class vars **/
  74. private static int timer = COUNTDOWN;
  75. private static Location location;
  76. public static boolean spawned;
  77.  
  78. public static final void tick() {
  79. if (spawned) {
  80. return;
  81. }
  82.  
  83. if (timer == NOTIF_COUNTDOWN) {
  84. location = Location.random();
  85. msgAll("5 mins left at location:" + location.name()); //TODO: Test
  86. }
  87. if (timer == 0) {
  88. spawn();
  89. }
  90. if (timer != 0) {
  91. timer--;
  92. }
  93. }
  94.  
  95. private static void spawn() {
  96. spawned = true;
  97. Location loc = location;
  98. System.err.println("Being spawned");
  99. NPCHandler.spawnNpc(NPC_ID, loc.getX(), loc.getY(), loc.getHeight(), 1, 1, 1, 500, 500);
  100. msgAll("Spawned");
  101. }
  102.  
  103. public static void restart(Optional<Player> killer) {
  104.  
  105. timer = COUNTDOWN;
  106. spawned = false;
  107. killer.ifPresent(player -> msgAll(player.playerName + " has killed the boss"));
  108. }
  109.  
  110. private static void msgAll(String msg) {
  111. Arrays.stream(PlayerHandler.players).filter(Objects::nonNull)
  112. .forEach(player -> player.sendMessage(msg));
  113.  
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement