mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 22:34:35 +01:00
Allow challenge instances to persist through the database
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package emu.lunarcore.game.challenge;
|
package emu.lunarcore.game.challenge;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.config.GroupInfo;
|
import emu.lunarcore.data.config.GroupInfo;
|
||||||
import emu.lunarcore.data.config.MonsterInfo;
|
import emu.lunarcore.data.config.MonsterInfo;
|
||||||
@@ -20,30 +21,35 @@ import emu.lunarcore.util.Position;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter @Entity(useDiscriminator = false)
|
||||||
public class ChallengeInstance {
|
public class ChallengeInstance {
|
||||||
private final Player player;
|
private transient Player player;
|
||||||
private final ChallengeExcel excel;
|
private transient ChallengeExcel excel;
|
||||||
private Position startPos;
|
private Position startPos;
|
||||||
private Position startRot;
|
private Position startRot;
|
||||||
|
|
||||||
private boolean hasAvatarDied;
|
private int challengeId;
|
||||||
private int currentStage;
|
private int currentStage;
|
||||||
private ExtraLineupType currentExtraLineup;
|
private int currentExtraLineup;
|
||||||
private ChallengeStatus status;
|
private int status;
|
||||||
|
private boolean hasAvatarDied;
|
||||||
|
|
||||||
@Setter private int roundsLeft;
|
@Setter private int roundsLeft;
|
||||||
@Setter private int stars;
|
@Setter private int stars;
|
||||||
|
|
||||||
|
@Deprecated // Morphia only
|
||||||
|
public ChallengeInstance() {}
|
||||||
|
|
||||||
public ChallengeInstance(Player player, ChallengeExcel excel) {
|
public ChallengeInstance(Player player, ChallengeExcel excel) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.excel = excel;
|
this.excel = excel;
|
||||||
|
this.challengeId = excel.getId();
|
||||||
this.startPos = new Position();
|
this.startPos = new Position();
|
||||||
this.startRot = new Position();
|
this.startRot = new Position();
|
||||||
this.currentStage = 1;
|
this.currentStage = 1;
|
||||||
this.roundsLeft = excel.getChallengeCountDown();
|
this.roundsLeft = excel.getChallengeCountDown();
|
||||||
this.status = ChallengeStatus.CHALLENGE_DOING;
|
this.setStatus(ChallengeStatus.CHALLENGE_DOING);
|
||||||
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE;
|
this.setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Scene getScene() {
|
private Scene getScene() {
|
||||||
@@ -54,6 +60,14 @@ public class ChallengeInstance {
|
|||||||
return this.getExcel().getId();
|
return this.getExcel().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStatus(ChallengeStatus status) {
|
||||||
|
this.status = status.getNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCurrentExtraLineup(ExtraLineupType type) {
|
||||||
|
this.currentExtraLineup = type.getNumber();
|
||||||
|
}
|
||||||
|
|
||||||
protected void setupStage1() {
|
protected void setupStage1() {
|
||||||
this.setupStage(
|
this.setupStage(
|
||||||
excel.getMazeGroupID1(),
|
excel.getMazeGroupID1(),
|
||||||
@@ -110,7 +124,7 @@ public class ChallengeInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWin() {
|
public boolean isWin() {
|
||||||
return status == ChallengeStatus.CHALLENGE_FINISH;
|
return status == ChallengeStatus.CHALLENGE_FINISH_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBattleStart(Battle battle) {
|
public void onBattleStart(Battle battle) {
|
||||||
@@ -133,7 +147,7 @@ public class ChallengeInstance {
|
|||||||
// Progress to the next stage
|
// Progress to the next stage
|
||||||
if (this.currentStage >= excel.getStageNum()) {
|
if (this.currentStage >= excel.getStageNum()) {
|
||||||
// Last stage
|
// Last stage
|
||||||
this.status = ChallengeStatus.CHALLENGE_FINISH;
|
this.setStatus(ChallengeStatus.CHALLENGE_FINISH);
|
||||||
this.stars = this.calculateStars();
|
this.stars = this.calculateStars();
|
||||||
// Save history
|
// Save history
|
||||||
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars());
|
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars());
|
||||||
@@ -144,7 +158,7 @@ public class ChallengeInstance {
|
|||||||
this.currentStage++;
|
this.currentStage++;
|
||||||
this.setupStage2();
|
this.setupStage2();
|
||||||
// Change player line up
|
// Change player line up
|
||||||
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE_2;
|
this.setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_2);
|
||||||
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
||||||
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
||||||
// Move player
|
// Move player
|
||||||
@@ -156,13 +170,13 @@ public class ChallengeInstance {
|
|||||||
this.roundsLeft = Math.min(Math.max(this.roundsLeft - stats.getRoundCnt(), 0), this.roundsLeft);
|
this.roundsLeft = Math.min(Math.max(this.roundsLeft - stats.getRoundCnt(), 0), this.roundsLeft);
|
||||||
} else {
|
} else {
|
||||||
// Fail challenge
|
// Fail challenge
|
||||||
this.status = ChallengeStatus.CHALLENGE_FAILED;
|
this.setStatus(ChallengeStatus.CHALLENGE_FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
// End challenge if its done
|
// End challenge if its done
|
||||||
if (status != ChallengeStatus.CHALLENGE_DOING) {
|
if (status != ChallengeStatus.CHALLENGE_DOING_VALUE) {
|
||||||
getPlayer().setChallengeInstance(null);
|
getPlayer().setChallengeInstance(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,13 +207,22 @@ public class ChallengeInstance {
|
|||||||
|
|
||||||
return Math.min(stars, 7);
|
return Math.min(stars, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean validate(Player player) {
|
||||||
|
if (this.player == null) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.excel = GameData.getChallengeExcelMap().get(this.challengeId);
|
||||||
|
return this.excel != null;
|
||||||
|
}
|
||||||
|
|
||||||
public ChallengeInfo toProto() {
|
public ChallengeInfo toProto() {
|
||||||
var proto = ChallengeInfo.newInstance()
|
var proto = ChallengeInfo.newInstance()
|
||||||
.setChallengeId(this.getExcel().getId())
|
.setChallengeId(this.getExcel().getId())
|
||||||
.setStatus(this.getStatus())
|
.setStatusValue(this.getStatus())
|
||||||
.setRoundCount(this.getRoundsElapsed())
|
.setRoundCount(this.getRoundsElapsed())
|
||||||
.setExtraLineupType(this.getCurrentExtraLineup());
|
.setExtraLineupTypeValue(this.getCurrentExtraLineup());
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,14 +57,14 @@ public class ChallengeManager extends BasePlayerManager {
|
|||||||
// Set technique points
|
// Set technique points
|
||||||
lineup.setMp(5);
|
lineup.setMp(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set first lineup before we enter scenes
|
|
||||||
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE, false);
|
|
||||||
|
|
||||||
// Set challenge data for player
|
// Set challenge data for player
|
||||||
ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel);
|
ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel);
|
||||||
getPlayer().setChallengeInstance(instance);
|
getPlayer().setChallengeInstance(instance);
|
||||||
|
|
||||||
|
// Set first lineup before we enter scenes
|
||||||
|
getPlayer().getLineupManager().setCurrentExtraLineup(instance.getCurrentExtraLineup(), false);
|
||||||
|
|
||||||
// Enter scene
|
// Enter scene
|
||||||
boolean success = getPlayer().enterScene(excel.getMapEntranceID(), 0, false);
|
boolean success = getPlayer().enterScene(excel.getMapEntranceID(), 0, false);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|||||||
@@ -97,14 +97,16 @@ public class Player {
|
|||||||
// Database persistent data
|
// Database persistent data
|
||||||
private LineupManager lineupManager;
|
private LineupManager lineupManager;
|
||||||
private PlayerGachaInfo gachaInfo;
|
private PlayerGachaInfo gachaInfo;
|
||||||
|
|
||||||
|
// Instances
|
||||||
|
@Setter private ChallengeInstance challengeInstance;
|
||||||
|
@Setter private transient RogueInstance rogueInstance;
|
||||||
|
|
||||||
// Etc
|
// Etc
|
||||||
private transient boolean inAnchorRange;
|
private transient boolean inAnchorRange;
|
||||||
private transient int nextBattleId;
|
private transient int nextBattleId;
|
||||||
|
|
||||||
@Setter private transient boolean paused;
|
@Setter private transient boolean paused;
|
||||||
@Setter private transient ChallengeInstance challengeInstance;
|
|
||||||
@Setter private transient RogueInstance rogueInstance;
|
|
||||||
|
|
||||||
@Deprecated // Morphia only
|
@Deprecated // Morphia only
|
||||||
public Player() {
|
public Player() {
|
||||||
@@ -553,6 +555,12 @@ public class Player {
|
|||||||
|
|
||||||
// Post database load
|
// Post database load
|
||||||
this.getAvatars().setupHeroPaths();
|
this.getAvatars().setupHeroPaths();
|
||||||
|
|
||||||
|
// Check instances
|
||||||
|
if (this.getChallengeInstance() != null && !this.getChallengeInstance().validate(this)) {
|
||||||
|
// Delete instance if it failed to validate (example: missing an excel)
|
||||||
|
this.challengeInstance = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Load into saved scene (should happen after everything else loads)
|
// Load into saved scene (should happen after everything else loads)
|
||||||
this.loadScene(planeId, floorId, entryId, this.getPos(), this.getRot());
|
this.loadScene(planeId, floorId, entryId, this.getPos(), this.getRot());
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
package emu.lunarcore.server.packet.send;
|
package emu.lunarcore.server.packet.send;
|
||||||
|
|
||||||
import emu.lunarcore.proto.ChallengeLineupNotifyOuterClass.ChallengeLineupNotify;
|
import emu.lunarcore.proto.ChallengeLineupNotifyOuterClass.ChallengeLineupNotify;
|
||||||
import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType;
|
|
||||||
import emu.lunarcore.server.packet.BasePacket;
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
import emu.lunarcore.server.packet.CmdId;
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
|
|
||||||
public class PacketChallengeLineupNotify extends BasePacket {
|
public class PacketChallengeLineupNotify extends BasePacket {
|
||||||
|
|
||||||
public PacketChallengeLineupNotify(ExtraLineupType type) {
|
public PacketChallengeLineupNotify(int type) {
|
||||||
super(CmdId.ChallengeLineupNotify);
|
super(CmdId.ChallengeLineupNotify);
|
||||||
|
|
||||||
var data = ChallengeLineupNotify.newInstance()
|
var data = ChallengeLineupNotify.newInstance()
|
||||||
.setExtraLineupType(type);
|
.setExtraLineupTypeValue(type);
|
||||||
|
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user