mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 21:04: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 StrengthenGroupId;
|
||||||
private int PromoteGroupId;
|
private int PromoteGroupId;
|
||||||
private int TransformItemId;
|
private int TransformItemId;
|
||||||
|
private int[] ReadReward;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
// 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);
|
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