Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
KingRainbow44 committed Sep 2, 2023
2 parents 70ee3ed + 88d7be8 commit 34589d0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
18 changes: 8 additions & 10 deletions src/main/java/emu/grasscutter/game/home/HomeSceneItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import emu.grasscutter.game.world.Position;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.*;
import lombok.experimental.FieldDefaults;

Expand Down Expand Up @@ -84,17 +83,16 @@ public boolean isRoom() {
return mainHouse == null || mainHouse.getAsItem() == null;
}

@Nullable
public Position getTeleportPointPos(int guid) {
@Nullable public Position getTeleportPointPos(int guid) {
var pos = new AtomicReference<Position>();

this.getBlockItems().values().stream()
.map(HomeBlockItem::getDeployFurnitureList)
.flatMap(Collection::stream)
.filter(homeFurnitureItem -> homeFurnitureItem.getGuid() == guid)
.map(HomeFurnitureItem::getSpawnPos)
.findFirst()
.ifPresent(pos::set);
.map(HomeBlockItem::getDeployFurnitureList)
.flatMap(Collection::stream)
.filter(homeFurnitureItem -> homeFurnitureItem.getGuid() == guid)
.map(HomeFurnitureItem::getSpawnPos)
.findFirst()
.ifPresent(pos::set);

return pos.get();
}
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/emu/grasscutter/game/home/HomeWorldMPSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public void enterHome(Player requester, Player owner, int teleportPoint, boolean
int realmId = 2000 + owner.getCurrentRealmId();
var item = targetHome.getHomeSceneItem(realmId);
targetHome.save();
var pos = toSafe ? world.getSceneById(realmId).getScriptManager().getConfig().born_pos : item.getBornPos();
var pos =
toSafe
? world.getSceneById(realmId).getScriptManager().getConfig().born_pos
: item.getBornPos();

if (teleportPoint != 0) {
var target = item.getTeleportPointPos(teleportPoint);
Expand Down Expand Up @@ -202,12 +205,23 @@ public boolean leaveCoop(Player player, int prevScene, Position pos) {
player.getPosition().set(pos);
var world = new World(player);
world.addPlayer(player, prevScene);
player.getCurHomeWorld().sendPacketToHostIfOnline(new PacketOtherPlayerEnterOrLeaveHomeNotify(player, OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.LEAVE));
player
.getCurHomeWorld()
.sendPacketToHostIfOnline(
new PacketOtherPlayerEnterOrLeaveHomeNotify(
player,
OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.LEAVE));
var myHome = this.server.getHomeWorldOrCreate(player);
player.setCurHomeWorld(myHome);
myHome.getHome().onOwnerLogin(player);

player.sendPacket(new PacketPlayerEnterSceneNotify(player, EnterTypeOuterClass.EnterType.ENTER_TYPE_BACK, EnterReason.TeamBack, prevScene, pos));
player.sendPacket(
new PacketPlayerEnterSceneNotify(
player,
EnterTypeOuterClass.EnterType.ENTER_TYPE_BACK,
EnterReason.TeamBack,
prevScene,
pos));

return true;
}
Expand Down Expand Up @@ -239,7 +253,12 @@ public boolean kickPlayerFromHome(Player owner, int targetUid) {
victim.getPosition().set(victim.getPrevPosForHome());
var world = new World(victim);
world.addPlayer(victim, 3);
victim.getCurHomeWorld().sendPacketToHostIfOnline(new PacketOtherPlayerEnterOrLeaveHomeNotify(victim, OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.LEAVE));
victim
.getCurHomeWorld()
.sendPacketToHostIfOnline(
new PacketOtherPlayerEnterOrLeaveHomeNotify(
victim,
OtherPlayerEnterHomeNotifyOuterClass.OtherPlayerEnterHomeNotify.Reason.LEAVE));
var myHome = this.server.getHomeWorldOrCreate(victim);
victim.setCurHomeWorld(myHome);
myHome.getHome().onOwnerLogin(victim);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex
var home = player.getCurHomeWorld().getHome();
var item = home.getHomeSceneItem(player.getSceneId());

var pos = req.getIsTransferToMainHousePoint() ? item.getBornPos() : player.getCurHomeWorld().getSceneById(player.getSceneId()).getScriptManager().getConfig().born_pos;
var pos =
req.getIsTransferToMainHousePoint()
? item.getBornPos()
: player
.getCurHomeWorld()
.getSceneById(player.getSceneId())
.getScriptManager()
.getConfig()
.born_pos;
if (req.getGuid() != 0) {
var target = item.getTeleportPointPos(req.getGuid());
if (target != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,29 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex
req.getTargetUid()));
}

case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption.FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE -> {
session.getServer().getHomeWorldMPSystem().enterHome(session.getPlayer(), targetPlayer, req.getTargetPoint(), req.getIsTransferToSafePoint());

case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption
.FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE -> {
session
.getServer()
.getHomeWorldMPSystem()
.enterHome(
session.getPlayer(),
targetPlayer,
req.getTargetPoint(),
req.getIsTransferToSafePoint());
}
}

return;
}

session.getServer().getHomeWorldMPSystem().enterHome(session.getPlayer(), targetPlayer, req.getTargetPoint(), req.getIsTransferToSafePoint());
session
.getServer()
.getHomeWorldMPSystem()
.enterHome(
session.getPlayer(),
targetPlayer,
req.getTargetPoint(),
req.getIsTransferToSafePoint());
}
}

0 comments on commit 34589d0

Please sign in to comment.