RuneHive-Game
Loading...
Searching...
No Matches
Boundary.java
Go to the documentation of this file.
1package com.runehive.game.world.position;
2
3import com.runehive.game.world.World;
4import com.runehive.game.world.entity.mob.Mob;
5import com.runehive.game.world.entity.mob.player.Player;
6
7import java.util.*;
8
9/**
10 * Created by Daniel on 2017-11-24.
11 */
12public class Boundary {
13
15 int height;
16
17 public Boundary(int minX, int minY, int highX, int highY) {
18 this.minX = minX;
19 this.minY = minY;
20 this.highX = highX;
21 this.highY = highY;
22 height = -1;
23 }
24
25 public Boundary(int minX, int minY, int highX, int highY, int height) {
26 this.minX = minX;
27 this.minY = minY;
28 this.highX = highX;
29 this.highY = highY;
30 this.height = height;
31 }
32
33 public int getMinimumX() {
34 return minX;
35 }
36
37 public int getMinimumY() {
38 return minY;
39 }
40
41 public int getMaximumX() {
42 return highX;
43 }
44
45 public int getMaximumY() {
46 return highY;
47 }
48
49 public static boolean isIn(Mob mob, Boundary... boundaries) {
50 for (Boundary b : boundaries) {
51 if (b.height >= 0) {
52 if (mob.getHeight() != b.height)
53 continue;
54 }
55 if (mob.getX() >= b.minX && mob.getX() <= b.highX && mob.getY() >= b.minY && mob.getY() <= b.highY)
56 return true;
57 }
58 return false;
59 }
60
61 public static boolean isIn(int x, int y, int z, Boundary boundaries) {
62 if (boundaries.height >= 0) {
63 if (z != boundaries.height) {
64 return false;
65 }
66 }
67 return x >= boundaries.minX && x <= boundaries.highX && y >= boundaries.minY && y <= boundaries.highY;
68 }
69
70 public static List<Player> getPlayers(Boundary boundary) {
71 List<Player> list = new ArrayList<>();
72 for (Player player : World.getPlayers()) {
73 if (player != null && isIn(player, boundary))
74 list.add(player);
75 }
76 return list;
77 }
78
79 public static boolean isInSameBoundary(Player player1, Player player2, Boundary[] boundaries) {
80 Optional<Boundary> boundary1 = Arrays.stream(boundaries).filter(b -> isIn(player1, b)).findFirst();
81 Optional<Boundary> boundary2 = Arrays.stream(boundaries).filter(b -> isIn(player2, b)).findFirst();
82 if (!boundary1.isPresent() || !boundary2.isPresent()) {
83 return false;
84 }
85 return Objects.equals(boundary1.get(), boundary2.get());
86 }
87
88}
Represents the game world.
Definition World.java:46
static MobList< Player > getPlayers()
Definition World.java:544
Handles the mob class.
Definition Mob.java:66
This class represents a character controlled by a player.
Definition Player.java:125
Boundary(int minX, int minY, int highX, int highY, int height)
Definition Boundary.java:25
static boolean isIn(Mob mob, Boundary... boundaries)
Definition Boundary.java:49
Boundary(int minX, int minY, int highX, int highY)
Definition Boundary.java:17
static boolean isInSameBoundary(Player player1, Player player2, Boundary[] boundaries)
Definition Boundary.java:79
static boolean isIn(int x, int y, int z, Boundary boundaries)
Definition Boundary.java:61
static List< Player > getPlayers(Boundary boundary)
Definition Boundary.java:70