mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-24 06:23:54 +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;
|
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) {
|
||||||
if (!player.setProperty(prop, (int) p.getVal(), false)) {
|
default -> player.setProperty(prop, (int) p.getVal(), true);
|
||||||
session.send(new PacketSetPlayerPropRsp(1));
|
case PROP_IS_MP_MODE_AVAILABLE -> {
|
||||||
return;
|
if (!player.setProperty(prop, (int) p.getVal(), false)) {
|
||||||
|
session.send(new PacketSetPlayerPropRsp(1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.save();
|
player.save();
|
||||||
session.send(new PacketSetPlayerPropRsp(0));
|
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.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user