mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 06:45:04 +01:00
Rework lineup system to allow for extra types of lineups
This commit is contained in:
@@ -6,6 +6,8 @@ import dev.morphia.annotations.Entity;
|
|||||||
import emu.lunarcore.GameConstants;
|
import emu.lunarcore.GameConstants;
|
||||||
import emu.lunarcore.game.avatar.GameAvatar;
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
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
|
||||||
@@ -15,10 +17,14 @@ public class LineupManager {
|
|||||||
private PlayerLineup[] lineups;
|
private PlayerLineup[] lineups;
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
private int currentLeader;
|
private int currentLeader;
|
||||||
|
|
||||||
|
// Extra lineups for challenges/simulated universe/etc
|
||||||
|
private transient int currentExtraLineup;
|
||||||
|
private transient Int2ObjectMap<PlayerLineup> extraLineups;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated // Morphia only!
|
||||||
public LineupManager() {
|
public LineupManager() {
|
||||||
// Morphia only!
|
this.extraLineups = new Int2ObjectOpenHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LineupManager(Player player) {
|
public LineupManager(Player player) {
|
||||||
@@ -26,7 +32,19 @@ public class LineupManager {
|
|||||||
|
|
||||||
this.validate(player);
|
this.validate(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerLineup getLineup(int index, int extraLineup) {
|
||||||
|
// Sanity
|
||||||
|
if (extraLineup > 0) {
|
||||||
|
return getExtraLineup(extraLineup);
|
||||||
|
} else {
|
||||||
|
return getLineup(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get player lineup by index. Only normal lineups are returned
|
||||||
|
*/
|
||||||
public PlayerLineup getLineup(int index) {
|
public PlayerLineup getLineup(int index) {
|
||||||
// Sanity
|
// Sanity
|
||||||
if (index < 0 || index >= this.getLineups().length) {
|
if (index < 0 || index >= this.getLineups().length) {
|
||||||
@@ -35,9 +53,26 @@ public class LineupManager {
|
|||||||
|
|
||||||
return this.lineups[index];
|
return this.lineups[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets player lineup by ExtraLineupType. Creates a lineup for the player if it doesnt exist.
|
||||||
|
* @param extraLineupType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private PlayerLineup getExtraLineup(int extraLineupType) {
|
||||||
|
PlayerLineup lineup = this.extraLineups.get(extraLineupType);
|
||||||
|
|
||||||
|
if (lineup == null) {
|
||||||
|
lineup = new PlayerLineup(0, extraLineupType);
|
||||||
|
lineup.setOwnerAndIndex(this.getPlayer(), 0);
|
||||||
|
this.extraLineups.put(extraLineupType, lineup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lineup;
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerLineup getCurrentLineup() {
|
public PlayerLineup getCurrentLineup() {
|
||||||
return getLineup(this.currentIndex);
|
return this.getLineup(this.currentIndex, this.getCurrentExtraLineup());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameAvatar getCurrentLeaderAvatar() {
|
public GameAvatar getCurrentLeaderAvatar() {
|
||||||
@@ -164,16 +199,16 @@ public class LineupManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean replaceLineup(int index, List<Integer> lineupList) {
|
public boolean replaceLineup(int index, int extraLineupType, List<Integer> lineupList) {
|
||||||
|
// Get lineup
|
||||||
|
PlayerLineup lineup = this.getLineup(index, extraLineupType);
|
||||||
|
if (lineup == null) return false;
|
||||||
|
|
||||||
// Sanity - Make sure player cant remove all avatars from the current lineup
|
// Sanity - Make sure player cant remove all avatars from the current lineup
|
||||||
if (index == this.currentIndex && lineupList.size() == 0) {
|
if (lineup == this.getCurrentLineup() && lineupList.size() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get lineup
|
|
||||||
PlayerLineup lineup = this.getLineup(index);
|
|
||||||
if (lineup == null) return false;
|
|
||||||
|
|
||||||
// Clear
|
// Clear
|
||||||
lineup.getAvatars().clear();
|
lineup.getAvatars().clear();
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import lombok.Getter;
|
|||||||
public class PlayerLineup {
|
public class PlayerLineup {
|
||||||
private transient Player owner;
|
private transient Player owner;
|
||||||
private transient int index;
|
private transient int index;
|
||||||
|
private transient int extraLineupType;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private List<Integer> avatars;
|
private List<Integer> avatars;
|
||||||
@@ -22,16 +23,31 @@ public class PlayerLineup {
|
|||||||
public PlayerLineup() {
|
public PlayerLineup() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerLineup(int index) {
|
public PlayerLineup(int index) {
|
||||||
this.name = "Squad " + (index + 1);
|
this(index, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerLineup(int index, int extraLineupType) {
|
||||||
|
this.extraLineupType = extraLineupType;
|
||||||
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
|
||||||
|
if (!this.isExtraLineup()) {
|
||||||
|
this.name = "Squad " + (index + 1);
|
||||||
|
} else {
|
||||||
|
this.name = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setOwnerAndIndex(Player player, int index) {
|
protected void setOwnerAndIndex(Player player, int index) {
|
||||||
this.owner = player;
|
this.owner = player;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isExtraLineup() {
|
||||||
|
return this.extraLineupType != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class HandlerReplaceLineupCsReq extends PacketHandler {
|
|||||||
lineupList.add(slot.getId());
|
lineupList.add(slot.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getPlayer().getLineupManager().replaceLineup(req.getIndex(), lineupList);
|
session.getPlayer().getLineupManager().replaceLineup(req.getIndex(), req.getExtraLineupType().getNumber(), lineupList);
|
||||||
session.send(new BasePacket(CmdId.ReplaceLineupScRsp));
|
session.send(new BasePacket(CmdId.ReplaceLineupScRsp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user