RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Boundary.java
1package com.osroyale.game.world.position;
2
3import com.osroyale.game.world.World;
4import com.osroyale.game.world.entity.mob.Mob;
5import com.osroyale.game.world.entity.mob.player.Player;
6
7import java.util.*;
8
39
40public class Boundary {
41
42 int minX, minY, highX, highY;
43 int height;
44
45 public Boundary(int minX, int minY, int highX, int highY) {
46 this.minX = minX;
47 this.minY = minY;
48 this.highX = highX;
49 this.highY = highY;
50 height = -1;
51 }
52
53 public Boundary(int minX, int minY, int highX, int highY, int height) {
54 this.minX = minX;
55 this.minY = minY;
56 this.highX = highX;
57 this.highY = highY;
58 this.height = height;
59 }
60
61 public int getMinimumX() {
62 return minX;
63 }
64
65 public int getMinimumY() {
66 return minY;
67 }
68
69 public int getMaximumX() {
70 return highX;
71 }
72
73 public int getMaximumY() {
74 return highY;
75 }
76
77 public static boolean isIn(Mob mob, Boundary... boundaries) {
78 for (Boundary b : boundaries) {
79 if (b.height >= 0) {
80 if (mob.getHeight() != b.height)
81 continue;
82 }
83 if (mob.getX() >= b.minX && mob.getX() <= b.highX && mob.getY() >= b.minY && mob.getY() <= b.highY)
84 return true;
85 }
86 return false;
87 }
88
89 public static boolean isIn(int x, int y, int z, Boundary boundaries) {
90 if (boundaries.height >= 0) {
91 if (z != boundaries.height) {
92 return false;
93 }
94 }
95 return x >= boundaries.minX && x <= boundaries.highX && y >= boundaries.minY && y <= boundaries.highY;
96 }
97
98 public static List<Player> getPlayers(Boundary boundary) {
99 List<Player> list = new ArrayList<>();
100 for (Player player : World.getPlayers()) {
101 if (player != null && isIn(player, boundary))
102 list.add(player);
103 }
104 return list;
105 }
106
107 public static boolean isInSameBoundary(Player player1, Player player2, Boundary[] boundaries) {
108 Optional<Boundary> boundary1 = Arrays.stream(boundaries).filter(b -> isIn(player1, b)).findFirst();
109 Optional<Boundary> boundary2 = Arrays.stream(boundaries).filter(b -> isIn(player2, b)).findFirst();
110 if (!boundary1.isPresent() || !boundary2.isPresent()) {
111 return false;
112 }
113 return Objects.equals(boundary1.get(), boundary2.get());
114 }
115
116}