From a49f37edb358efe7a8dbd57e126b782894f179ed Mon Sep 17 00:00:00 2001 From: hamusuke Date: Sat, 2 Sep 2023 14:47:06 +0900 Subject: [PATCH] feat: finish home avatar talk (#2328) --- .../emu/grasscutter/game/home/GameHome.java | 39 ++++++++++++++++--- .../packet/recv/HandlerHomeAvatarTalkReq.java | 20 ++++++++++ .../recv/HandlerHomeChangeModuleReq.java | 13 +++++-- .../HandlerHomeUpdateArrangementInfoReq.java | 9 ++++- .../PacketHomeAvatarTalkFinishInfoNotify.java | 15 +++++++ .../packet/send/PacketHomeAvatarTalkRsp.java | 20 ++++++++++ 6 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarTalkReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkFinishInfoNotify.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkRsp.java diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index 3c179582c..b0b955a5c 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -9,8 +9,10 @@ import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.SceneType; +import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass; import emu.grasscutter.server.packet.send.*; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; + import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.*; @@ -52,6 +54,7 @@ public class GameHome { ConcurrentHashMap sceneMap; Set unlockedHomeBgmList; int enterHomeOption; + Map> finishedTalkIdMap; public static GameHome getByUid(Integer uid) { var home = DatabaseHelper.getHomeByUid(uid); @@ -67,11 +70,12 @@ public class GameHome { public static GameHome create(Integer uid) { return GameHome.of() - .ownerUid(uid) - .level(1) - .sceneMap(new ConcurrentHashMap<>()) - .unlockedHomeBgmList(new HashSet<>()) - .build(); + .ownerUid(uid) + .level(1) + .sceneMap(new ConcurrentHashMap<>()) + .unlockedHomeBgmList(new HashSet<>()) + .finishedTalkIdMap(new HashMap<>()) + .build(); } public void save() { @@ -102,6 +106,7 @@ public class GameHome { player.getSession().send(new PacketHomeComfortInfoNotify(player)); player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify()); player.getSession().send(new PacketHomeMarkPointNotify(player)); + player.getSession().send(new PacketHomeAvatarTalkFinishInfoNotify(player)); player.getSession().send(new PacketHomeAllUnlockedBgmIdListNotify(player)); checkAccumulatedResources(player); player.getSession().send(new PacketHomeResourceNotify(player)); @@ -141,6 +146,30 @@ public class GameHome { return GameData.getHomeWorldLevelDataMap().get(level); } + public Set onTalkedWithAvatar(int avatarId, int talkId) { + if (this.finishedTalkIdMap == null) { + this.finishedTalkIdMap = new HashMap<>(); + } + + this.finishedTalkIdMap.computeIfAbsent(avatarId, HashSet::new).add(talkId); + this.save(); + + return this.finishedTalkIdMap.get(avatarId); + } + + public List toAvatarTalkFinishInfoProto() { + if (this.finishedTalkIdMap == null) { + this.finishedTalkIdMap = new HashMap<>(); + } + + return this.finishedTalkIdMap.entrySet().stream().map(e -> { + return HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTalkFinishInfo.newBuilder() + .setAvatarId(e.getKey()) + .addAllFinishTalkIdList(e.getValue()) + .build(); + }).toList(); + } + public boolean addUnlockedHomeBgm(int homeBgmId) { if (!getUnlockedHomeBgmList().add(homeBgmId)) return false; diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarTalkReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarTalkReq.java new file mode 100644 index 000000000..383987329 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarTalkReq.java @@ -0,0 +1,20 @@ +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.HomeAvatarTalkReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeAvatarTalkFinishInfoNotify; +import emu.grasscutter.server.packet.send.PacketHomeAvatarTalkRsp; + +@Opcodes(PacketOpcodes.HomeAvatarTalkReq) +public class HandlerHomeAvatarTalkReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = HomeAvatarTalkReqOuterClass.HomeAvatarTalkReq.parseFrom(payload); + var talkIdSet = session.getPlayer().getCurHomeWorld().getHome().onTalkedWithAvatar(req.getAvatarId(), req.getTalkId()); + session.send(new PacketHomeAvatarTalkFinishInfoNotify(session.getPlayer())); + session.send(new PacketHomeAvatarTalkRsp(req.getAvatarId(), talkIdSet)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java index 7e547f522..e4e397269 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java @@ -1,11 +1,17 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.game.world.*; -import emu.grasscutter.net.packet.*; +import emu.grasscutter.game.world.Position; +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.HomeChangeModuleReqOuterClass; import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.*; +import emu.grasscutter.server.packet.send.PacketHomeAvatarTalkFinishInfoNotify; +import emu.grasscutter.server.packet.send.PacketHomeChangeModuleRsp; +import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; +import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; @Opcodes(PacketOpcodes.HomeChangeModuleReq) public class HandlerHomeChangeModuleReq extends PacketHandler { @@ -15,6 +21,7 @@ public class HandlerHomeChangeModuleReq extends PacketHandler { HomeChangeModuleReqOuterClass.HomeChangeModuleReq req = HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); session.getPlayer().setCurrentRealmId(req.getTargetModuleId()); + session.send(new PacketHomeAvatarTalkFinishInfoNotify(session.getPlayer())); session.send(new PacketHomeChangeModuleRsp(req.getTargetModuleId())); session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java index 906475a1d..be36159e4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java @@ -1,9 +1,13 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.net.packet.*; +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.*; +import emu.grasscutter.server.packet.send.PacketHomeAvatarTalkFinishInfoNotify; +import emu.grasscutter.server.packet.send.PacketHomeMarkPointNotify; +import emu.grasscutter.server.packet.send.PacketHomeUpdateArrangementInfoRsp; @Opcodes(PacketOpcodes.HomeUpdateArrangementInfoReq) public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler { @@ -18,6 +22,7 @@ public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler { homeScene.update(req.getSceneArrangementInfo()); + session.send(new PacketHomeAvatarTalkFinishInfoNotify(session.getPlayer())); session.send(new PacketHomeMarkPointNotify(session.getPlayer())); session.getPlayer().getHome().save(); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkFinishInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkFinishInfoNotify.java new file mode 100644 index 000000000..6ae06e3e1 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkFinishInfoNotify.java @@ -0,0 +1,15 @@ +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.HomeAvatarTalkFinishInfoNotifyOuterClass; + +public class PacketHomeAvatarTalkFinishInfoNotify extends BasePacket { + public PacketHomeAvatarTalkFinishInfoNotify(Player homeOwner) { + super(PacketOpcodes.HomeAvatarTalkFinishInfoNotify); + + this.setData(HomeAvatarTalkFinishInfoNotifyOuterClass.HomeAvatarTalkFinishInfoNotify.newBuilder() + .addAllAvatarTalkInfoList(homeOwner.getHome().toAvatarTalkFinishInfoProto())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkRsp.java new file mode 100644 index 000000000..7068fa815 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarTalkRsp.java @@ -0,0 +1,20 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass; +import emu.grasscutter.net.proto.HomeAvatarTalkRspOuterClass; + +import java.util.Set; + +public class PacketHomeAvatarTalkRsp extends BasePacket { + public PacketHomeAvatarTalkRsp(int avatarId, Set talkIdSet) { + super(PacketOpcodes.HomeAvatarTalkRsp); + + this.setData(HomeAvatarTalkRspOuterClass.HomeAvatarTalkRsp.newBuilder() + .setAvatarTalkInfo(HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTalkFinishInfo.newBuilder() + .setAvatarId(avatarId) + .addAllFinishTalkIdList(talkIdSet) + .build())); + } +}