Format code [skip actions]

This commit is contained in:
github-actions 2023-11-10 02:57:50 +00:00
parent f1c1a84683
commit 13c40b53a7
8 changed files with 124 additions and 134 deletions

View File

@ -13,17 +13,16 @@ import emu.grasscutter.net.proto.HomeAvatarTalkFinishInfoOuterClass.HomeAvatarTa
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
@ -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;
@ -205,7 +205,9 @@ public class GameHome {
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);
@ -217,7 +219,11 @@ public class GameHome {
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.
@ -268,8 +274,7 @@ public class GameHome {
return this.finishedTalkIdMap.get(avatarId);
}
public List<HomeAvatarTalkFinishInfo>
toAvatarTalkFinishInfoProto() {
public List<HomeAvatarTalkFinishInfo> toAvatarTalkFinishInfoProto() {
if (this.finishedTalkIdMap == null) {
this.finishedTalkIdMap = new HashMap<>();
}

View File

@ -12,14 +12,13 @@ import emu.grasscutter.net.proto.HomeAvatarSummonAllEventNotifyOuterClass.HomeAv
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 {
@ -27,10 +26,8 @@ public class HomeModuleManager {
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;
@ -77,45 +74,45 @@ public class HomeModuleManager {
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;
}
.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();
@ -125,15 +122,15 @@ public class HomeModuleManager {
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()));
}
@ -156,16 +153,16 @@ public class HomeModuleManager {
}
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)) {
@ -188,8 +185,8 @@ public class HomeModuleManager {
}
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);
@ -205,9 +202,9 @@ public class HomeModuleManager {
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();
@ -215,22 +212,20 @@ public class HomeModuleManager {
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();
}

View File

@ -10,11 +10,10 @@ 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 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 {
@ -170,8 +169,7 @@ public class HomeWorld extends World {
}
@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;

View File

@ -144,10 +144,7 @@ public class HomeWorldMPSystem extends BaseGameSystem {
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();
}

View File

@ -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;
@ -27,11 +29,6 @@ import io.netty.util.concurrent.FastThreadLocalThread;
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;
@ -40,8 +37,10 @@ import java.util.concurrent.ExecutorService;
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;
@ -140,8 +139,7 @@ public class World implements Iterable<Player> {
* @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) {

View File

@ -34,8 +34,7 @@ public class HandlerHomeSceneJumpReq extends PacketHandler {
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()));
}

View File

@ -10,10 +10,8 @@ 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);
}
@ -21,7 +19,6 @@ public class PacketHomeChangeModuleRsp extends BasePacket {
public PacketHomeChangeModuleRsp(Retcode retcode) {
super(PacketOpcodes.HomeChangeModuleRsp);
this.setData(HomeChangeModuleRsp.newBuilder()
.setRetcode(retcode.getNumber()));
this.setData(HomeChangeModuleRsp.newBuilder().setRetcode(retcode.getNumber()));
}
}

View File

@ -8,7 +8,6 @@ import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass.HomeMarkPointNotify;
import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData;
import java.util.Collection;
import java.util.Set;
@ -30,41 +29,43 @@ public class PacketHomeMarkPointNotify extends BasePacket {
var moduleId = owner.getCurrentRealmId();
var scene = world.getSceneById(moduleId + 2000);
if (scene == null) {
Grasscutter.getLogger().warn("Current Realm id is invalid! SceneExcelConfigData.json, game resource not loaded correctly or the realm id maybe wrong?!");
Grasscutter.getLogger()
.warn(
"Current Realm id is invalid! SceneExcelConfigData.json, game resource not loaded correctly or the realm id maybe wrong?!");
return;
}
var homeScene = home.getHomeSceneItem(moduleId + 2000);
var mainHouse = home.getMainHouseItem(moduleId + 2000);
Set.of(homeScene, mainHouse)
.forEach(
homeSceneItem -> {
var markPointData =
HomeMarkPointSceneData.newBuilder()
.setModuleId(moduleId)
.setSceneId(homeSceneItem.getSceneId());
.forEach(
homeSceneItem -> {
var markPointData =
HomeMarkPointSceneData.newBuilder()
.setModuleId(moduleId)
.setSceneId(homeSceneItem.getSceneId());
if (!homeSceneItem.isRoom()) {
var config = scene.getScriptManager().getConfig();
markPointData
.setSafePointPos(
config == null
? homeSceneItem.getBornPos().toProto()
: config.born_pos.toProto())
.setTeapotSpiritPos(homeSceneItem.getDjinnPos().toProto());
}
if (!homeSceneItem.isRoom()) {
var config = scene.getScriptManager().getConfig();
markPointData
.setSafePointPos(
config == null
? homeSceneItem.getBornPos().toProto()
: config.born_pos.toProto())
.setTeapotSpiritPos(homeSceneItem.getDjinnPos().toProto());
}
var marks =
homeSceneItem.getBlockItems().values().stream()
.map(HomeBlockItem::getMarkPointProtoFactories)
.flatMap(Collection::stream)
.filter(HomeMarkPointProtoFactory::isProtoConvertible)
.map(HomeMarkPointProtoFactory::toMarkPointProto)
.toList();
var marks =
homeSceneItem.getBlockItems().values().stream()
.map(HomeBlockItem::getMarkPointProtoFactories)
.flatMap(Collection::stream)
.filter(HomeMarkPointProtoFactory::isProtoConvertible)
.map(HomeMarkPointProtoFactory::toMarkPointProto)
.toList();
markPointData.addAllFurnitureList(marks);
proto.addMarkPointDataList(markPointData);
});
markPointData.addAllFurnitureList(marks);
proto.addMarkPointDataList(markPointData);
});
this.setData(proto);
}