SceneRegion.java 1.01 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
package emu.grasscutter.scripts.data;

import emu.grasscutter.scripts.constants.ScriptRegionShape;
import emu.grasscutter.utils.Position;
Akka's avatar
Akka committed
5
import lombok.Setter;
Melledy's avatar
Melledy committed
6

Akka's avatar
Akka committed
7

Akka's avatar
Akka committed
8
@Setter
Melledy's avatar
Melledy committed
9
10
11
12
public class SceneRegion {
	public int config_id;
	public int shape;
	public Position pos;
Akka's avatar
Akka committed
13
    // for CUBIC
Melledy's avatar
Melledy committed
14
	public Position size;
Akka's avatar
Akka committed
15
16
    // for SPHERE
    public int radius;
Melledy's avatar
Melledy committed
17

Akka's avatar
Akka committed
18
19
    public transient SceneGroup group;
	public boolean contains(Position position) {
Melledy's avatar
Melledy committed
20
21
		switch (shape) {
			case ScriptRegionShape.CUBIC:
Akka's avatar
Akka committed
22
23
24
				return (Math.abs(pos.getX() - position.getX()) <= size.getX()) &&
				       (Math.abs(pos.getY() - position.getY()) <= size.getY()) &&
				       (Math.abs(pos.getZ() - position.getZ()) <= size.getZ());
Melledy's avatar
Melledy committed
25
			case ScriptRegionShape.SPHERE:
Akka's avatar
Akka committed
26
27
28
                var x = Math.pow(pos.getX() - position.getX(), 2);
                var y = Math.pow(pos.getY() - position.getY(), 2);
                var z = Math.pow(pos.getZ() - position.getZ(), 2);
akatatsu27's avatar
akatatsu27 committed
29
30
                // ^ means XOR in java!
				return x + y + z <= (radius*radius);
Melledy's avatar
Melledy committed
31
32
33
34
35
		}
		return false;
	}

}