Rework how avatar skills and rank are stored

This commit is contained in:
Melledy
2023-09-29 02:21:47 -07:00
parent b139ea10c4
commit e1bbf5589f
5 changed files with 75 additions and 51 deletions

View File

@@ -0,0 +1,32 @@
package emu.lunarcore.game.avatar;
import java.util.HashMap;
import java.util.Map;
import dev.morphia.annotations.Entity;
import emu.lunarcore.data.excel.AvatarExcel;
import lombok.Getter;
import lombok.Setter;
/**
* A helper class that contains information about an avatar's rank.
*/
@Entity(useDiscriminator = false)
public class AvatarData {
@Getter @Setter
private int rank; // Eidolons
@Getter
private Map<Integer, Integer> skills; // Skill tree
@Deprecated
public AvatarData() {
}
public AvatarData(AvatarExcel excel) {
this.skills = new HashMap<>();
for (var skillTree : excel.getDefaultSkillTrees()) {
this.skills.put(skillTree.getPointID(), skillTree.getLevel());
}
}
}

View File

@@ -1,18 +0,0 @@
package emu.lunarcore.game.avatar;
import dev.morphia.annotations.Entity;
import lombok.Getter;
import lombok.Setter;
@Entity(useDiscriminator = false)
public class AvatarRank {
@Getter @Setter
private int value;
/**
* A helper class that contains information about an avatar's rank.
*/
public AvatarRank() {
}
}

View File

@@ -120,7 +120,7 @@ public class AvatarStorage extends BasePlayerManager implements Iterable<GameAva
if (excel == null) {
return;
}
// Set ownerships
avatar.setExcel(excel);
}

View File

@@ -42,14 +42,13 @@ public class GameAvatar implements GameEntity {
@Indexed @Getter private int ownerUid; // Uid of player that this avatar belongs to
private transient Player owner;
@Setter private transient AvatarExcel excel;
private transient AvatarExcel excel;
private int avatarId; // Id of avatar
@Setter private int level;
@Setter private int exp;
@Setter private int promotion;
private AvatarRank rank; // Eidolons - We use an object for this so we can sync it easily with hero paths
private Map<Integer, Integer> skills;
private AvatarData data;
private int currentHp;
private int currentSp;
@@ -73,17 +72,8 @@ public class GameAvatar implements GameEntity {
public GameAvatar(AvatarExcel excel) {
this();
this.excel = excel;
this.avatarId = excel.getId();
// Set defaults
this.rank = new AvatarRank();
this.skills = new HashMap<>();
// Add skills
for (var skillTree : excel.getDefaultSkillTrees()) {
this.skills.put(skillTree.getPointID(), skillTree.getLevel());
}
this.setExcel(excel);
}
public GameAvatar(HeroPath path) {
@@ -91,6 +81,15 @@ public class GameAvatar implements GameEntity {
this.avatarId = GameConstants.TRAILBLAZER_AVATAR_ID;
this.setHeroPath(path);
}
public void setExcel(AvatarExcel excel) {
if (this.excel == null) {
this.excel = excel;
}
if (this.data == null) {
this.data = new AvatarData(excel);
}
}
public void setOwner(Player player) {
this.owner = player;
@@ -119,11 +118,15 @@ public class GameAvatar implements GameEntity {
}
public int getRank() {
return this.rank.getValue();
return this.getData().getRank();
}
public void setRank(int rank) {
this.rank.setValue(rank);
this.getData().setRank(rank);
}
public Map<Integer, Integer> getSkills() {
return this.getData().getSkills();
}
public void setHeroPath(HeroPath heroPath) {
@@ -132,9 +135,8 @@ public class GameAvatar implements GameEntity {
this.getHeroPath().setAvatar(null);
}
this.rank = heroPath.getRank();
this.skills = heroPath.getSkills();
this.excel = heroPath.getExcel();
this.data = heroPath.getData();
this.excel = heroPath.getExcel(); // DO NOT USE GameAvatar::setExcel for this
this.heroPath = heroPath;
this.heroPath.setAvatar(this);
}

View File

@@ -1,16 +1,17 @@
package emu.lunarcore.game.avatar;
import java.util.HashMap;
import java.util.Map;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import emu.lunarcore.LunarRail;
import emu.lunarcore.data.excel.AvatarExcel;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.AvatarSkillTreeOuterClass.AvatarSkillTree;
import emu.lunarcore.proto.HeroBasicTypeInfoOuterClass.HeroBasicTypeInfo;
import lombok.Getter;
import lombok.Setter;
@@ -22,11 +23,10 @@ public class HeroPath {
@Indexed
private int ownerUid;
private AvatarRank rank;
private Map<Integer, Integer> skills;
private AvatarData data;
@Setter private transient GameAvatar avatar;
@Setter private transient AvatarExcel excel;
private transient AvatarExcel excel;
@Deprecated // Morphia only!
public HeroPath() {
@@ -37,22 +37,30 @@ public class HeroPath {
// Set excel avatar id as id
this.id = excel.getId();
this.ownerUid = player.getUid();
this.excel = excel;
// Set defaults
this.rank = new AvatarRank();
this.skills = new HashMap<>();
// Add skills
for (var skillTree : excel.getDefaultSkillTrees()) {
this.skills.put(skillTree.getPointID(), skillTree.getLevel());
this.setExcel(excel);
}
public void setExcel(AvatarExcel excel) {
if (this.excel == null) {
this.excel = excel;
}
if (this.data == null) {
this.data = new AvatarData(excel);
}
}
public int getRank() {
return this.getData().getRank();
}
public Map<Integer, Integer> getSkills() {
return this.getData().getSkills();
}
public HeroBasicTypeInfo toProto() {
var proto = HeroBasicTypeInfo.newInstance()
.setBasicTypeValue(this.getId())
.setRank(this.getRank().getValue());
.setRank(this.getRank());
for (var skill : getSkills().entrySet()) {
proto.addSkillTreeList(AvatarSkillTree.newInstance().setPointId(skill.getKey()).setLevel(skill.getValue()));