diff --git a/src/main/java/emu/grasscutter/data/excels/HomeWorldEventData.java b/src/main/java/emu/grasscutter/data/excels/HomeWorldEventData.java index d5977c817..704ef73ce 100644 --- a/src/main/java/emu/grasscutter/data/excels/HomeWorldEventData.java +++ b/src/main/java/emu/grasscutter/data/excels/HomeWorldEventData.java @@ -12,14 +12,27 @@ import lombok.experimental.FieldDefaults; @FieldDefaults(level = AccessLevel.PRIVATE) @Getter public class HomeWorldEventData extends GameResource { - @SerializedName(value = "id", alternate = {"BBEIIPEFDPE"}) + @SerializedName( + value = "id", + alternate = {"BBEIIPEFDPE"}) int id; - @SerializedName(value = "eventType", alternate = {"JOCKIMECHDP"}) + + @SerializedName( + value = "eventType", + alternate = {"JOCKIMECHDP"}) SuiteEventType eventType; + int avatarID; - @SerializedName(value = "talkId", alternate = {"IGNJAICDFPD"}) + + @SerializedName( + value = "talkId", + alternate = {"IGNJAICDFPD"}) int talkId; + int rewardID; - @SerializedName(value = "suiteId", alternate = {"FEHOKMJPOED"}) + + @SerializedName( + value = "suiteId", + alternate = {"FEHOKMJPOED"}) int suiteId; } diff --git a/src/main/java/emu/grasscutter/game/entity/EntityHomeAnimal.java b/src/main/java/emu/grasscutter/game/entity/EntityHomeAnimal.java index c6652d967..40e61c339 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityHomeAnimal.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityHomeAnimal.java @@ -8,9 +8,8 @@ import emu.grasscutter.game.world.Scene; import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify; import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify; -import lombok.Getter; - import java.util.concurrent.atomic.AtomicBoolean; +import lombok.Getter; public class EntityHomeAnimal extends EntityMonster implements Rebornable { private int rebornCDTickCount; diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index fd5bcc893..d4a2348c5 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -12,17 +12,16 @@ 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 lombok.AccessLevel; -import lombok.Builder; -import lombok.Data; -import lombok.experimental.FieldDefaults; - import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; @Entity(value = "homes", useDiscriminator = false) @Data @@ -91,10 +90,10 @@ public class GameHome { // avoid NPE caused by database remover. private void reassignIfNull() { this.getSceneMap().values().stream() - .map(HomeSceneItem::getBlockItems) - .map(Map::values) - .flatMap(Collection::stream) - .forEach(HomeBlockItem::reassignIfNull); + .map(HomeSceneItem::getBlockItems) + .map(Map::values) + .flatMap(Collection::stream) + .forEach(HomeBlockItem::reassignIfNull); } // Data fixer. @@ -114,14 +113,14 @@ public class GameHome { private void syncHomeAvatarCostume() { Stream.of(this.sceneMap, this.mainHouseMap) - .map(ConcurrentHashMap::values) - .flatMap(Collection::stream) - .map(HomeSceneItem::getBlockItems) - .map(Map::values) - .flatMap(Collection::stream) - .map(HomeBlockItem::getDeployNPCList) - .flatMap(Collection::stream) - .forEach(npc -> npc.setCostumeId(this.getPlayer().getCostumeFrom(npc.getAvatarId()))); + .map(ConcurrentHashMap::values) + .flatMap(Collection::stream) + .map(HomeSceneItem::getBlockItems) + .map(Map::values) + .flatMap(Collection::stream) + .map(HomeBlockItem::getDeployNPCList) + .flatMap(Collection::stream) + .forEach(npc -> npc.setCostumeId(this.getPlayer().getCostumeFrom(npc.getAvatarId()))); } public void save() { diff --git a/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java b/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java index 3fa916e78..69fe9f50a 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeBlockItem.java @@ -67,9 +67,10 @@ public class HomeBlockItem { .map(homeNpcData -> HomeNPCItem.parseFrom(homeNpcData, owner)) .toList(); - this.suiteList = homeBlockArrangementInfo.getFurnitureSuiteListList().stream() - .map(HomeSuiteItem::parseFrom) - .toList(); + this.suiteList = + homeBlockArrangementInfo.getFurnitureSuiteListList().stream() + .map(HomeSuiteItem::parseFrom) + .toList(); } public int calComfort() { @@ -98,7 +99,11 @@ public class HomeBlockItem { public List getMarkPointProtoFactories() { this.reassignIfNull(); - return Stream.of(this.deployFurnitureList, this.persistentFurnitureList, this.deployNPCList, this.suiteList) + return Stream.of( + this.deployFurnitureList, + this.persistentFurnitureList, + this.deployNPCList, + this.suiteList) .flatMap(Collection::stream) .toList(); } diff --git a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java index d49f5650f..c739c077e 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java +++ b/src/main/java/emu/grasscutter/game/home/HomeModuleManager.java @@ -1,7 +1,6 @@ package emu.grasscutter.game.home; import com.github.davidmoten.guavamini.Lists; -import emu.grasscutter.Grasscutter; import emu.grasscutter.game.home.suite.event.HomeAvatarRewardEvent; import emu.grasscutter.game.home.suite.event.HomeAvatarSummonEvent; import emu.grasscutter.game.home.suite.event.SuiteEventType; @@ -12,13 +11,12 @@ import emu.grasscutter.net.proto.HomeAvatarSummonAllEventNotifyOuterClass; import emu.grasscutter.net.proto.RetcodeOuterClass; import emu.grasscutter.server.packet.send.PacketHomeAvatarSummonAllEventNotify; import emu.grasscutter.utils.Either; +import java.util.*; +import java.util.stream.Stream; import lombok.AccessLevel; import lombok.Getter; import lombok.experimental.FieldDefaults; -import java.util.*; -import java.util.stream.Stream; - @Getter @FieldDefaults(level = AccessLevel.PRIVATE) public class HomeModuleManager { @@ -59,31 +57,44 @@ public class HomeModuleManager { private void fireAllAvatarRewardEvent() { this.rewardEvents.clear(); - var allBlockItems = Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) - .map(HomeSceneItem::getBlockItems) - .map(Map::values) - .flatMap(Collection::stream) - .toList(); + var allBlockItems = + Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) + .map(HomeSceneItem::getBlockItems) + .map(Map::values) + .flatMap(Collection::stream) + .toList(); - var suites = allBlockItems.stream() - .map(HomeBlockItem::getSuiteList) - .flatMap(Collection::stream) - .distinct() - .toList(); + var suites = + allBlockItems.stream() + .map(HomeBlockItem::getSuiteList) + .flatMap(Collection::stream) + .distinct() + .toList(); allBlockItems.stream() - .map(HomeBlockItem::getDeployNPCList) - .flatMap(Collection::stream) - .forEach(avatar -> { - suites.forEach(suite -> { - var data = SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom(avatar.getAvatarId(), suite.getSuiteId()); - if (data == null || this.home.isRewardEventFinished(data.getId())) { - return; - } + .map(HomeBlockItem::getDeployNPCList) + .flatMap(Collection::stream) + .forEach( + avatar -> { + suites.forEach( + suite -> { + var data = + SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom( + avatar.getAvatarId(), suite.getSuiteId()); + if (data == null || this.home.isRewardEventFinished(data.getId())) { + return; + } - this.rewardEvents.add(new HomeAvatarRewardEvent(homeOwner, data.getId(), data.getRewardID(), data.getAvatarID(), data.getSuiteId(), suite.getGuid())); - }); - }); + this.rewardEvents.add( + new HomeAvatarRewardEvent( + homeOwner, + data.getId(), + data.getRewardID(), + data.getAvatarID(), + data.getSuiteId(), + suite.getGuid())); + }); + }); if (this.summonEvents != null) { var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList(); @@ -92,14 +103,15 @@ public class HomeModuleManager { } private void cancelSummonEventIfAvatarLeave() { - var avatars = Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) - .map(HomeSceneItem::getBlockItems) - .map(Map::values) - .flatMap(Collection::stream) - .map(HomeBlockItem::getDeployNPCList) - .flatMap(Collection::stream) - .map(HomeNPCItem::getAvatarId) - .toList(); + var avatars = + Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) + .map(HomeSceneItem::getBlockItems) + .map(Map::values) + .flatMap(Collection::stream) + .map(HomeBlockItem::getDeployNPCList) + .flatMap(Collection::stream) + .map(HomeNPCItem::getAvatarId) + .toList(); this.summonEvents.removeIf(event -> !avatars.contains(event.getAvatarId())); } @@ -121,13 +133,16 @@ public class HomeModuleManager { return Either.left(event.giveRewards()); } - public Either fireAvatarSummonEvent(Player owner, int avatarId, int guid, int suiteId) { - var targetSuite = ((HomeScene) owner.getScene()).getSceneItem().getBlockItems().values().stream() - .map(HomeBlockItem::getSuiteList) - .flatMap(Collection::stream) - .filter(suite -> suite.getGuid() == guid) - .findFirst() - .orElse(null); + public Either fireAvatarSummonEvent( + Player owner, int avatarId, int guid, int suiteId) { + var targetSuite = + ((HomeScene) owner.getScene()) + .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); @@ -148,7 +163,9 @@ public class HomeModuleManager { return Either.right(RetcodeOuterClass.Retcode.RET_HOME_CLIENT_PARAM_INVALID_VALUE); } - var event = new HomeAvatarSummonEvent(owner, eventData.getId(), eventData.getRewardID(), avatarId, suiteId, guid); + var event = + new HomeAvatarSummonEvent( + owner, eventData.getId(), eventData.getRewardID(), avatarId, suiteId, guid); this.summonEvents.add(event); owner.sendPacket(new PacketHomeAvatarSummonAllEventNotify(owner)); return Either.left(event); @@ -163,20 +180,21 @@ public class HomeModuleManager { if (!this.rewardEvents.isEmpty()) { notify.setRewardEvent(this.rewardEvents.get(0).toProto()).setIsEventTrigger(true); - notify.addAllPendingList(this.rewardEvents.subList(1, this.rewardEvents.size()).stream() - .map(HomeAvatarRewardEvent::toProto) - .toList()); + notify.addAllPendingList( + this.rewardEvents.subList(1, this.rewardEvents.size()).stream() + .map(HomeAvatarRewardEvent::toProto) + .toList()); } return notify.build(); } - public HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify toSummonEventProto() { + public HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify + toSummonEventProto() { return HomeAvatarSummonAllEventNotifyOuterClass.HomeAvatarSummonAllEventNotify.newBuilder() - .addAllSummonEventList(this.summonEvents.stream() - .map(HomeAvatarSummonEvent::toProto) - .toList()) - .build(); + .addAllSummonEventList( + this.summonEvents.stream().map(HomeAvatarSummonEvent::toProto).toList()) + .build(); } public boolean isInRewardEvent(int avatarId) { diff --git a/src/main/java/emu/grasscutter/game/home/HomeScene.java b/src/main/java/emu/grasscutter/game/home/HomeScene.java index 3c6df4b22..c03247c1d 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeScene.java +++ b/src/main/java/emu/grasscutter/game/home/HomeScene.java @@ -48,10 +48,10 @@ public class HomeScene extends Scene { public void onEnterEditModeFinish() { this.removeEntities( - this.getEntities().values().stream() - .filter(gameEntity -> gameEntity instanceof EntityHomeAnimal) - .toList(), - VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE); + this.getEntities().values().stream() + .filter(gameEntity -> gameEntity instanceof EntityHomeAnimal) + .toList(), + VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE); } public void onLeaveEditMode() { diff --git a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java index 21da833dd..93031537c 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeSceneItem.java @@ -10,16 +10,15 @@ import emu.grasscutter.game.player.Player; import emu.grasscutter.game.world.Position; import emu.grasscutter.game.world.Scene; import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Data; -import lombok.experimental.FieldDefaults; - -import javax.annotation.Nullable; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.annotation.Nullable; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.experimental.FieldDefaults; @Entity @Data diff --git a/src/main/java/emu/grasscutter/game/home/HomeWorld.java b/src/main/java/emu/grasscutter/game/home/HomeWorld.java index 8f871657b..73718925f 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeWorld.java +++ b/src/main/java/emu/grasscutter/game/home/HomeWorld.java @@ -11,10 +11,9 @@ import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify; import emu.grasscutter.server.packet.send.PacketPlayerChatNotify; import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify; -import lombok.Getter; - import java.util.List; import java.util.function.Consumer; +import lombok.Getter; public class HomeWorld extends World { @Getter private final GameHome home; diff --git a/src/main/java/emu/grasscutter/game/home/HomeWorldMPSystem.java b/src/main/java/emu/grasscutter/game/home/HomeWorldMPSystem.java index f0da0bf86..0835975b0 100644 --- a/src/main/java/emu/grasscutter/game/home/HomeWorldMPSystem.java +++ b/src/main/java/emu/grasscutter/game/home/HomeWorldMPSystem.java @@ -212,7 +212,10 @@ public class HomeWorldMPSystem extends BaseGameSystem { player.setCurHomeWorld(myHome); myHome.getHome().onOwnerLogin(player); - player.sendPacket(new PacketPlayerQuitFromHomeNotify(PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason.BACK_TO_MY_WORLD)); + player.sendPacket( + new PacketPlayerQuitFromHomeNotify( + PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason + .BACK_TO_MY_WORLD)); player.sendPacket( new PacketPlayerEnterSceneNotify( player, @@ -261,7 +264,9 @@ public class HomeWorldMPSystem extends BaseGameSystem { victim.setCurHomeWorld(myHome); myHome.getHome().onOwnerLogin(victim); - victim.sendPacket(new PacketPlayerQuitFromHomeNotify(PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason.KICK_BY_HOST)); + victim.sendPacket( + new PacketPlayerQuitFromHomeNotify( + PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason.KICK_BY_HOST)); victim.sendPacket( new PacketPlayerEnterSceneNotify( victim, diff --git a/src/main/java/emu/grasscutter/game/home/suite/HomeSuiteItem.java b/src/main/java/emu/grasscutter/game/home/suite/HomeSuiteItem.java index 263240452..88841e9fb 100644 --- a/src/main/java/emu/grasscutter/game/home/suite/HomeSuiteItem.java +++ b/src/main/java/emu/grasscutter/game/home/suite/HomeSuiteItem.java @@ -7,15 +7,14 @@ import emu.grasscutter.game.world.Position; import emu.grasscutter.net.proto.HomeFurnitureSuiteDataOuterClass; import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass; import emu.grasscutter.net.proto.HomeMarkPointSuiteDataOuterClass; +import java.util.List; +import java.util.Objects; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.experimental.FieldDefaults; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.Objects; - @Entity @Builder(builderMethodName = "of") @Getter @@ -28,38 +27,39 @@ public class HomeSuiteItem implements HomeMarkPointProtoFactory { List includedFurnitureIndexList; boolean isAllowSummon; - public static HomeSuiteItem parseFrom(HomeFurnitureSuiteDataOuterClass.HomeFurnitureSuiteData data) { + public static HomeSuiteItem parseFrom( + HomeFurnitureSuiteDataOuterClass.HomeFurnitureSuiteData data) { return HomeSuiteItem.of() - .guid(data.getGuid()) - .suiteId(data.getSuiteId()) - .pos(new Position(data.getSpawnPos())) - .includedFurnitureIndexList(data.getIncludedFurnitureIndexListList()) - .isAllowSummon(data.getIsAllowSummon()) - .build(); + .guid(data.getGuid()) + .suiteId(data.getSuiteId()) + .pos(new Position(data.getSpawnPos())) + .includedFurnitureIndexList(data.getIncludedFurnitureIndexListList()) + .isAllowSummon(data.getIsAllowSummon()) + .build(); } public HomeFurnitureSuiteDataOuterClass.HomeFurnitureSuiteData toProto() { return HomeFurnitureSuiteDataOuterClass.HomeFurnitureSuiteData.newBuilder() - .setSuiteId(this.suiteId) - .setGuid(this.guid) - .setIsAllowSummon(this.isAllowSummon) - .addAllIncludedFurnitureIndexList(this.includedFurnitureIndexList) - .setSpawnPos(this.pos.toProto()) - .build(); + .setSuiteId(this.suiteId) + .setGuid(this.guid) + .setIsAllowSummon(this.isAllowSummon) + .addAllIncludedFurnitureIndexList(this.includedFurnitureIndexList) + .setSpawnPos(this.pos.toProto()) + .build(); } - @Nullable - @Override + @Nullable @Override public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto() { return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder() - .setFurnitureId(SUITE_FURNITURE_ID) - .setPos(this.pos.toProto()) - .setFurnitureType(this.getType().getValue()) - .setGuid(this.guid) - .setSuiteData(HomeMarkPointSuiteDataOuterClass.HomeMarkPointSuiteData.newBuilder() - .setSuiteId(this.suiteId) - .build()) - .build(); + .setFurnitureId(SUITE_FURNITURE_ID) + .setPos(this.pos.toProto()) + .setFurnitureType(this.getType().getValue()) + .setGuid(this.guid) + .setSuiteData( + HomeMarkPointSuiteDataOuterClass.HomeMarkPointSuiteData.newBuilder() + .setSuiteId(this.suiteId) + .build()) + .build(); } @Override diff --git a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarEvent.java b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarEvent.java index 60a4707f9..06d2fc2a9 100644 --- a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarEvent.java +++ b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarEvent.java @@ -3,13 +3,12 @@ package emu.grasscutter.game.home.suite.event; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; import emu.grasscutter.utils.Utils; +import java.util.List; +import java.util.Objects; import lombok.AccessLevel; import lombok.Getter; import lombok.experimental.FieldDefaults; -import java.util.List; -import java.util.Objects; - @Getter @FieldDefaults(level = AccessLevel.PRIVATE) public abstract class HomeAvatarEvent { @@ -21,7 +20,8 @@ public abstract class HomeAvatarEvent { final int guid; final int randomPos; - public HomeAvatarEvent(Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { + public HomeAvatarEvent( + Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { this.homeOwner = homeOwner; this.eventId = eventId; this.rewardId = rewardId; diff --git a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarRewardEvent.java b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarRewardEvent.java index 651212142..de897faf0 100644 --- a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarRewardEvent.java +++ b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarRewardEvent.java @@ -5,22 +5,22 @@ import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.proto.HomeAvatarRewardEventInfoOuterClass; - import java.util.List; public class HomeAvatarRewardEvent extends HomeAvatarEvent { - public HomeAvatarRewardEvent(Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { + public HomeAvatarRewardEvent( + Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { super(homeOwner, eventId, rewardId, avatarId, suiteId, guid); } public HomeAvatarRewardEventInfoOuterClass.HomeAvatarRewardEventInfo toProto() { return HomeAvatarRewardEventInfoOuterClass.HomeAvatarRewardEventInfo.newBuilder() - .setAvatarId(this.getAvatarId()) - .setEventId(this.getEventId()) - .setGuid(this.getGuid()) - .setSuiteId(this.getSuiteId()) - .setRandomPosition(this.getRandomPos()) - .build(); + .setAvatarId(this.getAvatarId()) + .setEventId(this.getEventId()) + .setGuid(this.getGuid()) + .setSuiteId(this.getSuiteId()) + .setRandomPosition(this.getRandomPos()) + .build(); } @Override diff --git a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarSummonEvent.java b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarSummonEvent.java index 961cfe7ab..f6b9c0b5e 100644 --- a/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarSummonEvent.java +++ b/src/main/java/emu/grasscutter/game/home/suite/event/HomeAvatarSummonEvent.java @@ -13,7 +13,8 @@ public class HomeAvatarSummonEvent extends HomeAvatarEvent { public static final int TIME_LIMIT_SECS = 240; final int eventOverTime; - public HomeAvatarSummonEvent(Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { + public HomeAvatarSummonEvent( + Player homeOwner, int eventId, int rewardId, int avatarId, int suiteId, int guid) { super(homeOwner, eventId, rewardId, avatarId, suiteId, guid); this.eventOverTime = Utils.getCurrentSeconds() + TIME_LIMIT_SECS; @@ -21,13 +22,13 @@ public class HomeAvatarSummonEvent extends HomeAvatarEvent { public HomeAvatarSummonEventInfoOuterClass.HomeAvatarSummonEventInfo toProto() { return HomeAvatarSummonEventInfoOuterClass.HomeAvatarSummonEventInfo.newBuilder() - .setAvatarId(this.getAvatarId()) - .setEventId(this.getEventId()) - .setGuid(this.getGuid()) - .setSuitId(this.getSuiteId()) - .setRandomPosition(this.getRandomPos()) - .setEventOverTime(this.eventOverTime) - .build(); + .setAvatarId(this.getAvatarId()) + .setEventId(this.getEventId()) + .setGuid(this.getGuid()) + .setSuitId(this.getSuiteId()) + .setRandomPosition(this.getRandomPos()) + .setEventOverTime(this.eventOverTime) + .build(); } public boolean isTimeOver() { diff --git a/src/main/java/emu/grasscutter/game/home/suite/event/SuiteEventType.java b/src/main/java/emu/grasscutter/game/home/suite/event/SuiteEventType.java index 8c501f462..6056744e8 100644 --- a/src/main/java/emu/grasscutter/game/home/suite/event/SuiteEventType.java +++ b/src/main/java/emu/grasscutter/game/home/suite/event/SuiteEventType.java @@ -2,18 +2,20 @@ package emu.grasscutter.game.home.suite.event; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.HomeWorldEventData; - import javax.annotation.Nullable; public enum SuiteEventType { HOME_AVATAR_REWARD_EVENT, HOME_AVATAR_SUMMON_EVENT; - @Nullable - public HomeWorldEventData getEventDataFrom(int avatarId, int suiteId) { + @Nullable public HomeWorldEventData getEventDataFrom(int avatarId, int suiteId) { return GameData.getHomeWorldEventDataMap().values().stream() - .filter(data -> data.getEventType() == this && data.getAvatarID() == avatarId && data.getSuiteId() == suiteId) - .findFirst() - .orElse(null); + .filter( + data -> + data.getEventType() == this + && data.getAvatarID() == avatarId + && data.getSuiteId() == suiteId) + .findFirst() + .orElse(null); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarRewardEventGetReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarRewardEventGetReq.java index 6a5482edf..6b616795b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarRewardEventGetReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarRewardEventGetReq.java @@ -16,15 +16,14 @@ public class HandlerHomeAvatarRewardEventGetReq extends PacketHandler { var req = HomeAvatarRewardEventGetReqOuterClass.HomeAvatarRewardEventGetReq.parseFrom(payload); var player = session.getPlayer(); - var rewardsOrError = player.getCurHomeWorld().getModuleManager().claimAvatarRewards(req.getEventId()); + var rewardsOrError = + player.getCurHomeWorld().getModuleManager().claimAvatarRewards(req.getEventId()); session.send(new PacketHomeAvatarRewardEventNotify(player)); session.send(new PacketHomeAvatarAllFinishRewardNotify(player)); session.send( - rewardsOrError.map( - gameItems -> new PacketHomeAvatarRewardEventGetRsp(req.getEventId(), gameItems), - integer -> new PacketHomeAvatarRewardEventGetRsp(req.getEventId(), integer) - ) - ); + rewardsOrError.map( + gameItems -> new PacketHomeAvatarRewardEventGetRsp(req.getEventId(), gameItems), + integer -> new PacketHomeAvatarRewardEventGetRsp(req.getEventId(), integer))); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarSummonEventReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarSummonEventReq.java index c650e0110..ada4476b3 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarSummonEventReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeAvatarSummonEventReq.java @@ -13,7 +13,10 @@ public class HandlerHomeAvatarSummonEventReq extends PacketHandler { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { var req = HomeAvatarSummonEventReqOuterClass.HomeAvatarSummonEventReq.parseFrom(payload); var moduleManager = session.getPlayer().getCurHomeWorld().getModuleManager(); - var eventOrError = moduleManager.fireAvatarSummonEvent(session.getPlayer(), req.getAvatarId(), req.getGuid(), req.getSuitId()); - session.send(eventOrError.map(PacketHomeAvatarSummonEventRsp::new, PacketHomeAvatarSummonEventRsp::new)); + var eventOrError = + moduleManager.fireAvatarSummonEvent( + session.getPlayer(), req.getAvatarId(), req.getGuid(), req.getSuitId()); + session.send( + eventOrError.map(PacketHomeAvatarSummonEventRsp::new, PacketHomeAvatarSummonEventRsp::new)); } } 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 f18e5c141..e05831d40 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java @@ -17,7 +17,7 @@ public class HandlerHomeChangeModuleReq extends PacketHandler { @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { HomeChangeModuleReqOuterClass.HomeChangeModuleReq req = - HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); + HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); var homeWorld = session.getPlayer().getCurHomeWorld(); if (!homeWorld.getGuests().isEmpty()) { diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java index a86e8f32c..4f7e972c7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java @@ -18,20 +18,22 @@ public class HandlerHomeSceneInitFinishReq extends PacketHandler { session.getPlayer().setHasSentInitPacketInHome(true); if (curHomeWorld.getHost().isOnline() - && !curHomeWorld.getHost().equals(session.getPlayer())) { + && !curHomeWorld.getHost().equals(session.getPlayer())) { curHomeWorld - .getHost() - .sendPacket( - new PacketOtherPlayerEnterOrLeaveHomeNotify( - session.getPlayer(), - OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.ENTER)); + .getHost() + .sendPacket( + new PacketOtherPlayerEnterOrLeaveHomeNotify( + session.getPlayer(), + OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.ENTER)); } } - curHomeWorld.ifHost(session.getPlayer(), player -> { - player.sendPacket(new PacketHomeAvatarRewardEventNotify(player)); - player.sendPacket(new PacketHomeAvatarSummonAllEventNotify(player)); - }); + curHomeWorld.ifHost( + session.getPlayer(), + player -> { + player.sendPacket(new PacketHomeAvatarRewardEventNotify(player)); + player.sendPacket(new PacketHomeAvatarSummonAllEventNotify(player)); + }); session.send(new PacketHomeMarkPointNotify(session.getPlayer())); session.send(new PacketHomeSceneInitFinishRsp()); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarAllFinishRewardNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarAllFinishRewardNotify.java index eda4ae116..df07429f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarAllFinishRewardNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarAllFinishRewardNotify.java @@ -11,8 +11,9 @@ public class PacketHomeAvatarAllFinishRewardNotify extends BasePacket { var list = player.getHome().getFinishedRewardEventIdSet(); if (list != null) { - this.setData(HomeAvatarAllFinishRewardNotifyOuterClass.HomeAvatarAllFinishRewardNotify.newBuilder() - .addAllEventIdList(player.getHome().getFinishedRewardEventIdSet())); + this.setData( + HomeAvatarAllFinishRewardNotifyOuterClass.HomeAvatarAllFinishRewardNotify.newBuilder() + .addAllEventIdList(player.getHome().getFinishedRewardEventIdSet())); } } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarRewardEventGetRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarRewardEventGetRsp.java index 73aa4d762..8bff115ec 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarRewardEventGetRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarRewardEventGetRsp.java @@ -4,23 +4,24 @@ import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.HomeAvatarRewardEventGetRspOuterClass; - import java.util.List; public class PacketHomeAvatarRewardEventGetRsp extends BasePacket { public PacketHomeAvatarRewardEventGetRsp(int eventId, List rewards) { super(PacketOpcodes.HomeAvatarRewardEventGetRsp); - this.setData(HomeAvatarRewardEventGetRspOuterClass.HomeAvatarRewardEventGetRsp.newBuilder() - .setEventId(eventId) - .addAllItemList(rewards.stream().map(GameItem::toItemParam).toList())); + this.setData( + HomeAvatarRewardEventGetRspOuterClass.HomeAvatarRewardEventGetRsp.newBuilder() + .setEventId(eventId) + .addAllItemList(rewards.stream().map(GameItem::toItemParam).toList())); } public PacketHomeAvatarRewardEventGetRsp(int eventId, int retcode) { super(PacketOpcodes.HomeAvatarRewardEventGetRsp); - this.setData(HomeAvatarRewardEventGetRspOuterClass.HomeAvatarRewardEventGetRsp.newBuilder() - .setEventId(eventId) - .setRetcode(retcode)); + this.setData( + HomeAvatarRewardEventGetRspOuterClass.HomeAvatarRewardEventGetRsp.newBuilder() + .setEventId(eventId) + .setRetcode(retcode)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonEventRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonEventRsp.java index 6c28fb695..713e45574 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonEventRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonEventRsp.java @@ -9,14 +9,16 @@ public class PacketHomeAvatarSummonEventRsp extends BasePacket { public PacketHomeAvatarSummonEventRsp(HomeAvatarSummonEvent event) { super(PacketOpcodes.HomeAvatarSummonEventRsp); - this.setData(HomeAvatarSummonEventRspOuterClass.HomeAvatarSummonEventRsp.newBuilder() - .setEventId(event.getEventId())); + this.setData( + HomeAvatarSummonEventRspOuterClass.HomeAvatarSummonEventRsp.newBuilder() + .setEventId(event.getEventId())); } public PacketHomeAvatarSummonEventRsp(int retcode) { super(PacketOpcodes.HomeAvatarSummonEventRsp); - this.setData(HomeAvatarSummonEventRspOuterClass.HomeAvatarSummonEventRsp.newBuilder() - .setRetcode(retcode)); + this.setData( + HomeAvatarSummonEventRspOuterClass.HomeAvatarSummonEventRsp.newBuilder() + .setRetcode(retcode)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonFinishRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonFinishRsp.java index 66ad749e4..47be3d18c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonFinishRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAvatarSummonFinishRsp.java @@ -8,7 +8,8 @@ public class PacketHomeAvatarSummonFinishRsp extends BasePacket { public PacketHomeAvatarSummonFinishRsp(int eventId) { super(PacketOpcodes.HomeAvatarSummonFinishRsp); - this.setData(HomeAvatarSummonFinishRspOuterClass.HomeAvatarSummonFinishRsp.newBuilder() - .setEventId(eventId)); + this.setData( + HomeAvatarSummonFinishRspOuterClass.HomeAvatarSummonFinishRsp.newBuilder() + .setEventId(eventId)); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerQuitFromHomeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerQuitFromHomeNotify.java index 2c5a82332..be2a61763 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerQuitFromHomeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerQuitFromHomeNotify.java @@ -5,10 +5,11 @@ import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.PlayerQuitFromHomeNotifyOuterClass; public class PacketPlayerQuitFromHomeNotify extends BasePacket { - public PacketPlayerQuitFromHomeNotify(PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason reason) { + public PacketPlayerQuitFromHomeNotify( + PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.QuitReason reason) { super(PacketOpcodes.PlayerQuitFromHomeNotify); - this.setData(PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.newBuilder() - .setReason(reason)); + this.setData( + PlayerQuitFromHomeNotifyOuterClass.PlayerQuitFromHomeNotify.newBuilder().setReason(reason)); } } diff --git a/src/main/java/emu/grasscutter/utils/Either.java b/src/main/java/emu/grasscutter/utils/Either.java index b976fdfbd..533340a3c 100644 --- a/src/main/java/emu/grasscutter/utils/Either.java +++ b/src/main/java/emu/grasscutter/utils/Either.java @@ -14,7 +14,8 @@ public abstract class Either { } @Override - public Either mapBoth(Function f1, Function f2) { + public Either mapBoth( + Function f1, Function f2) { return new Left<>(f1.apply(this.value)); } @@ -71,7 +72,8 @@ public abstract class Either { } @Override - public Either mapBoth(Function f1, Function f2) { + public Either mapBoth( + Function f1, Function f2) { return new Right<>(f2.apply(this.value)); } @@ -120,10 +122,10 @@ public abstract class Either { } } - private Either() { - } + private Either() {} - public abstract Either mapBoth(Function f1, Function f2); + public abstract Either mapBoth( + Function f1, Function f2); public abstract T map(Function l, Function r);