EntityRegion.java 2.38 KB
Newer Older
Akka's avatar
Akka committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package emu.grasscutter.game.entity;

import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass;
import emu.grasscutter.scripts.data.SceneRegion;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
import lombok.Getter;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Getter
public class EntityRegion extends GameEntity{
    private final Position position;
    private boolean hasNewEntities;
akatatsu27's avatar
akatatsu27 committed
18
    private boolean entityLeave;
Akka's avatar
Akka committed
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
    private final Set<Integer> entities; // Ids of entities inside this region
    private final SceneRegion metaRegion;

    public EntityRegion(Scene scene, SceneRegion region) {
        super(scene);
        this.id = getScene().getWorld().getNextEntityId(EntityIdType.REGION);
        setGroupId(region.group.id);
        setBlockId(region.group.block_id);
        setConfigId(region.config_id);
        this.position = region.pos.clone();
        this.entities = ConcurrentHashMap.newKeySet();
        this.metaRegion = region;
    }

    public void addEntity(GameEntity entity) {
        if (this.getEntities().contains(entity.getId())) {
            return;
        }
        this.getEntities().add(entity.getId());
        this.hasNewEntities = true;
    }

    public boolean hasNewEntities() {
        return hasNewEntities;
    }

    public void resetNewEntities() {
        hasNewEntities = false;
    }

akatatsu27's avatar
akatatsu27 committed
49
50
51
52
53
    public void removeEntity(int entityId) {
        this.getEntities().remove(entityId);
        this.entityLeave = true;
    }

Akka's avatar
Akka committed
54
55
    public void removeEntity(GameEntity entity) {
        this.getEntities().remove(entity.getId());
akatatsu27's avatar
akatatsu27 committed
56
        this.entityLeave = true;
Akka's avatar
Akka committed
57
    }
akatatsu27's avatar
akatatsu27 committed
58
59
    public boolean entityLeave() {return this.entityLeave;}
    public void resetEntityLeave() {this.entityLeave = false;}
Akka's avatar
Akka committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    @Override
    public Int2FloatOpenHashMap getFightProperties() {
        return null;
    }

    @Override
    public Position getPosition() {
        return position;
    }

    @Override
    public Position getRotation() {
        return null;
    }

    @Override
    public SceneEntityInfoOuterClass.SceneEntityInfo toProto() {
        /**
         * The Region Entity would not be sent to client.
         */
        return null;
    }
Akka's avatar
Akka committed
82
83
84
85

    public int getFirstEntityId() {
        return entities.stream().findFirst().orElse(0);
    }
Akka's avatar
Akka committed
86
}