Commit 3ea9e157 authored by Melledy's avatar Melledy
Browse files

Make co-op players spawn into the host's scene too

parent dd8d1752
...@@ -58,25 +58,25 @@ public class MultiplayerManager { ...@@ -58,25 +58,25 @@ public class MultiplayerManager {
target.sendPacket(new PacketPlayerApplyEnterMpNotify(player)); target.sendPacket(new PacketPlayerApplyEnterMpNotify(player));
} }
public void applyEnterMpReply(GenshinPlayer player, int applyUid, boolean isAgreed) { public void applyEnterMpReply(GenshinPlayer hostPlayer, int applyUid, boolean isAgreed) {
// Checks // Checks
CoopRequest request = player.getCoopRequests().get(applyUid); CoopRequest request = hostPlayer.getCoopRequests().get(applyUid);
if (request == null || request.isExpired()) { if (request == null || request.isExpired()) {
return; return;
} }
// Remove now that we are handling it // Remove now that we are handling it
GenshinPlayer requester = request.getRequester(); GenshinPlayer requester = request.getRequester();
player.getCoopRequests().remove(applyUid); hostPlayer.getCoopRequests().remove(applyUid);
// Sanity checks - Dont let player join if already in multiplayer // Sanity checks - Dont let the requesting player join if they are already in multiplayer
if (requester.getWorld().isMultiplayer()) { if (requester.getWorld().isMultiplayer()) {
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(player, false, PlayerApplyEnterMpReason.PlayerCannotEnterMp)); request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(hostPlayer, false, PlayerApplyEnterMpReason.PlayerCannotEnterMp));
return; return;
} }
// Response packet // Response packet
request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(player, isAgreed, PlayerApplyEnterMpReason.PlayerJudge)); request.getRequester().sendPacket(new PacketPlayerApplyEnterMpResultNotify(hostPlayer, isAgreed, PlayerApplyEnterMpReason.PlayerJudge));
// Declined // Declined
if (!isAgreed) { if (!isAgreed) {
...@@ -84,24 +84,27 @@ public class MultiplayerManager { ...@@ -84,24 +84,27 @@ public class MultiplayerManager {
} }
// Success // Success
if (!player.getWorld().isMultiplayer()) { if (!hostPlayer.getWorld().isMultiplayer()) {
// Player not in multiplayer, create multiplayer world // Player not in multiplayer, create multiplayer world
World world = new World(player, true); World world = new World(hostPlayer, true);
// Add // Add
world.addPlayer(player); world.addPlayer(hostPlayer);
// Rejoin packet // Rejoin packet
player.sendPacket(new PacketPlayerEnterSceneNotify(player, player, EnterType.EnterSelf, EnterReason.HostFromSingleToMp, player.getScene().getId(), player.getPos())); hostPlayer.sendPacket(new PacketPlayerEnterSceneNotify(hostPlayer, hostPlayer, EnterType.EnterSelf, EnterReason.HostFromSingleToMp, hostPlayer.getScene().getId(), hostPlayer.getPos()));
} }
// Make requester join // Make requester join
player.getWorld().addPlayer(requester); hostPlayer.getWorld().addPlayer(requester);
// Set scene pos and id of requester to the host player's
requester.getPos().set(hostPlayer.getPos());
requester.getRotation().set(hostPlayer.getRotation());
requester.setSceneId(hostPlayer.getSceneId());
// Packet // Packet
requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, player, EnterType.EnterOther, EnterReason.TeamJoin, player.getScene().getId(), player.getPos())); requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.EnterOther, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPos()));
requester.getPos().set(player.getPos());
requester.getRotation().set(player.getRotation());
} }
public boolean leaveCoop(GenshinPlayer player) { public boolean leaveCoop(GenshinPlayer player) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment