EntityVehicle.java 4.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
package emu.grasscutter.game.entity;

import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.world.Scene;

import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
import emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo;
import emu.grasscutter.net.proto.FightPropPairOuterClass.*;
Melledy's avatar
Melledy committed
13
import emu.grasscutter.net.proto.GadgetInteractReqOuterClass.GadgetInteractReq;
14
15
16
17
18
19
20
21
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.net.proto.VehicleInfoOuterClass.*;
22
import emu.grasscutter.net.proto.VehicleMemberOuterClass.*;
23
24
25
26
27
28
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.ProtoHelper;

import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;

29
30
31
import java.util.List;
import java.util.ArrayList;

Melledy's avatar
Melledy committed
32
public class EntityVehicle extends EntityBaseGadget {
33

34
35
36
37
38
39
40
41
42
	private final Player owner;
	private final Int2FloatOpenHashMap fightProp;

	private final Position pos;
	private final Position rot;

	private final int pointId;
	private final int gadgetId;

43
44
45
	private float curStamina;
	private List<VehicleMember> vehicleMembers;

46
47
48
49
50
51
52
53
54
55
	public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) {
		super(scene);
		this.owner = player;
		this.id = getScene().getWorld().getNextEntityId(EntityIdType.GADGET);
		this.fightProp = new Int2FloatOpenHashMap();
		this.pos = new Position(pos);
		this.rot = new Position(rot);
		this.gadgetId = gadgetId;
		this.pointId = pointId;
		this.curStamina = 240;
56
		this.vehicleMembers = new ArrayList<VehicleMember>();
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	}

	@Override
	public int getGadgetId() { return gadgetId; }

	public Player getOwner() {
		return owner;
	}

	public float getCurStamina() { return curStamina; }

	public void setCurStamina(float stamina) { this.curStamina = stamina; }

	public int getPointId() { return pointId; }

72
73
	public List<VehicleMember> getVehicleMembers() { return vehicleMembers; }

74
75
76
77
78
79
80
81
82
83
84
85
	@Override
	public Int2FloatOpenHashMap getFightProperties() {
		return fightProp;
	}

	@Override
	public Position getPosition() { return this.pos; }

	@Override
	public Position getRotation() {
		return this.rot;
	}
Melledy's avatar
Melledy committed
86
87
88
89
90
	
	@Override
    public void onInteract(Player player, GadgetInteractReq interactReq) {
	    player.getInsectCaptureManager().arrestSmallCreature(this);
	}
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

	@Override
	public SceneEntityInfo toProto() {

		VehicleInfo vehicle = VehicleInfo.newBuilder()
				.setOwnerUid(this.owner.getUid())
				.setCurStamina(getCurStamina())
				.build();

		EntityAuthorityInfo authority = EntityAuthorityInfo.newBuilder()
				.setAbilityInfo(AbilitySyncStateInfo.newBuilder())
				.setRendererChangedInfo(EntityRendererChangedInfo.newBuilder())
				.setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(getPosition().toProto()))
				.setBornPos(getPosition().toProto())
				.build();

		SceneGadgetInfo.Builder gadgetInfo = SceneGadgetInfo.newBuilder()
				.setGadgetId(this.getGadgetId())
				.setAuthorityPeerId(this.getOwner().getPeerId())
				.setIsEnableInteract(true)
				.setVehicleInfo(vehicle);

		SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder()
				.setEntityId(getId())
115
				.setEntityType(ProtEntityType.PROT_ENTITY_TYPE_GADGET)
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
				.setMotionInfo(MotionInfo.newBuilder().setPos(getPosition().toProto()).setRot(getRotation().toProto()).setSpeed(Vector.newBuilder()))
				.addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder())
				.setGadget(gadgetInfo)
				.setEntityAuthorityInfo(authority)
				.setLifeState(1);

		PropPair pair = PropPair.newBuilder()
				.setType(PlayerProperty.PROP_LEVEL.getId())
				.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 47))
				.build();

		for (Int2FloatMap.Entry entry : getFightProperties().int2FloatEntrySet()) {
			if (entry.getIntKey() == 0) {
				continue;
			}
			FightPropPair fightProp = FightPropPair.newBuilder().setPropType(entry.getIntKey()).setPropValue(entry.getFloatValue()).build();
			entityInfo.addFightPropList(fightProp);
		}

		entityInfo.addPropList(pair);

		return entityInfo.build();
	}
}