EntityNPC.java 2.95 KB
Newer Older
Akka's avatar
Akka committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package emu.grasscutter.game.entity;

import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.*;
import emu.grasscutter.scripts.data.SceneNPC;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;

public class EntityNPC extends GameEntity{

    private final Position position;
    private final Position rotation;
    private final SceneNPC metaNpc;
    private final int suiteId;

    public EntityNPC(Scene scene, SceneNPC metaNPC, int blockId, int suiteId) {
        super(scene);
        this.id = getScene().getWorld().getNextEntityId(EntityIdType.NPC);
        setConfigId(metaNPC.config_id);
        setGroupId(metaNPC.group.id);
        setBlockId(blockId);
        this.suiteId = suiteId;
        this.position = metaNPC.pos.clone();
        this.rotation = metaNPC.rot.clone();
        this.metaNpc = metaNPC;

    }

    @Override
    public Int2FloatOpenHashMap getFightProperties() {
        return null;
    }

    @Override
    public Position getPosition() {
        return position;
    }

    @Override
    public Position getRotation() {
        return rotation;
    }

    public int getSuiteId() {
        return suiteId;
    }

    @Override
    public SceneEntityInfoOuterClass.SceneEntityInfo toProto() {

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

        SceneEntityInfoOuterClass.SceneEntityInfo.Builder entityInfo = SceneEntityInfoOuterClass.SceneEntityInfo.newBuilder()
                .setEntityId(getId())
Melledy's avatar
Melledy committed
63
                .setEntityType(ProtEntityTypeOuterClass.ProtEntityType.PROT_ENTITY_TYPE_NPC)
Akka's avatar
Akka committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
                .setMotionInfo(MotionInfoOuterClass.MotionInfo.newBuilder()
                        .setPos(getPosition().toProto())
                        .setRot(getRotation().toProto())
                        .setSpeed(VectorOuterClass.Vector.newBuilder()))
                .addAnimatorParaList(AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair.newBuilder())
                .setEntityClientData(EntityClientDataOuterClass.EntityClientData.newBuilder())
                .setEntityAuthorityInfo(authority)
                .setLifeState(1);


        entityInfo.setNpc(SceneNpcInfoOuterClass.SceneNpcInfo.newBuilder()
                        .setNpcId(metaNpc.npc_id)
                        .setBlockId(getBlockId())
                .build());

        return entityInfo.build();
    }
}