mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-14 22:34:35 +01:00
Calculate stars in challenges properly
This commit is contained in:
@@ -28,6 +28,7 @@ public class GameData {
|
|||||||
@Getter private static Int2ObjectMap<MapEntranceExcel> mapEntranceExcelMap = new Int2ObjectOpenHashMap<>();
|
@Getter private static Int2ObjectMap<MapEntranceExcel> mapEntranceExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
@Getter private static Int2ObjectMap<HeroExcel> heroExcelMap = new Int2ObjectOpenHashMap<>();
|
@Getter private static Int2ObjectMap<HeroExcel> heroExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
@Getter private static Int2ObjectMap<ChallengeExcel> challengeExcelMap = new Int2ObjectOpenHashMap<>();
|
@Getter private static Int2ObjectMap<ChallengeExcel> challengeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
@Getter private static Int2ObjectMap<ChallengeTargetExcel> challengeTargetExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
@Getter private static Int2ObjectMap<ShopExcel> shopExcelMap = new Int2ObjectOpenHashMap<>();
|
@Getter private static Int2ObjectMap<ShopExcel> shopExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
private static Int2ObjectMap<AvatarPromotionExcel> avatarPromotionExcelMap = new Int2ObjectOpenHashMap<>();
|
private static Int2ObjectMap<AvatarPromotionExcel> avatarPromotionExcelMap = new Int2ObjectOpenHashMap<>();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class ChallengeExcel extends GameResource {
|
|||||||
private int ChallengeCountDown;
|
private int ChallengeCountDown;
|
||||||
private int MazeBuffID;
|
private int MazeBuffID;
|
||||||
|
|
||||||
|
private int[] ChallengeTargetID;
|
||||||
|
|
||||||
private int MazeGroupID1;
|
private int MazeGroupID1;
|
||||||
private int[] ConfigList1;
|
private int[] ConfigList1;
|
||||||
private int[] NpcMonsterIDList1;
|
private int[] NpcMonsterIDList1;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package emu.lunarcore.data.excel;
|
||||||
|
|
||||||
|
import emu.lunarcore.data.GameResource;
|
||||||
|
import emu.lunarcore.data.ResourceType;
|
||||||
|
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ResourceType(name = {"ChallengeTargetConfig.json"}, loadPriority = LoadPriority.HIGH)
|
||||||
|
public class ChallengeTargetExcel extends GameResource {
|
||||||
|
private int ID;
|
||||||
|
private ChallengeType ChallengeTargetType;
|
||||||
|
private int ChallengeTargetParam1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ChallengeType {
|
||||||
|
None, ROUNDS, DEAD_AVATAR, KILL_MONSTER, AVATAR_BASE_TYPE_MORE, AVATAR_BASE_TYPE_LESS, ROUNDS_LEFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -146,6 +146,10 @@ public class GameAvatar implements GameEntity {
|
|||||||
this.currentSp = Math.max(Math.min(amount, getMaxSp()), 0);
|
this.currentSp = Math.max(Math.min(amount, getMaxSp()), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlive() {
|
||||||
|
return this.getCurrentHp() <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int getRank() {
|
public int getRank() {
|
||||||
return this.getData().getRank();
|
return this.getData().getRank();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import emu.lunarcore.data.config.GroupInfo;
|
|||||||
import emu.lunarcore.data.config.MonsterInfo;
|
import emu.lunarcore.data.config.MonsterInfo;
|
||||||
import emu.lunarcore.data.excel.ChallengeExcel;
|
import emu.lunarcore.data.excel.ChallengeExcel;
|
||||||
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||||
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
import emu.lunarcore.game.battle.Battle;
|
import emu.lunarcore.game.battle.Battle;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.game.scene.Scene;
|
import emu.lunarcore.game.scene.Scene;
|
||||||
@@ -28,11 +29,12 @@ public class ChallengeData {
|
|||||||
private final Position startPos;
|
private final Position startPos;
|
||||||
private final Position startRot;
|
private final Position startRot;
|
||||||
|
|
||||||
|
private boolean hasAvatarDied;
|
||||||
private int currentStage;
|
private int currentStage;
|
||||||
private ExtraLineupType currentExtraLineup;
|
private ExtraLineupType currentExtraLineup;
|
||||||
private ChallengeStatus status;
|
private ChallengeStatus status;
|
||||||
|
|
||||||
@Setter private int roundsLimit;
|
@Setter private int roundsLeft;
|
||||||
@Setter private int stars;
|
@Setter private int stars;
|
||||||
|
|
||||||
public ChallengeData(Player player, ChallengeExcel excel) {
|
public ChallengeData(Player player, ChallengeExcel excel) {
|
||||||
@@ -42,7 +44,7 @@ public class ChallengeData {
|
|||||||
this.startPos = player.getPos().clone();
|
this.startPos = player.getPos().clone();
|
||||||
this.startRot = player.getRot().clone();
|
this.startRot = player.getRot().clone();
|
||||||
this.currentStage = 1;
|
this.currentStage = 1;
|
||||||
this.roundsLimit = excel.getChallengeCountDown();
|
this.roundsLeft = excel.getChallengeCountDown();
|
||||||
this.status = ChallengeStatus.CHALLENGE_DOING;
|
this.status = ChallengeStatus.CHALLENGE_DOING;
|
||||||
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE;
|
this.currentExtraLineup = ExtraLineupType.LINEUP_CHALLENGE;
|
||||||
|
|
||||||
@@ -107,8 +109,8 @@ public class ChallengeData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRoundCount() {
|
private int getRoundsElapsed() {
|
||||||
return getExcel().getChallengeCountDown() - this.roundsLimit;
|
return getExcel().getChallengeCountDown() - this.roundsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWin() {
|
public boolean isWin() {
|
||||||
@@ -116,11 +118,21 @@ public class ChallengeData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBattleStart(Battle battle) {
|
public void onBattleStart(Battle battle) {
|
||||||
battle.setRoundsLimit(player.getChallengeData().getRoundsLimit());
|
battle.setRoundsLimit(player.getChallengeData().getRoundsLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBattleFinish(Battle battle, BattleEndStatus result, BattleStatistics stats) {
|
public void onBattleFinish(Battle battle, BattleEndStatus result, BattleStatistics stats) {
|
||||||
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
||||||
|
// Check if any avatar in the lineup has died
|
||||||
|
for (int avatarId : player.getCurrentLineup().getAvatars()) {
|
||||||
|
GameAvatar avatar = player.getAvatarById(avatarId);
|
||||||
|
if (avatar == null) continue;
|
||||||
|
|
||||||
|
if (!avatar.isAlive()) {
|
||||||
|
this.hasAvatarDied = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get monster count in stage
|
// Get monster count in stage
|
||||||
long monsters = player.getScene().getEntities().values().stream().filter(e -> e instanceof EntityMonster).count();
|
long monsters = player.getScene().getEntities().values().stream().filter(e -> e instanceof EntityMonster).count();
|
||||||
|
|
||||||
@@ -129,7 +141,7 @@ public class ChallengeData {
|
|||||||
if (this.currentStage >= excel.getStageNum()) {
|
if (this.currentStage >= excel.getStageNum()) {
|
||||||
// Last stage
|
// Last stage
|
||||||
this.status = ChallengeStatus.CHALLENGE_FINISH;
|
this.status = ChallengeStatus.CHALLENGE_FINISH;
|
||||||
this.stars = 7; // TODO calculate the right amount stars
|
this.stars = this.calculateStars();
|
||||||
// Save history
|
// Save history
|
||||||
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars());
|
player.getChallengeManager().addHistory(this.getChallengeId(), this.getStars());
|
||||||
// Send challenge result data
|
// Send challenge result data
|
||||||
@@ -148,7 +160,7 @@ public class ChallengeData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate rounds left
|
// Calculate rounds left
|
||||||
this.roundsLimit = Math.min(Math.max(this.roundsLimit - stats.getRoundCnt(), 0), this.roundsLimit);
|
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.status = ChallengeStatus.CHALLENGE_FAILED;
|
||||||
@@ -162,11 +174,38 @@ public class ChallengeData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int calculateStars() {
|
||||||
|
int[] targets = getExcel().getChallengeTargetID();
|
||||||
|
int stars = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < targets.length; i++) {
|
||||||
|
var target = GameData.getChallengeTargetExcelMap().get(targets[i]);
|
||||||
|
if (target == null) continue;
|
||||||
|
|
||||||
|
switch (target.getChallengeTargetType()) {
|
||||||
|
case ROUNDS_LEFT:
|
||||||
|
if (this.getRoundsLeft() >= target.getChallengeTargetParam1()) {
|
||||||
|
stars += (1 << i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DEAD_AVATAR:
|
||||||
|
if (!this.hasAvatarDied) {
|
||||||
|
stars += (1 << i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.min(stars, 7);
|
||||||
|
}
|
||||||
|
|
||||||
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())
|
.setStatus(this.getStatus())
|
||||||
.setRoundCount(this.getRoundCount())
|
.setRoundCount(this.getRoundsElapsed())
|
||||||
.setExtraLineupType(this.getCurrentExtraLineup());
|
.setExtraLineupType(this.getCurrentExtraLineup());
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
|
|||||||
Reference in New Issue
Block a user