mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Refactor support for codex(aka archive) animal, weapon, reliquary
This commit is contained in:
@@ -240,6 +240,7 @@ public class Inventory implements Iterable<GameItem> {
|
||||
}
|
||||
|
||||
private synchronized void putItem(GameItem item, InventoryTab tab) {
|
||||
getPlayer().getCodex().checkAddedItem(item);
|
||||
// Set owner and guid FIRST!
|
||||
item.setOwner(getPlayer());
|
||||
// Put in item store
|
||||
|
||||
@@ -2,7 +2,6 @@ package emu.grasscutter.game.player;
|
||||
|
||||
import dev.morphia.annotations.*;
|
||||
import emu.grasscutter.GameConstants;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.def.PlayerLevelData;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
@@ -30,8 +29,6 @@ import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.EntityType;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.props.SceneType;
|
||||
import emu.grasscutter.game.quest.GameMainQuest;
|
||||
import emu.grasscutter.game.quest.GameQuest;
|
||||
import emu.grasscutter.game.quest.QuestManager;
|
||||
import emu.grasscutter.game.shop.ShopLimit;
|
||||
import emu.grasscutter.game.managers.MapMarkManager.*;
|
||||
@@ -80,6 +77,7 @@ public class Player {
|
||||
private Position pos;
|
||||
private Position rotation;
|
||||
private PlayerBirthday birthday;
|
||||
private PlayerCodex codex;
|
||||
|
||||
private Map<Integer, Integer> properties;
|
||||
private Set<Integer> nameCardList;
|
||||
@@ -189,6 +187,7 @@ public class Player {
|
||||
this.birthday = new PlayerBirthday();
|
||||
this.rewardedLevels = new HashSet<>();
|
||||
this.moonCardGetTimes = new HashSet<>();
|
||||
this.codex = new PlayerCodex();
|
||||
|
||||
this.shopLimit = new ArrayList<>();
|
||||
this.expeditionInfo = new HashMap<>();
|
||||
@@ -209,6 +208,7 @@ public class Player {
|
||||
this.signature = "";
|
||||
this.teamManager = new TeamManager(this);
|
||||
this.birthday = new PlayerBirthday();
|
||||
this.codex = new PlayerCodex();
|
||||
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1);
|
||||
this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1);
|
||||
this.setProperty(PlayerProperty.PROP_SPRING_AUTO_USE_PERCENT, 50);
|
||||
@@ -758,7 +758,6 @@ public class Player {
|
||||
return expeditionInfo.get(avaterGuid);
|
||||
}
|
||||
|
||||
|
||||
public List<ShopLimit> getShopLimit() {
|
||||
return shopLimit;
|
||||
}
|
||||
@@ -984,6 +983,8 @@ public class Player {
|
||||
return this.birthday.getDay() > 0;
|
||||
}
|
||||
|
||||
public PlayerCodex getCodex(){ return this.codex; }
|
||||
|
||||
public Set<Integer> getRewardedLevels() {
|
||||
return rewardedLevels;
|
||||
}
|
||||
@@ -1159,6 +1160,7 @@ public class Player {
|
||||
|
||||
@PostLoad
|
||||
private void onLoad() {
|
||||
this.getCodex().setPlayer(this);
|
||||
this.getTeamManager().setPlayer(this);
|
||||
this.getTowerManager().setPlayer(this);
|
||||
}
|
||||
@@ -1229,7 +1231,6 @@ public class Player {
|
||||
session.send(new PacketFinishedParentQuestNotify(this));
|
||||
session.send(new PacketQuestListNotify(this));
|
||||
session.send(new PacketCodexDataFullNotify(this));
|
||||
session.send(new PacketServerCondMeetQuestListUpdateNotify(this));
|
||||
session.send(new PacketAllWidgetDataNotify(this));
|
||||
session.send(new PacketWidgetGadgetAllDataNotify());
|
||||
session.send(new PacketPlayerHomeCompInfoNotify(this));
|
||||
|
||||
160
src/main/java/emu/grasscutter/game/player/PlayerCodex.java
Normal file
160
src/main/java/emu/grasscutter/game/player/PlayerCodex.java
Normal file
@@ -0,0 +1,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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -121,7 +121,6 @@ public class QuestManager {
|
||||
mainQuest.save();
|
||||
|
||||
// Send packet
|
||||
getPlayer().sendPacket(new PacketServerCondMeetQuestListUpdateNotify(quest));
|
||||
getPlayer().sendPacket(new PacketQuestListUpdateNotify(quest));
|
||||
|
||||
return quest;
|
||||
|
||||
@@ -2,10 +2,7 @@ package emu.grasscutter.game.world;
|
||||
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.GameDepot;
|
||||
import emu.grasscutter.data.def.DungeonData;
|
||||
import emu.grasscutter.data.def.MonsterData;
|
||||
import emu.grasscutter.data.def.SceneData;
|
||||
import emu.grasscutter.data.def.WorldLevelData;
|
||||
import emu.grasscutter.data.def.*;
|
||||
import emu.grasscutter.game.dungeons.DungeonChallenge;
|
||||
import emu.grasscutter.game.dungeons.DungeonSettleListener;
|
||||
import emu.grasscutter.game.entity.*;
|
||||
@@ -389,6 +386,9 @@ public class Scene {
|
||||
}
|
||||
|
||||
public void killEntity(GameEntity target, int attackerId) {
|
||||
for (Player player : this.getPlayers()) {
|
||||
player.getCodex().checkAnimal(target, CodexAnimalData.CodexAnimalUnlockCondition.CODEX_COUNT_TYPE_KILL);
|
||||
}
|
||||
// Packet
|
||||
this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user