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 Sep 8, 2023
1 parent fc42f66 commit cdcdf92
Show file tree
Hide file tree
Showing 24 changed files with 238 additions and 186 deletions.
21 changes: 17 additions & 4 deletions src/main/java/emu/grasscutter/data/excels/HomeWorldEventData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@
@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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
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;
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/emu/grasscutter/game/home/GameHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
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
Expand Down Expand Up @@ -91,10 +90,10 @@ public static GameHome create(Integer uid) {
// 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.
Expand All @@ -114,14 +113,14 @@ private void fixMainHouseIfOld() {

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() {
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/emu/grasscutter/game/home/HomeBlockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public void update(HomeBlockArrangementInfo homeBlockArrangementInfo, Player own
.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() {
Expand Down Expand Up @@ -98,7 +99,11 @@ public HomeBlockArrangementInfo toProto() {
public List<? extends HomeMarkPointProtoFactory> 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();
}
Expand Down
120 changes: 69 additions & 51 deletions src/main/java/emu/grasscutter/game/home/HomeModuleManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,13 +11,12 @@
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 {
Expand Down Expand Up @@ -59,31 +57,44 @@ public void onUpdateArrangement() {

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 suites = allBlockItems.stream()
.map(HomeBlockItem::getSuiteList)
.flatMap(Collection::stream)
.distinct()
.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();

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 @@ -92,14 +103,15 @@ private void fireAllAvatarRewardEvent() {
}

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()));
}
Expand All @@ -121,13 +133,16 @@ public Either<List<GameItem>, Integer> claimAvatarRewards(int eventId) {
return Either.left(event.giveRewards());
}

public Either<HomeAvatarSummonEvent, Integer> 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<HomeAvatarSummonEvent, Integer> 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);
Expand All @@ -148,7 +163,9 @@ public Either<HomeAvatarSummonEvent, Integer> fireAvatarSummonEvent(Player owner
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);
Expand All @@ -163,20 +180,21 @@ public HomeAvatarRewardEventNotifyOuterClass.HomeAvatarRewardEventNotify toRewar
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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/emu/grasscutter/game/home/HomeScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public void onTick() {

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() {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/emu/grasscutter/game/home/HomeSceneItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
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
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/emu/grasscutter/game/home/HomeWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public boolean leaveCoop(Player player, int prevScene, Position pos) {
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,
Expand Down Expand Up @@ -261,7 +264,9 @@ public boolean kickPlayerFromHome(Player owner, int targetUid) {
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,
Expand Down
Loading

0 comments on commit cdcdf92

Please sign in to comment.