Fix showcase not updating when new characters/discs are added

This commit is contained in:
Melledy
2025-11-21 02:05:36 -08:00
parent e25d58d7f5
commit fdd4264b40
4 changed files with 67 additions and 13 deletions

View File

@@ -15,12 +15,16 @@ import emu.nebula.game.player.PlayerChangeInfo;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
@Getter @Getter
public class CharacterStorage extends PlayerManager { public class CharacterStorage extends PlayerManager {
private final Int2ObjectMap<GameCharacter> characters; private final Int2ObjectMap<GameCharacter> characters;
private final Int2ObjectMap<GameDisc> discs; private final Int2ObjectMap<GameDisc> discs;
@Setter private boolean updateCharHandbook;
@Setter private boolean updateDiscHandbook;
public CharacterStorage(Player player) { public CharacterStorage(Player player) {
super(player); super(player);
@@ -63,6 +67,9 @@ public class CharacterStorage extends PlayerManager {
// Save to database // Save to database
character.save(); character.save();
// Set flag for player to update character skins in their handbook
this.setUpdateCharHandbook(true);
// Add to characters // Add to characters
this.characters.put(character.getCharId(), character); this.characters.put(character.getCharId(), character);
return character; return character;
@@ -138,6 +145,9 @@ public class CharacterStorage extends PlayerManager {
// Save to database // Save to database
disc.save(); disc.save();
// Set flag for player to update discs in their handbook
this.setUpdateDiscHandbook(true);
// Add to discs // Add to discs
this.discs.put(disc.getDiscId(), disc); this.discs.put(disc.getDiscId(), disc);
return disc; return disc;

View File

@@ -245,7 +245,7 @@ public class GameCharacter implements GameDatabaseObject {
// Set advance skin // Set advance skin
this.skin = this.getData().getAdvanceSkinId(); this.skin = this.getData().getAdvanceSkinId();
// Send packets // Add next packages
this.getPlayer().addNextPackage( this.getPlayer().addNextPackage(
NetMsgId.character_skin_gain_notify, NetMsgId.character_skin_gain_notify,
Skin.newInstance().setNew(UI32.newInstance().setValue(this.getSkin())) Skin.newInstance().setNew(UI32.newInstance().setValue(this.getSkin()))
@@ -254,6 +254,9 @@ public class GameCharacter implements GameDatabaseObject {
NetMsgId.character_skin_change_notify, NetMsgId.character_skin_change_notify,
SkinChange.newInstance().setCharId(this.getCharId()).setSkinId(this.getSkin()) SkinChange.newInstance().setCharId(this.getCharId()).setSkinId(this.getSkin())
); );
// Set flag for player to update character skins in their handbook
this.getPlayer().getCharacters().setUpdateCharHandbook(true);
} }
// Save to database // Save to database

View File

@@ -152,12 +152,15 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
// Save to database // Save to database
Nebula.getGameDatabase().addToSet(this, this.getUid(), "extraSkins", id); Nebula.getGameDatabase().addToSet(this, this.getUid(), "extraSkins", id);
// Send packet // Send packets
this.getPlayer().addNextPackage( this.getPlayer().addNextPackage(
NetMsgId.character_skin_gain_notify, NetMsgId.character_skin_gain_notify,
Skin.newInstance().setNew(UI32.newInstance().setValue(id)) Skin.newInstance().setNew(UI32.newInstance().setValue(id))
); );
// Set flag for player to update character skins in their handbook
this.getPlayer().getCharacters().setUpdateCharHandbook(true);
// Success // Success
return true; return true;
} }

View File

@@ -144,29 +144,42 @@ public class GameSession {
@SneakyThrows @SneakyThrows
public byte[] encodeMsg(int msgId, ProtoMessage<?> proto) { public byte[] encodeMsg(int msgId, ProtoMessage<?> proto) {
// Add any extra data // Check if we have any packages to send to the client
this.addNextPackages(proto); if (this.getPlayer() != null) {
// Check if player should add any packages
this.checkPlayerStates();
// Chain next packages for player
if (this.getPlayer().hasNextPackages()) {
this.addNextPackages(proto);
}
}
// Encode to message like normal // Encode to message like normal
return PacketHelper.encodeMsg(msgId, proto); return PacketHelper.encodeMsg(msgId, proto);
} }
public byte[] encodeMsg(int msgId) { public byte[] encodeMsg(int msgId) {
// Create a proto so we can add next packages // Check if we have any packages to send to the client
if (this.getPlayer() != null && this.getPlayer().hasNextPackages()) { if (this.getPlayer() != null) {
return this.encodeMsg(msgId, Nil.newInstance()); // Check if player should add any packages
this.checkPlayerStates();
// Chain next packages for player
if (this.getPlayer().hasNextPackages()) {
// Create a proto so we can add next packages
var proto = Nil.newInstance();
// Encode proto with next packages
return this.encodeMsg(msgId, this.addNextPackages(proto));
}
} }
// Encode simple message // Encode simple message
return PacketHelper.encodeMsg(msgId); return PacketHelper.encodeMsg(msgId);
} }
private void addNextPackages(ProtoMessage<?> proto) { private void checkPlayerStates() {
// Sanity check and make sure proto has a "nextPackage" field
if (this.getPlayer() == null || !PacketHelper.hasNextPackageMethod(proto)) {
return;
}
// Update mail state flag // Update mail state flag
if (this.getPlayer().getMailbox().isNewState()) { if (this.getPlayer().getMailbox().isNewState()) {
// Clear // Clear
@@ -179,6 +192,29 @@ public class GameSession {
); );
} }
// Check handbook states
if (this.getPlayer().getCharacters().isUpdateCharHandbook()) {
getPlayer().getCharacters().setUpdateCharHandbook(false);
getPlayer().addNextPackage(
NetMsgId.handbook_change_notify,
this.getPlayer().getCharacters().getCharacterHandbook()
);
}
if (this.getPlayer().getCharacters().isUpdateDiscHandbook()) {
getPlayer().getCharacters().setUpdateDiscHandbook(false);
getPlayer().addNextPackage(
NetMsgId.handbook_change_notify,
this.getPlayer().getCharacters().getDiscHandbook()
);
}
}
private ProtoMessage<?> addNextPackages(ProtoMessage<?> proto) {
// Sanity check and make sure proto has a "nextPackage" field
if (!PacketHelper.hasNextPackageMethod(proto)) {
return proto;
}
// Set next package // Set next package
if (this.getPlayer().getNextPackages().size() > 0) { if (this.getPlayer().getNextPackages().size() > 0) {
// Set current package // Set current package
@@ -212,5 +248,7 @@ public class GameSession {
PacketHelper.setNextPackage(proto, curPacket.toByteArray()); PacketHelper.setNextPackage(proto, curPacket.toByteArray());
} }
} }
return proto;
} }
} }