mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 18:54:37 +01:00
Implement entering rogue portals
This commit is contained in:
@@ -54,7 +54,7 @@ public class RogueEntityLoader extends SceneEntityLoader {
|
||||
PropRogueData propExtra = null;
|
||||
|
||||
// Rogue Door id is 1000
|
||||
if (propId == 1000) {
|
||||
if (propId == 1000 || propId == 1021) {
|
||||
// Site index
|
||||
int index = 0;
|
||||
|
||||
|
||||
@@ -4,12 +4,15 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import emu.lunarcore.data.config.AnchorInfo;
|
||||
import emu.lunarcore.data.excel.RogueAreaExcel;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.RogueCurrentInfoOuterClass.RogueCurrentInfo;
|
||||
import emu.lunarcore.proto.RogueMapInfoOuterClass.RogueMapInfo;
|
||||
import emu.lunarcore.proto.RogueRoomStatusOuterClass.RogueRoomStatus;
|
||||
import emu.lunarcore.proto.RogueStatusOuterClass.RogueStatus;
|
||||
import emu.lunarcore.server.packet.send.PacketSyncRogueMapRoomScNotify;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -19,6 +22,7 @@ public class RogueInstance {
|
||||
|
||||
private int currentRoomProgress;
|
||||
private int currentSiteId;
|
||||
private int startSiteId;
|
||||
private Set<Integer> baseAvatarIds;
|
||||
private TreeMap<Integer, RogueRoomData> rooms;
|
||||
|
||||
@@ -45,18 +49,61 @@ public class RogueInstance {
|
||||
this.rooms.put(roomData.getSiteId(), roomData);
|
||||
|
||||
if (mapExcel.isIsStart()) {
|
||||
this.setCurrentRoom(roomData);
|
||||
this.startSiteId = roomData.getSiteId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentRoom(RogueRoomData roomData) {
|
||||
this.currentSiteId = roomData.getSiteId();
|
||||
roomData.setStatus(RogueRoomStatus.ROGUE_ROOM_STATUS_PLAY); // TODO reset when changing rooms
|
||||
private RogueRoomData getRoomBySiteId(int siteId) {
|
||||
return this.rooms.get(siteId);
|
||||
}
|
||||
|
||||
public RogueRoomData getCurrentRoom() {
|
||||
return this.rooms.get(this.getCurrentSiteId());
|
||||
return this.getRoomBySiteId(this.getCurrentSiteId());
|
||||
}
|
||||
|
||||
public RogueRoomData enterRoom(int siteId) {
|
||||
// Set status on previous room
|
||||
RogueRoomData prevRoom = getCurrentRoom();
|
||||
if (prevRoom != null) {
|
||||
// Make sure the site we want to go into is connected to the current room we are in
|
||||
if (!Utils.arrayContains(prevRoom.getNextSiteIds(), siteId)) {
|
||||
return null;
|
||||
}
|
||||
// Update status
|
||||
prevRoom.setStatus(RogueRoomStatus.ROGUE_ROOM_STATUS_FINISH);
|
||||
}
|
||||
|
||||
// Get next room
|
||||
RogueRoomData nextRoom = this.getRoomBySiteId(siteId);
|
||||
if (nextRoom == null) return null;
|
||||
|
||||
// Enter room
|
||||
this.currentSiteId = nextRoom.getSiteId();
|
||||
nextRoom.setStatus(RogueRoomStatus.ROGUE_ROOM_STATUS_PLAY);
|
||||
|
||||
// Enter scene
|
||||
boolean success = getPlayer().enterScene(nextRoom.getRoomExcel().getMapEntrance(), 0, false);
|
||||
if (!success) return null;
|
||||
|
||||
// Move player to rogue start position
|
||||
AnchorInfo anchor = getPlayer().getScene().getFloorInfo().getAnchorInfo(nextRoom.getExcel().getGroupID(), 1);
|
||||
if (anchor != null) {
|
||||
getPlayer().getPos().set(anchor.getPos());
|
||||
getPlayer().getRot().set(anchor.getRot());
|
||||
}
|
||||
|
||||
// Load scene groups. THIS NEEDS TO BE LAST
|
||||
for (int key : nextRoom.getExcel().getGroupWithContent().keySet()) {
|
||||
getPlayer().getScene().loadGroup(key);
|
||||
}
|
||||
|
||||
// Send packet if we are not entering the rogue instance for the first time
|
||||
if (prevRoom != null) {
|
||||
getPlayer().sendPacket(new PacketSyncRogueMapRoomScNotify(this, nextRoom));
|
||||
}
|
||||
|
||||
return nextRoom;
|
||||
}
|
||||
|
||||
// Serialization
|
||||
|
||||
@@ -6,8 +6,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.config.AnchorInfo;
|
||||
import emu.lunarcore.data.excel.RogueRoomExcel;
|
||||
import emu.lunarcore.game.player.BasePlayerManager;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.player.PlayerLineup;
|
||||
@@ -52,11 +50,10 @@ public class RogueManager extends BasePlayerManager {
|
||||
getPlayer().sendPacket(new PacketStartRogueScRsp());
|
||||
return;
|
||||
}
|
||||
|
||||
// Get entrance id
|
||||
// Get entrance id
|
||||
RogueInstance data = new RogueInstance(getPlayer(), excel);
|
||||
getPlayer().setRogueInstance(data);
|
||||
|
||||
|
||||
// Reset hp/sp
|
||||
lineup.forEachAvatar(avatar -> {
|
||||
avatar.setCurrentHp(lineup, 10000);
|
||||
@@ -69,10 +66,10 @@ public class RogueManager extends BasePlayerManager {
|
||||
// Set first lineup before we enter scenes
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_ROGUE, false);
|
||||
|
||||
// Enter scene
|
||||
int entranceId = data.getCurrentRoom().getRoomExcel().getMapEntrance();
|
||||
boolean success = getPlayer().enterScene(entranceId, 0, false);
|
||||
if (!success) {
|
||||
// Enter rogue
|
||||
RogueRoomData room = data.enterRoom(data.getStartSiteId());
|
||||
|
||||
if (room == null) {
|
||||
// Reset lineup/instance if entering scene failed
|
||||
getPlayer().getLineupManager().setCurrentExtraLineup(0, false);
|
||||
getPlayer().setRogueInstance(null);
|
||||
@@ -80,21 +77,6 @@ public class RogueManager extends BasePlayerManager {
|
||||
getPlayer().sendPacket(new PacketStartRogueScRsp());
|
||||
return;
|
||||
}
|
||||
|
||||
// Get room excel
|
||||
RogueRoomExcel roomExcel = data.getCurrentRoom().getExcel();
|
||||
|
||||
// Move player to rogue start position
|
||||
AnchorInfo anchor = getPlayer().getScene().getFloorInfo().getAnchorInfo(roomExcel.getGroupID(), 1);
|
||||
if (anchor != null) {
|
||||
getPlayer().getPos().set(anchor.getPos());
|
||||
getPlayer().getRot().set(anchor.getRot());
|
||||
}
|
||||
|
||||
// Load scene groups. THIS NEEDS TO BE LAST
|
||||
for (int key : roomExcel.getGroupWithContent().keySet()) {
|
||||
getPlayer().getScene().loadGroup(key);
|
||||
}
|
||||
|
||||
// Done
|
||||
getPlayer().sendPacket(new PacketStartRogueScRsp(getPlayer()));
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.game.rogue.RogueRoomData;
|
||||
import emu.lunarcore.proto.EnterRogueMapRoomCsReqOuterClass.EnterRogueMapRoomCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketEnterRogueMapRoomScRsp;
|
||||
|
||||
@Opcodes(CmdId.EnterRogueMapRoomCsReq)
|
||||
public class HandlerEnterRogueMapRoomCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
var req = EnterRogueMapRoomCsReq.parseFrom(data);
|
||||
|
||||
RogueRoomData enteredRoom = null;
|
||||
if (session.getPlayer().getRogueInstance() != null) {
|
||||
enteredRoom = session.getPlayer().getRogueInstance().enterRoom(req.getSiteId());
|
||||
}
|
||||
|
||||
if (enteredRoom != null) {
|
||||
session.send(new PacketEnterRogueMapRoomScRsp(session.getPlayer(), enteredRoom));
|
||||
} else {
|
||||
session.send(CmdId.EnterRogueMapRoomScRsp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.rogue.RogueRoomData;
|
||||
import emu.lunarcore.proto.EnterRogueMapRoomScRspOuterClass.EnterRogueMapRoomScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketEnterRogueMapRoomScRsp extends BasePacket {
|
||||
|
||||
public PacketEnterRogueMapRoomScRsp(Player player, RogueRoomData room) {
|
||||
super(CmdId.EnterRogueMapRoomScRsp);
|
||||
|
||||
var data = EnterRogueMapRoomScRsp.newInstance()
|
||||
.setLineup(player.getCurrentLineup().toProto())
|
||||
.setScene(player.getScene().toProto())
|
||||
.setCurSiteId(room.getSiteId());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,19 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.rogue.RogueInstance;
|
||||
import emu.lunarcore.game.rogue.RogueRoomData;
|
||||
import emu.lunarcore.proto.SyncRogueMapRoomScNotifyOuterClass.SyncRogueMapRoomScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSyncRogueMapRoomScNotify extends BasePacket {
|
||||
|
||||
public PacketSyncRogueMapRoomScNotify(Player player) {
|
||||
public PacketSyncRogueMapRoomScNotify(RogueInstance rogue, RogueRoomData room) {
|
||||
super(CmdId.SyncRogueMapRoomScNotify);
|
||||
|
||||
var data = SyncRogueMapRoomScNotify.newInstance();
|
||||
|
||||
if (player.getRogueInstance() != null) {
|
||||
data.setMapId(player.getRogueInstance().getExcel().getMapId());
|
||||
data.setCurRoom(player.getRogueInstance().getCurrentRoom().toProto());
|
||||
}
|
||||
var data = SyncRogueMapRoomScNotify.newInstance()
|
||||
.setMapId(rogue.getExcel().getMapId())
|
||||
.setCurRoom(room.toProto());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
@@ -135,6 +135,18 @@ public class Utils {
|
||||
public static <T> T randomElement(List<T> list) {
|
||||
return list.get(ThreadLocalRandom.current().nextInt(0, list.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an integer array contains a value
|
||||
* @param array
|
||||
* @param value The value to check for
|
||||
*/
|
||||
public static boolean arrayContains(int[] array, int value) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == value) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 encodes a given byte array.
|
||||
|
||||
Reference in New Issue
Block a user