mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
pc improvement - implement priority
This commit is contained in:
parent
8d383bad19
commit
e1edd1bf90
2 changed files with 27 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ package core.game.content.activity.pestcontrol;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
import rs09.ServerConstants;
|
||||
import core.game.component.Component;
|
||||
|
|
@ -17,6 +18,7 @@ import core.game.node.entity.state.EntityState;
|
|||
import core.game.node.item.GroundItemManager;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.system.task.Pulse;
|
||||
import rs09.game.ai.AIPlayer;
|
||||
import rs09.game.world.GameWorld;
|
||||
import core.game.world.map.Location;
|
||||
import core.game.world.map.build.DynamicRegion;
|
||||
|
|
@ -60,7 +62,13 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
|
|||
/**
|
||||
* The waiting players.
|
||||
*/
|
||||
private final List<Player> waitingPlayers = new ArrayList<>(20);
|
||||
private final PriorityQueue<Player> waitingPlayers = new PriorityQueue<Player>(20, (player1, player2) -> {
|
||||
//get priorities of players. default to 0
|
||||
int p1 = player1.getAttribute("pc_prior", 0);
|
||||
int p2 = player2.getAttribute("pc_prior", 0);
|
||||
//return in descending order
|
||||
return p2 - p1;
|
||||
});
|
||||
|
||||
/**
|
||||
* The active game sessions.
|
||||
|
|
@ -313,7 +321,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
|
|||
* Gets the list of waiting players.
|
||||
* @return The list of waiting players.
|
||||
*/
|
||||
public List<Player> getWaitingPlayers() {
|
||||
public PriorityQueue<Player> getWaitingPlayers() {
|
||||
return waitingPlayers;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
package core.game.content.activity.pestcontrol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import core.game.component.Component;
|
||||
import core.game.content.dialogue.FacialExpression;
|
||||
|
|
@ -212,7 +208,7 @@ public final class PestControlSession {
|
|||
* Starts a game.
|
||||
* @param waitingPlayers The list of waiting players.
|
||||
*/
|
||||
public void startGame(List<Player> waitingPlayers) {
|
||||
public void startGame(PriorityQueue<Player> waitingPlayers) {
|
||||
region.flagActive();
|
||||
initBarricadesList();
|
||||
List<Integer> list = new ArrayList<>(20);
|
||||
|
|
@ -225,21 +221,29 @@ public final class PestControlSession {
|
|||
ids = list.toArray(new Integer[4]);
|
||||
int count = 0;
|
||||
String portalHealth = "<col=00FF00>" + (activity.getType().ordinal() == 0 ? 200 : 250);
|
||||
for (Iterator<Player> it = waitingPlayers.iterator(); it.hasNext();) {
|
||||
Player p = it.next();
|
||||
|
||||
List<Player> remainingPlayers = new ArrayList<>();
|
||||
for (Player p = waitingPlayers.poll(); p != null; p = waitingPlayers.poll()) {
|
||||
if (p.getSession().isActive()) {
|
||||
if (++count > MAX_TEAM_SIZE) {
|
||||
int priority = p.getAttribute("pc_prior", 0) + 1;
|
||||
p.getPacketDispatch().sendMessage("You have been given priority level " + priority + " over other players in joining the next");
|
||||
p.getPacketDispatch().sendMessage("game.");
|
||||
p.setAttribute("pc_prior", priority);
|
||||
remainingPlayers.add(p);
|
||||
continue;
|
||||
}
|
||||
addPlayer(p, portalHealth);
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
|
||||
for (Player p : remainingPlayers)
|
||||
{
|
||||
int priority = p.getAttribute("pc_prior", 0) + 1;
|
||||
p.getPacketDispatch().sendMessage("You have been given priority level " + priority + " over other players in joining the next");
|
||||
p.getPacketDispatch().sendMessage("game.");
|
||||
p.setAttribute("pc_prior", priority);
|
||||
waitingPlayers.add(p);
|
||||
}
|
||||
|
||||
spawnNPCs();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue