From c3e57c1195b5eb2f163422b9513e666b699beec2 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Mon, 3 Nov 2025 05:53:38 -0800 Subject: [PATCH] Implement record score calculation --- .../nebula/data/resources/PotentialDef.java | 1 + .../emu/nebula/game/tower/StarTowerBuild.java | 43 +++++++++++++++---- .../emu/nebula/game/tower/StarTowerGame.java | 33 +++++++------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/main/java/emu/nebula/data/resources/PotentialDef.java b/src/main/java/emu/nebula/data/resources/PotentialDef.java index ca847b2..9148c2e 100644 --- a/src/main/java/emu/nebula/data/resources/PotentialDef.java +++ b/src/main/java/emu/nebula/data/resources/PotentialDef.java @@ -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() { diff --git a/src/main/java/emu/nebula/game/tower/StarTowerBuild.java b/src/main/java/emu/nebula/game/tower/StarTowerBuild.java index 9b99cbc..65e6c66 100644 --- a/src/main/java/emu/nebula/game/tower/StarTowerBuild.java +++ b/src/main/java/emu/nebula/game/tower/StarTowerBuild.java @@ -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() { diff --git a/src/main/java/emu/nebula/game/tower/StarTowerGame.java b/src/main/java/emu/nebula/game/tower/StarTowerGame.java index 430973e..551a873 100644 --- a/src/main/java/emu/nebula/game/tower/StarTowerGame.java +++ b/src/main/java/emu/nebula/game/tower/StarTowerGame.java @@ -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() {