mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 04:45:02 +01:00
Fix disc secondary skills
This commit is contained in:
@@ -52,6 +52,8 @@ public class GameData {
|
|||||||
@Getter private static DataTable<DiscPromoteDef> DiscPromoteDataTable = new DataTable<>();
|
@Getter private static DataTable<DiscPromoteDef> DiscPromoteDataTable = new DataTable<>();
|
||||||
@Getter private static DataTable<DiscPromoteLimitDef> DiscPromoteLimitDataTable = new DataTable<>();
|
@Getter private static DataTable<DiscPromoteLimitDef> DiscPromoteLimitDataTable = new DataTable<>();
|
||||||
|
|
||||||
|
@Getter private static DataTable<SecondarySkillDef> SecondarySkillDataTable = new DataTable<>();
|
||||||
|
|
||||||
// Items
|
// Items
|
||||||
@Getter private static DataTable<ItemDef> ItemDataTable = new DataTable<>();
|
@Getter private static DataTable<ItemDef> ItemDataTable = new DataTable<>();
|
||||||
@Getter private static DataTable<ProductionDef> ProductionDataTable = new DataTable<>();
|
@Getter private static DataTable<ProductionDef> ProductionDataTable = new DataTable<>();
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public class DiscDef extends BaseDef {
|
|||||||
private int TransformItemId;
|
private int TransformItemId;
|
||||||
private int[] MaxStarTransformItem;
|
private int[] MaxStarTransformItem;
|
||||||
private int[] ReadReward;
|
private int[] ReadReward;
|
||||||
|
|
||||||
|
private int SecondarySkillGroupId1;
|
||||||
|
private int SecondarySkillGroupId2;
|
||||||
private int SubNoteSkillGroupId;
|
private int SubNoteSkillGroupId;
|
||||||
|
|
||||||
private transient ElementType elementType;
|
private transient ElementType elementType;
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package emu.nebula.data.resources;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import emu.nebula.data.BaseDef;
|
||||||
|
import emu.nebula.data.ResourceType;
|
||||||
|
import emu.nebula.game.inventory.ItemParamMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ResourceType(name = "SecondarySkill.json")
|
||||||
|
public class SecondarySkillDef extends BaseDef {
|
||||||
|
private int Id;
|
||||||
|
private int GroupId;
|
||||||
|
private int Score;
|
||||||
|
private String NeedSubNoteSkills;
|
||||||
|
|
||||||
|
private transient ItemParamMap reqSubNotes;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static transient Int2ObjectMap<List<SecondarySkillDef>> groups = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean match(ItemParamMap subNotes) {
|
||||||
|
for (var item : this.reqSubNotes) {
|
||||||
|
int reqId = item.getIntKey();
|
||||||
|
int reqCount = item.getIntValue();
|
||||||
|
|
||||||
|
int curCount = subNotes.get(reqId);
|
||||||
|
if (curCount < reqCount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
// Setup required subnotes
|
||||||
|
this.reqSubNotes = ItemParamMap.fromJsonString(this.NeedSubNoteSkills);
|
||||||
|
|
||||||
|
// Add to group cache
|
||||||
|
var group = groups.computeIfAbsent(this.GroupId, id -> new ArrayList<>());
|
||||||
|
group.add(this);
|
||||||
|
|
||||||
|
// Clear to save memory
|
||||||
|
this.NeedSubNoteSkills = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SecondarySkillDef> getGroup(int id) {
|
||||||
|
return groups.get(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import dev.morphia.annotations.Id;
|
|||||||
import dev.morphia.annotations.Indexed;
|
import dev.morphia.annotations.Indexed;
|
||||||
import emu.nebula.Nebula;
|
import emu.nebula.Nebula;
|
||||||
import emu.nebula.data.GameData;
|
import emu.nebula.data.GameData;
|
||||||
|
import emu.nebula.data.resources.SecondarySkillDef;
|
||||||
import emu.nebula.database.GameDatabaseObject;
|
import emu.nebula.database.GameDatabaseObject;
|
||||||
import emu.nebula.game.character.GameCharacter;
|
import emu.nebula.game.character.GameCharacter;
|
||||||
import emu.nebula.game.character.GameDisc;
|
import emu.nebula.game.character.GameDisc;
|
||||||
@@ -19,7 +20,8 @@ import emu.nebula.proto.PublicStarTower.StarTowerBuildDetail;
|
|||||||
import emu.nebula.proto.PublicStarTower.StarTowerBuildInfo;
|
import emu.nebula.proto.PublicStarTower.StarTowerBuildInfo;
|
||||||
import emu.nebula.proto.PublicStarTower.TowerBuildChar;
|
import emu.nebula.proto.PublicStarTower.TowerBuildChar;
|
||||||
import emu.nebula.util.Snowflake;
|
import emu.nebula.util.Snowflake;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -42,6 +44,8 @@ public class StarTowerBuild implements GameDatabaseObject {
|
|||||||
private ItemParamMap potentials;
|
private ItemParamMap potentials;
|
||||||
private ItemParamMap subNoteSkills;
|
private ItemParamMap subNoteSkills;
|
||||||
|
|
||||||
|
private IntList secondarySkills;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public StarTowerBuild() {
|
public StarTowerBuild() {
|
||||||
|
|
||||||
@@ -54,6 +58,7 @@ public class StarTowerBuild implements GameDatabaseObject {
|
|||||||
this.charPots = new ItemParamMap();
|
this.charPots = new ItemParamMap();
|
||||||
this.potentials = new ItemParamMap();
|
this.potentials = new ItemParamMap();
|
||||||
this.subNoteSkills = new ItemParamMap();
|
this.subNoteSkills = new ItemParamMap();
|
||||||
|
this.secondarySkills = new IntArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StarTowerBuild(StarTowerGame game) {
|
public StarTowerBuild(StarTowerGame game) {
|
||||||
@@ -129,13 +134,70 @@ public class StarTowerBuild implements GameDatabaseObject {
|
|||||||
Nebula.getGameDatabase().update(this, this.getUid(), "preference", this.isPreference());
|
Nebula.getGameDatabase().update(this, this.getUid(), "preference", this.isPreference());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Secondary skills
|
||||||
|
|
||||||
|
private void calculateSecondarySkills() {
|
||||||
|
// Reset active secondary skills
|
||||||
|
if (this.secondarySkills == null) {
|
||||||
|
this.secondarySkills = new IntArrayList();
|
||||||
|
} else {
|
||||||
|
this.secondarySkills.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get first 3 discs
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
// Disc id
|
||||||
|
int discId = this.getDiscIds()[i];
|
||||||
|
|
||||||
|
// Get disc data
|
||||||
|
var data = GameData.getDiscDataTable().get(discId);
|
||||||
|
if (data == null) continue;
|
||||||
|
|
||||||
|
// Add secondary skills
|
||||||
|
int s1= this.getSecondarySkill(data.getSecondarySkillGroupId1());
|
||||||
|
if (s1 > 0) {
|
||||||
|
this.getSecondarySkills().add(s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int s2 = this.getSecondarySkill(data.getSecondarySkillGroupId2());
|
||||||
|
if (s2 > 0) {
|
||||||
|
this.getSecondarySkills().add(s2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getSecondarySkill(int groupId) {
|
||||||
|
// Check group id
|
||||||
|
if (groupId <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get group
|
||||||
|
var group = SecondarySkillDef.getGroup(groupId);
|
||||||
|
if (group == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse iterator to try and match highest secondary skill first
|
||||||
|
for (int i = group.size() - 1; i >= 0; i--) {
|
||||||
|
var data = group.get(i);
|
||||||
|
|
||||||
|
if (data.match(this.getSubNoteSkills())) {
|
||||||
|
return data.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failure
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Score
|
// Score
|
||||||
|
|
||||||
public int calculateScore() {
|
public int calculateScore() {
|
||||||
// Clear score
|
// Clear score
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
|
|
||||||
// Potentials
|
// Add score from potentials
|
||||||
for (var potential : this.getPotentials().int2IntEntrySet()) {
|
for (var potential : this.getPotentials().int2IntEntrySet()) {
|
||||||
var data = GameData.getPotentialDataTable().get(potential.getIntKey());
|
var data = GameData.getPotentialDataTable().get(potential.getIntKey());
|
||||||
if (data == null) continue;
|
if (data == null) continue;
|
||||||
@@ -143,11 +205,22 @@ public class StarTowerBuild implements GameDatabaseObject {
|
|||||||
this.score += data.getBuildScore(potential.getIntValue());
|
this.score += data.getBuildScore(potential.getIntValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub note skills
|
// Add score from sub note skills
|
||||||
for (var item : this.getSubNoteSkills()) {
|
for (var item : this.getSubNoteSkills()) {
|
||||||
this.score += item.getIntValue() * 15;
|
this.score += item.getIntValue() * 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate secondary skills
|
||||||
|
this.calculateSecondarySkills();
|
||||||
|
|
||||||
|
// Add score from secondary skills
|
||||||
|
for (int id : this.getSecondarySkills()) {
|
||||||
|
var data = GameData.getSecondarySkillDataTable().get(id);
|
||||||
|
if (data == null) continue;
|
||||||
|
|
||||||
|
this.score += data.getScore();
|
||||||
|
}
|
||||||
|
|
||||||
// Complete
|
// Complete
|
||||||
return this.score;
|
return this.score;
|
||||||
}
|
}
|
||||||
@@ -204,6 +277,11 @@ public class StarTowerBuild implements GameDatabaseObject {
|
|||||||
proto.addSubNoteSkills(skill);
|
proto.addSubNoteSkills(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Secondary skills
|
||||||
|
for (int id : this.getSecondarySkills()) {
|
||||||
|
proto.addActiveSecondaryIds(id);
|
||||||
|
}
|
||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -327,9 +327,18 @@ public class StarTowerManager extends PlayerManager {
|
|||||||
// Database
|
// Database
|
||||||
|
|
||||||
public void loadFromDatabase() {
|
public void loadFromDatabase() {
|
||||||
|
// Init builds
|
||||||
this.builds = new Long2ObjectOpenHashMap<>();
|
this.builds = new Long2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
// Load builds with the current player's uid
|
||||||
Nebula.getGameDatabase().getObjects(StarTowerBuild.class, "playerUid", getPlayerUid()).forEach(build -> {
|
Nebula.getGameDatabase().getObjects(StarTowerBuild.class, "playerUid", getPlayerUid()).forEach(build -> {
|
||||||
|
// Fix outdated builds
|
||||||
|
if (build.getSecondarySkills() == null) {
|
||||||
|
build.calculateScore();
|
||||||
|
build.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add build
|
||||||
this.builds.put(build.getUid(), build);
|
this.builds.put(build.getUid(), build);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user