Split PlayerLineup into normal and extra types

This commit is contained in:
Melledy
2023-10-23 06:28:09 -07:00
parent 7288db7c14
commit 0a72a6ea82
3 changed files with 66 additions and 29 deletions

View File

@@ -22,7 +22,7 @@ public class LineupManager {
// Extra lineups for challenges/simulated universe/etc // Extra lineups for challenges/simulated universe/etc
private transient int currentExtraLineup; private transient int currentExtraLineup;
private transient Int2ObjectMap<PlayerLineup> extraLineups; private transient Int2ObjectMap<PlayerExtraLineup> extraLineups;
@Deprecated // Morphia only! @Deprecated // Morphia only!
public LineupManager() { public LineupManager() {
@@ -95,7 +95,7 @@ public class LineupManager {
* @return * @return
*/ */
private PlayerLineup getExtraLineupByType(int extraLineupType) { private PlayerLineup getExtraLineupByType(int extraLineupType) {
return getExtraLineups().computeIfAbsent(extraLineupType, type -> new PlayerLineup(getPlayer(), 0, type)); return getExtraLineups().computeIfAbsent(extraLineupType, type -> new PlayerExtraLineup(getPlayer(), type));
} }
public PlayerLineup getCurrentLineup() { public PlayerLineup getCurrentLineup() {
@@ -322,7 +322,7 @@ public class LineupManager {
// Create new lineups for any missing ones // Create new lineups for any missing ones
for (int i = 0; i < this.lineups.length; i++) { for (int i = 0; i < this.lineups.length; i++) {
if (this.lineups[i] == null) { if (this.lineups[i] == null) {
this.lineups[i] = new PlayerLineup(getPlayer(), i, 0); this.lineups[i] = new PlayerLineup(getPlayer(), i);
} else { } else {
this.lineups[i].setOwnerAndIndex(getPlayer(), i); this.lineups[i].setOwnerAndIndex(getPlayer(), i);
} }

View File

@@ -0,0 +1,53 @@
package emu.lunarcore.game.player;
import java.util.ArrayList;
import emu.lunarcore.GameConstants;
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
import lombok.Getter;
public class PlayerExtraLineup extends PlayerLineup {
private int extraLineupType;
private int mp;
@Deprecated // Morphia only!
public PlayerExtraLineup() {
}
public PlayerExtraLineup(Player player, int extraLineupType) {
super(player, 0);
this.extraLineupType = extraLineupType;
}
@Override
public boolean isExtraLineup() {
return true;
}
@Override
public int getExtraLineupType() {
return extraLineupType;
}
@Override
public void addMp(int i) {
this.mp = Math.min(this.mp + i, GameConstants.MAX_MP);
this.getOwner().sendPacket(new PacketSyncLineupNotify(this.getOwner().getCurrentLineup()));
}
@Override
public void setMp(int i) {
this.mp = i;
}
@Override
public void removeMp(int i) {
this.mp = Math.max(this.mp - i, 0);
}
@Override
public int getMp() {
return this.mp;
}
}

View File

@@ -15,8 +15,6 @@ 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 transient int mp;
private String name; private String name;
private List<Integer> avatars; private List<Integer> avatars;
@@ -26,10 +24,9 @@ public class PlayerLineup {
} }
public PlayerLineup(Player player, int index, int extraLineupType) { public PlayerLineup(Player player, int index) {
this.owner = player; this.owner = player;
this.index = index; this.index = index;
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 // Set team name if not an extra lineup
@@ -46,7 +43,11 @@ public class PlayerLineup {
} }
public boolean isExtraLineup() { public boolean isExtraLineup() {
return this.extraLineupType != 0; return false;
}
public int getExtraLineupType() {
return 0;
} }
public void setName(String name) { public void setName(String name) {
@@ -62,36 +63,19 @@ public class PlayerLineup {
} }
public void addMp(int i) { public void addMp(int i) {
if (this.getExtraLineupType() > 0) { this.getOwner().getLineupManager().addMp(i);
this.mp = Math.min(this.mp + i, GameConstants.MAX_MP);
this.getOwner().sendPacket(new PacketSyncLineupNotify(this.getOwner().getCurrentLineup()));
} else {
this.getOwner().getLineupManager().addMp(i);
}
} }
public void setMp(int i) { public void setMp(int i) {
if (this.getExtraLineupType() > 0) { this.getOwner().getLineupManager().setMp(i);
this.mp = i;
} else {
this.getOwner().getLineupManager().setMp(i);
}
} }
public void removeMp(int i) { public void removeMp(int i) {
if (this.getExtraLineupType() > 0) { this.getOwner().getLineupManager().removeMp(i);
this.mp = Math.max(this.mp - i, 0);
} else {
this.getOwner().getLineupManager().removeMp(i);
}
} }
public int getMp() { public int getMp() {
if (this.getExtraLineupType() > 0) { return this.getOwner().getLineupManager().getMp();
return this.mp;
} else {
return this.getOwner().getLineupManager().getMp();
}
} }
public void heal(int heal, boolean allowRevive) { public void heal(int heal, boolean allowRevive) {