mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-15 13:54:51 +01:00
Implement character showcase
This commit is contained in:
@@ -30,6 +30,7 @@ import emu.nebula.net.NetMsgPacket;
|
|||||||
import emu.nebula.proto.PlayerData.DictionaryEntry;
|
import emu.nebula.proto.PlayerData.DictionaryEntry;
|
||||||
import emu.nebula.proto.PlayerData.DictionaryTab;
|
import emu.nebula.proto.PlayerData.DictionaryTab;
|
||||||
import emu.nebula.proto.PlayerData.PlayerInfo;
|
import emu.nebula.proto.PlayerData.PlayerInfo;
|
||||||
|
import emu.nebula.proto.Public.CharShow;
|
||||||
import emu.nebula.proto.Public.Energy;
|
import emu.nebula.proto.Public.Energy;
|
||||||
import emu.nebula.proto.Public.NewbieInfo;
|
import emu.nebula.proto.Public.NewbieInfo;
|
||||||
import emu.nebula.proto.Public.QuestType;
|
import emu.nebula.proto.Public.QuestType;
|
||||||
@@ -61,6 +62,7 @@ public class Player implements GameDatabaseObject {
|
|||||||
private int titleSuffix;
|
private int titleSuffix;
|
||||||
private int level;
|
private int level;
|
||||||
private int exp;
|
private int exp;
|
||||||
|
private int[] showChars;
|
||||||
private int[] boards;
|
private int[] boards;
|
||||||
|
|
||||||
private int energy;
|
private int energy;
|
||||||
@@ -127,6 +129,7 @@ public class Player implements GameDatabaseObject {
|
|||||||
this.level = 1;
|
this.level = 1;
|
||||||
this.energy = 240;
|
this.energy = 240;
|
||||||
this.energyLastUpdate = this.createTime;
|
this.energyLastUpdate = this.createTime;
|
||||||
|
this.showChars = new int[3];
|
||||||
this.boards = new int[] {410301};
|
this.boards = new int[] {410301};
|
||||||
|
|
||||||
// Setup inventory
|
// Setup inventory
|
||||||
@@ -265,6 +268,36 @@ public class Player implements GameDatabaseObject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean setShowChars(RepeatedInt charIds) {
|
||||||
|
// Sanity check
|
||||||
|
if (charIds.length() > this.getShowChars().length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that we have the correct characters
|
||||||
|
for (int id : charIds) {
|
||||||
|
if (id != 0 && !this.getCharacters().hasCharacter(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear
|
||||||
|
this.showChars[0] = 0;
|
||||||
|
this.showChars[1] = 0;
|
||||||
|
this.showChars[2] = 0;
|
||||||
|
|
||||||
|
// Set
|
||||||
|
for (int i = 0; i < charIds.length(); i++) {
|
||||||
|
this.showChars[i] = charIds.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update in database
|
||||||
|
Nebula.getGameDatabase().update(this, this.getUid(), "showChars", this.getShowChars());
|
||||||
|
|
||||||
|
// Success
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setBoard(RepeatedInt ids) {
|
public boolean setBoard(RepeatedInt ids) {
|
||||||
// Length check
|
// Length check
|
||||||
if (ids.length() <= 0 || ids.length() > GameConstants.MAX_SHOWCASE_IDS) {
|
if (ids.length() <= 0 || ids.length() > GameConstants.MAX_SHOWCASE_IDS) {
|
||||||
@@ -499,6 +532,12 @@ public class Player implements GameDatabaseObject {
|
|||||||
this.progress = this.loadManagerFromDatabase(PlayerProgress.class);
|
this.progress = this.loadManagerFromDatabase(PlayerProgress.class);
|
||||||
this.storyManager = this.loadManagerFromDatabase(StoryManager.class);
|
this.storyManager = this.loadManagerFromDatabase(StoryManager.class);
|
||||||
this.questManager = this.loadManagerFromDatabase(QuestManager.class);
|
this.questManager = this.loadManagerFromDatabase(QuestManager.class);
|
||||||
|
|
||||||
|
// Database fixes
|
||||||
|
if (this.showChars == null) {
|
||||||
|
this.showChars = new int[3];
|
||||||
|
this.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLogin() {
|
public void onLogin() {
|
||||||
@@ -538,6 +577,21 @@ public class Player implements GameDatabaseObject {
|
|||||||
.setTitleSuffix(this.getTitleSuffix())
|
.setTitleSuffix(this.getTitleSuffix())
|
||||||
.setCreateTime(this.getCreateTime());
|
.setCreateTime(this.getCreateTime());
|
||||||
|
|
||||||
|
// Set showcase character
|
||||||
|
for (int charId : this.getShowChars()) {
|
||||||
|
var info = CharShow.newInstance();
|
||||||
|
var character = this.getCharacters().getCharacterById(charId);
|
||||||
|
|
||||||
|
if (character != null) {
|
||||||
|
info.setCharId(character.getCharId())
|
||||||
|
.setLevel(character.getLevel())
|
||||||
|
.setSkin(character.getSkin());
|
||||||
|
}
|
||||||
|
|
||||||
|
acc.addChars(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set world class
|
||||||
proto.getMutableWorldClass()
|
proto.getMutableWorldClass()
|
||||||
.setCur(this.getLevel())
|
.setCur(this.getLevel())
|
||||||
.setLastExp(this.getExp());
|
.setLastExp(this.getExp());
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package emu.nebula.server.handlers;
|
||||||
|
|
||||||
|
import emu.nebula.net.NetHandler;
|
||||||
|
import emu.nebula.net.NetMsgId;
|
||||||
|
import emu.nebula.proto.PlayerCharsShow.PlayerCharsShowReq;
|
||||||
|
import emu.nebula.net.HandlerId;
|
||||||
|
import emu.nebula.net.GameSession;
|
||||||
|
|
||||||
|
@HandlerId(NetMsgId.player_chars_show_req)
|
||||||
|
public class HandlerPlayerCharsShowReq extends NetHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||||
|
// Parse req
|
||||||
|
var req = PlayerCharsShowReq.parseFrom(message);
|
||||||
|
|
||||||
|
// Set
|
||||||
|
boolean success = session.getPlayer().setShowChars(req.getCharIds());
|
||||||
|
|
||||||
|
// Encode and send
|
||||||
|
return session.encodeMsg(success ? NetMsgId.player_chars_show_succeed_ack : NetMsgId.player_chars_show_failed_ack);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user