Fix logic of SetPlayerPropReq

This commit is contained in:
KingRainbow44 2023-05-17 00:24:40 -04:00
parent 4e0274cfc3
commit 6a0cb2732c
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 17 additions and 14 deletions

View File

@ -1,11 +1,9 @@
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PropValueOuterClass.PropValue;
import emu.grasscutter.net.proto.SetPlayerPropReqOuterClass.SetPlayerPropReq; import emu.grasscutter.net.proto.SetPlayerPropReqOuterClass.SetPlayerPropReq;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSetPlayerPropRsp; import emu.grasscutter.server.packet.send.PacketSetPlayerPropRsp;
@ -15,18 +13,22 @@ public class HandlerSetPlayerPropReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
// Auto template var req = SetPlayerPropReq.parseFrom(payload);
SetPlayerPropReq req = SetPlayerPropReq.parseFrom(payload); var player = session.getPlayer();
Player player = session.getPlayer();
for (PropValue p : req.getPropListList()) { for (var p : req.getPropListList()) {
PlayerProperty prop = PlayerProperty.getPropById(p.getType()); var prop = PlayerProperty.getPropById(p.getType());
if (prop == PlayerProperty.PROP_IS_MP_MODE_AVAILABLE) { switch (prop) {
default -> player.setProperty(prop, (int) p.getVal(), true);
case PROP_IS_MP_MODE_AVAILABLE -> {
if (!player.setProperty(prop, (int) p.getVal(), false)) { if (!player.setProperty(prop, (int) p.getVal(), false)) {
session.send(new PacketSetPlayerPropRsp(1)); session.send(new PacketSetPlayerPropRsp(1));
return; return;
} }
} }
} }
}
player.save(); player.save();
session.send(new PacketSetPlayerPropRsp(0)); session.send(new PacketSetPlayerPropRsp(0));
} }

View File

@ -2,17 +2,18 @@ package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; 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 class PacketSetPlayerPropRsp extends BasePacket {
public PacketSetPlayerPropRsp(int retCode) { public PacketSetPlayerPropRsp(int retCode) {
super(PacketOpcodes.SetPlayerPropRsp); super(PacketOpcodes.SetPlayerPropRsp);
SetPlayerPropRspOuterClass.SetPlayerPropRsp.Builder proto =
SetPlayerPropRspOuterClass.SetPlayerPropRsp.newBuilder(); var proto = SetPlayerPropRsp.newBuilder();
if (retCode != 0) { if (retCode != 0) {
proto.setRetcode(retCode); proto.setRetcode(retCode);
} }
this.setData(proto.build()); this.setData(proto.build());
} }
} }