Commit 41542297 authored by AnimeGitB's avatar AnimeGitB
Browse files

refactor HandlerWidgetDoBagReq

parent badda362
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.GadgetData;
import emu.grasscutter.game.entity.EntityVehicle; import emu.grasscutter.game.entity.EntityVehicle;
import emu.grasscutter.game.entity.GameEntity;
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;
...@@ -14,60 +11,32 @@ import emu.grasscutter.server.packet.send.PacketWidgetDoBagRsp; ...@@ -14,60 +11,32 @@ import emu.grasscutter.server.packet.send.PacketWidgetDoBagRsp;
import emu.grasscutter.server.packet.send.PacketWidgetGadgetDataNotify; import emu.grasscutter.server.packet.send.PacketWidgetGadgetDataNotify;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.List;
@Opcodes(PacketOpcodes.WidgetDoBagReq) @Opcodes(PacketOpcodes.WidgetDoBagReq)
public class HandlerWidgetDoBagReq extends PacketHandler { public class HandlerWidgetDoBagReq 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 {
WidgetDoBagReqOuterClass.WidgetDoBagReq req = WidgetDoBagReqOuterClass.WidgetDoBagReq.parseFrom(payload); WidgetDoBagReqOuterClass.WidgetDoBagReq req = WidgetDoBagReqOuterClass.WidgetDoBagReq.parseFrom(payload);
var locationInfo = req.getWidgetCreatorInfo().getLocationInfo();
Position pos = new Position(locationInfo.getPos());
Position rot = new Position(locationInfo.getRot());
switch (req.getMaterialId()) { switch (req.getMaterialId()) {
case 220026 -> { case 220026 -> {
GadgetData gadgetData = GameData.getGadgetDataMap().get(70500025); this.spawnVehicle(session, 70500025, pos, rot);
Position pos = new Position(req.getWidgetCreatorInfo().getLocationInfo().getPos());
Position rot = new Position(req.getWidgetCreatorInfo().getLocationInfo().getRot());
GameEntity entity = new EntityVehicle(
session.getPlayer().getScene(),
session.getPlayer(),
gadgetData.getId(),
0,
pos,
rot
);
session.getPlayer().getScene().addEntity(entity);
session.send(new PacketWidgetGadgetDataNotify(70500025, entity.getId())); // ???
session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true));
session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true));
// Send twice, and I don't know why, Ask mhy
session.send(new PacketWidgetDoBagRsp());
} }
case 220047 -> { case 220047 -> this.spawnVehicle(session, 70800058, pos, rot);
GadgetData gadgetData = GameData.getGadgetDataMap().get(70800058); default -> {}
Position pos = new Position(req.getWidgetCreatorInfo().getLocationInfo().getPos());
Position rot = new Position(req.getWidgetCreatorInfo().getLocationInfo().getRot());
GameEntity entity = new EntityVehicle(
session.getPlayer().getScene(),
session.getPlayer(),
gadgetData.getId(),
0,
pos,
rot
);
session.getPlayer().getScene().addEntity(entity);
session.send(new PacketWidgetGadgetDataNotify(70800058, entity.getId())); // ???
// Send twice, and I don't know why, Ask mhy
session.send(new PacketWidgetDoBagRsp());
}
default -> {
session.send(new PacketWidgetDoBagRsp());
}
} }
session.send(new PacketWidgetDoBagRsp());
} }
private void spawnVehicle(GameSession session, int gadgetId, Position pos, Position rot) throws Exception {
var player = session.getPlayer();
var scene = player.getScene();
var entity = new EntityVehicle(scene, player, gadgetId, 0, pos, rot);
scene.addEntity(entity);
session.send(new PacketWidgetGadgetDataNotify(gadgetId, entity.getId()));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment