From e140284d37b9c40f58d7296f48e868de8e90175a Mon Sep 17 00:00:00 2001 From: ImmuState Date: Thu, 2 Jun 2022 15:06:08 -0700 Subject: [PATCH] Persist unlocked blueprints to the database. --- .../emu/grasscutter/game/managers/InventoryManager.java | 4 ++-- src/main/java/emu/grasscutter/game/player/Player.java | 6 ++++++ .../server/packet/send/PacketForgeDataNotify.java | 9 ++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 054d350d5..3d50873bf 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -824,7 +824,6 @@ public class InventoryManager { int used = 0; // Use - Grasscutter.getLogger().info("Item: {}", useItem.getItemData().getId()); switch (useItem.getItemData().getMaterialType()) { case MATERIAL_FOOD: if (useItem.getItemData().getUseTarget().equals("ITEM_USE_TARGET_SPECIFY_DEAD_AVATAR")) { @@ -856,8 +855,9 @@ public class InventoryManager { // Determine the forging item we should unlock. int forgeId = Integer.parseInt(useItem.getItemData().getItemUse().get(0).getUseParam().get(0)); - // Tell the client that this blueprint is now unlocked. + // Tell the client that this blueprint is now unlocked and add the unlocked item to the player. player.sendPacket(new PacketForgeFormulaDataNotify(forgeId)); + player.getUnlockedForgingBlueprints().add(forgeId); // Use up the blueprint item. used = 1; diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index b5ab55e33..a35821852 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -89,6 +89,7 @@ public class Player { private Set nameCardList; private Set flyCloakList; private Set costumeList; + private Set unlockedForgingBlueprints; private Integer widgetId; @@ -183,6 +184,7 @@ public class Player { this.nameCardList = new HashSet<>(); this.flyCloakList = new HashSet<>(); this.costumeList = new HashSet<>(); + this.unlockedForgingBlueprints = new HashSet<>(); this.setSceneId(3); this.setRegionId(1); @@ -515,6 +517,10 @@ public class Player { return this.nameCardList; } + public Set getUnlockedForgingBlueprints() { + return unlockedForgingBlueprints; + } + public MpSettingType getMpSetting() { return MpSettingType.MP_SETTING_TYPE_ENTER_AFTER_APPLY; // TEMP } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java index 3f22e62a9..48ea79ba4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java @@ -1,13 +1,9 @@ package emu.grasscutter.server.packet.send; -import java.util.List; - -import dev.morphia.AdvancedDatastore; import emu.grasscutter.game.player.Player; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify; -import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; public class PacketForgeDataNotify extends BasePacket { @@ -22,10 +18,13 @@ public class PacketForgeDataNotify extends BasePacket { : 1; ForgeDataNotify proto = ForgeDataNotify.newBuilder() - .addAllForgeIdList(List.of(14017, 14009, 14008)) + .addAllForgeIdList(player.getUnlockedForgingBlueprints()) .setMaxQueueNum(numQueues) .build(); + // ToDo: Add the information for the actual forging queues + // and ongoing forges. + this.setData(proto); } }