mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Fix showcase not updating when new characters/discs are added
This commit is contained in:
@@ -15,12 +15,16 @@ import emu.nebula.game.player.PlayerChangeInfo;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class CharacterStorage extends PlayerManager {
|
||||
private final Int2ObjectMap<GameCharacter> characters;
|
||||
private final Int2ObjectMap<GameDisc> discs;
|
||||
|
||||
@Setter private boolean updateCharHandbook;
|
||||
@Setter private boolean updateDiscHandbook;
|
||||
|
||||
public CharacterStorage(Player player) {
|
||||
super(player);
|
||||
|
||||
@@ -63,6 +67,9 @@ public class CharacterStorage extends PlayerManager {
|
||||
// Save to database
|
||||
character.save();
|
||||
|
||||
// Set flag for player to update character skins in their handbook
|
||||
this.setUpdateCharHandbook(true);
|
||||
|
||||
// Add to characters
|
||||
this.characters.put(character.getCharId(), character);
|
||||
return character;
|
||||
@@ -138,6 +145,9 @@ public class CharacterStorage extends PlayerManager {
|
||||
// Save to database
|
||||
disc.save();
|
||||
|
||||
// Set flag for player to update discs in their handbook
|
||||
this.setUpdateDiscHandbook(true);
|
||||
|
||||
// Add to discs
|
||||
this.discs.put(disc.getDiscId(), disc);
|
||||
return disc;
|
||||
|
||||
@@ -245,7 +245,7 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
// Set advance skin
|
||||
this.skin = this.getData().getAdvanceSkinId();
|
||||
|
||||
// Send packets
|
||||
// Add next packages
|
||||
this.getPlayer().addNextPackage(
|
||||
NetMsgId.character_skin_gain_notify,
|
||||
Skin.newInstance().setNew(UI32.newInstance().setValue(this.getSkin()))
|
||||
@@ -254,6 +254,9 @@ public class GameCharacter implements GameDatabaseObject {
|
||||
NetMsgId.character_skin_change_notify,
|
||||
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
|
||||
|
||||
@@ -152,12 +152,15 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "extraSkins", id);
|
||||
|
||||
// Send packet
|
||||
// Send packets
|
||||
this.getPlayer().addNextPackage(
|
||||
NetMsgId.character_skin_gain_notify,
|
||||
Skin.newInstance().setNew(UI32.newInstance().setValue(id))
|
||||
);
|
||||
|
||||
// Set flag for player to update character skins in their handbook
|
||||
this.getPlayer().getCharacters().setUpdateCharHandbook(true);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -144,29 +144,42 @@ public class GameSession {
|
||||
|
||||
@SneakyThrows
|
||||
public byte[] encodeMsg(int msgId, ProtoMessage<?> proto) {
|
||||
// Add any extra data
|
||||
this.addNextPackages(proto);
|
||||
// Check if we have any packages to send to the client
|
||||
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
|
||||
return PacketHelper.encodeMsg(msgId, proto);
|
||||
}
|
||||
|
||||
public byte[] encodeMsg(int msgId) {
|
||||
// Create a proto so we can add next packages
|
||||
if (this.getPlayer() != null && this.getPlayer().hasNextPackages()) {
|
||||
return this.encodeMsg(msgId, Nil.newInstance());
|
||||
// Check if we have any packages to send to the client
|
||||
if (this.getPlayer() != null) {
|
||||
// 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
|
||||
return PacketHelper.encodeMsg(msgId);
|
||||
}
|
||||
|
||||
private void addNextPackages(ProtoMessage<?> proto) {
|
||||
// Sanity check and make sure proto has a "nextPackage" field
|
||||
if (this.getPlayer() == null || !PacketHelper.hasNextPackageMethod(proto)) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void checkPlayerStates() {
|
||||
// Update mail state flag
|
||||
if (this.getPlayer().getMailbox().isNewState()) {
|
||||
// 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
|
||||
if (this.getPlayer().getNextPackages().size() > 0) {
|
||||
// Set current package
|
||||
@@ -212,5 +248,7 @@ public class GameSession {
|
||||
PacketHelper.setNextPackage(proto, curPacket.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user