Implement disc read reward

This commit is contained in:
Melledy
2025-11-02 19:18:12 -08:00
parent 42f8233132
commit d5c112bcf9
3 changed files with 53 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ public class DiscDef extends BaseDef {
private int StrengthenGroupId; private int StrengthenGroupId;
private int PromoteGroupId; private int PromoteGroupId;
private int TransformItemId; private int TransformItemId;
private int[] ReadReward;
@Override @Override
public int getId() { public int getId() {

View File

@@ -34,6 +34,7 @@ public class GameDisc implements GameDatabaseObject {
private int exp; private int exp;
private int phase; private int phase;
private int star; private int star;
private boolean read;
private long createTime; private long createTime;
@@ -149,16 +150,16 @@ public class GameDisc implements GameDatabaseObject {
} }
// Create change info // Create change info
var changes = new PlayerChangeInfo(); var change = new PlayerChangeInfo();
// Remove items // Remove items
this.getPlayer().getInventory().removeItems(params, changes); this.getPlayer().getInventory().removeItems(params, change);
// Add exp // Add exp
this.addExp(exp); this.addExp(exp);
// Success // Success
return changes.setSuccess(true); return change.setSuccess(true);
} }
public PlayerChangeInfo promote() { public PlayerChangeInfo promote() {
@@ -178,7 +179,7 @@ public class GameDisc implements GameDatabaseObject {
} }
// Remove items // Remove items
var changes = this.getPlayer().getInventory().removeItems(data.getMaterials(), null); var change = this.getPlayer().getInventory().removeItems(data.getMaterials(), null);
// Add phase level // Add phase level
this.phase++; this.phase++;
@@ -187,7 +188,7 @@ public class GameDisc implements GameDatabaseObject {
this.save(); this.save();
// Success // Success
return changes.setSuccess(true); return change.setSuccess(true);
} }
public PlayerChangeInfo limitBreak(int count) { public PlayerChangeInfo limitBreak(int count) {
@@ -206,7 +207,7 @@ public class GameDisc implements GameDatabaseObject {
} }
// Remove items // Remove items
var changes = this.getPlayer().getInventory().removeItems(materials, null); var change = this.getPlayer().getInventory().removeItems(materials, null);
// Add phase level // Add phase level
this.star = Math.max(this.star + count, 4); this.star = Math.max(this.star + count, 4);
@@ -215,7 +216,32 @@ public class GameDisc implements GameDatabaseObject {
this.save(); this.save();
// Success // Success
return changes.setSuccess(true); return change.setSuccess(true);
}
public PlayerChangeInfo receiveReadReward() {
// Create change info
var change = new PlayerChangeInfo();
// Sanity check
if (this.isRead()) {
return change;
}
// Add reward
if (this.getData().getReadReward() != null) {
int id = getData().getReadReward()[0];
int count = getData().getReadReward()[1];
this.getPlayer().getInventory().addItem(id, count, change);
}
// Set read flag
this.read = true;
this.save();
// Success
return change;
} }
// Proto // Proto
@@ -227,6 +253,7 @@ public class GameDisc implements GameDatabaseObject {
.setExp(this.getExp()) .setExp(this.getExp())
.setPhase(this.getPhase()) .setPhase(this.getPhase())
.setStar(this.getStar()) .setStar(this.getStar())
.setRead(this.isRead())
.setCreateTime(this.getCreateTime()); .setCreateTime(this.getCreateTime());
return proto; return proto;

View File

@@ -2,6 +2,7 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler; import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId; import emu.nebula.net.NetMsgId;
import emu.nebula.proto.DiscReadRewardReceive.DiscReadRewardReceiveReq;
import emu.nebula.net.HandlerId; import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession; import emu.nebula.net.GameSession;
@@ -10,7 +11,23 @@ public class HandlerDiscReadRewardReceiveReq extends NetHandler {
@Override @Override
public byte[] handle(GameSession session, byte[] message) throws Exception { public byte[] handle(GameSession session, byte[] message) throws Exception {
return session.encodeMsg(NetMsgId.disc_read_reward_receive_failed_ack); // Parse request
var req = DiscReadRewardReceiveReq.parseFrom(message);
// Get disc
var disc = session.getPlayer().getCharacters().getDiscById(req.getId());
if (disc == null) {
return session.encodeMsg(NetMsgId.disc_read_reward_receive_failed_ack);
}
// Set read reward
var change = disc.receiveReadReward();
if (change == null) {
return session.encodeMsg(NetMsgId.disc_read_reward_receive_failed_ack);
}
// Encode and send
return session.encodeMsg(NetMsgId.disc_read_reward_receive_succeed_ack, change.toProto());
} }
} }