diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 2f9f7763be3..a1ef20a8e79 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -302,6 +302,10 @@ public final class GameData { private static final Int2ObjectMap homeWorldLevelDataMap = new Int2ObjectOpenHashMap<>(); + @Getter + private static final Int2ObjectMap homeWorldModuleDataMap = + new Int2ObjectOpenHashMap<>(); + @Getter private static final Int2ObjectMap homeWorldNPCDataMap = new Int2ObjectOpenHashMap<>(); diff --git a/src/main/java/emu/grasscutter/data/excels/HomeWorldModuleData.java b/src/main/java/emu/grasscutter/data/excels/HomeWorldModuleData.java new file mode 100644 index 00000000000..b4e4a845b10 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/excels/HomeWorldModuleData.java @@ -0,0 +1,17 @@ +package emu.grasscutter.data.excels; + +import emu.grasscutter.data.GameResource; +import emu.grasscutter.data.ResourceType; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.experimental.FieldDefaults; + +@ResourceType(name = "HomeworldModuleExcelConfigData.json") +@FieldDefaults(level = AccessLevel.PRIVATE) +@Getter +public class HomeWorldModuleData extends GameResource { + int Id; + boolean isFree; + int worldSceneId; + int defaultRoomSceneId; +} diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index d4b0a4d3bd6..5bfcab79623 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -12,6 +12,7 @@ import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass; import emu.grasscutter.server.packet.send.*; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.IntSets; import lombok.AccessLevel; import lombok.Builder; import lombok.Data; @@ -37,6 +38,9 @@ public class GameHome { || sceneData.getSceneType() == SceneType.SCENE_HOME_ROOM) .map(SceneData::getId) .collect(Collectors.toUnmodifiableSet()); + public static final Set HOME_MODULE_IDS = + GameData.getHomeWorldModuleDataMap().isEmpty() ? + IntSets.fromTo(1, 6) : GameData.getHomeWorldModuleDataMap().keySet(); @Id String id; @@ -201,6 +205,8 @@ private void fixModuleIdIfInvalid() { return; } + this.player.getRealmList().removeIf(integer -> !HOME_MODULE_IDS.contains(integer)); // Delete invalid module ids. + if (this.player.getRealmList().isEmpty()) { this.player.setRealmList(null); return; diff --git a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java index 3895214f7ad..6ecff98de77 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java +++ b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java @@ -1,14 +1,15 @@ package emu.grasscutter.game.home; import com.github.davidmoten.guavamini.Lists; +import emu.grasscutter.game.home.suite.HomeSuiteItem; import emu.grasscutter.game.home.suite.event.HomeAvatarRewardEvent; import emu.grasscutter.game.home.suite.event.HomeAvatarSummonEvent; import emu.grasscutter.game.home.suite.event.SuiteEventType; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.proto.HomeAvatarRewardEventNotifyOuterClass; -import emu.grasscutter.net.proto.HomeAvatarSummonAllEventNotifyOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.HomeAvatarRewardEventNotifyOuterClass.HomeAvatarRewardEventNotify; +import emu.grasscutter.net.proto.HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.server.packet.send.PacketHomeAvatarSummonAllEventNotify; import emu.grasscutter.utils.Either; import lombok.AccessLevel; @@ -139,16 +140,16 @@ private void cancelSummonEventsIfAvatarLeave() { public Either, Integer> claimAvatarRewards(int eventId) { if (this.rewardEvents.isEmpty()) { - return Either.right(RetcodeOuterClass.Retcode.RET_FAIL_VALUE); + return Either.right(Retcode.RET_FAIL_VALUE); } var event = this.rewardEvents.remove(0); if (event.getEventId() != eventId) { - return Either.right(RetcodeOuterClass.Retcode.RET_FAIL_VALUE); + return Either.right(Retcode.RET_FAIL_VALUE); } if (!this.homeOwner.getHome().onClaimAvatarRewards(eventId)) { - return Either.right(RetcodeOuterClass.Retcode.RET_FAIL_VALUE); + return Either.right(Retcode.RET_FAIL_VALUE); } return Either.left(event.giveRewards()); @@ -156,32 +157,34 @@ public Either, Integer> claimAvatarRewards(int eventId) { public Either fireAvatarSummonEvent( Player owner, int avatarId, int guid, int suiteId) { - var targetSuite = - ((HomeScene) owner.getScene()) + HomeSuiteItem targetSuite = null; + if (owner.getScene() instanceof HomeScene homeScene) { + targetSuite = homeScene .getSceneItem().getBlockItems().values().stream() .map(HomeBlockItem::getSuiteList) .flatMap(Collection::stream) .filter(suite -> suite.getGuid() == guid) .findFirst() .orElse(null); + } if (this.isInRewardEvent(avatarId)) { - return Either.right(RetcodeOuterClass.Retcode.RET_DUPLICATE_AVATAR_VALUE); + return Either.right(Retcode.RET_DUPLICATE_AVATAR_VALUE); } if (this.rewardEvents.stream().anyMatch(event -> event.getGuid() == guid)) { - return Either.right(RetcodeOuterClass.Retcode.RET_HOME_FURNITURE_GUID_ERROR_VALUE); + return Either.right(Retcode.RET_HOME_FURNITURE_GUID_ERROR_VALUE); } this.summonEvents.removeIf(event -> event.getGuid() == guid || event.getAvatarId() == avatarId); if (targetSuite == null) { - return Either.right(RetcodeOuterClass.Retcode.RET_HOME_CLIENT_PARAM_INVALID_VALUE); + return Either.right(Retcode.RET_HOME_CLIENT_PARAM_INVALID_VALUE); } var eventData = SuiteEventType.HOME_AVATAR_SUMMON_EVENT.getEventDataFrom(avatarId, suiteId); if (eventData == null) { - return Either.right(RetcodeOuterClass.Retcode.RET_HOME_CLIENT_PARAM_INVALID_VALUE); + return Either.right(Retcode.RET_HOME_CLIENT_PARAM_INVALID_VALUE); } var event = @@ -196,8 +199,8 @@ public void onFinishSummonEvent(int eventId) { this.summonEvents.removeIf(event -> event.getEventId() == eventId); } - public HomeAvatarRewardEventNotifyOuterClass.HomeAvatarRewardEventNotify toRewardEventProto() { - var notify = HomeAvatarRewardEventNotifyOuterClass.HomeAvatarRewardEventNotify.newBuilder(); + public HomeAvatarRewardEventNotify toRewardEventProto() { + var notify = HomeAvatarRewardEventNotify.newBuilder(); if (!this.rewardEvents.isEmpty()) { notify.setRewardEvent(this.rewardEvents.get(0).toProto()).setIsEventTrigger(true); @@ -210,9 +213,8 @@ public HomeAvatarRewardEventNotifyOuterClass.HomeAvatarRewardEventNotify toRewar return notify.build(); } - public HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify - toSummonEventProto() { - return HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify.newBuilder() + public HomeAvatarSummonAllEventNotify toSummonEventProto() { + return HomeAvatarSummonAllEventNotify.newBuilder() .addAllSummonEventList( this.summonEvents.stream().map(HomeAvatarSummonEvent::toProto).toList()) .build(); 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 74d0b1aa458..edc5829abec 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java @@ -4,8 +4,8 @@ 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.RetcodeOuterClass; +import emu.grasscutter.net.proto.HomeChangeModuleReqOuterClass.HomeChangeModuleReq; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketHomeAvatarTalkFinishInfoNotify; @@ -18,12 +18,11 @@ public class HandlerHomeChangeModuleReq extends PacketHandler { @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - HomeChangeModuleReqOuterClass.HomeChangeModuleReq req = - HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); + var req = HomeChangeModuleReq.parseFrom(payload); var homeWorld = session.getPlayer().getCurHomeWorld(); if (!homeWorld.getGuests().isEmpty()) { - session.send(new PacketHomeChangeModuleRsp(RetcodeOuterClass.Retcode.RET_HOME_HAS_GUEST)); + session.send(new PacketHomeChangeModuleRsp(Retcode.RET_HOME_HAS_GUEST)); return; } @@ -32,7 +31,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex if (scene == null) { Grasscutter.getLogger().warn("scene == null! Changing module will fail."); - session.send(new PacketHomeChangeModuleRsp(RetcodeOuterClass.Retcode.RET_INVALID_SCENE_ID)); + session.send(new PacketHomeChangeModuleRsp(Retcode.RET_INVALID_SCENE_ID)); return; }