HomeFurnitureItem.java 2.78 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;
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
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;

    public HomeFurnitureDataOuterClass.HomeFurnitureData toProto(){
        return HomeFurnitureDataOuterClass.HomeFurnitureData.newBuilder()
                .setFurnitureId(furnitureId)
                .setGuid(guid)
                .setParentFurnitureIndex(parentFurnitureIndex)
                .setSpawnPos(spawnPos.toProto())
                .setSpawnRot(spawnRot.toProto())
                .build();
    }

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

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    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()))
                .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();
    }
}