feat: finish home avatar talk (#2328)

This commit is contained in:
hamusuke 2023-09-02 14:47:06 +09:00 committed by GitHub
parent 97138d8c84
commit a49f37edb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 10 deletions

View File

@ -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<Integer, HomeSceneItem> sceneMap;
Set<Integer> unlockedHomeBgmList;
int enterHomeOption;
Map<Integer, Set<Integer>> 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<Integer> 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<HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTalkFinishInfo> 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;

View File

@ -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));
}
}

View File

@ -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()));

View File

@ -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();

View File

@ -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()));
}
}

View File

@ -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<Integer> talkIdSet) {
super(PacketOpcodes.HomeAvatarTalkRsp);
this.setData(HomeAvatarTalkRspOuterClass.HomeAvatarTalkRsp.newBuilder()
.setAvatarTalkInfo(HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTalkFinishInfo.newBuilder()
.setAvatarId(avatarId)
.addAllFinishTalkIdList(talkIdSet)
.build()));
}
}