Skip to content

Commit

Permalink
Format code [skip actions]
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 10, 2023
1 parent f1c1a84 commit 13c40b5
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 135 deletions.
27 changes: 16 additions & 11 deletions src/main/java/emu/grasscutter/game/home/GameHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
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;
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
Expand All @@ -39,8 +38,9 @@ public class GameHome {
.map(SceneData::getId)
.collect(Collectors.toUnmodifiableSet());
public static final Set<Integer> HOME_MODULE_IDS =
GameData.getHomeWorldModuleDataMap().isEmpty() ?
IntSets.fromTo(1, 6) : GameData.getHomeWorldModuleDataMap().keySet();
GameData.getHomeWorldModuleDataMap().isEmpty()
? IntSets.fromTo(1, 6)
: GameData.getHomeWorldModuleDataMap().keySet();

@Id String id;

Expand Down Expand Up @@ -205,7 +205,9 @@ private void fixModuleIdIfInvalid() {
return;
}

this.player.getRealmList().removeIf(integer -> !HOME_MODULE_IDS.contains(integer)); // Delete invalid module ids.
this.player
.getRealmList()
.removeIf(integer -> !HOME_MODULE_IDS.contains(integer)); // Delete invalid module ids.

if (this.player.getRealmList().isEmpty()) {
this.player.setRealmList(null);
Expand All @@ -217,7 +219,11 @@ private void fixModuleIdIfInvalid() {
int firstRId = this.player.getRealmList().iterator().next();
this.player.setCurrentRealmId(firstRId);
this.player.save();
Grasscutter.getLogger().info("Set player {}'s current realm id to {} cuz the id is invalid.", this.player.getUid(), firstRId);
Grasscutter.getLogger()
.info(
"Set player {}'s current realm id to {} cuz the id is invalid.",
this.player.getUid(),
firstRId);
}

this.player.getCurHomeWorld().refreshModuleManager(); // Apply module id fix.
Expand Down Expand Up @@ -268,8 +274,7 @@ public Set<Integer> onTalkedWithAvatar(int avatarId, int talkId) {
return this.finishedTalkIdMap.get(avatarId);
}

public List<HomeAvatarTalkFinishInfo>
toAvatarTalkFinishInfoProto() {
public List<HomeAvatarTalkFinishInfo> toAvatarTalkFinishInfoProto() {
if (this.finishedTalkIdMap == null) {
this.finishedTalkIdMap = new HashMap<>();
}
Expand Down
137 changes: 66 additions & 71 deletions src/main/java/emu/grasscutter/game/home/HomeModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,22 @@
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.server.packet.send.PacketHomeAvatarSummonAllEventNotify;
import emu.grasscutter.utils.Either;
import java.util.*;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.FieldDefaults;

import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Stream;

@Getter
@FieldDefaults(level = AccessLevel.PRIVATE)
public class HomeModuleManager {
final Player homeOwner;
final HomeWorld homeWorld;
final GameHome home;
final int moduleId;
@Nullable
final HomeScene outdoor;
@Nullable
HomeScene indoor;
@Nullable final HomeScene outdoor;
@Nullable HomeScene indoor;
final List<HomeAvatarRewardEvent> rewardEvents;
final List<HomeAvatarSummonEvent> summonEvents;

Expand Down Expand Up @@ -77,45 +74,45 @@ public void onUpdateArrangement() {
private void fireAllAvatarRewardEvents() {
this.rewardEvents.clear();
var allBlockItems =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.filter(Objects::nonNull)
.map(HomeSceneItem::getBlockItems)
.map(Map::values)
.flatMap(Collection::stream)
.toList();
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.filter(Objects::nonNull)
.map(HomeSceneItem::getBlockItems)
.map(Map::values)
.flatMap(Collection::stream)
.toList();

var suites =
allBlockItems.stream()
.map(HomeBlockItem::getSuiteList)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.distinct()
.toList();
allBlockItems.stream()
.map(HomeBlockItem::getSuiteList)
.filter(Objects::nonNull)
.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;
}

this.rewardEvents.add(
new HomeAvatarRewardEvent(
homeOwner,
data.getId(),
data.getRewardID(),
data.getAvatarID(),
data.getSuiteId(),
suite.getGuid()));
.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()));
});
});
});

if (this.summonEvents != null) {
var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList();
Expand All @@ -125,15 +122,15 @@ private void fireAllAvatarRewardEvents() {

private void cancelSummonEventsIfAvatarLeave() {
var avatars =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.filter(Objects::nonNull)
.map(HomeSceneItem::getBlockItems)
.map(Map::values)
.flatMap(Collection::stream)
.map(HomeBlockItem::getDeployNPCList)
.flatMap(Collection::stream)
.map(HomeNPCItem::getAvatarId)
.toList();
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.filter(Objects::nonNull)
.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()));
}
Expand All @@ -156,16 +153,16 @@ public Either<List<GameItem>, Integer> claimAvatarRewards(int eventId) {
}

