Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.brutality.model.npcs.boss;
- import java.util.Arrays;
- import java.util.EnumSet;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.Set;
- import java.util.concurrent.ThreadLocalRandom;
- import java.util.concurrent.TimeUnit;
- import org.brutality.model.content.teleport.Position;
- import org.brutality.model.npcs.NPCHandler;
- import org.brutality.model.players.Player;
- import org.brutality.model.players.PlayerHandler;
- /**
- * Represents a random {@lin NPC} spawned within the Wilderness location on a regular basis
- * @author Rene
- *
- */
- public final class NewWildernessBoss {
- public enum Location {
- EXAMPLE(new Position(3222, 3222, 0)),
- ANOTHER_EXAMPLE(new Position(3100, 3100, 0)), //TESTING, now you can add as much locations as yo uwant
- //it is complete
- //can add that 1hour thing +5mins and rare item drop i can add more items
- ;
- private final Position pos;
- Location(Position pos) {
- this.pos = pos;
- }
- public static final Set<Location> SET = EnumSet.allOf(Location.class);
- public static Location random() {
- int size = SET.size();
- int random = ThreadLocalRandom.current().nextInt(size);
- int index = 0;
- for (Location loc : SET) {
- if (index == random) {
- return loc;
- }
- index++;
- }
- throw new AssertionError("Won't be reached");
- }
- public int getX() {
- return pos.getX();
- }
- public int getY() {
- return pos.getY();
- }
- public int getHeight() {
- return pos.getZ();
- }
- public Position getPos() {
- return pos;
- }
- }
- /** Configuration **/
- public static final int NPC_ID = 5; //TODO
- private static final int NOTIF_COUNTDOWN = (int) TimeUnit.MINUTES.toSeconds(5) *2;
- private static final int COUNTDOWN = (int) TimeUnit.HOURS.toSeconds(1) * 2;
- /** Class vars **/
- private static int timer = COUNTDOWN;
- private static Location location;
- public static boolean spawned;
- public static final void tick() {
- if (spawned) {
- return;
- }
- if (timer == NOTIF_COUNTDOWN) {
- location = Location.random();
- msgAll("5 mins left at location:" + location.name()); //TODO: Test
- }
- if (timer == 0) {
- spawn();
- }
- if (timer != 0) {
- timer--;
- }
- }
- private static void spawn() {
- spawned = true;
- Location loc = location;
- System.err.println("Being spawned");
- NPCHandler.spawnNpc(NPC_ID, loc.getX(), loc.getY(), loc.getHeight(), 1, 1, 1, 500, 500);
- msgAll("Spawned");
- }
- public static void restart(Optional<Player> killer) {
- timer = COUNTDOWN;
- spawned = false;
- killer.ifPresent(player -> msgAll(player.playerName + " has killed the boss"));
- }
- private static void msgAll(String msg) {
- Arrays.stream(PlayerHandler.players).filter(Objects::nonNull)
- .forEach(player -> player.sendMessage(msg));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement