Refactor some stuff in LineupManager

This commit is contained in:
Melledy
2023-09-30 02:09:02 -07:00
parent 2076efaef2
commit 7b6ee81910
7 changed files with 24 additions and 21 deletions

View File

@@ -221,7 +221,7 @@ public class BattleService extends BaseGameService {
}
// Create new battle for player
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), stage);
Battle battle = new Battle(player, player.getCurrentLineup(), stage);
player.setBattle(battle);
// Send packet

View File

@@ -33,19 +33,19 @@ public class LineupManager {
this.validate(player);
}
public PlayerLineup getLineup(int index, int extraLineup) {
public PlayerLineup getLineupByIndex(int index, int extraLineup) {
// Sanity
if (extraLineup > 0) {
return getExtraLineup(extraLineup);
return getExtraLineupByType(extraLineup);
} else {
return getLineup(index);
return getLineupByIndex(index);
}
}
/*
* Get player lineup by index. Only normal lineups are returned
*/
public PlayerLineup getLineup(int index) {
public PlayerLineup getLineupByIndex(int index) {
// Sanity
if (index < 0 || index >= this.getLineups().length) {
return null;
@@ -59,7 +59,7 @@ public class LineupManager {
* @param extraLineupType
* @return
*/
private PlayerLineup getExtraLineup(int extraLineupType) {
private PlayerLineup getExtraLineupByType(int extraLineupType) {
PlayerLineup lineup = this.extraLineups.get(extraLineupType);
if (lineup == null) {
@@ -72,7 +72,7 @@ public class LineupManager {
}
public PlayerLineup getCurrentLineup() {
return this.getLineup(this.currentIndex, this.getCurrentExtraLineup());
return this.getLineupByIndex(this.currentIndex, this.getCurrentExtraLineup());
}
public GameAvatar getCurrentLeaderAvatar() {
@@ -97,7 +97,7 @@ public class LineupManager {
public boolean joinLineup(int index, int slot, int avatarId) {
// Get lineup
PlayerLineup lineup = this.getLineup(index);
PlayerLineup lineup = this.getLineupByIndex(index);
if (lineup == null) return false;
boolean isCurrentLineup = lineup == getCurrentLineup();
@@ -134,7 +134,7 @@ public class LineupManager {
public boolean quitLineup(int index, int avatarId) {
// Get lineup
PlayerLineup lineup = this.getLineup(index);
PlayerLineup lineup = this.getLineupByIndex(index);
if (lineup == null) return false;
boolean isCurrentLineup = lineup == getCurrentLineup();
@@ -178,7 +178,7 @@ public class LineupManager {
}
// Get lineup
PlayerLineup lineup = this.getLineup(index);
PlayerLineup lineup = this.getLineupByIndex(index);
// Make sure lineup exists and has size
if (lineup == null || lineup.size() == 0) {
@@ -201,7 +201,7 @@ public class LineupManager {
public boolean replaceLineup(int index, int extraLineupType, List<Integer> lineupList) {
// Get lineup
PlayerLineup lineup = this.getLineup(index, extraLineupType);
PlayerLineup lineup = this.getLineupByIndex(index, extraLineupType);
if (lineup == null) return false;
// Sanity - Make sure player cant remove all avatars from the current lineup
@@ -244,7 +244,7 @@ public class LineupManager {
if (src == dest) return false;
// Get lineup
PlayerLineup lineup = this.getLineup(index);
PlayerLineup lineup = this.getLineupByIndex(index);
// Validate slots
if ((lineup == null) || (src < 0 && src >= lineup.size())) {
return false;
@@ -271,7 +271,7 @@ public class LineupManager {
public boolean changeLineupName(int index, String name) {
// Get lineup
PlayerLineup lineup = this.getLineup(index);
PlayerLineup lineup = this.getLineupByIndex(index);
if (lineup == null) return false;
// Change name

View File

@@ -108,7 +108,7 @@ public class Player {
// TODO script tutorial
GameAvatar avatar = new GameAvatar(this.getCurHeroPath());
this.getAvatars().addAvatar(avatar);
this.getLineupManager().getCurrentLineup().getAvatars().add(avatar.getAvatarId());
this.getCurrentLineup().getAvatars().add(avatar.getAvatarId());
}
public GameServer getServer() {
@@ -173,6 +173,10 @@ public class Player {
return getAvatars().getAvatarById(avatarId);
}
public PlayerLineup getCurrentLineup() {
return this.getLineupManager().getCurrentLineup();
}
private void initUid() {
if (this.uid > 0) return;

View File

@@ -3,13 +3,11 @@ package emu.lunarcore.game.scene;
import java.util.ArrayList;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.config.*;
import emu.lunarcore.data.config.GroupInfo.GroupLoadSide;
import emu.lunarcore.data.excel.MazePlaneExcel;
import emu.lunarcore.data.excel.NpcMonsterExcel;
import emu.lunarcore.data.excel.StageExcel;
import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.player.PlayerLineup;
@@ -19,6 +17,7 @@ import emu.lunarcore.proto.SceneEntityGroupInfoOuterClass.SceneEntityGroupInfo;
import emu.lunarcore.proto.SceneInfoOuterClass.SceneInfo;
import emu.lunarcore.server.packet.send.PacketActivateFarmElementScRsp;
import emu.lunarcore.server.packet.send.PacketSceneGroupRefreshScNotify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
@@ -53,7 +52,7 @@ public class Scene {
this.avatars = new Int2ObjectOpenHashMap<>();
this.entities = new Int2ObjectOpenHashMap<>();
PlayerLineup lineup = getPlayer().getLineupManager().getCurrentLineup();
PlayerLineup lineup = getPlayer().getCurrentLineup();
for (int avatarId : lineup.getAvatars()) {
GameAvatar avatar = getPlayer().getAvatarById(avatarId);
@@ -249,7 +248,7 @@ public class Scene {
.setEntryId(this.getEntryId());
// Get current lineup
PlayerLineup lineup = getPlayer().getLineupManager().getCurrentLineup();
PlayerLineup lineup = getPlayer().getCurrentLineup();
int leaderAvatarId = lineup.getAvatars().get(getPlayer().getLineupManager().getCurrentLeader());
// Sort entities into groups

View File

@@ -15,7 +15,7 @@ public class HandlerSwitchLineupIndexCsReq extends PacketHandler {
var req = SwitchLineupIndexCsReq.parseFrom(data);
session.getPlayer().getLineupManager().switchLineup(req.getIndex());
session.send(new PacketSwitchLineupIndexScRsp(session.getPlayer().getLineupManager().getCurrentLineup()));
session.send(new PacketSwitchLineupIndexScRsp(session.getPlayer().getCurrentLineup()));
}
}

View File

@@ -11,7 +11,7 @@ public class PacketEnterSceneByServerScNotify extends BasePacket {
super(CmdId.EnterSceneByServerScNotify);
var data = EnterSceneByServerScNotify.newInstance()
.setLineup(player.getLineupManager().getCurrentLineup().toProto())
.setLineup(player.getCurrentLineup().toProto())
.setScene(player.getScene().toProto());
this.setData(data);

View File

@@ -11,7 +11,7 @@ public class PacketGetCurLineupDataScRsp extends BasePacket {
super(CmdId.GetCurLineupDataScRsp);
var data = GetCurLineupDataScRsp.newInstance()
.setLineup(session.getPlayer().getLineupManager().getCurrentLineup().toProto());
.setLineup(session.getPlayer().getCurrentLineup().toProto());
this.setData(data);
}