PlayerCodex.java 6.24 KB
Newer Older
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
63
64
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package emu.grasscutter.game.player;

import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.CodexAnimalData;
import emu.grasscutter.data.def.CodexReliquaryData;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify;

import java.util.*;

@Entity
public class PlayerCodex {
    @Transient private Player player;

    //itemId is not codexId!
    private Set<Integer> unlockedWeapon;
    private Map<Integer, Integer> unlockedAnimal;
    private Set<Integer> unlockedMaterial;
    private Set<Integer> unlockedBook;
    private Set<Integer> unlockedTip;
    private Set<Integer> unlockedView;
    private Set<Integer> unlockedReliquary;
    private Set<Integer> unlockedReliquarySuitCodex;

    public PlayerCodex(){
        this.unlockedWeapon = new HashSet<>();
        this.unlockedAnimal = new HashMap<>();
        this.unlockedMaterial = new HashSet<>();
        this.unlockedBook = new HashSet<>();
        this.unlockedTip = new HashSet<>();
        this.unlockedView = new HashSet<>();
        this.unlockedReliquary = new HashSet<>();
        this.unlockedReliquarySuitCodex = new HashSet<>();
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    public void checkAddedItem(GameItem item){
        ItemType type = item.getItemData().getItemType();
        if (type == ItemType.ITEM_WEAPON){
            if(!getUnlockedWeapon().contains(item.getItemId())){
                getUnlockedWeapon().add(item.getItemId());
                var codexItem = GameData.getCodexWeaponDataIdMap().get(item.getItemId());
                if(codexItem != null){
                    player.save();
                    this.player.sendPacket(new PacketCodexDataUpdateNotify(2, codexItem.getId()));
                }
            }
        }
        else if(type == ItemType.ITEM_MATERIAL){
            if( item.getItemData().getMaterialType() == MaterialType.MATERIAL_FOOD ||
                item.getItemData().getMaterialType() == MaterialType.MATERIAL_WIDGET||
                item.getItemData().getMaterialType() == MaterialType.MATERIAL_EXCHANGE||
                item.getItemData().getMaterialType() == MaterialType.MATERIAL_AVATAR_MATERIAL||
                item.getItemData().getMaterialType() == MaterialType.MATERIAL_NOTICE_ADD_HP){
                if (!getUnlockedMaterial().contains(item.getItemId())) {
                    var codexMaterial = GameData.getCodexMaterialDataIdMap().get(item.getItemId());
                    if (codexMaterial != null) {
                        getUnlockedMaterial().add(item.getItemId());
                        player.save();
                        this.player.sendPacket(new PacketCodexDataUpdateNotify(4, codexMaterial.getId()));
                    }
                }
            }
        }
        else if(type == ItemType.ITEM_RELIQUARY) {
            if(!getUnlockedReliquary().contains(item.getItemId())){
                getUnlockedReliquary().add(item.getItemId());
                checkUnlockedSuits(item);
            }
        }
    }

    public void checkAnimal(GameEntity target, CodexAnimalData.CodexAnimalUnlockCondition condition){
        if(target.getEntityType() == 2){
            var monsterId = target.getSpawnEntry().getMonsterId();
            var codexAnimal = GameData.getCodexAnimalDataMap().get(monsterId);

            if(!getUnlockedAnimal().containsKey(monsterId)) {
                if (codexAnimal != null) {
                    if(codexAnimal.getUnlockCondition() == condition){
                        getUnlockedAnimal().put(monsterId, 1);
                        player.save();
                        this.player.sendPacket(new PacketCodexDataUpdateNotify(3, monsterId));
                    }
                }
            }else{
                getUnlockedAnimal().put(monsterId, getUnlockedAnimal().get(monsterId) + 1);
                player.save();
            }
        }
    }

    public void checkUnlockedSuits(GameItem item){
        int reliquaryId = item.getItemId();
        Optional<CodexReliquaryData> excelReliquarySuitList = GameData.getcodexReliquaryArrayList().stream().filter(
                x -> x.getCupId() == reliquaryId
                        || x.getLeatherId() == reliquaryId
                        || x.getCapId() == reliquaryId
                        || x.getFlowerId() == reliquaryId
                        || x.getSandId() == reliquaryId
        ).findFirst();
        if(excelReliquarySuitList.isPresent()) {
            var excelReliquarySuit = excelReliquarySuitList.get();
            if(!getUnlockedReliquarySuitCodex().contains(excelReliquarySuit.getId())){
                if(
                        getUnlockedReliquary().contains(excelReliquarySuit.getCupId()) &&
                        getUnlockedReliquary().contains(excelReliquarySuit.getLeatherId()) &&
                        getUnlockedReliquary().contains(excelReliquarySuit.getCapId()) &&
                        getUnlockedReliquary().contains(excelReliquarySuit.getFlowerId()) &&
                        getUnlockedReliquary().contains(excelReliquarySuit.getSandId())
                ){
                    getUnlockedReliquarySuitCodex().add(excelReliquarySuit.getId());
                    player.save();
                    this.player.sendPacket(new PacketCodexDataUpdateNotify(8, excelReliquarySuit.getId()));
                }
            }
        }
    }

    public Set<Integer> getUnlockedWeapon() {
        return unlockedWeapon;
    }

    public Map<Integer, Integer> getUnlockedAnimal() {
        return unlockedAnimal;
    }

    public Set<Integer> getUnlockedMaterial() {
        return unlockedMaterial;
    }

    public Set<Integer> getUnlockedBook() {
        return unlockedBook;
    }

    public Set<Integer> getUnlockedTip() {
        return unlockedTip;
    }

    public Set<Integer> getUnlockedView() {
        return unlockedView;
    }

    public Set<Integer> getUnlockedReliquary() {
        return unlockedReliquary;
    }

    public Set<Integer> getUnlockedReliquarySuitCodex() {
        return unlockedReliquarySuitCodex;
    }

}