HomeFurnitureItem.java 2.93 KB
Newer Older
1
2
3
4
5
6
7
package emu.grasscutter.game.home;

import dev.morphia.annotations.Entity;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.HomeworldDefaultSaveData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.net.proto.HomeFurnitureDataOuterClass;
8
import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass;
Akka's avatar
Akka committed
9
import emu.grasscutter.net.proto.VectorOuterClass;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import emu.grasscutter.utils.Position;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;

@Entity
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(builderMethodName = "of")
public class HomeFurnitureItem {
    int furnitureId;
    int guid;
    int parentFurnitureIndex;
    Position spawnPos;
    Position spawnRot;
Akka's avatar
Akka committed
26
    int version;
27
28
29
30
31
32
33
    public HomeFurnitureDataOuterClass.HomeFurnitureData toProto(){
        return HomeFurnitureDataOuterClass.HomeFurnitureData.newBuilder()
                .setFurnitureId(furnitureId)
                .setGuid(guid)
                .setParentFurnitureIndex(parentFurnitureIndex)
                .setSpawnPos(spawnPos.toProto())
                .setSpawnRot(spawnRot.toProto())
Akka's avatar
Akka committed
34
                .setVersion(version)
35
36
37
                .build();
    }

38
39
40
41
42
43
44
45
46
47
    public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto(int type){
        return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder()
                .setFurnitureId(furnitureId)
                .setGuid(guid)
                .setFurnitureType(type)
                .setPos(spawnPos.toProto())
                // TODO NPC and farm
                .build();
    }

48
49
50
51
52
53
54
    public static HomeFurnitureItem parseFrom(HomeFurnitureDataOuterClass.HomeFurnitureData homeFurnitureData) {
        return HomeFurnitureItem.of()
                .furnitureId(homeFurnitureData.getFurnitureId())
                .guid(homeFurnitureData.getGuid())
                .parentFurnitureIndex(homeFurnitureData.getParentFurnitureIndex())
                .spawnPos(new Position(homeFurnitureData.getSpawnPos()))
                .spawnRot(new Position(homeFurnitureData.getSpawnRot()))
Akka's avatar
Akka committed
55
                .version(homeFurnitureData.getVersion())
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
                .build();
    }

    public static HomeFurnitureItem parseFrom(HomeworldDefaultSaveData.HomeFurniture homeFurniture) {
        return HomeFurnitureItem.of()
                .furnitureId(homeFurniture.getId())
                .parentFurnitureIndex(1)
                .spawnPos(homeFurniture.getPos() == null ? new Position() : homeFurniture.getPos())
                .spawnRot(homeFurniture.getRot() == null ? new Position() : homeFurniture.getRot())
                .build();
    }

    public ItemData getAsItem() {
        return GameData.getItemDataMap().get(this.furnitureId);
    }

    public int getComfort() {
        var item = getAsItem();

        if (item == null){
            return 0;
        }
        return item.getComfort();
    }
}