Lineup system rewrite

This commit is contained in:
Melledy
2023-10-29 15:33:06 -07:00
parent d34b26a86c
commit ac1751a749
16 changed files with 233 additions and 132 deletions

View File

@@ -16,7 +16,7 @@ import emu.lunarcore.data.excel.AvatarExcel;
import emu.lunarcore.game.inventory.GameItem; import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.inventory.ItemMainType; import emu.lunarcore.game.inventory.ItemMainType;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.game.scene.Scene; import emu.lunarcore.game.scene.Scene;
import emu.lunarcore.game.scene.entity.GameEntity; import emu.lunarcore.game.scene.entity.GameEntity;
import emu.lunarcore.proto.AvatarOuterClass.Avatar; import emu.lunarcore.proto.AvatarOuterClass.Avatar;

View File

@@ -12,7 +12,7 @@ import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.enums.StageType; import emu.lunarcore.game.enums.StageType;
import emu.lunarcore.game.inventory.GameItem; import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.game.scene.entity.EntityMonster; import emu.lunarcore.game.scene.entity.EntityMonster;
import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo; import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo;
import emu.lunarcore.proto.SceneMonsterOuterClass.SceneMonster; import emu.lunarcore.proto.SceneMonsterOuterClass.SceneMonster;

View File

@@ -118,6 +118,7 @@ public class BattleService extends BaseGameService {
// Add buffs to battle // Add buffs to battle
if (isPlayerCaster) { if (isPlayerCaster) {
GameAvatar avatar = player.getCurrentLeaderAvatar(); GameAvatar avatar = player.getCurrentLeaderAvatar();
if (avatar != null) { if (avatar != null) {
// Maze skill attack event // Maze skill attack event
if (castedSkill) { // Dont need to null check maze skill since we already did it in HandlerSceneCastSkillCsReq if (castedSkill) { // Dont need to null check maze skill since we already did it in HandlerSceneCastSkillCsReq
@@ -126,9 +127,9 @@ public class BattleService extends BaseGameService {
avatar.getExcel().getMazeAttack().onAttack(avatar, battle); avatar.getExcel().getMazeAttack().onAttack(avatar, battle);
} }
// Add elemental weakness buff to enemies // Add elemental weakness buff to enemies
MazeBuff buff = battle.addBuff(avatar.getExcel().getDamageType().getEnterBattleBuff(), player.getLineupManager().getCurrentLeader()); MazeBuff buff = battle.addBuff(avatar.getExcel().getDamageType().getEnterBattleBuff(), battle.getLineup().getLeader());
if (buff != null) { if (buff != null) {
buff.addTargetIndex(player.getLineupManager().getCurrentLeader()); buff.addTargetIndex(battle.getLineup().getLeader());
buff.addDynamicValue("SkillIndex", castedSkill ? 2 : 1); buff.addDynamicValue("SkillIndex", castedSkill ? 2 : 1);
} }
} }

View File

@@ -26,7 +26,7 @@ public class MazeSkillAddBuff extends MazeSkillAction {
int waveCount = battle.getMonsterWaveCount(); int waveCount = battle.getMonsterWaveCount();
// Add buff for each wave id // Add buff for each wave id
for (int i = 0; i < waveCount; i++) { for (int i = 0; i < waveCount; i++) {
battle.addBuff(buffId, caster.getOwner().getLineupManager().getCurrentLeader(), 1 << i); battle.addBuff(buffId, battle.getLineup().getLeader(), 1 << i);
} }
} }

View File

@@ -7,7 +7,7 @@ import emu.lunarcore.data.GameData;
import emu.lunarcore.data.excel.ChallengeExcel; import emu.lunarcore.data.excel.ChallengeExcel;
import emu.lunarcore.game.player.BasePlayerManager; import emu.lunarcore.game.player.BasePlayerManager;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType; import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType;
import emu.lunarcore.server.packet.send.PacketStartChallengeScRsp; import emu.lunarcore.server.packet.send.PacketStartChallengeScRsp;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@@ -34,7 +34,7 @@ public class ChallengeManager extends BasePlayerManager {
// Sanity check lineups // Sanity check lineups
if (excel.getStageNum() >= 1) { if (excel.getStageNum() >= 1) {
// Get lineup // Get lineup
PlayerLineup lineup = getPlayer().getLineupManager().getLineupByIndex(0, ExtraLineupType.LINEUP_CHALLENGE_VALUE); PlayerLineup lineup = getPlayer().getLineupManager().getExtraLineupByType(ExtraLineupType.LINEUP_CHALLENGE_VALUE);
// Make sure this lineup has avatars set // Make sure this lineup has avatars set
if (lineup.getAvatars().size() == 0) return; if (lineup.getAvatars().size() == 0) return;
// Reset hp/sp // Reset hp/sp
@@ -46,7 +46,7 @@ public class ChallengeManager extends BasePlayerManager {
lineup.setMp(5); lineup.setMp(5);
} }
if (excel.getStageNum() >= 2) { if (excel.getStageNum() >= 2) {
PlayerLineup lineup = getPlayer().getLineupManager().getLineupByIndex(0, ExtraLineupType.LINEUP_CHALLENGE_2_VALUE); PlayerLineup lineup = getPlayer().getLineupManager().getExtraLineupByType(ExtraLineupType.LINEUP_CHALLENGE_2_VALUE);
// Make sure this lineup has avatars set // Make sure this lineup has avatars set
if (lineup.getAvatars().size() == 0) return; if (lineup.getAvatars().size() == 0) return;
// Reset hp/sp // Reset hp/sp
@@ -59,7 +59,7 @@ public class ChallengeManager extends BasePlayerManager {
} }
// Set first lineup before we enter scenes // Set first lineup before we enter scenes
getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE_VALUE, false); getPlayer().getLineupManager().setCurrentExtraLineup(ExtraLineupType.LINEUP_CHALLENGE, false);
// Set challenge data for player // Set challenge data for player
ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel); ChallengeInstance instance = new ChallengeInstance(getPlayer(), excel);

View File

@@ -1,4 +1,4 @@
package emu.lunarcore.game.service; package emu.lunarcore.game.inventory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -9,7 +9,6 @@ import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.data.excel.*; import emu.lunarcore.data.excel.*;
import emu.lunarcore.data.excel.ItemComposeExcel.FormulaType; import emu.lunarcore.data.excel.ItemComposeExcel.FormulaType;
import emu.lunarcore.game.avatar.GameAvatar; import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.server.game.BaseGameService; import emu.lunarcore.server.game.BaseGameService;
import emu.lunarcore.server.game.GameServer; import emu.lunarcore.server.game.GameServer;

View File

@@ -29,6 +29,8 @@ import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.gacha.PlayerGachaInfo; import emu.lunarcore.game.gacha.PlayerGachaInfo;
import emu.lunarcore.game.inventory.Inventory; import emu.lunarcore.game.inventory.Inventory;
import emu.lunarcore.game.mail.Mailbox; import emu.lunarcore.game.mail.Mailbox;
import emu.lunarcore.game.player.lineup.LineupManager;
import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.game.rogue.RogueInstance; import emu.lunarcore.game.rogue.RogueInstance;
import emu.lunarcore.game.rogue.RogueManager; import emu.lunarcore.game.rogue.RogueManager;
import emu.lunarcore.game.scene.Scene; import emu.lunarcore.game.scene.Scene;
@@ -138,9 +140,9 @@ public class Player {
// Setup hero paths // Setup hero paths
this.getAvatars().setupHeroPaths(); this.getAvatars().setupHeroPaths();
// Give us a starter character and add it to our main lineup. // Give us the main character
// TODO script tutorial // TODO script tutorial
GameAvatar avatar = new GameAvatar(this.getCurHeroPath()); GameAvatar avatar = new GameAvatar(GameConstants.TRAILBLAZER_AVATAR_ID);
this.addAvatar(avatar); this.addAvatar(avatar);
this.getCurrentLineup().getAvatars().add(avatar.getAvatarId()); this.getCurrentLineup().getAvatars().add(avatar.getAvatarId());
} }
@@ -264,12 +266,7 @@ public class Player {
} }
public GameAvatar getCurrentLeaderAvatar() { public GameAvatar getCurrentLeaderAvatar() {
try { return this.getLineupManager().getCurrentLeaderAvatar();
int avatarId = getCurrentLineup().getAvatars().get(this.getLineupManager().getCurrentLeader());
return this.getAvatarById(avatarId);
} catch (Exception e) {
return null;
}
} }
private void initUid() { private void initUid() {
@@ -544,17 +541,17 @@ public class Player {
public void onLogin() { public void onLogin() {
// Validate // Validate
if (this.getRot() == null) this.rot = new Position(); this.getLineupManager().setPlayer(this);
// Load avatars and inventory first // Load avatars and inventory first
this.getAvatars().loadFromDatabase(); this.getAvatars().loadFromDatabase();
this.getInventory().loadFromDatabase(); this.getInventory().loadFromDatabase();
this.getLineupManager().loadFromDatabase();
this.getMailbox().loadFromDatabase(); this.getMailbox().loadFromDatabase();
this.getChallengeManager().loadFromDatabase(); this.getChallengeManager().loadFromDatabase();
this.getRogueManager().loadFromDatabase(); this.getRogueManager().loadFromDatabase();
// Load Etc // Post database load
this.getLineupManager().validate(this);
this.getAvatars().setupHeroPaths(); this.getAvatars().setupHeroPaths();
// Load into saved scene (should happen after everything else loads) // Load into saved scene (should happen after everything else loads)

View File

@@ -1,38 +1,44 @@
package emu.lunarcore.game.player; package emu.lunarcore.game.player.lineup;
import java.util.List; import java.util.List;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.lunarcore.GameConstants; import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.game.avatar.GameAvatar; import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType; import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType;
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify; import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
@Entity(useDiscriminator = false) @Getter @Entity(useDiscriminator = false) @Getter
public class LineupManager { public class LineupManager {
private transient Player player; private transient Player player;
private PlayerLineup[] lineups;
private int currentIndex; // Team index private int currentIndex; // Team index
private int currentLeader; private int currentExtraIndex;
private int mp; private int mp;
// Extra lineups for challenges/simulated universe/etc private transient PlayerLineup[] lineups;
private transient int currentExtraLineup; private transient PlayerExtraLineup[] extraLineups;
private transient Int2ObjectMap<PlayerExtraLineup> extraLineups;
@Deprecated // Morphia only! @Deprecated // Morphia only!
public LineupManager() { public LineupManager() {
this.extraLineups = new Int2ObjectOpenHashMap<>(); this.lineups = new PlayerLineup[GameConstants.DEFAULT_TEAMS];
this.extraLineups = new PlayerExtraLineup[ExtraLineupType.values().length];
} }
public LineupManager(Player player) { public LineupManager(Player player) {
this(); this();
this.player = player;
this.mp = 5; this.mp = 5;
this.validate(player);
this.validate();
}
public void setPlayer(Player player) {
this.player = player;
} }
protected void addMp(int i) { protected void addMp(int i) {
@@ -54,8 +60,8 @@ public class LineupManager {
* @param sync Whether or not to sync lineup with scene. Not needed when changing scenes. * @param sync Whether or not to sync lineup with scene. Not needed when changing scenes.
*/ */
public void setCurrentExtraLineup(int type, boolean sync) { public void setCurrentExtraLineup(int type, boolean sync) {
this.currentExtraLineup = type; this.currentExtraIndex = type;
this.currentLeader = 0; this.getPlayer().save();
if (sync) { if (sync) {
// Sync with scene entities // Sync with scene entities
@@ -65,25 +71,36 @@ public class LineupManager {
} }
} }
/**
* Sets the player's current extra lineup type.
* @param type Extra lineup type
* @param sync Whether or not to sync lineup with scene. Not needed when changing scenes.
*/
public void setCurrentExtraLineup(ExtraLineupType type, boolean sync) { public void setCurrentExtraLineup(ExtraLineupType type, boolean sync) {
this.setCurrentExtraLineup(type.getNumber(), sync); this.setCurrentExtraLineup(type.getNumber(), sync);
} }
public PlayerLineup getLineupByIndex(int index, int extraLineup) { /**
* Returns a lineup by the type
* @param index Regular lineup index
* @param extraLineup
* @return
*/
public PlayerLineup getLineupByIndex(int index, int extraLineupType) {
// Sanity // Sanity
if (extraLineup > 0) { if (extraLineupType > 0) {
return getExtraLineupByType(extraLineup); return getExtraLineupByType(extraLineupType);
} else { } else {
return getLineupByIndex(index); return getLineupByIndex(index);
} }
} }
/* /**
* Get player lineup by index. Only normal lineups are returned * Gets a regular player lineup by index. Only normal lineups are returned
*/ */
public PlayerLineup getLineupByIndex(int index) { public PlayerLineup getLineupByIndex(int index) {
// Sanity // Sanity check
if (index < 0 || index >= this.getLineups().length) { if (index < 0 || index >= this.lineups.length) {
return null; return null;
} }
@@ -91,21 +108,40 @@ public class LineupManager {
} }
/** /**
* Gets player lineup by ExtraLineupType. Creates a lineup for the player if it doesnt exist. * Returns a lineup by ExtraLineupType. Creates a lineup for the player if it doesnt exist.
* @param extraLineupType * @param type ExtraLineupType
* @return
*/ */
private PlayerLineup getExtraLineupByType(int extraLineupType) { public PlayerLineup getExtraLineupByType(int type) {
return getExtraLineups().computeIfAbsent(extraLineupType, type -> new PlayerExtraLineup(getPlayer(), type)); // Sanity check to make sure the extra lineup type actually exists
if (type <= 0 || type >= this.extraLineups.length) {
return null;
}
// Actually get the lineup
PlayerExtraLineup lineup = this.extraLineups[type];
if (lineup == null) {
lineup = new PlayerExtraLineup(this.getPlayer(), type);
this.extraLineups[type] = lineup;
}
return lineup;
} }
/**
* Returns the current lineup that the player is using.
*/
public PlayerLineup getCurrentLineup() { public PlayerLineup getCurrentLineup() {
return this.getLineupByIndex(this.currentIndex, this.getCurrentExtraLineup()); return this.getLineupByIndex(this.currentIndex, this.currentExtraIndex);
} }
/**
* Returns the avatar that the player is playing as from the current lineup.
*/
public GameAvatar getCurrentLeaderAvatar() { public GameAvatar getCurrentLeaderAvatar() {
try { try {
int avatarId = this.getCurrentLineup().getAvatars().get(currentLeader); PlayerLineup lineup = this.getCurrentLineup();
int avatarId = lineup.getAvatars().get(lineup.getLeader());
return this.getPlayer().getAvatarById(avatarId); return this.getPlayer().getAvatarById(avatarId);
} catch (Exception e) { } catch (Exception e) {
return null; return null;
@@ -115,8 +151,10 @@ public class LineupManager {
// Lineup functions // Lineup functions
public boolean changeLeader(int slot) { public boolean changeLeader(int slot) {
if (slot >= 0 && slot < this.getCurrentLineup().size()) { PlayerLineup lineup = this.getCurrentLineup();
this.currentLeader = slot;
if (slot >= 0 && slot < lineup.size()) {
lineup.setLeader(slot);
return true; return true;
} }
@@ -147,7 +185,7 @@ public class LineupManager {
} }
// Save // Save
this.getPlayer().save(); lineup.save();
// Sync lineup with scene // Sync lineup with scene
if (isCurrentLineup) { if (isCurrentLineup) {
@@ -180,13 +218,13 @@ public class LineupManager {
return false; return false;
} }
// Validate leader index // Validate leader slot
if (this.getCurrentLeader() >= lineup.size()) { if (lineup.getLeader() >= lineup.size()) {
this.currentLeader = 0; lineup.setLeader(0);
} }
// Save // Save
this.getPlayer().save(); lineup.save();
// Sync lineup with scene // Sync lineup with scene
if (isCurrentLineup) { if (isCurrentLineup) {
@@ -201,7 +239,7 @@ public class LineupManager {
public boolean switchLineup(int index) { public boolean switchLineup(int index) {
// Sanity + Prevent lineups from being changed when the player is using an extra lineup // Sanity + Prevent lineups from being changed when the player is using an extra lineup
if (index == this.getCurrentIndex() || this.currentExtraLineup > 0) { if (index == this.getCurrentIndex() || this.currentExtraIndex > 0) {
return false; return false;
} }
@@ -215,9 +253,8 @@ public class LineupManager {
// Set index // Set index
this.currentIndex = index; this.currentIndex = index;
this.currentLeader = 0;
// Save // Save player
this.getPlayer().save(); this.getPlayer().save();
// Sync lineup data // Sync lineup data
@@ -248,13 +285,13 @@ public class LineupManager {
} }
} }
// Validate leader index // Validate leader slot
if (this.getCurrentLeader() >= lineup.size()) { if (lineup.getLeader() >= lineup.size()) {
this.currentLeader = 0; lineup.setLeader(0);
} }
// Save // Save
this.getPlayer().save(); lineup.save();
// Sync lineup with scene // Sync lineup with scene
if (lineup == getCurrentLineup()) { if (lineup == getCurrentLineup()) {
@@ -289,7 +326,7 @@ public class LineupManager {
lineup.getAvatars().set(dest, srcId); lineup.getAvatars().set(dest, srcId);
// Save // Save
this.getPlayer().save(); lineup.save();
// Sync lineup data // Sync lineup data
player.sendPacket(new PacketSyncLineupNotify(lineup)); player.sendPacket(new PacketSyncLineupNotify(lineup));
@@ -302,38 +339,78 @@ public class LineupManager {
PlayerLineup lineup = this.getLineupByIndex(index); PlayerLineup lineup = this.getLineupByIndex(index);
if (lineup == null) return false; if (lineup == null) return false;
// Change name // Change name and save lineup
lineup.setName(name); lineup.setName(name);
lineup.save();
return true; return true;
} }
// Max sure all lineups exist in the array public void loadFromDatabase() {
public void validate(Player player) { // Load lineups from database
// Set player var list = LunarCore.getGameDatabase()
this.player = player; .getObjects(PlayerLineup.class, "ownerUid", getPlayer().getUid())
.toList();
// Make sure lineups exist for (var lineup : list) {
if (this.getLineups() == null) { // Set owner
this.lineups = new PlayerLineup[GameConstants.DEFAULT_TEAMS]; lineup.setOwner(this.getPlayer());
} else if (this.getLineups().length != GameConstants.DEFAULT_TEAMS) {
// TODO move lineups from old array to this new one
this.lineups = new PlayerLineup[GameConstants.DEFAULT_TEAMS];
}
// Create new lineups for any missing ones // Add to lineups
for (int i = 0; i < this.lineups.length; i++) { try {
if (this.lineups[i] == null) { this.lineups[lineup.getIndex()] = lineup;
this.lineups[i] = new PlayerLineup(getPlayer(), i); } catch (Exception e) {
} else { lineup.delete();
this.lineups[i].setOwnerAndIndex(getPlayer(), i);
} }
} }
// Set current index if out of bounds // Load extra lineups from database
if (this.currentIndex < 0) { var extraList = LunarCore.getGameDatabase()
.getObjects(PlayerExtraLineup.class, "ownerUid", getPlayer().getUid())
.toList();
for (var lineup : extraList) {
// Set owner
lineup.setOwner(this.getPlayer());
// Add to lineups
try {
this.extraLineups[lineup.getExtraLineupType()] = lineup;
} catch (Exception e) {
lineup.delete();
}
}
// Validate lineups
this.validate();
}
private void validate() {
// Populate all lineups
for (int i = 0; i < GameConstants.DEFAULT_TEAMS; i++) {
PlayerLineup lineup = this.lineups[i];
if (lineup == null) {
lineup = new PlayerLineup(this.getPlayer(), i);
this.lineups[i] = lineup;
} else {
lineup.setOwner(this.getPlayer());
}
}
// Make sure current lineup has at least one avatar
PlayerLineup lineup = this.getCurrentLineup();
if (lineup == null) {
this.currentIndex = 0; this.currentIndex = 0;
} else if (this.currentIndex >= this.lineups.length) { this.currentExtraIndex = 0;
this.currentIndex = this.lineups.length - 1; lineup = this.getCurrentLineup();
}
if (lineup.getAvatars().size() == 0) {
GameAvatar avatar = this.getPlayer().getAvatarById(GameConstants.TRAILBLAZER_AVATAR_ID);
if (avatar != null) {
lineup.getAvatars().add(avatar.getAvatarId());
}
} }
} }
} }

View File

@@ -1,20 +1,19 @@
package emu.lunarcore.game.player; package emu.lunarcore.game.player.lineup;
import dev.morphia.annotations.Entity;
import emu.lunarcore.GameConstants; import emu.lunarcore.GameConstants;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify; import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
@Entity(value = "lineupsExtra", useDiscriminator = false)
public class PlayerExtraLineup extends PlayerLineup { public class PlayerExtraLineup extends PlayerLineup {
private int extraLineupType;
private int mp; private int mp;
@Deprecated // Morphia only! @Deprecated // Morphia only!
public PlayerExtraLineup() { public PlayerExtraLineup() {}
}
public PlayerExtraLineup(Player player, int extraLineupType) { public PlayerExtraLineup(Player player, int extraLineupType) {
super(player, 0); super(player, extraLineupType);
this.extraLineupType = extraLineupType;
} }
@Override @Override
@@ -22,9 +21,14 @@ public class PlayerExtraLineup extends PlayerLineup {
return true; return true;
} }
@Override
public int getIndex() {
return 0;
}
@Override @Override
public int getExtraLineupType() { public int getExtraLineupType() {
return extraLineupType; return this.index;
} }
@Override @Override

View File

@@ -1,57 +1,65 @@
package emu.lunarcore.game.player; package emu.lunarcore.game.player.lineup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.bson.types.ObjectId;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Indexed;
import emu.lunarcore.GameConstants; import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.game.avatar.GameAvatar; import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.LineupInfoOuterClass.LineupInfo; import emu.lunarcore.proto.LineupInfoOuterClass.LineupInfo;
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify; import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
@Entity(useDiscriminator = false) @Getter @Entity(value = "lineups", useDiscriminator = false) @Getter
public class PlayerLineup { public class PlayerLineup {
private transient Player owner; @Id private ObjectId id;
private transient int index;
private String name; @Indexed private int ownerUid;
private List<Integer> avatars; private transient Player owner;
protected int index;
protected List<Integer> avatars;
@Setter private int leader;
@Setter private String name;
@Deprecated // Morphia only! @Deprecated // Morphia only!
public PlayerLineup() { public PlayerLineup() {}
}
public PlayerLineup(Player player, int index) { public PlayerLineup(Player player, int index) {
this.owner = player; this.owner = player;
this.ownerUid = player.getUid();
this.index = index; this.index = index;
this.avatars = new ArrayList<>(GameConstants.MAX_AVATARS_IN_TEAM); this.avatars = new ArrayList<>(GameConstants.MAX_AVATARS_IN_TEAM);
// Set team name if not an extra lineup // Set team name if not an extra lineup
if (!this.isExtraLineup()) { if (!this.isExtraLineup()) {
this.name = "Team " + (index + 1); this.name = "Team " + (index + 1);
} else {
this.name = "";
} }
} }
protected void setOwnerAndIndex(Player player, int index) { protected void setOwner(Player player) {
this.owner = player; this.owner = player;
this.index = index;
} }
public boolean isExtraLineup() { public boolean isExtraLineup() {
return false; return false;
} }
public int getExtraLineupType() { public int getIndex() {
return 0; return this.index;
} }
public void setName(String name) { public int getExtraLineupType() {
this.name = name; return 0;
} }
public synchronized List<Integer> getAvatars() { public synchronized List<Integer> getAvatars() {
@@ -115,15 +123,30 @@ public class PlayerLineup {
} }
} }
// Database
public void save() {
LunarCore.getGameDatabase().save(this);
}
public void delete() {
LunarCore.getGameDatabase().delete(this);
}
// Serialization
public LineupInfo toProto() { public LineupInfo toProto() {
var proto = LineupInfo.newInstance() var proto = LineupInfo.newInstance()
.setIndex(index) .setIndex(this.getIndex())
.setName(this.getName()) .setLeaderSlot(this.getLeader())
.setLeaderSlot(this.getOwner().getLineupManager().getCurrentLeader())
.setMp(this.getMp()) .setMp(this.getMp())
.setMaxMp(GameConstants.MAX_MP) .setMaxMp(GameConstants.MAX_MP)
.setExtraLineupTypeValue(this.getExtraLineupType()); .setExtraLineupTypeValue(this.getExtraLineupType());
if (this.getName() != null) {
proto.setName(this.getName());
}
for (int slot = 0; slot < this.getAvatars().size(); slot++) { for (int slot = 0; slot < this.getAvatars().size(); slot++) {
GameAvatar avatar = owner.getAvatars().getAvatarById(getAvatars().get(slot)); GameAvatar avatar = owner.getAvatars().getAvatarById(getAvatars().get(slot));
if (avatar == null) continue; if (avatar == null) continue;

View File

@@ -10,7 +10,7 @@ import emu.lunarcore.data.GameDepot;
import emu.lunarcore.data.excel.RogueTalentExcel; import emu.lunarcore.data.excel.RogueTalentExcel;
import emu.lunarcore.game.player.BasePlayerManager; import emu.lunarcore.game.player.BasePlayerManager;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType; import emu.lunarcore.proto.ExtraLineupTypeOuterClass.ExtraLineupType;
import emu.lunarcore.proto.RogueAeonInfoOuterClass.RogueAeonInfo; import emu.lunarcore.proto.RogueAeonInfoOuterClass.RogueAeonInfo;
import emu.lunarcore.proto.RogueAreaOuterClass.RogueArea; import emu.lunarcore.proto.RogueAreaOuterClass.RogueArea;

View File

@@ -9,11 +9,11 @@ import emu.lunarcore.data.config.GroupInfo.GroupLoadSide;
import emu.lunarcore.data.excel.MazePlaneExcel; import emu.lunarcore.data.excel.MazePlaneExcel;
import emu.lunarcore.game.avatar.GameAvatar; import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.enums.PlaneType; import emu.lunarcore.game.enums.PlaneType;
import emu.lunarcore.game.player.PlayerLineup;
import emu.lunarcore.game.scene.entity.*; import emu.lunarcore.game.scene.entity.*;
import emu.lunarcore.game.scene.triggers.PropTrigger; import emu.lunarcore.game.scene.triggers.PropTrigger;
import emu.lunarcore.game.scene.triggers.PropTriggerType; import emu.lunarcore.game.scene.triggers.PropTriggerType;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.SceneEntityGroupInfoOuterClass.SceneEntityGroupInfo; import emu.lunarcore.proto.SceneEntityGroupInfoOuterClass.SceneEntityGroupInfo;
import emu.lunarcore.proto.SceneGroupStateOuterClass.SceneGroupState; import emu.lunarcore.proto.SceneGroupStateOuterClass.SceneGroupState;
import emu.lunarcore.proto.SceneInfoOuterClass.SceneInfo; import emu.lunarcore.proto.SceneInfoOuterClass.SceneInfo;
@@ -316,7 +316,7 @@ public class Scene {
// Get current lineup // Get current lineup
PlayerLineup lineup = getPlayer().getCurrentLineup(); PlayerLineup lineup = getPlayer().getCurrentLineup();
int leaderAvatarId = lineup.getAvatars().get(getPlayer().getLineupManager().getCurrentLeader()); int leaderAvatarId = lineup.getAvatars().get(lineup.getLeader());
// Sort entities into groups // Sort entities into groups
var groups = new Int2ObjectOpenHashMap<SceneEntityGroupInfo>(); var groups = new Int2ObjectOpenHashMap<SceneEntityGroupInfo>();

View File

@@ -8,8 +8,8 @@ import emu.lunarcore.Config.GameServerConfig;
import emu.lunarcore.LunarCore; import emu.lunarcore.LunarCore;
import emu.lunarcore.game.battle.BattleService; import emu.lunarcore.game.battle.BattleService;
import emu.lunarcore.game.gacha.GachaService; import emu.lunarcore.game.gacha.GachaService;
import emu.lunarcore.game.inventory.InventoryService;
import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.service.InventoryService;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import kcp.highway.ChannelConfig; import kcp.highway.ChannelConfig;

View File

@@ -1,7 +1,7 @@
package emu.lunarcore.server.packet.send; package emu.lunarcore.server.packet.send;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.LineupManager;
import emu.lunarcore.game.player.LineupManager; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.GetAllLineupDataScRspOuterClass.GetAllLineupDataScRsp; import emu.lunarcore.proto.GetAllLineupDataScRspOuterClass.GetAllLineupDataScRsp;
import emu.lunarcore.server.game.GameSession; import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.BasePacket; import emu.lunarcore.server.packet.BasePacket;

View File

@@ -1,6 +1,6 @@
package emu.lunarcore.server.packet.send; package emu.lunarcore.server.packet.send;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.SwitchLineupIndexScRspOuterClass.SwitchLineupIndexScRsp; import emu.lunarcore.proto.SwitchLineupIndexScRspOuterClass.SwitchLineupIndexScRsp;
import emu.lunarcore.server.packet.BasePacket; import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId; import emu.lunarcore.server.packet.CmdId;

View File

@@ -1,6 +1,6 @@
package emu.lunarcore.server.packet.send; package emu.lunarcore.server.packet.send;
import emu.lunarcore.game.player.PlayerLineup; import emu.lunarcore.game.player.lineup.PlayerLineup;
import emu.lunarcore.proto.SyncLineupNotifyOuterClass.SyncLineupNotify; import emu.lunarcore.proto.SyncLineupNotifyOuterClass.SyncLineupNotify;
import emu.lunarcore.server.packet.BasePacket; import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId; import emu.lunarcore.server.packet.CmdId;