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

import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.scripts.constants.ScriptRegionShape;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
Akka's avatar
Akka committed
8
9
10
import lombok.Data;
import lombok.Setter;
import lombok.ToString;
Melledy's avatar
Melledy committed
11

Akka's avatar
Akka committed
12
13
@ToString
@Setter
Melledy's avatar
Melledy committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class SceneRegion {
	public int config_id;
	public int shape;
	public Position pos;
	public Position size;
	
	private boolean hasNewEntities;
	private final IntSet entities; // Ids of entities inside this region
	
	public SceneRegion() {
		this.entities = new IntOpenHashSet();
	}
	
	public IntSet getEntities() {
		return entities;
	}

	public void addEntity(GameEntity entity) {
		if (this.getEntities().contains(entity.getId())) {
			return;
		}
		this.getEntities().add(entity.getId());
		this.hasNewEntities = true;
	}
	
	public void removeEntity(GameEntity entity) {
		this.getEntities().remove(entity.getId());
	}
	
	public boolean contains(Position p) {
		switch (shape) {
			case ScriptRegionShape.CUBIC:
				return (Math.abs(pos.getX() - p.getX()) <= size.getX()) &&
				       (Math.abs(pos.getZ() - p.getZ()) <= size.getZ());
			case ScriptRegionShape.SPHERE:
				return false;
		}
		
		return false;
	}

	public boolean hasNewEntities() {
		return hasNewEntities;
	}
	
	public void resetNewEntities() {
		hasNewEntities = false;
	}
}