GameEntity.java 3.38 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
package emu.grasscutter.game.entity;

import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState;
Melledy's avatar
Melledy committed
5
import emu.grasscutter.game.world.Scene;
Melledy's avatar
Melledy committed
6
import emu.grasscutter.game.world.SpawnDataEntry;
Melledy's avatar
Melledy committed
7
import emu.grasscutter.game.world.World;
Melledy's avatar
Melledy committed
8
9
10
11
12
13
14
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;

15
public abstract class GameEntity {
Melledy's avatar
Melledy committed
16
	protected int id;
17
	private final Scene scene;
Melledy's avatar
Melledy committed
18
	private SpawnDataEntry spawnEntry;
Melledy's avatar
Melledy committed
19
	
20
21
22
23
	private int blockId;
	private int configId;
	private int groupId;
	
Melledy's avatar
Melledy committed
24
25
26
27
	private MotionState moveState;
	private int lastMoveSceneTimeMs;
	private int lastMoveReliableSeq;
	
28
	public GameEntity(Scene scene) {
29
		this.scene = scene;
30
		this.moveState = MotionState.MOTION_NONE;
Melledy's avatar
Melledy committed
31
32
33
34
35
	}
	
	public int getId() {
		return this.id;
	}
36
	
Melledy's avatar
Melledy committed
37
38
39
40
	public int getEntityType() {
		return getId() >> 24;
	}
	
Melledy's avatar
Melledy committed
41
	public World getWorld() {
42
43
44
		return this.getScene().getWorld();
	}

45
	public Scene getScene() {
46
		return this.scene;
Melledy's avatar
Melledy committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
	}
	
	public boolean isAlive() {
		return true;
	}

	public LifeState getLifeState() {
		return isAlive() ? LifeState.LIFE_ALIVE : LifeState.LIFE_DEAD;
	}
	
	public abstract Int2FloatOpenHashMap getFightProperties();
	
	public abstract Position getPosition();
	
	public abstract Position getRotation();
	
	public MotionState getMotionState() {
		return moveState;
	}

	public void setMotionState(MotionState moveState) {
		this.moveState = moveState;
	}

	public int getLastMoveSceneTimeMs() {
		return lastMoveSceneTimeMs;
	}

	public void setLastMoveSceneTimeMs(int lastMoveSceneTimeMs) {
		this.lastMoveSceneTimeMs = lastMoveSceneTimeMs;
	}

	public int getLastMoveReliableSeq() {
		return lastMoveReliableSeq;
	}

	public void setLastMoveReliableSeq(int lastMoveReliableSeq) {
		this.lastMoveReliableSeq = lastMoveReliableSeq;
	}

	public abstract SceneEntityInfo toProto();
	
	public abstract void onDeath(int killerId);
	
	public void setFightProperty(FightProperty prop, float value) {
		this.getFightProperties().put(prop.getId(), value);
	}
	
	private void setFightProperty(int id, float value) {
		this.getFightProperties().put(id, value);
	}
	
	public void addFightProperty(FightProperty prop, float value) {
		this.getFightProperties().put(prop.getId(), getFightProperty(prop) + value);
	}
	
	public float getFightProperty(FightProperty prop) {
		return getFightProperties().getOrDefault(prop.getId(), 0f);
	}
	
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
	public int getBlockId() {
		return blockId;
	}

	public void setBlockId(int blockId) {
		this.blockId = blockId;
	}
	
	public int getConfigId() {
		return configId;
	}

	public void setConfigId(int configId) {
		this.configId = configId;
	}
	
	public int getGroupId() {
		return groupId;
	}

	public void setGroupId(int groupId) {
		this.groupId = groupId;
	}
	
Melledy's avatar
Melledy committed
131
132
133
134
135
136
137
138
139
140
	protected MotionInfo getMotionInfo() {
		MotionInfo proto = MotionInfo.newBuilder()
				.setPos(getPosition().toProto())
				.setRot(getRotation().toProto())
				.setSpeed(Vector.newBuilder())
				.setState(this.getMotionState())
				.build();
		
		return proto;
	}
Melledy's avatar
Melledy committed
141
142
143
144
145
146
147
148

	public SpawnDataEntry getSpawnEntry() {
		return spawnEntry;
	}

	public void setSpawnEntry(SpawnDataEntry spawnEntry) {
		this.spawnEntry = spawnEntry;
	}
Melledy's avatar
Melledy committed
149
}