From 906f15c5a3fc6ccf2a3891743489d1c6f71b0850 Mon Sep 17 00:00:00 2001 From: Nazrin Date: Fri, 21 Jun 2024 02:35:00 -0700 Subject: [PATCH] Books update Codex (#127) * Books update Codex * Add codex saving --- .../grasscutter/game/player/PlayerCodex.java | 6 ++++++ .../props/ItemUseAction/ItemUseAction.java | 2 +- .../ItemUseAction/ItemUseUnlockCodex.java | 4 +++- .../packet/send/PacketCodexDataFullNotify.java | 18 +++++++++++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java index bb17a3e4..0a6e8265 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerCodex.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerCodex.java @@ -119,4 +119,10 @@ public class PlayerCodex { this.player.save(); this.player.sendPacket(new PacketCodexDataUpdateNotify(7, viewpoint.getId())); } + + public void checkBook(int bookId) { + this.getUnlockedBook().add(bookId); + this.player.save(); + this.player.sendPacket(new PacketCodexDataUpdateNotify(5, bookId)); + } } diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java index 6af7ac8e..1ee53b82 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseAction.java @@ -38,7 +38,7 @@ public class ItemUseAction { case ITEM_USE_MAKE_GADGET -> new ItemUseMakeGadget(useParam); // Unlock recipes - TODO: allow scheduling packets for after recipe is removed case ITEM_USE_UNLOCK_COMBINE -> new ItemUseUnlockCombine(useParam); - case ITEM_USE_UNLOCK_CODEX -> new ItemUseUnlockCodex(useParam); // TODO: No backend for this yet + case ITEM_USE_UNLOCK_CODEX -> new ItemUseUnlockCodex(useParam); case ITEM_USE_UNLOCK_COOK_RECIPE -> new ItemUseUnlockCookRecipe(useParam); case ITEM_USE_UNLOCK_FORGE -> new ItemUseUnlockForge(useParam); case ITEM_USE_UNLOCK_FURNITURE_FORMULA -> new ItemUseUnlockFurnitureFormula(useParam); diff --git a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseUnlockCodex.java b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseUnlockCodex.java index 0d62e770..bd80867e 100644 --- a/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseUnlockCodex.java +++ b/src/main/java/emu/grasscutter/game/props/ItemUseAction/ItemUseUnlockCodex.java @@ -1,6 +1,7 @@ package emu.grasscutter.game.props.ItemUseAction; import emu.grasscutter.game.props.ItemUseOp; +import emu.grasscutter.server.packet.send.PacketCodexDataUpdateNotify; public class ItemUseUnlockCodex extends ItemUseInt { @Override @@ -14,6 +15,7 @@ public class ItemUseUnlockCodex extends ItemUseInt { @Override public boolean useItem(UseItemParams params) { - return false; + params.player.getCodex().checkBook(this.i); + return true; } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java index 23d70d92..dd30c808 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java @@ -45,6 +45,7 @@ public class PacketCodexDataFullNotify extends BasePacket { CodexTypeData.Builder reliquaryData = CodexTypeData.newBuilder() .setTypeValue(8); + //Quests player.getQuestManager().forEachMainQuest(mainQuest -> { if(mainQuest.isFinished()){ var codexQuest = GameData.getCodexQuestDataIdMap().get(mainQuest.getParentQuestId()); @@ -54,6 +55,7 @@ public class PacketCodexDataFullNotify extends BasePacket { } }); + //Weapons player.getCodex().getUnlockedWeapon().forEach(weapon -> { var codexWeapon = GameData.getCodexWeaponDataIdMap().get(weapon); if(codexWeapon != null){ @@ -61,6 +63,7 @@ public class PacketCodexDataFullNotify extends BasePacket { } }); + //Animals player.getCodex().getUnlockedAnimal().forEach((animal, amount) -> { var codexAnimal = GameData.getCodexAnimalDataMap().get(animal); if(codexAnimal != null){ @@ -68,19 +71,28 @@ public class PacketCodexDataFullNotify extends BasePacket { } }); + //Materials player.getCodex().getUnlockedMaterial().forEach(material -> { var codexMaterial = GameData.getCodexMaterialDataIdMap().get(material); - if(codexMaterial != null){ + if (codexMaterial != null) { materialTypeData.addCodexIdList(codexMaterial.getId()).addAllHaveViewedList(Collections.singleton(true)); } }); + //Books + player.getCodex().getUnlockedBook().forEach(view -> bookTypeData.addCodexIdList(view).addAllHaveViewedList(Collections.singleton(true))); + + //Tips + //TODO: Tips + + //Views + player.getCodex().getUnlockedView().forEach(view -> viewTypeData.addCodexIdList(view).addAllHaveViewedList(Collections.singleton(true))); + + //Reliquary player.getCodex().getUnlockedReliquarySuitCodex().forEach(reliquarySuit -> { reliquaryData.addCodexIdList(reliquarySuit).addAllHaveViewedList(Collections.singleton(true)); }); - player.getCodex().getUnlockedView().forEach(view -> viewTypeData.addCodexIdList(view).addAllHaveViewedList(Collections.singleton(true))); - CodexDataFullNotify.Builder proto = CodexDataFullNotify.newBuilder() .addTypeDataList(questTypeData.build()) .addTypeDataList(weaponTypeData)