mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-28 01:02:59 +08:00
implement McoinExchange packet Handler
This commit is contained in:
parent
1ac5aeb286
commit
7b22b575b7
8
proto/McoinExchangeHcoinReq.proto
Normal file
8
proto/McoinExchangeHcoinReq.proto
Normal file
@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "emu.grasscutter.net.proto";
|
||||
|
||||
message McoinExchangeHcoinReq {
|
||||
uint32 mCoinNum = 1;
|
||||
uint32 hCoinNum = 2;
|
||||
}
|
8
proto/McoinExchangeHcoinRsp.proto
Normal file
8
proto/McoinExchangeHcoinRsp.proto
Normal file
@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "emu.grasscutter.net.proto";
|
||||
|
||||
message McoinExchangeHcoinRsp {
|
||||
uint32 mCoinNum = 1;
|
||||
uint32 hCoinNum = 2;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.McoinExchangeHcoinReqOuterClass;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketMcoinExchangeHcoinRsp;
|
||||
|
||||
@Opcodes(PacketOpcodes.McoinExchangeHcoinReq)
|
||||
public class HandlerMcoinExchangeHcoinReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq exchangeReq = McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq.parseFrom(payload);
|
||||
if (session == null) {
|
||||
return;
|
||||
} else if (session.getPlayer().getCrystals() < exchangeReq.getMCoinNum()) {
|
||||
return;
|
||||
}
|
||||
session.getPlayer().setCrystals(session.getPlayer().getCrystals() - exchangeReq.getMCoinNum());
|
||||
session.getPlayer().setPrimogems(session.getPlayer().getPrimogems() + exchangeReq.getHCoinNum());
|
||||
session.getPlayer().save();
|
||||
session.send(new PacketMcoinExchangeHcoinRsp(session.getPlayer().getCrystals(), session.getPlayer().getPrimogems()));
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.McoinExchangeHcoinRspOuterClass;
|
||||
|
||||
public class PacketMcoinExchangeHcoinRsp extends BasePacket {
|
||||
|
||||
public PacketMcoinExchangeHcoinRsp(int mcoin, int hcoin) {
|
||||
super(PacketOpcodes.McoinExchangeHcoinRsp);
|
||||
|
||||
McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp mcoinExchangeHcoinRsp = McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp.newBuilder()
|
||||
.setMCoinNum(mcoin)
|
||||
.setHCoinNum(hcoin).build();
|
||||
|
||||
this.setData(mcoinExchangeHcoinRsp);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user