Books update Codex (#127)

* Books update Codex
* Add codex saving
This commit is contained in:
Nazrin 2024-06-21 02:35:00 -07:00 committed by GitHub
parent cedda3167f
commit 906f15c5a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 5 deletions

View File

@ -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));
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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)