public Either<HomeAvatarSummonEvent, Integer> fireAvatarSummonEvent(
Player owner, int avatarId, int guid, int suiteId) {
Player owner, int avatarId, int guid, int suiteId) {
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);
targetSuite =
homeScene.getSceneItem().getBlockItems().values().stream()
.map(HomeBlockItem::getSuiteList)
.flatMap(Collection::stream)
.filter(suite -> suite.getGuid() == guid)
.findFirst()
.orElse(null);
}

if (this.isInRewardEvent(avatarId)) {
Expand All @@ -188,8 +185,8 @@ public Either<HomeAvatarSummonEvent, Integer> fireAvatarSummonEvent(
}

var event =
new HomeAvatarSummonEvent(
owner, eventData.getId(), eventData.getRewardID(), avatarId, suiteId, guid);
new HomeAvatarSummonEvent(
owner, eventData.getId(), eventData.getRewardID(), avatarId, suiteId, guid);
this.summonEvents.add(event);
owner.sendPacket(new PacketHomeAvatarSummonAllEventNotify(owner));
return Either.left(event);
Expand All @@ -205,32 +202,30 @@ public HomeAvatarRewardEventNotify toRewardEventProto() {
notify.setRewardEvent(this.rewardEvents.get(0).toProto()).setIsEventTrigger(true);

notify.addAllPendingList(
this.rewardEvents.subList(1, this.rewardEvents.size()).stream()
.map(HomeAvatarRewardEvent::toProto)
.toList());
this.rewardEvents.subList(1, this.rewardEvents.size()).stream()
.map(HomeAvatarRewardEvent::toProto)
.toList());
}

return notify.build();
}

public HomeAvatarSummonAllEventNotify toSummonEventProto() {
return 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) {
return this.rewardEvents.stream().anyMatch(e -> e.getAvatarId() == avatarId);
}

@Nullable
public HomeSceneItem getOutdoorSceneItem() {
@Nullable public HomeSceneItem getOutdoorSceneItem() {
return this.outdoor == null ? null : this.outdoor.getSceneItem();
}

@Nullable
public HomeSceneItem getIndoorSceneItem() {
@Nullable public HomeSceneItem getIndoorSceneItem() {
return this.indoor == null ? null : this.indoor.getSceneItem();
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/emu/grasscutter/game/home/HomeWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
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 javax.annotation.Nullable;
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import lombok.Getter;

@Getter
public class HomeWorld extends World {
Expand Down Expand Up @@ -170,8 +169,7 @@ public synchronized void removePlayer(Player player) {
}

@Override
@Nullable
public HomeScene getSceneById(int sceneId) {
@Nullable public HomeScene getSceneById(int sceneId) {
var scene = this.getScenes().get(sceneId);
if (scene instanceof HomeScene homeScene) {
return homeScene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ public void enterHome(Player requester, Player owner, int teleportPoint, boolean

Position pos;
if (scene != null) {
pos =
toSafe
? scene.getScriptManager().getConfig().born_pos
: item.getBornPos();
pos = toSafe ? scene.getScriptManager().getConfig().born_pos : item.getBornPos();
} else {
pos = item.getBornPos();
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/emu/grasscutter/game/world/World.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package emu.grasscutter.game.world;

import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.dungeon.DungeonData;
Expand Down Expand Up @@ -27,11 +29,6 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand All @@ -40,8 +37,10 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.NotNull;

public class World implements Iterable<Player> {
@Getter private final GameServer server;
Expand Down Expand Up @@ -140,8 +139,7 @@ protected synchronized void setHost(Player host) {
* @param sceneId The scene ID.
* @return The scene.
*/
@Nullable
public Scene getSceneById(int sceneId) {
@Nullable public Scene getSceneById(int sceneId) {
// Get scene normally
var scene = this.getScenes().get(sceneId);
if (scene != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex
pos = home.getSceneMap().get(realmId).getBornPos();
}

world.transferPlayerToScene(
session.getPlayer(), scene.getId(), pos);
world.transferPlayerToScene(session.getPlayer(), scene.getId(), pos);

session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ public class PacketHomeChangeModuleRsp extends BasePacket {
public PacketHomeChangeModuleRsp(int targetModuleId) {
super(PacketOpcodes.HomeChangeModuleRsp);

var proto = HomeChangeModuleRsp.newBuilder()
.setRetcode(0)
.setTargetModuleId(targetModuleId)
.build();
var proto =
HomeChangeModuleRsp.newBuilder().setRetcode(0).setTargetModuleId(targetModuleId).build();

this.setData(proto);
}

public PacketHomeChangeModuleRsp(Retcode retcode) {
super(PacketOpcodes.HomeChangeModuleRsp);

this.setData(HomeChangeModuleRsp.newBuilder()
.setRetcode(retcode.getNumber()));
this.setData(HomeChangeModuleRsp.newBuilder().setRetcode(retcode.getNumber()));
}
}
Loading

0 comments on commit 13c40b5

Please sign in to comment.