EntityClientGadget.java 4.97 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
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;
AnimeGitB's avatar
AnimeGitB committed
22
23
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import lombok.Getter;
Melledy's avatar
Melledy committed
24

25
public class EntityClientGadget extends EntityBaseGadget {
AnimeGitB's avatar
AnimeGitB committed
26
    @Getter private final Player owner;
github-actions's avatar
github-actions committed
27

AnimeGitB's avatar
AnimeGitB committed
28
29
    @Getter(onMethod = @__(@Override))
    private int gadgetId;
github-actions's avatar
github-actions committed
30

AnimeGitB's avatar
AnimeGitB committed
31
32
33
34
35
    @Getter private int campId;
    @Getter private int campType;
    @Getter private int ownerEntityId;
    @Getter private int targetEntityId;
    @Getter private boolean asyncLoad;
github-actions's avatar
github-actions committed
36

AnimeGitB's avatar
AnimeGitB committed
37
    @Getter private int originalOwnerEntityId;
github-actions's avatar
github-actions committed
38
39

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

        GameEntity owner = scene.getEntityById(this.ownerEntityId);
        if (owner instanceof EntityClientGadget ownerGadget) {
            this.originalOwnerEntityId = ownerGadget.getOriginalOwnerEntityId();
        }
        else {
            this.originalOwnerEntityId = this.ownerEntityId;
        }
    }

    @Override
    public void onDeath(int killerId) {
61
        super.onDeath(killerId); // Invoke super class's onDeath() method.
github-actions's avatar
github-actions committed
62
63
    }

AnimeGitB's avatar
AnimeGitB committed
64
    @Override public Int2FloatMap getFightProperties() {return null;}
github-actions's avatar
github-actions committed
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
107
108
109

    @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();

        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())
                .setEntityClientData(EntityClientData.newBuilder())
                .setEntityAuthorityInfo(authority)
                .setLifeState(1);

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

        ClientGadgetInfoOuterClass.ClientGadgetInfo clientGadget = ClientGadgetInfoOuterClass.ClientGadgetInfo.newBuilder()
                .setCampId(this.getCampId())
                .setCampType(this.getCampType())
                .setOwnerEntityId(this.getOwnerEntityId())
                .setTargetEntityId(this.getTargetEntityId())
                .setAsyncLoad(this.isAsyncLoad())
                .build();

        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);

        return entityInfo.build();
    }
Melledy's avatar
Melledy committed
110
}