mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 14:54:43 +01:00
Rework how avatar skills and rank are stored
This commit is contained in:
32
src/main/java/emu/lunarcore/game/avatar/AvatarData.java
Normal file
32
src/main/java/emu/lunarcore/game/avatar/AvatarData.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -120,7 +120,7 @@ public class AvatarStorage extends BasePlayerManager implements Iterable<GameAva
|
|||||||
if (excel == null) {
|
if (excel == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ownerships
|
// Set ownerships
|
||||||
avatar.setExcel(excel);
|
avatar.setExcel(excel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,14 +42,13 @@ public class GameAvatar implements GameEntity {
|
|||||||
@Indexed @Getter private int ownerUid; // Uid of player that this avatar belongs to
|
@Indexed @Getter private int ownerUid; // Uid of player that this avatar belongs to
|
||||||
|
|
||||||
private transient Player owner;
|
private transient Player owner;
|
||||||
@Setter private transient AvatarExcel excel;
|
private transient AvatarExcel excel;
|
||||||
|
|
||||||
private int avatarId; // Id of avatar
|
private int avatarId; // Id of avatar
|
||||||
@Setter private int level;
|
@Setter private int level;
|
||||||
@Setter private int exp;
|
@Setter private int exp;
|
||||||
@Setter private int promotion;
|
@Setter private int promotion;
|
||||||
private AvatarRank rank; // Eidolons - We use an object for this so we can sync it easily with hero paths
|
private AvatarData data;
|
||||||
private Map<Integer, Integer> skills;
|
|
||||||
|
|
||||||
private int currentHp;
|
private int currentHp;
|
||||||
private int currentSp;
|
private int currentSp;
|
||||||
@@ -73,17 +72,8 @@ public class GameAvatar implements GameEntity {
|
|||||||
|
|
||||||
public GameAvatar(AvatarExcel excel) {
|
public GameAvatar(AvatarExcel excel) {
|
||||||
this();
|
this();
|
||||||
this.excel = excel;
|
|
||||||
this.avatarId = excel.getId();
|
this.avatarId = excel.getId();
|
||||||
|
this.setExcel(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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameAvatar(HeroPath path) {
|
public GameAvatar(HeroPath path) {
|
||||||
@@ -91,6 +81,15 @@ public class GameAvatar implements GameEntity {
|
|||||||
this.avatarId = GameConstants.TRAILBLAZER_AVATAR_ID;
|
this.avatarId = GameConstants.TRAILBLAZER_AVATAR_ID;
|
||||||
this.setHeroPath(path);
|
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) {
|
public void setOwner(Player player) {
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
@@ -119,11 +118,15 @@ public class GameAvatar implements GameEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRank() {
|
public int getRank() {
|
||||||
return this.rank.getValue();
|
return this.getData().getRank();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRank(int rank) {
|
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) {
|
public void setHeroPath(HeroPath heroPath) {
|
||||||
@@ -132,9 +135,8 @@ public class GameAvatar implements GameEntity {
|
|||||||
this.getHeroPath().setAvatar(null);
|
this.getHeroPath().setAvatar(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rank = heroPath.getRank();
|
this.data = heroPath.getData();
|
||||||
this.skills = heroPath.getSkills();
|
this.excel = heroPath.getExcel(); // DO NOT USE GameAvatar::setExcel for this
|
||||||
this.excel = heroPath.getExcel();
|
|
||||||
this.heroPath = heroPath;
|
this.heroPath = heroPath;
|
||||||
this.heroPath.setAvatar(this);
|
this.heroPath.setAvatar(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
package emu.lunarcore.game.avatar;
|
package emu.lunarcore.game.avatar;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Id;
|
import dev.morphia.annotations.Id;
|
||||||
import dev.morphia.annotations.Indexed;
|
import dev.morphia.annotations.Indexed;
|
||||||
|
|
||||||
import emu.lunarcore.LunarRail;
|
import emu.lunarcore.LunarRail;
|
||||||
import emu.lunarcore.data.excel.AvatarExcel;
|
import emu.lunarcore.data.excel.AvatarExcel;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.proto.AvatarSkillTreeOuterClass.AvatarSkillTree;
|
import emu.lunarcore.proto.AvatarSkillTreeOuterClass.AvatarSkillTree;
|
||||||
import emu.lunarcore.proto.HeroBasicTypeInfoOuterClass.HeroBasicTypeInfo;
|
import emu.lunarcore.proto.HeroBasicTypeInfoOuterClass.HeroBasicTypeInfo;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -22,11 +23,10 @@ public class HeroPath {
|
|||||||
@Indexed
|
@Indexed
|
||||||
private int ownerUid;
|
private int ownerUid;
|
||||||
|
|
||||||
private AvatarRank rank;
|
private AvatarData data;
|
||||||
private Map<Integer, Integer> skills;
|
|
||||||
|
|
||||||
@Setter private transient GameAvatar avatar;
|
@Setter private transient GameAvatar avatar;
|
||||||
@Setter private transient AvatarExcel excel;
|
private transient AvatarExcel excel;
|
||||||
|
|
||||||
@Deprecated // Morphia only!
|
@Deprecated // Morphia only!
|
||||||
public HeroPath() {
|
public HeroPath() {
|
||||||
@@ -37,22 +37,30 @@ public class HeroPath {
|
|||||||
// Set excel avatar id as id
|
// Set excel avatar id as id
|
||||||
this.id = excel.getId();
|
this.id = excel.getId();
|
||||||
this.ownerUid = player.getUid();
|
this.ownerUid = player.getUid();
|
||||||
this.excel = excel;
|
this.setExcel(excel);
|
||||||
|
}
|
||||||
// Set defaults
|
|
||||||
this.rank = new AvatarRank();
|
public void setExcel(AvatarExcel excel) {
|
||||||
this.skills = new HashMap<>();
|
if (this.excel == null) {
|
||||||
|
this.excel = excel;
|
||||||
// Add skills
|
|
||||||
for (var skillTree : excel.getDefaultSkillTrees()) {
|
|
||||||
this.skills.put(skillTree.getPointID(), skillTree.getLevel());
|
|
||||||
}
|
}
|
||||||
|
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() {
|
public HeroBasicTypeInfo toProto() {
|
||||||
var proto = HeroBasicTypeInfo.newInstance()
|
var proto = HeroBasicTypeInfo.newInstance()
|
||||||
.setBasicTypeValue(this.getId())
|
.setBasicTypeValue(this.getId())
|
||||||
.setRank(this.getRank().getValue());
|
.setRank(this.getRank());
|
||||||
|
|
||||||
for (var skill : getSkills().entrySet()) {
|
for (var skill : getSkills().entrySet()) {
|
||||||
proto.addSkillTreeList(AvatarSkillTree.newInstance().setPointId(skill.getKey()).setLevel(skill.getValue()));
|
proto.addSkillTreeList(AvatarSkillTree.newInstance().setPointId(skill.getKey()).setLevel(skill.getValue()));
|
||||||
|
|||||||
Reference in New Issue
Block a user