EntityClientGadget.java 5.15 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.game.entity;

Melledy's avatar
Melledy committed
3
import emu.grasscutter.game.player.Player;
Melledy's avatar
Melledy committed
4
import emu.grasscutter.game.props.PlayerProperty;
Melledy's avatar
Melledy committed
5
import emu.grasscutter.game.world.Scene;
Melledy's avatar
Melledy committed
6
7
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
8
import emu.grasscutter.net.proto.ClientGadgetInfoOuterClass;
Melledy's avatar
Melledy committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
import emu.grasscutter.net.proto.EntityClientDataOuterClass.EntityClientData;
import emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo;
import emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify;
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import emu.grasscutter.net.proto.PropPairOuterClass.PropPair;
import emu.grasscutter.net.proto.ProtEntityTypeOuterClass.ProtEntityType;
import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;

24
public class EntityClientGadget extends EntityBaseGadget {
25
	private final Player owner;
26

Melledy's avatar
Melledy committed
27
28
	private final Position pos;
	private final Position rot;
29

Melledy's avatar
Melledy committed
30
31
32
33
34
35
	private int configId;
	private int campId;
	private int campType;
	private int ownerEntityId;
	private int targetEntityId;
	private boolean asyncLoad;
36
37

	private int originalOwnerEntityId;
38

39
	public EntityClientGadget(Scene scene, Player player, EvtCreateGadgetNotify notify) {
40
		super(scene);
Melledy's avatar
Melledy committed
41
42
43
44
45
46
47
48
49
50
		this.owner = player;
		this.id = notify.getEntityId();
		this.pos = new Position(notify.getInitPos());
		this.rot = new Position(notify.getInitEulerAngles());
		this.configId = notify.getConfigId();
		this.campId = notify.getCampId();
		this.campType = notify.getCampType();
		this.ownerEntityId = notify.getPropOwnerEntityId();
		this.targetEntityId = notify.getTargetEntityId();
		this.asyncLoad = notify.getIsAsyncLoad();
51
52
53
54
55
56
57
58

		GameEntity owner = scene.getEntityById(this.ownerEntityId);
		if (owner instanceof EntityClientGadget ownerGadget) {
			this.originalOwnerEntityId = ownerGadget.getOriginalOwnerEntityId();
		}
		else {
			this.originalOwnerEntityId = this.ownerEntityId;
		}
Melledy's avatar
Melledy committed
59
	}
60

Melledy's avatar
Melledy committed
61
62
63
64
	@Override
	public int getGadgetId() {
		return configId;
	}
65

66
	public Player getOwner() {
Melledy's avatar
Melledy committed
67
68
		return owner;
	}
69

Melledy's avatar
Melledy committed
70
71
72
	public int getCampId() {
		return campId;
	}
73

Melledy's avatar
Melledy committed
74
75
76
77
78
79
80
	public int getCampType() {
		return campType;
	}

	public int getOwnerEntityId() {
		return ownerEntityId;
	}
81

Melledy's avatar
Melledy committed
82
83
84
85
86
87
88
89
	public int getTargetEntityId() {
		return targetEntityId;
	}

	public boolean isAsyncLoad() {
		return this.asyncLoad;
	}

90
91
92
93
	public int getOriginalOwnerEntityId() {
		return this.originalOwnerEntityId;
	}

Melledy's avatar
Melledy committed
94
95
	@Override
	public void onDeath(int killerId) {
96
        super.onDeath(killerId); // Invoke super class's onDeath() method.
Melledy's avatar
Melledy committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
	}

	@Override
	public Int2FloatOpenHashMap getFightProperties() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Position getPosition() {
		// TODO Auto-generated method stub
		return this.pos;
	}

	@Override
	public Position getRotation() {
		// TODO Auto-generated method stub
		return this.rot;
	}

	@Override
	public SceneEntityInfo toProto() {
		EntityAuthorityInfo authority = EntityAuthorityInfo.newBuilder()
				.setAbilityInfo(AbilitySyncStateInfo.newBuilder())
				.setRendererChangedInfo(EntityRendererChangedInfo.newBuilder())
				.setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(Vector.newBuilder()))
				.setBornPos(Vector.newBuilder())
				.build();
125

Melledy's avatar
Melledy committed
126
127
		SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder()
				.setEntityId(getId())
128
				.setEntityType(ProtEntityType.PROT_ENTITY_TYPE_GADGET)
Melledy's avatar
Melledy committed
129
130
131
132
133
				.setMotionInfo(MotionInfo.newBuilder().setPos(getPosition().toProto()).setRot(getRotation().toProto()).setSpeed(Vector.newBuilder()))
				.addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder())
				.setEntityClientData(EntityClientData.newBuilder())
				.setEntityAuthorityInfo(authority)
				.setLifeState(1);
134

Melledy's avatar
Melledy committed
135
136
137
138
139
		PropPair pair = PropPair.newBuilder()
				.setType(PlayerProperty.PROP_LEVEL.getId())
				.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 1))
				.build();
		entityInfo.addPropList(pair);
140

141
		ClientGadgetInfoOuterClass.ClientGadgetInfo clientGadget = ClientGadgetInfoOuterClass.ClientGadgetInfo.newBuilder()
Melledy's avatar
Melledy committed
142
143
144
145
146
147
				.setCampId(this.getCampId())
				.setCampType(this.getCampType())
				.setOwnerEntityId(this.getOwnerEntityId())
				.setTargetEntityId(this.getTargetEntityId())
				.setAsyncLoad(this.isAsyncLoad())
				.build();
148

Melledy's avatar
Melledy committed
149
150
151
152
153
154
155
156
157
		SceneGadgetInfo.Builder gadgetInfo = SceneGadgetInfo.newBuilder()
				.setGadgetId(this.getGadgetId())
				.setOwnerEntityId(this.getOwnerEntityId())
				.setIsEnableInteract(true)
				.setClientGadget(clientGadget)
				.setPropOwnerEntityId(this.getOwnerEntityId())
				.setAuthorityPeerId(this.getOwner().getPeerId());

		entityInfo.setGadget(gadgetInfo);
158

Melledy's avatar
Melledy committed
159
160
161
		return entityInfo.build();
	}
}