mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-09 17:53:17 +08:00
feat: finish home avatar talk (#2328)
This commit is contained in:
parent
97138d8c84
commit
a49f37edb3
@ -9,8 +9,10 @@ import emu.grasscutter.database.DatabaseHelper;
|
|||||||
import emu.grasscutter.game.avatar.Avatar;
|
import emu.grasscutter.game.avatar.Avatar;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.SceneType;
|
import emu.grasscutter.game.props.SceneType;
|
||||||
|
import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass;
|
||||||
import emu.grasscutter.server.packet.send.*;
|
import emu.grasscutter.server.packet.send.*;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -52,6 +54,7 @@ public class GameHome {
|
|||||||
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
|
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
|
||||||
Set<Integer> unlockedHomeBgmList;
|
Set<Integer> unlockedHomeBgmList;
|
||||||
int enterHomeOption;
|
int enterHomeOption;
|
||||||
|
Map<Integer, Set<Integer>> finishedTalkIdMap;
|
||||||
|
|
||||||
public static GameHome getByUid(Integer uid) {
|
public static GameHome getByUid(Integer uid) {
|
||||||
var home = DatabaseHelper.getHomeByUid(uid);
|
var home = DatabaseHelper.getHomeByUid(uid);
|
||||||
@ -71,6 +74,7 @@ public class GameHome {
|
|||||||
.level(1)
|
.level(1)
|
||||||
.sceneMap(new ConcurrentHashMap<>())
|
.sceneMap(new ConcurrentHashMap<>())
|
||||||
.unlockedHomeBgmList(new HashSet<>())
|
.unlockedHomeBgmList(new HashSet<>())
|
||||||
|
.finishedTalkIdMap(new HashMap<>())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +106,7 @@ public class GameHome {
|
|||||||
player.getSession().send(new PacketHomeComfortInfoNotify(player));
|
player.getSession().send(new PacketHomeComfortInfoNotify(player));
|
||||||
player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify());
|
player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify());
|
||||||
player.getSession().send(new PacketHomeMarkPointNotify(player));
|
player.getSession().send(new PacketHomeMarkPointNotify(player));
|
||||||
|
player.getSession().send(new PacketHomeAvatarTalkFinishInfoNotify(player));
|
||||||
player.getSession().send(new PacketHomeAllUnlockedBgmIdListNotify(player));
|
player.getSession().send(new PacketHomeAllUnlockedBgmIdListNotify(player));
|
||||||
checkAccumulatedResources(player);
|
checkAccumulatedResources(player);
|
||||||
player.getSession().send(new PacketHomeResourceNotify(player));
|
player.getSession().send(new PacketHomeResourceNotify(player));
|
||||||
@ -141,6 +146,30 @@ public class GameHome {
|
|||||||
return GameData.getHomeWorldLevelDataMap().get(level);
|
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) {
|
public boolean addUnlockedHomeBgm(int homeBgmId) {
|
||||||
if (!getUnlockedHomeBgmList().add(homeBgmId)) return false;
|
if (!getUnlockedHomeBgmList().add(homeBgmId)) return false;
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,17 @@
|
|||||||
package emu.grasscutter.server.packet.recv;
|
package emu.grasscutter.server.packet.recv;
|
||||||
|
|
||||||
import emu.grasscutter.game.world.*;
|
import emu.grasscutter.game.world.Position;
|
||||||
import emu.grasscutter.net.packet.*;
|
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.net.proto.HomeChangeModuleReqOuterClass;
|
||||||
import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType;
|
import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType;
|
||||||
import emu.grasscutter.server.game.GameSession;
|
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)
|
@Opcodes(PacketOpcodes.HomeChangeModuleReq)
|
||||||
public class HandlerHomeChangeModuleReq extends PacketHandler {
|
public class HandlerHomeChangeModuleReq extends PacketHandler {
|
||||||
@ -15,6 +21,7 @@ public class HandlerHomeChangeModuleReq extends PacketHandler {
|
|||||||
HomeChangeModuleReqOuterClass.HomeChangeModuleReq req =
|
HomeChangeModuleReqOuterClass.HomeChangeModuleReq req =
|
||||||
HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload);
|
HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload);
|
||||||
session.getPlayer().setCurrentRealmId(req.getTargetModuleId());
|
session.getPlayer().setCurrentRealmId(req.getTargetModuleId());
|
||||||
|
session.send(new PacketHomeAvatarTalkFinishInfoNotify(session.getPlayer()));
|
||||||
session.send(new PacketHomeChangeModuleRsp(req.getTargetModuleId()));
|
session.send(new PacketHomeChangeModuleRsp(req.getTargetModuleId()));
|
||||||
session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer()));
|
session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer()));
|
||||||
session.send(new PacketHomeComfortInfoNotify(session.getPlayer()));
|
session.send(new PacketHomeComfortInfoNotify(session.getPlayer()));
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package emu.grasscutter.server.packet.recv;
|
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.net.proto.HomeUpdateArrangementInfoReqOuterClass;
|
||||||
import emu.grasscutter.server.game.GameSession;
|
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)
|
@Opcodes(PacketOpcodes.HomeUpdateArrangementInfoReq)
|
||||||
public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler {
|
public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler {
|
||||||
@ -18,6 +22,7 @@ public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler {
|
|||||||
|
|
||||||
homeScene.update(req.getSceneArrangementInfo());
|
homeScene.update(req.getSceneArrangementInfo());
|
||||||
|
|
||||||
|
session.send(new PacketHomeAvatarTalkFinishInfoNotify(session.getPlayer()));
|
||||||
session.send(new PacketHomeMarkPointNotify(session.getPlayer()));
|
session.send(new PacketHomeMarkPointNotify(session.getPlayer()));
|
||||||
|
|
||||||
session.getPlayer().getHome().save();
|
session.getPlayer().getHome().save();
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user