mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-14 21:34:52 +01:00
Implement title/signature switching
This commit is contained in:
@@ -24,6 +24,7 @@ import emu.nebula.proto.Public.NewbieInfo;
|
||||
import emu.nebula.proto.Public.QuestType;
|
||||
import emu.nebula.proto.Public.Story;
|
||||
import emu.nebula.proto.Public.WorldClass;
|
||||
import emu.nebula.proto.Public.Title;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
@@ -41,6 +42,7 @@ public class Player implements GameDatabaseObject {
|
||||
|
||||
// Details
|
||||
private String name;
|
||||
private String signature;
|
||||
private boolean gender;
|
||||
private int headIcon;
|
||||
private int skinId;
|
||||
@@ -52,6 +54,7 @@ public class Player implements GameDatabaseObject {
|
||||
private int energy;
|
||||
|
||||
private IntSet boards;
|
||||
private IntSet headIcons;
|
||||
private IntSet titles;
|
||||
|
||||
private long createTime;
|
||||
@@ -86,6 +89,7 @@ public class Player implements GameDatabaseObject {
|
||||
// Set basic info
|
||||
this.accountUid = account.getUid();
|
||||
this.name = name;
|
||||
this.signature = "";
|
||||
this.gender = gender;
|
||||
this.headIcon = 101;
|
||||
this.skinId = 10301;
|
||||
@@ -93,6 +97,7 @@ public class Player implements GameDatabaseObject {
|
||||
this.titleSuffix = 2;
|
||||
this.level = 1;
|
||||
this.boards = new IntOpenHashSet();
|
||||
this.headIcons = new IntOpenHashSet();
|
||||
this.titles = new IntOpenHashSet();
|
||||
this.createTime = Nebula.getCurrentTime();
|
||||
|
||||
@@ -173,6 +178,48 @@ public class Player implements GameDatabaseObject {
|
||||
// Update in database
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "gender", this.getGender());
|
||||
}
|
||||
|
||||
public boolean editTitle(int prefix, int suffix) {
|
||||
// Check to make sure we own these titles
|
||||
if (!getTitles().contains(prefix) || !getTitles().contains(suffix)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip if we are not changing titles
|
||||
if (this.titlePrefix == prefix && this.titleSuffix == suffix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Set
|
||||
this.titlePrefix = prefix;
|
||||
this.titleSuffix = suffix;
|
||||
|
||||
// Update in database
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "titlePrefix", this.getTitlePrefix(), "titleSuffix", this.getTitleSuffix());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean editSignature(String signature) {
|
||||
// Sanity check
|
||||
if (signature == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Limit signature to 30 max chars
|
||||
if (signature.length() > 30) {
|
||||
signature = signature.substring(0, 29);
|
||||
}
|
||||
|
||||
// Set signature
|
||||
this.signature = signature;
|
||||
|
||||
// Update in database
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "signature", this.getSignature());
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setNewbieInfo(int groupId, int stepId) {
|
||||
// TODO
|
||||
@@ -276,6 +323,7 @@ public class Player implements GameDatabaseObject {
|
||||
|
||||
var acc = proto.getMutableAcc()
|
||||
.setNickName(this.getName())
|
||||
.setSignature(this.getSignature())
|
||||
.setGender(this.getGender())
|
||||
.setId(this.getUid())
|
||||
.setHeadIcon(this.getHeadIcon())
|
||||
@@ -357,9 +405,21 @@ public class Player implements GameDatabaseObject {
|
||||
|
||||
story.addStories(storyProto);
|
||||
}
|
||||
|
||||
// Add titles
|
||||
for (int titleId : this.getTitles()) {
|
||||
var titleProto = Title.newInstance()
|
||||
.setTitleId(titleId);
|
||||
|
||||
proto.addTitles(titleProto);
|
||||
}
|
||||
|
||||
// Add board ids
|
||||
for (int boardId : this.getBoards()) {
|
||||
proto.addBoard(boardId);
|
||||
}
|
||||
|
||||
//
|
||||
proto.addBoard(410301);
|
||||
// Server timestamp
|
||||
proto.setServerTs(Nebula.getCurrentTime());
|
||||
|
||||
// Extra
|
||||
|
||||
@@ -16,13 +16,11 @@ public class HandlerActivityDetailReq extends NetHandler {
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
var rsp = ActivityResp.newInstance();
|
||||
|
||||
/*
|
||||
var activity = ActivityMsg.newInstance()
|
||||
.setId(700101)
|
||||
.setTrial(ActivityTrial.newInstance());
|
||||
|
||||
rsp.addList(activity);
|
||||
*/
|
||||
|
||||
return this.encodeMsg(NetMsgId.activity_detail_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PlayerSignatureEdit.PlayerSignatureEditReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.player_signature_edit_req)
|
||||
public class HandlerPlayerSignatureEdit extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PlayerSignatureEditReq.parseFrom(message);
|
||||
|
||||
session.getPlayer().editSignature(req.getSignature());
|
||||
|
||||
return this.encodeMsg(NetMsgId.player_signature_edit_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PlayerTitleEdit.PlayerTitleEditReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.player_title_edit_req)
|
||||
public class HandlerPlayerTitleEditReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PlayerTitleEditReq.parseFrom(message);
|
||||
|
||||
boolean success = session.getPlayer().editTitle(req.getTitlePrefix(), req.getTitleSuffix());
|
||||
|
||||
return this.encodeMsg(success ? NetMsgId.player_title_edit_succeed_ack : NetMsgId.player_title_edit_failed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user