EntityVehicle.java 4.91 KB
Newer Older
1
2
package emu.grasscutter.game.entity;

3
4
5
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.ConfigGadget;
import emu.grasscutter.data.excels.GadgetData;
6
7
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityIdType;
AnimeGitB's avatar
AnimeGitB committed
8
import emu.grasscutter.game.props.FightProperty;
9
10
11
12
13
14
15
16
17
18
19
20
21
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.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;
22
23
import emu.grasscutter.net.proto.VehicleInfoOuterClass.VehicleInfo;
import emu.grasscutter.net.proto.VehicleMemberOuterClass.VehicleMember;
24
25
26
27
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
AnimeGitB's avatar
AnimeGitB committed
28
29
import lombok.Getter;
import lombok.Setter;
30

31
import javax.annotation.Nullable;
32
import java.util.ArrayList;
33
import java.util.List;
34

Melledy's avatar
Melledy committed
35
public class EntityVehicle extends EntityBaseGadget {
36

AnimeGitB's avatar
AnimeGitB committed
37
    @Getter private final Player owner;
AnimeGitB's avatar
AnimeGitB committed
38
39
    @Getter(onMethod = @__(@Override))
    private final Int2FloatMap fightProperties;
github-actions's avatar
github-actions committed
40

AnimeGitB's avatar
AnimeGitB committed
41
42
    @Getter private final int pointId;
    @Getter private final int gadgetId;
github-actions's avatar
github-actions committed
43

AnimeGitB's avatar
AnimeGitB committed
44
45
    @Getter @Setter private float curStamina;
    @Getter private List<VehicleMember> vehicleMembers;
46
    @Nullable @Getter private ConfigGadget configGadget;
github-actions's avatar
github-actions committed
47
48

    public EntityVehicle(Scene scene, Player player, int gadgetId, int pointId, Position pos, Position rot) {
AnimeGitB's avatar
AnimeGitB committed
49
        super(scene, pos, rot);
github-actions's avatar
github-actions committed
50
51
        this.owner = player;
        this.id = getScene().getWorld().getNextEntityId(EntityIdType.GADGET);
AnimeGitB's avatar
AnimeGitB committed
52
        this.fightProperties = new Int2FloatOpenHashMap();
github-actions's avatar
github-actions committed
53
54
        this.gadgetId = gadgetId;
        this.pointId = pointId;
55
56
57
58
59
        this.curStamina = 240; // might be in configGadget.GCALKECLLLP.JBAKBEFIMBN.ANBMPHPOALP
        this.vehicleMembers = new ArrayList<>();
        GadgetData data = GameData.getGadgetDataMap().get(gadgetId);
        if (data != null && data.getJsonName() != null) {
            this.configGadget = GameData.getGadgetConfigData().get(data.getJsonName());
AnimeGitB's avatar
AnimeGitB committed
60
        }
61
62
63
64
65
66
67
68
69

        fillFightProps(configGadget);
    }

    @Override
    protected void fillFightProps(ConfigGadget configGadget) {
        super.fillFightProps(configGadget);
        this.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
        this.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
github-actions's avatar
github-actions committed
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
    }

    @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())
                .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_GADGET)
                .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();

AnimeGitB's avatar
AnimeGitB committed
107
        this.addAllFightPropsToEntityInfo(entityInfo);
github-actions's avatar
github-actions committed
108
109
110
111
        entityInfo.addPropList(pair);

        return entityInfo.build();
    }
112
}