mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 12:54:36 +01:00
Implement disc read reward
This commit is contained in:
@@ -11,6 +11,7 @@ public class DiscDef extends BaseDef {
|
||||
private int StrengthenGroupId;
|
||||
private int PromoteGroupId;
|
||||
private int TransformItemId;
|
||||
private int[] ReadReward;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class GameDisc implements GameDatabaseObject {
|
||||
private int exp;
|
||||
private int phase;
|
||||
private int star;
|
||||
private boolean read;
|
||||
|
||||
private long createTime;
|
||||
|
||||
@@ -149,16 +150,16 @@ public class GameDisc implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
// Create change info
|
||||
var changes = new PlayerChangeInfo();
|
||||
var change = new PlayerChangeInfo();
|
||||
|
||||
// Remove items
|
||||
this.getPlayer().getInventory().removeItems(params, changes);
|
||||
this.getPlayer().getInventory().removeItems(params, change);
|
||||
|
||||
// Add exp
|
||||
this.addExp(exp);
|
||||
|
||||
// Success
|
||||
return changes.setSuccess(true);
|
||||
return change.setSuccess(true);
|
||||
}
|
||||
|
||||
public PlayerChangeInfo promote() {
|
||||
@@ -178,7 +179,7 @@ public class GameDisc implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
// Remove items
|
||||
var changes = this.getPlayer().getInventory().removeItems(data.getMaterials(), null);
|
||||
var change = this.getPlayer().getInventory().removeItems(data.getMaterials(), null);
|
||||
|
||||
// Add phase level
|
||||
this.phase++;
|
||||
@@ -187,7 +188,7 @@ public class GameDisc implements GameDatabaseObject {
|
||||
this.save();
|
||||
|
||||
// Success
|
||||
return changes.setSuccess(true);
|
||||
return change.setSuccess(true);
|
||||
}
|
||||
|
||||
public PlayerChangeInfo limitBreak(int count) {
|
||||
@@ -206,7 +207,7 @@ public class GameDisc implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
// Remove items
|
||||
var changes = this.getPlayer().getInventory().removeItems(materials, null);
|
||||
var change = this.getPlayer().getInventory().removeItems(materials, null);
|
||||
|
||||
// Add phase level
|
||||
this.star = Math.max(this.star + count, 4);
|
||||
@@ -215,7 +216,32 @@ public class GameDisc implements GameDatabaseObject {
|
||||
this.save();
|
||||
|
||||
// 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
|
||||
@@ -227,6 +253,7 @@ public class GameDisc implements GameDatabaseObject {
|
||||
.setExp(this.getExp())
|
||||
.setPhase(this.getPhase())
|
||||
.setStar(this.getStar())
|
||||
.setRead(this.isRead())
|
||||
.setCreateTime(this.getCreateTime());
|
||||
|
||||
return proto;
|
||||
|
||||
@@ -2,6 +2,7 @@ package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.DiscReadRewardReceive.DiscReadRewardReceiveReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@@ -10,7 +11,23 @@ public class HandlerDiscReadRewardReceiveReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user