From 7a247e70e07134272d92718d786a3aa7617bd879 Mon Sep 17 00:00:00 2001 From: Akka <104902222+Akka0@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:20:08 +0800 Subject: [PATCH] npc/animals arrangement & support enter room scene --- .../emu/grasscutter/game/home/GameHome.java | 2 +- .../grasscutter/game/home/HomeAnimalItem.java | 37 ++++++++++++++++++ .../grasscutter/game/home/HomeBlockItem.java | 17 ++++++-- .../game/home/HomeFurnitureItem.java | 11 ++++++ .../grasscutter/game/home/HomeNPCItem.java | 39 +++++++++++++++++++ .../grasscutter/game/home/HomeSceneItem.java | 4 +- .../packet/recv/HandlerHomeSceneJumpReq.java | 25 +++++------- .../packet/recv/HandlerTryEnterHomeReq.java | 7 +++- .../send/PacketHomeMarkPointNotify.java | 24 ++++++++++++ 9 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 src/main/java/emu/grasscutter/game/home/HomeAnimalItem.java create mode 100644 src/main/java/emu/grasscutter/game/home/HomeNPCItem.java diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index b2b5c1ecb..fb4a94556 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -65,6 +65,6 @@ public class GameHome { player.getSession().send(new PacketPlayerHomeCompInfoNotify(player)); player.getSession().send(new PacketHomeComfortInfoNotify(player)); player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify()); - player.getSession().send(new PacketUnlockedFurnitureFormulaDataNotify()); + player.getSession().send(new PacketHomeMarkPointNotify(player, this)); } } diff --git a/src/main/java/emu/grasscutter/game/home/HomeAnimalItem.java b/src/main/java/emu/grasscutter/game/home/HomeAnimalItem.java new file mode 100644 index 000000000..ea67a69fd --- /dev/null +++ b/src/main/java/emu/grasscutter/game/home/HomeAnimalItem.java @@ -0,0 +1,37 @@ +package emu.grasscutter.game.home; + +import dev.morphia.annotations.Entity; +import emu.grasscutter.net.proto.HomeAnimalDataOuterClass; +import emu.grasscutter.net.proto.HomeFurnitureDataOuterClass; +import emu.grasscutter.utils.Position; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Entity +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +@Builder(builderMethodName = "of") +public class HomeAnimalItem { + int furnitureId; + Position spawnPos; + Position spawnRot; + + public HomeAnimalDataOuterClass.HomeAnimalData toProto(){ + return HomeAnimalDataOuterClass.HomeAnimalData.newBuilder() + .setFurnitureId(furnitureId) + .setSpawnPos(spawnPos.toProto()) + .setSpawnRot(spawnRot.toProto()) + .build(); + } + + public static HomeAnimalItem parseFrom(HomeAnimalDataOuterClass.HomeAnimalData homeAnimalData) { + return HomeAnimalItem.of() + .furnitureId(homeAnimalData.getFurnitureId()) + .spawnPos(new Position(homeAnimalData.getSpawnPos())) + .spawnRot(new Position(homeAnimalData.getSpawnRot())) + .build(); + } + +} diff --git a/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java b/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java index e936d0264..7401b7a6c 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java @@ -16,13 +16,12 @@ import java.util.List; @Builder(builderMethodName = "of") @FieldDefaults(level = AccessLevel.PRIVATE) public class HomeBlockItem { - @Id int blockId; boolean unlocked; - List deployFurnitureList; - + List deployAnimalList; + List deployNPCList; public void update(HomeBlockArrangementInfo homeBlockArrangementInfo) { this.blockId = homeBlockArrangementInfo.getBlockId(); @@ -30,6 +29,14 @@ public class HomeBlockItem { this.deployFurnitureList = homeBlockArrangementInfo.getDeployFurniureListList().stream() .map(HomeFurnitureItem::parseFrom) .toList(); + + this.deployAnimalList = homeBlockArrangementInfo.getDeployAnimalListList().stream() + .map(HomeAnimalItem::parseFrom) + .toList(); + + this.deployNPCList = homeBlockArrangementInfo.getDeployNpcListList().stream() + .map(HomeNPCItem::parseFrom) + .toList(); } public int calComfort(){ @@ -45,6 +52,8 @@ public class HomeBlockItem { .setComfortValue(calComfort()); this.deployFurnitureList.forEach(f -> proto.addDeployFurniureList(f.toProto())); + this.deployAnimalList.forEach(f -> proto.addDeployAnimalList(f.toProto())); + this.deployNPCList.forEach(f -> proto.addDeployNpcList(f.toProto())); return proto.build(); } @@ -59,6 +68,8 @@ public class HomeBlockItem { homeBlock.getFurnitures().stream() .map(HomeFurnitureItem::parseFrom) .toList()) + .deployAnimalList(List.of()) + .deployNPCList(List.of()) .build(); } } diff --git a/src/main/java/emu/grasscutter/game/home/HomeFurnitureItem.java b/src/main/java/emu/grasscutter/game/home/HomeFurnitureItem.java index 0cf4fed28..34a50d833 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeFurnitureItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeFurnitureItem.java @@ -5,6 +5,7 @@ import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.HomeworldDefaultSaveData; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.net.proto.HomeFurnitureDataOuterClass; +import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass; import emu.grasscutter.utils.Position; import lombok.AccessLevel; import lombok.Builder; @@ -32,6 +33,16 @@ public class HomeFurnitureItem { .build(); } + public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto(int type){ + return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder() + .setFurnitureId(furnitureId) + .setGuid(guid) + .setFurnitureType(type) + .setPos(spawnPos.toProto()) + // TODO NPC and farm + .build(); + } + public static HomeFurnitureItem parseFrom(HomeFurnitureDataOuterClass.HomeFurnitureData homeFurnitureData) { return HomeFurnitureItem.of() .furnitureId(homeFurnitureData.getFurnitureId()) diff --git a/src/main/java/emu/grasscutter/game/home/HomeNPCItem.java b/src/main/java/emu/grasscutter/game/home/HomeNPCItem.java new file mode 100644 index 000000000..e86b73e1d --- /dev/null +++ b/src/main/java/emu/grasscutter/game/home/HomeNPCItem.java @@ -0,0 +1,39 @@ +package emu.grasscutter.game.home; + +import dev.morphia.annotations.Entity; +import emu.grasscutter.net.proto.HomeAnimalDataOuterClass; +import emu.grasscutter.net.proto.HomeNpcDataOuterClass; +import emu.grasscutter.utils.Position; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Entity +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +@Builder(builderMethodName = "of") +public class HomeNPCItem { + int avatarId; + Position spawnPos; + Position spawnRot; + int costumeId; + + public HomeNpcDataOuterClass.HomeNpcData toProto(){ + return HomeNpcDataOuterClass.HomeNpcData.newBuilder() + .setAvatarId(avatarId) + .setSpawnPos(spawnPos.toProto()) + .setSpawnRot(spawnRot.toProto()) + .setCostumeId(costumeId) + .build(); + } + + public static HomeNPCItem parseFrom(HomeNpcDataOuterClass.HomeNpcData homeNpcData) { + return HomeNPCItem.of() + .avatarId(homeNpcData.getAvatarId()) + .spawnPos(new Position(homeNpcData.getSpawnPos())) + .spawnRot(new Position(homeNpcData.getSpawnRot())) + .costumeId(homeNpcData.getCostumeId()) + .build(); + } +} diff --git a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java index 5ec4ced1e..77ef40317 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java @@ -2,6 +2,7 @@ package emu.grasscutter.game.home; import dev.morphia.annotations.Entity; import dev.morphia.annotations.Id; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.HomeworldDefaultSaveData; import emu.grasscutter.net.proto.HomeBasicInfoOuterClass.HomeBasicInfo; import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo; @@ -45,7 +46,7 @@ public class HomeSceneItem { for(var blockItem : arrangementInfo.getBlockArrangementInfoListList()){ var block = this.blockItems.get(blockItem.getBlockId()); if(block == null){ - System.out.println(111); + Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId()); continue; } block.update(blockItem); @@ -79,6 +80,7 @@ public class HomeSceneItem { .setBornPos(bornPos.toProto()) .setBornRot(bornRot.toProto()) .setDjinnPos(djinnPos.toProto()) + .setIsSetBornPos(true) .setSceneId(sceneId) .setTmpVersion(1); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java index 6d8168109..4f6bcd2b4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java @@ -1,11 +1,13 @@ package emu.grasscutter.server.packet.recv; +import emu.grasscutter.game.world.Scene; 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; +import emu.grasscutter.utils.Position; @Opcodes(PacketOpcodes.HomeSceneJumpReq) public class HandlerHomeSceneJumpReq extends PacketHandler { @@ -20,21 +22,14 @@ public class HandlerHomeSceneJumpReq extends PacketHandler { 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() - ); - } + Scene scene = session.getPlayer().getWorld().getSceneById(req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId); + Position pos = scene.getScriptManager().getConfig().born_pos; + + session.getPlayer().getWorld().transferPlayerToScene( + session.getPlayer(), + req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId, + pos + ); session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene())); } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java index 2de3ffe1b..69e66e7d9 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java @@ -30,13 +30,18 @@ public class HandlerTryEnterHomeReq extends PacketHandler { int realmId = 2000 + session.getPlayer().getCurrentRealmId(); var home = session.getPlayer().getHome(); + + // prepare the default arrangement for first come in var homeScene = home.getHomeSceneItem(realmId); home.save(); + Scene scene = session.getPlayer().getWorld().getSceneById(realmId); + Position pos = scene.getScriptManager().getConfig().born_pos; + session.getPlayer().getWorld().transferPlayerToScene( session.getPlayer(), realmId, - homeScene.getBornPos() + pos ); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java index 8b74ecadc..bc9f019c4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java @@ -1,10 +1,14 @@ package emu.grasscutter.server.packet.send; import emu.grasscutter.game.home.GameHome; +import emu.grasscutter.game.home.HomeBlockItem; import emu.grasscutter.game.player.Player; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass; +import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass; + +import java.util.Collection; public class PacketHomeMarkPointNotify extends BasePacket { @@ -13,6 +17,26 @@ public class PacketHomeMarkPointNotify extends BasePacket { var proto = HomeMarkPointNotifyOuterClass.HomeMarkPointNotify.newBuilder(); + for(var moduleId : player.getRealmList()){ + var homeScene = home.getHomeSceneItem(moduleId + 2000); + + var markPointData = HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData.newBuilder() + .setModuleId(moduleId) + .setSceneId(moduleId + 2000) + .setTeapotSpiritPos(homeScene.getDjinnPos().toProto()); + + // Now it only supports the teleport point + // TODO add more types + var marks = homeScene.getBlockItems().values().stream() + .map(HomeBlockItem::getDeployFurnitureList) + .flatMap(Collection::stream) + .filter(i -> i.getFurnitureId() == 373501) + .map(x -> x.toMarkPointProto(3)) + .toList(); + + markPointData.addAllFurnitureList(marks); + proto.addMarkPointDataList(markPointData); + } this.setData(proto); }