mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-07 02:26:43 +01:00
add region entity
This commit is contained in:
@@ -1,62 +1,34 @@
|
||||
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;
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
|
||||
@Setter
|
||||
public class SceneRegion {
|
||||
public int config_id;
|
||||
public int shape;
|
||||
public Position pos;
|
||||
// for CUBIC
|
||||
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;
|
||||
}
|
||||
// for SPHERE
|
||||
public int radius;
|
||||
|
||||
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) {
|
||||
public transient SceneGroup group;
|
||||
public boolean contains(Position position) {
|
||||
switch (shape) {
|
||||
case ScriptRegionShape.CUBIC:
|
||||
return (Math.abs(pos.getX() - p.getX()) <= size.getX()) &&
|
||||
(Math.abs(pos.getZ() - p.getZ()) <= size.getZ());
|
||||
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());
|
||||
case ScriptRegionShape.SPHERE:
|
||||
return false;
|
||||
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);
|
||||
return x + y + z <= (radius ^ 2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNewEntities() {
|
||||
return hasNewEntities;
|
||||
}
|
||||
|
||||
public void resetNewEntities() {
|
||||
hasNewEntities = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user