mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
Fix pure fiction score counter
This commit is contained in:
@@ -4,6 +4,7 @@ import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -12,6 +13,7 @@ public class ChallengeStoryExtraExcel extends GameResource {
|
||||
private int ID;
|
||||
private int TurnLimit;
|
||||
private int ClearScore;
|
||||
private IntArrayList BattleTargetID;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
|
||||
@@ -16,8 +16,13 @@ import emu.lunarcore.game.scene.entity.EntityMonster;
|
||||
import emu.lunarcore.proto.BattleEndStatusOuterClass.BattleEndStatus;
|
||||
import emu.lunarcore.proto.BattleEventBattleInfoOuterClass.BattleEventBattleInfo;
|
||||
import emu.lunarcore.proto.BattleStatisticsOuterClass.BattleStatistics;
|
||||
import emu.lunarcore.proto.BattleTargetListOuterClass.BattleTargetList;
|
||||
import emu.lunarcore.proto.BattleTargetOuterClass.BattleTarget;
|
||||
import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo;
|
||||
import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo.BattleTargetInfoEntry;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.Getter;
|
||||
@@ -36,6 +41,7 @@ public class Battle {
|
||||
|
||||
private StageExcel stage; // Main battle stage
|
||||
private IntList battleEvents; // TODO maybe turn it into a map?
|
||||
private Int2ObjectMap<BattleTargetList> battleTargets; // TODO use custom battle target object as value type in case we need to save battles to the db
|
||||
|
||||
// Internal battle data
|
||||
@Setter private BattleEndStatus result;
|
||||
@@ -144,6 +150,22 @@ public class Battle {
|
||||
return this.battleEvents;
|
||||
}
|
||||
|
||||
public Int2ObjectMap<BattleTargetList> getBattleTargets() {
|
||||
if (this.battleTargets == null) {
|
||||
this.battleTargets = new Int2ObjectOpenHashMap<>();
|
||||
}
|
||||
return this.battleTargets;
|
||||
}
|
||||
|
||||
public void addBattleTarget(int key, int targetId, int progress) {
|
||||
var list = getBattleTargets().computeIfAbsent(key, i -> BattleTargetList.newInstance());
|
||||
var battleTarget = BattleTarget.newInstance()
|
||||
.setId(targetId)
|
||||
.setProgress(progress);
|
||||
|
||||
list.addBattleTargetList(battleTarget);
|
||||
}
|
||||
|
||||
public void setCustomLevel(int level) {
|
||||
for (var wave : this.getWaves()) {
|
||||
wave.setCustomLevel(level);
|
||||
@@ -245,6 +267,23 @@ public class Battle {
|
||||
}
|
||||
}
|
||||
|
||||
// Battle target map
|
||||
if (this.battleTargets != null) {
|
||||
// Build battle target map
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
var battleTargetList = this.battleTargets.get(i);
|
||||
var battleTargetEntry = BattleTargetInfoEntry.newInstance().setKey(i);
|
||||
|
||||
if (battleTargetList == null) {
|
||||
battleTargetEntry.getMutableValue();
|
||||
} else {
|
||||
battleTargetEntry.setValue(battleTargetList);
|
||||
}
|
||||
|
||||
proto.addBattleTargetInfo(battleTargetEntry);
|
||||
}
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class ChallengeHistory {
|
||||
private int groupId;
|
||||
private int takenReward;
|
||||
private int stars;
|
||||
private int score;
|
||||
|
||||
@Deprecated // Morphia
|
||||
public ChallengeHistory() {}
|
||||
@@ -45,10 +46,15 @@ public class ChallengeHistory {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Challenge toProto() {
|
||||
var proto = Challenge.newInstance()
|
||||
.setChallengeId(this.getChallengeId())
|
||||
.setTakenReward(this.getTakenReward())
|
||||
.setScore(this.getScore())
|
||||
.setStars(this.getStars());
|
||||
|
||||
return proto;
|
||||
|
||||
@@ -7,6 +7,7 @@ import emu.lunarcore.game.battle.Battle;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.entity.EntityMonster;
|
||||
import emu.lunarcore.proto.BattleEndReasonOuterClass.BattleEndReason;
|
||||
import emu.lunarcore.proto.BattleEndStatusOuterClass.BattleEndStatus;
|
||||
import emu.lunarcore.proto.BattleStatisticsOuterClass.BattleStatistics;
|
||||
import emu.lunarcore.proto.ChallengeInfoOuterClass.ChallengeInfo;
|
||||
@@ -37,6 +38,8 @@ public class ChallengeInstance {
|
||||
@Setter private int savedMp;
|
||||
@Setter private int roundsLeft;
|
||||
@Setter private int stars;
|
||||
@Setter private int scoreStage1;
|
||||
@Setter private int scoreStage2;
|
||||
|
||||
private IntList storyBuffs;
|
||||
|
||||
@@ -63,6 +66,10 @@ public class ChallengeInstance {
|
||||
return this.getExcel().getId();
|
||||
}
|
||||
|
||||
public boolean isStory() {
|
||||
return this.excel.isStory();
|
||||
}
|
||||
|
||||
private void setStatus(ChallengeStatus status) {
|
||||
this.status = status.getNumber();
|
||||
}
|
||||
@@ -74,6 +81,10 @@ public class ChallengeInstance {
|
||||
private int getRoundsElapsed() {
|
||||
return getExcel().getChallengeCountDown() - this.roundsLeft;
|
||||
}
|
||||
|
||||
public int getTotalScore() {
|
||||
return this.scoreStage1 + this.scoreStage2;
|
||||
}
|
||||
|
||||
public boolean isWin() {
|
||||
return status == ChallengeStatus.CHALLENGE_FINISH_VALUE;
|
||||
@@ -101,9 +112,32 @@ public class ChallengeInstance {
|
||||
battle.addBuff(buffId);
|
||||
}
|
||||
}
|
||||
|
||||
// Add story battle targets
|
||||
if (this.getExcel().getStoryExcel() != null) {
|
||||
// Add base score counter
|
||||
battle.addBattleTarget(1, 10001, this.getTotalScore());
|
||||
// Add battle targets from story excel
|
||||
for (int id : getExcel().getStoryExcel().getBattleTargetID()) {
|
||||
battle.addBattleTarget(5, id, this.getTotalScore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onBattleFinish(Battle battle, BattleEndStatus result, BattleStatistics stats) {
|
||||
// Add challenge score
|
||||
if (this.isStory()) {
|
||||
// Calculate score for current stage
|
||||
int stageScore = stats.getChallengeScore() - this.getTotalScore();
|
||||
// Set score
|
||||
if (this.getCurrentStage() == 1) {
|
||||
this.scoreStage1 = stageScore;
|
||||
} else {
|
||||
this.scoreStage2 = stageScore;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle result
|
||||
switch (result) {
|
||||
case BATTLE_END_WIN:
|
||||
// Check if any avatar in the lineup has died
|
||||
@@ -117,28 +151,7 @@ public class ChallengeInstance {
|
||||
long monsters = player.getScene().getEntities().values().stream().filter(e -> e instanceof EntityMonster).count();
|
||||
|
||||
if (monsters == 0) {
|
||||
// Progress to the next stage
|
||||
if (this.currentStage >= excel.getStageNum()) {
|
||||
// Last stage
|
||||
this.setStatus(ChallengeStatus.CHALLENGE_FINISH);
|
||||
this.stars = this.calculateStars();
|
||||
// Save history
|
||||
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars());
|
||||
// Send challenge result data
|
||||
player.sendPacket(new PacketChallengeSettleNotify(this));
|
||||
} else {
|
||||
// Increment and reset stage
|
||||
this.currentStage++;
|
||||
// Load scene group for stage 2
|
||||
this.getScene().loadGroup(excel.getMazeGroupID2());
|
||||
// Change player line up
|
||||
this.setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_2);
|
||||
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
||||
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
||||
this.savedMp = player.getCurrentLineup().getMp();
|
||||
// Move player
|
||||
player.moveTo(this.getStartPos(), this.getStartRot());
|
||||
}
|
||||
this.advanceStage();
|
||||
}
|
||||
|
||||
// Calculate rounds left
|
||||
@@ -155,11 +168,41 @@ public class ChallengeInstance {
|
||||
player.sendPacket(new PacketSyncLineupNotify(lineup));
|
||||
break;
|
||||
default:
|
||||
// Fail challenge
|
||||
this.setStatus(ChallengeStatus.CHALLENGE_FAILED);
|
||||
// Determine challenge result
|
||||
if (this.isStory() && stats.getEndReason() == BattleEndReason.BATTLE_END_REASON_TURN_LIMIT) {
|
||||
this.advanceStage();
|
||||
} else {
|
||||
// Fail challenge
|
||||
this.setStatus(ChallengeStatus.CHALLENGE_FAILED);
|
||||
// Send challenge result data
|
||||
player.sendPacket(new PacketChallengeSettleNotify(this));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void advanceStage() {
|
||||
// Progress to the next stage
|
||||
if (this.currentStage >= excel.getStageNum()) {
|
||||
// Last stage
|
||||
this.setStatus(ChallengeStatus.CHALLENGE_FINISH);
|
||||
this.stars = this.calculateStars();
|
||||
// Save history
|
||||
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars(), this.getTotalScore());
|
||||
// Send challenge result data
|
||||
player.sendPacket(new PacketChallengeSettleNotify(this));
|
||||
break;
|
||||
} else {
|
||||
// Increment and reset stage
|
||||
this.currentStage++;
|
||||
// Load scene group for stage 2
|
||||
this.getScene().loadGroup(excel.getMazeGroupID2());
|
||||
// Change player line up
|
||||
this.setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_2);
|
||||
player.getLineupManager().setCurrentExtraLineup(this.getCurrentExtraLineup(), true);
|
||||
player.sendPacket(new PacketChallengeLineupNotify(this.getCurrentExtraLineup()));
|
||||
this.savedMp = player.getCurrentLineup().getMp();
|
||||
// Move player
|
||||
player.moveTo(this.getStartPos(), this.getStartRot());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +232,11 @@ public class ChallengeInstance {
|
||||
stars += (1 << i);
|
||||
}
|
||||
break;
|
||||
case TOTAL_SCORE:
|
||||
if (this.getTotalScore() >= target.getChallengeTargetParam1()) {
|
||||
stars += (1 << i);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -212,6 +260,8 @@ public class ChallengeInstance {
|
||||
var proto = ChallengeInfo.newInstance()
|
||||
.setChallengeId(this.getExcel().getId())
|
||||
.setStatusValue(this.getStatus())
|
||||
.setScore(this.getScoreStage1())
|
||||
.setScoreTwo(this.getScoreStage2())
|
||||
.setRoundCount(this.getRoundsElapsed())
|
||||
.setExtraLineupTypeValue(this.getCurrentExtraLineup());
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ChallengeManager extends BasePlayerManager {
|
||||
getPlayer().sendPacket(new PacketStartChallengeScRsp(getPlayer(), challengeId));
|
||||
}
|
||||
|
||||
public synchronized void addHistory(int challengeId, int stars) {
|
||||
public synchronized void addHistory(int challengeId, int stars, int score) {
|
||||
// Dont write challenge history if the player didnt get any stars
|
||||
if (stars <= 0) return;
|
||||
|
||||
@@ -115,6 +115,7 @@ public class ChallengeManager extends BasePlayerManager {
|
||||
|
||||
// Set
|
||||
info.setStars(stars);
|
||||
info.setScore(score);
|
||||
info.save();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ public class PacketChallengeSettleNotify extends BasePacket {
|
||||
var data = ChallengeSettleNotify.newInstance()
|
||||
.setChallengeId(challenge.getExcel().getId())
|
||||
.setIsWin(challenge.isWin())
|
||||
.setChallengeScore(challenge.getScoreStage1())
|
||||
.setScoreTwo(challenge.getScoreStage2())
|
||||
.setStars(challenge.getStars());
|
||||
|
||||
// Set empty rewards
|
||||
|
||||
Reference in New Issue
Block a user