Commit e16633e3 authored by Akka's avatar Akka Committed by Melledy
Browse files

Implement the Home System (Serenitea Pot)

parent 399275e8
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.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeBasicInfoNotify;
@Opcodes(PacketOpcodes.HomeGetBasicInfoReq)
public class HandlerHomeGetBasicInfoReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
session.send(new PacketHomeBasicInfoNotify(session.getPlayer(), false));
}
}
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.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeSceneInitFinishRsp;
@Opcodes(PacketOpcodes.HomeSceneInitFinishReq)
public class HandlerHomeSceneInitFinishReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
session.send(new PacketHomeSceneInitFinishRsp());
}
}
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.HomeSceneJumpReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeSceneJumpRsp;
@Opcodes(PacketOpcodes.HomeSceneJumpReq)
public class HandlerHomeSceneJumpReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = HomeSceneJumpReqOuterClass.HomeSceneJumpReq.parseFrom(payload);
int realmId = 2000 + session.getPlayer().getCurrentRealmId();
var home = session.getPlayer().getHome();
var homeScene = home.getHomeSceneItem(realmId);
home.save();
if(req.getIsEnterRoomScene()){
var roomScene = home.getHomeSceneItem(homeScene.getRoomSceneId());
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
homeScene.getRoomSceneId(),
roomScene.getBornPos()
);
}else{
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
realmId,
homeScene.getBornPos()
);
}
session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene()));
}
}
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.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeUnknown2Rsp;
@Opcodes(PacketOpcodes.HomeUnknown2Req)
public class HandlerHomeUnknown2Req extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
/*
* This packet is about the edit mode
*/
session.send(new PacketHomeUnknown2Rsp());
}
}
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.HomeUpdateArrangementInfoReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeUpdateArrangementInfoRsp;
@Opcodes(PacketOpcodes.HomeUpdateArrangementInfoReq)
public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = HomeUpdateArrangementInfoReqOuterClass.HomeUpdateArrangementInfoReq.parseFrom(payload);
var homeScene = session.getPlayer().getHome()
.getHomeSceneItem(session.getPlayer().getSceneId());
homeScene.update(req.getSceneArrangementInfo());
session.getPlayer().getHome().save();
session.send(new PacketHomeUpdateArrangementInfoRsp());
}
}
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.home.GameHome;
import emu.grasscutter.game.world.Scene; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
...@@ -27,13 +29,14 @@ public class HandlerTryEnterHomeReq extends PacketHandler { ...@@ -27,13 +29,14 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
int realmId = 2000 + session.getPlayer().getCurrentRealmId(); int realmId = 2000 + session.getPlayer().getCurrentRealmId();
Scene scene = session.getPlayer().getWorld().getSceneById(realmId); var home = session.getPlayer().getHome();
Position pos = scene.getScriptManager().getConfig().born_pos; var homeScene = home.getHomeSceneItem(realmId);
home.save();
session.getPlayer().getWorld().transferPlayerToScene( session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(), session.getPlayer(),
realmId, realmId,
pos homeScene.getBornPos()
); );
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.FurnitureCurModuleArrangeCountNotifyOuterClass;
import emu.grasscutter.net.proto.Uint32PairOuterClass;
public class PacketFurnitureCurModuleArrangeCountNotify extends BasePacket {
public PacketFurnitureCurModuleArrangeCountNotify() {
super(PacketOpcodes.FurnitureCurModuleArrangeCountNotify);
var proto = FurnitureCurModuleArrangeCountNotifyOuterClass.FurnitureCurModuleArrangeCountNotify.newBuilder();
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(360101)
.setValue(7)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(360201)
.setValue(7)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(360301)
.setValue(7)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(360401)
.setValue(2)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(360402)
.setValue(4)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(364301)
.setValue(1)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(364401)
.setValue(1)
.build());
proto.addFurnitureArrangeCountList(Uint32PairOuterClass.Uint32Pair.newBuilder()
.setKey(3750102)
.setValue(1)
.build());
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeBasicInfoNotifyOuterClass;
import emu.grasscutter.net.proto.HomeBasicInfoOuterClass;
import emu.grasscutter.net.proto.HomeLimitedShopInfoOuterClass;
import emu.grasscutter.net.proto.VectorOuterClass;
public class PacketHomeBasicInfoNotify extends BasePacket {
public PacketHomeBasicInfoNotify(Player player, boolean editMode) {
super(PacketOpcodes.HomeBasicInfoNotify);
if(player.getCurrentRealmId() == null){
return;
}
var proto = HomeBasicInfoNotifyOuterClass.HomeBasicInfoNotify.newBuilder();
var sceneId = player.getCurrentRealmId() + 2000;
var homeScene = player.getHome().getHomeSceneItem(sceneId);
proto.setBasicInfo(HomeBasicInfoOuterClass.HomeBasicInfo.newBuilder()
.setCurModuleId(player.getCurrentRealmId())
.setCurRoomSceneId(homeScene.getRoomSceneId())
.setIsInEditMode(editMode)
.setHomeOwnerUid(player.getUid())
.setLevel(1)
.setOwnerNickName(player.getNickname())
.setLimitedShopInfo(HomeLimitedShopInfoOuterClass.HomeLimitedShopInfo.newBuilder()
.setDjinnPos(VectorOuterClass.Vector.newBuilder()
.setZ(192)
.setX(792)
.setY(316.7f)
.build())
.setDjinnRot(VectorOuterClass.Vector.newBuilder()
.setY(176)
.build())
.setNextCloseTime(Integer.MAX_VALUE)
.setNextGuestOpenTime(0)
.setNextOpenTime(0)
.setUid(player.getUid())
.build())
.build());
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeChangeEditModeRspOuterClass;
public class PacketHomeChangeEditModeRsp extends BasePacket {
public PacketHomeChangeEditModeRsp(boolean enterEditMode) {
super(PacketOpcodes.HomeChangeEditModeRsp);
var proto = HomeChangeEditModeRspOuterClass.HomeChangeEditModeRsp.newBuilder();
proto.setIsEnterEditMode(enterEditMode);
this.setData(proto);
}
}
...@@ -25,6 +25,11 @@ public class PacketHomeComfortInfoNotify extends BasePacket { ...@@ -25,6 +25,11 @@ public class PacketHomeComfortInfoNotify extends BasePacket {
comfortInfoList.add( comfortInfoList.add(
HomeModuleComfortInfoOuterClass.HomeModuleComfortInfo.newBuilder() HomeModuleComfortInfoOuterClass.HomeModuleComfortInfo.newBuilder()
.setModuleId(moduleId) .setModuleId(moduleId)
.setRoomSceneComfortValue(1050)
.addWorldSceneBlockComfortValueList(750)
.addWorldSceneBlockComfortValueList(0)
.addWorldSceneBlockComfortValueList(0)
.addWorldSceneBlockComfortValueList(0)
.build() .build()
); );
} }
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.home.HomeSceneItem;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeGetArrangementInfoRspOuterClass;
import java.util.List;
public class PacketHomeGetArrangementInfoRsp extends BasePacket {
public PacketHomeGetArrangementInfoRsp(Player player, List<Integer> sceneIdList) {
super(PacketOpcodes.HomeGetArrangementInfoRsp);
var home = player.getHome();
var homeScenes = sceneIdList.stream()
.map(home::getHomeSceneItem)
.map(HomeSceneItem::toProto)
.toList();
home.save();
var proto = HomeGetArrangementInfoRspOuterClass.HomeGetArrangementInfoRsp.newBuilder();
proto.addAllSceneArrangementInfoList(homeScenes);
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.home.GameHome;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass;
public class PacketHomeMarkPointNotify extends BasePacket {
public PacketHomeMarkPointNotify(Player player, GameHome home) {
super(PacketOpcodes.HomeMarkPointNotify);
var proto = HomeMarkPointNotifyOuterClass.HomeMarkPointNotify.newBuilder();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass;
public class PacketHomeSceneInitFinishRsp extends BasePacket {
public PacketHomeSceneInitFinishRsp() {
super(PacketOpcodes.HomeSceneInitFinishRsp);
var proto = HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo.newBuilder();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeSceneJumpRspOuterClass;
public class PacketHomeSceneJumpRsp extends BasePacket {
public PacketHomeSceneJumpRsp(boolean enterRoomScene) {
super(PacketOpcodes.HomeSceneJumpRsp);
var proto = HomeSceneJumpRspOuterClass.HomeSceneJumpRsp.newBuilder();
proto.setIsEnterRoomScene(enterRoomScene);
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeUnknown1NotifyOuterClass;
public class PacketHomeUnknown1Notify extends BasePacket {
public PacketHomeUnknown1Notify(boolean isEnterEditMode) {
super(PacketOpcodes.HomeUnknown1Notify);
var proto = HomeUnknown1NotifyOuterClass.HomeUnknown1Notify.newBuilder();
proto.setIsEnterEditMode(isEnterEditMode);
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
public class PacketHomeUnknown2Rsp extends BasePacket {
public PacketHomeUnknown2Rsp() {
super(PacketOpcodes.HomeUnknown2Rsp);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
public class PacketHomeUpdateArrangementInfoRsp extends BasePacket {
public PacketHomeUpdateArrangementInfoRsp() {
super(PacketOpcodes.HomeUpdateArrangementInfoRsp);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.UnlockedFurnitureFormulaDataNotifyOuterClass;
public class PacketUnlockedFurnitureFormulaDataNotify extends BasePacket {
public PacketUnlockedFurnitureFormulaDataNotify() {
super(PacketOpcodes.UnlockedFurnitureFormulaDataNotify);
var proto = UnlockedFurnitureFormulaDataNotifyOuterClass.UnlockedFurnitureFormulaDataNotify.newBuilder();
proto.addFurnitureIdList(361207);
proto.addFurnitureIdList(362202);
proto.addFurnitureIdList(362304);
proto.addFurnitureIdList(363102);
proto.addFurnitureIdList(363103);
proto.addFurnitureIdList(363203);
proto.addFurnitureIdList(370201);
proto.addFurnitureIdList(370302);
proto.setIsAll(true);
this.setData(proto);
}
}
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