mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-23 23:32:58 +08:00
Fix logic of SetPlayerPropReq
This commit is contained in:
parent
4e0274cfc3
commit
6a0cb2732c
@ -1,11 +1,9 @@
|
||||
package emu.grasscutter.server.packet.recv;
|
||||
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.net.packet.Opcodes;
|
||||
import emu.grasscutter.net.packet.PacketHandler;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.PropValueOuterClass.PropValue;
|
||||
import emu.grasscutter.net.proto.SetPlayerPropReqOuterClass.SetPlayerPropReq;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
import emu.grasscutter.server.packet.send.PacketSetPlayerPropRsp;
|
||||
@ -15,18 +13,22 @@ public class HandlerSetPlayerPropReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||
// Auto template
|
||||
SetPlayerPropReq req = SetPlayerPropReq.parseFrom(payload);
|
||||
Player player = session.getPlayer();
|
||||
for (PropValue p : req.getPropListList()) {
|
||||
PlayerProperty prop = PlayerProperty.getPropById(p.getType());
|
||||
if (prop == PlayerProperty.PROP_IS_MP_MODE_AVAILABLE) {
|
||||
if (!player.setProperty(prop, (int) p.getVal(), false)) {
|
||||
session.send(new PacketSetPlayerPropRsp(1));
|
||||
return;
|
||||
var req = SetPlayerPropReq.parseFrom(payload);
|
||||
var player = session.getPlayer();
|
||||
|
||||
for (var p : req.getPropListList()) {
|
||||
var prop = PlayerProperty.getPropById(p.getType());
|
||||
switch (prop) {
|
||||
default -> player.setProperty(prop, (int) p.getVal(), true);
|
||||
case PROP_IS_MP_MODE_AVAILABLE -> {
|
||||
if (!player.setProperty(prop, (int) p.getVal(), false)) {
|
||||
session.send(new PacketSetPlayerPropRsp(1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.save();
|
||||
session.send(new PacketSetPlayerPropRsp(0));
|
||||
}
|
||||
|
@ -2,17 +2,18 @@ package emu.grasscutter.server.packet.send;
|
||||
|
||||
import emu.grasscutter.net.packet.BasePacket;
|
||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||
import emu.grasscutter.net.proto.SetPlayerPropRspOuterClass;
|
||||
import emu.grasscutter.net.proto.SetPlayerPropRspOuterClass.SetPlayerPropRsp;
|
||||
|
||||
public class PacketSetPlayerPropRsp extends BasePacket {
|
||||
|
||||
public PacketSetPlayerPropRsp(int retCode) {
|
||||
super(PacketOpcodes.SetPlayerPropRsp);
|
||||
SetPlayerPropRspOuterClass.SetPlayerPropRsp.Builder proto =
|
||||
SetPlayerPropRspOuterClass.SetPlayerPropRsp.newBuilder();
|
||||
|
||||
var proto = SetPlayerPropRsp.newBuilder();
|
||||
if (retCode != 0) {
|
||||
proto.setRetcode(retCode);
|
||||
}
|
||||
|
||||
this.setData(proto.build());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user