mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Implement record score calculation
This commit is contained in:
@@ -11,6 +11,7 @@ public class PotentialDef extends BaseDef {
|
||||
private int CharId;
|
||||
private int Build;
|
||||
private int MaxLevel;
|
||||
private int[] BuildScore;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.morphia.annotations.Indexed;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
import emu.nebula.game.inventory.ItemParamMap;
|
||||
import emu.nebula.proto.Public.ItemTpl;
|
||||
import emu.nebula.proto.PublicStarTower.BuildPotential;
|
||||
import emu.nebula.proto.PublicStarTower.StarTowerBuildBrief;
|
||||
@@ -13,8 +14,7 @@ import emu.nebula.proto.PublicStarTower.StarTowerBuildDetail;
|
||||
import emu.nebula.proto.PublicStarTower.StarTowerBuildInfo;
|
||||
import emu.nebula.proto.PublicStarTower.TowerBuildChar;
|
||||
import emu.nebula.util.Snowflake;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -33,9 +33,9 @@ public class StarTowerBuild implements GameDatabaseObject {
|
||||
private int[] charIds;
|
||||
private int[] discIds;
|
||||
|
||||
private Int2IntMap charPots;
|
||||
private Int2IntMap potentials;
|
||||
private Int2IntMap subNoteSkills;
|
||||
private ItemParamMap charPots;
|
||||
private ItemParamMap potentials;
|
||||
private ItemParamMap subNoteSkills;
|
||||
|
||||
@Deprecated
|
||||
public StarTowerBuild() {
|
||||
@@ -46,9 +46,9 @@ public class StarTowerBuild implements GameDatabaseObject {
|
||||
this.uid = Snowflake.newUid();
|
||||
this.playerUid = game.getPlayer().getUid();
|
||||
this.name = "";
|
||||
this.charPots = new Int2IntOpenHashMap();
|
||||
this.potentials = new Int2IntOpenHashMap();
|
||||
this.subNoteSkills = new Int2IntOpenHashMap();
|
||||
this.charPots = new ItemParamMap();
|
||||
this.potentials = new ItemParamMap();
|
||||
this.subNoteSkills = new ItemParamMap();
|
||||
|
||||
// Characters
|
||||
this.charIds = game.getChars().stream()
|
||||
@@ -83,6 +83,9 @@ public class StarTowerBuild implements GameDatabaseObject {
|
||||
for (var entry : game.getItems()) {
|
||||
this.getSubNoteSkills().put(entry.getIntKey(), entry.getIntValue());
|
||||
}
|
||||
|
||||
// Caclulate record score and cache it
|
||||
this.score = this.calculateScore();
|
||||
}
|
||||
|
||||
public void setName(String newName) {
|
||||
@@ -104,6 +107,30 @@ public class StarTowerBuild implements GameDatabaseObject {
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "preference", this.isPreference());
|
||||
}
|
||||
|
||||
// Score
|
||||
|
||||
private int calculateScore() {
|
||||
// Init score
|
||||
int score = 0;
|
||||
|
||||
// Potentials
|
||||
for (var potential : this.getPotentials().int2IntEntrySet()) {
|
||||
var data = GameData.getPotentialDataTable().get(potential.getIntKey());
|
||||
if (data == null) continue;
|
||||
|
||||
int index = potential.getIntValue() - 1;
|
||||
score += data.getBuildScore()[index];
|
||||
}
|
||||
|
||||
// Sub note skills
|
||||
for (var item : this.getSubNoteSkills()) {
|
||||
score += item.getIntValue() * 15;
|
||||
}
|
||||
|
||||
// Complete
|
||||
return score;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public StarTowerBuildInfo toProto() {
|
||||
|
||||
@@ -247,8 +247,22 @@ public class StarTowerGame {
|
||||
// Handle changes
|
||||
switch (itemData.getItemSubType()) {
|
||||
case Potential, SpecificPotential -> {
|
||||
// Get potential data
|
||||
var potentialData = GameData.getPotentialDataTable().get(id);
|
||||
if (potentialData == null) return change;
|
||||
|
||||
// Clamp level
|
||||
int curLevel = getPotentials().get(id);
|
||||
int nextLevel = Math.min(curLevel + count, potentialData.getMaxLevel());
|
||||
|
||||
// Sanity
|
||||
count = nextLevel - curLevel;
|
||||
if (count <= 0) {
|
||||
return change;
|
||||
}
|
||||
|
||||
// Add potential
|
||||
this.getPotentials().add(id, count);
|
||||
this.getPotentials().put(id, nextLevel);
|
||||
|
||||
// Add change
|
||||
var info = PotentialInfo.newInstance()
|
||||
@@ -503,23 +517,6 @@ public class StarTowerGame {
|
||||
return rsp;
|
||||
}
|
||||
|
||||
// Score
|
||||
|
||||
public int calculateScore() {
|
||||
// Init score
|
||||
int score = 0;
|
||||
|
||||
// Potentials TODO
|
||||
|
||||
// Sub note skills
|
||||
for (var item : this.getItems()) {
|
||||
score += item.getIntValue() * 15;
|
||||
}
|
||||
|
||||
// Complete
|
||||
return score;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public StarTowerInfo toProto() {
|
||||
|
||||
Reference in New Issue
Block a user