Skip to content

Instantly share code, notes, and snippets.

@St3eT
Created April 5, 2013 18:02
Show Gist options
  • Save St3eT/5321330 to your computer and use it in GitHub Desktop.
Save St3eT/5321330 to your computer and use it in GitHub Desktop.
High give random olympiad select
Index: dist/game/config/Olympiad.properties
===================================================================
--- dist/game/config/Olympiad.properties (revision 52)
+++ dist/game/config/Olympiad.properties (working copy)
@@ -138,6 +138,11 @@
# Default: 120
AltOlyWaitTime = 120
+# Old system for creating olympiad matches, based on random selection
+# If set false, point based selection is used (retail like)
+# Default: false
+RandomPlayerSelect = false
+
# Divider for points in classed and non-classed games
# Default: 5, 5
AltOlyDividerClassed = 5
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java (revision 52)
+++ java/com/l2jserver/Config.java (working copy)
@@ -573,6 +573,7 @@
public static boolean ALT_OLY_SHOW_MONTHLY_WINNERS;
public static boolean ALT_OLY_ANNOUNCE_GAMES;
public static List<Integer> LIST_OLY_RESTRICTED_ITEMS;
+ public static boolean OLY_PLAYER_SELECT_RANDOM;
public static int ALT_OLY_ENCHANT_LIMIT;
public static int ALT_OLY_WAIT_TIME;
public static int ALT_MANOR_REFRESH_TIME;
@@ -2772,6 +2773,7 @@
}
ALT_OLY_ENCHANT_LIMIT = Integer.parseInt(Olympiad.getProperty("AltOlyEnchantLimit", "-1"));
ALT_OLY_WAIT_TIME = Integer.parseInt(Olympiad.getProperty("AltOlyWaitTime", "120"));
+ OLY_PLAYER_SELECT_RANDOM = Boolean.parseBoolean(Olympiad.getProperty("RandomPlayerSelect","false"));
final File hex = new File(HEXID_FILE);
try (InputStream is = new FileInputStream(hex))
Index: java/com/l2jserver/gameserver/model/olympiad/OlympiadGameNormal.java
===================================================================
--- java/com/l2jserver/gameserver/model/olympiad/OlympiadGameNormal.java (revision 52)
+++ java/com/l2jserver/gameserver/model/olympiad/OlympiadGameNormal.java (working copy)
@@ -60,35 +60,83 @@
protected static final Participant[] createListOfParticipants(List<Integer> list)
{
- if ((list == null) || list.isEmpty() || (list.size() < 2))
- {
+ if (list == null || list.isEmpty() || list.size() < 2)
return null;
- }
-
+
int playerOneObjectId = 0;
L2PcInstance playerOne = null;
L2PcInstance playerTwo = null;
+ //old oly selection - random
+ if (Config.OLY_PLAYER_SELECT_RANDOM)
+ {
+ while (list.size() > 1)
+ {
+ playerOneObjectId = list.remove(Rnd.nextInt(list.size()));
+ playerOne = L2World.getInstance().getPlayer(playerOneObjectId);
+ if (playerOne == null || !playerOne.isOnline())
+ continue;
+
+ playerTwo = L2World.getInstance().getPlayer(list.remove(Rnd.nextInt(list.size())));
+ if (playerTwo == null || !playerTwo.isOnline())
+ {
+ list.add(playerOneObjectId);
+ continue;
+ }
+
+ Participant[] result = new Participant[2];
+ result[0] = new Participant(playerOne, 1);
+ result[1] = new Participant(playerTwo, 2);
+
+ return result;
+ }
+
+ return null;
+ }
+
while (list.size() > 1)
{
playerOneObjectId = list.remove(Rnd.nextInt(list.size()));
playerOne = L2World.getInstance().getPlayer(playerOneObjectId);
- if ((playerOne == null) || !playerOne.isOnline())
+ if (playerOne == null || !playerOne.isOnline())
+ continue;
+
+ int p1Points = Olympiad.getInstance().getNoblePoints(playerOneObjectId);
+ int p2PointsDiff = Integer.MAX_VALUE;
+ for (int id : list)
{
- continue;
+ L2PcInstance possibleTwo = L2World.getInstance().getPlayer(id);
+ if (possibleTwo == null || !possibleTwo.isOnline())
+ continue;
+
+ if (playerTwo == null) //not assigned yet
+ {
+ playerTwo = possibleTwo;
+ p2PointsDiff = Math.abs(Olympiad.getInstance().getNoblePoints(id) - p1Points);
+ }
+ else //lets compare
+ {
+ int newDiff = Math.abs(Olympiad.getInstance().getNoblePoints(id) - p1Points);
+ if (newDiff < p2PointsDiff)
+ {
+ p2PointsDiff = newDiff;
+ playerTwo = possibleTwo;
+ }
+ }
}
- playerTwo = L2World.getInstance().getPlayer(list.remove(Rnd.nextInt(list.size())));
- if ((playerTwo == null) || !playerTwo.isOnline())
+ if (playerTwo == null)
{
list.add(playerOneObjectId);
- continue;
+ return null;
}
+ list.remove(Integer.valueOf(playerTwo.getObjectId()));
+
Participant[] result = new Participant[2];
result[0] = new Participant(playerOne, 1);
result[1] = new Participant(playerTwo, 2);
-
+
return result;
}
return null;
Index: java/com/l2jserver/gameserver/model/olympiad/OlympiadGameTeams.java
===================================================================
--- java/com/l2jserver/gameserver/model/olympiad/OlympiadGameTeams.java (revision 52)
+++ java/com/l2jserver/gameserver/model/olympiad/OlympiadGameTeams.java (working copy)
@@ -94,10 +94,8 @@
protected static final Participant[][] createListOfParticipants(List<List<Integer>> list)
{
- if ((list == null) || list.isEmpty() || (list.size() < 2))
- {
+ if (list == null || list.isEmpty() || list.size() < 2)
return null;
- }
List<Integer> teamOne = null;
List<Integer> teamTwo = null;
@@ -105,42 +103,138 @@
List<L2PcInstance> teamOnePlayers = new ArrayList<>(MAX_TEAM_SIZE);
List<L2PcInstance> teamTwoPlayers = new ArrayList<>(MAX_TEAM_SIZE);
+ //old oly selection - random
+ if (Config.OLY_PLAYER_SELECT_RANDOM)
+ {
+ while (list.size() > 1)
+ {
+ teamOne = list.remove(Rnd.nextInt(list.size()));
+
+ if ((teamOne == null || teamOne.isEmpty()))
+ continue;
+
+ for (int objectId : teamOne)
+ {
+ player = L2World.getInstance().getPlayer(objectId);
+ if (player == null || !player.isOnline())
+ {
+ teamOnePlayers.clear();
+ break;
+ }
+ teamOnePlayers.add(player);
+ }
+ if (teamOnePlayers.isEmpty())
+ continue;
+
+ teamTwo = list.remove(Rnd.nextInt(list.size()));
+ if (teamTwo == null || teamTwo.isEmpty())
+ {
+ list.add(teamOne);
+ teamOnePlayers.clear();
+ continue;
+ }
+
+ for (int objectId : teamTwo)
+ {
+ player = L2World.getInstance().getPlayer(objectId);
+ if (player == null || !player.isOnline())
+ {
+ teamTwoPlayers.clear();
+ break;
+ }
+ teamTwoPlayers.add(player);
+ }
+ if (teamTwoPlayers.isEmpty())
+ {
+ list.add(teamOne);
+ teamOnePlayers.clear();
+ continue;
+ }
+
+ Participant[] t1 = new Participant[teamOnePlayers.size()];
+ Participant[] t2 = new Participant[teamTwoPlayers.size()];
+ Participant[][] result = new Participant[2][];
+
+ for (int i = 0; i < t1.length; i++)
+ t1[i] = new Participant(teamOnePlayers.get(i), 1);
+
+ for (int i = 0; i < t2.length; i++)
+ t2[i] = new Participant(teamTwoPlayers.get(i), 2);
+
+ result[0] = t1;
+ result[1] = t2;
+ return result;
+ }
+ return null;
+ }
+
while (list.size() > 1)
{
teamOne = list.remove(Rnd.nextInt(list.size()));
- if (((teamOne == null) || teamOne.isEmpty()))
- {
+ if ((teamOne == null || teamOne.isEmpty()))
continue;
- }
+ int t1Points = 0;
for (int objectId : teamOne)
{
player = L2World.getInstance().getPlayer(objectId);
- if ((player == null) || !player.isOnline())
+ if (player == null || !player.isOnline())
{
teamOnePlayers.clear();
break;
}
+ t1Points += Olympiad.getInstance().getNoblePoints(objectId);
teamOnePlayers.add(player);
}
if (teamOnePlayers.isEmpty())
+ continue;
+
+ int t2PointDiff = Integer.MAX_VALUE;
+
+ LOOP:
+ for (List<Integer> team : list)
{
- continue;
+ int tPoints = 0;
+
+ //check team and calc points
+ for (int objectId : team)
+ {
+ player = L2World.getInstance().getPlayer(objectId);
+ if (player == null || !player.isOnline())
+ {
+ continue LOOP;
+ }
+ tPoints += Olympiad.getInstance().getNoblePoints(objectId);
+ }
+
+ if (teamTwo == null) //not set
+ {
+ teamTwo = team;
+ t2PointDiff = Math.abs(tPoints - t1Points);
+ }
+ else // compare
+ {
+ int newDiff = Math.abs(tPoints - t1Points);
+ if (newDiff < t2PointDiff)
+ {
+ teamTwo = team;
+ t2PointDiff = newDiff;
+ }
+ }
}
- teamTwo = list.remove(Rnd.nextInt(list.size()));
- if ((teamTwo == null) || teamTwo.isEmpty())
+ if (teamTwo == null)
{
list.add(teamOne);
- teamOnePlayers.clear();
- continue;
+ return null;
}
+ list.remove(teamTwo);
for (int objectId : teamTwo)
{
player = L2World.getInstance().getPlayer(objectId);
- if ((player == null) || !player.isOnline())
+ if (player == null || !player.isOnline())
{
teamTwoPlayers.clear();
break;
@@ -159,14 +253,10 @@
Participant[][] result = new Participant[2][];
for (int i = 0; i < t1.length; i++)
- {
t1[i] = new Participant(teamOnePlayers.get(i), 1);
- }
for (int i = 0; i < t2.length; i++)
- {
t2[i] = new Participant(teamTwoPlayers.get(i), 2);
- }
result[0] = t1;
result[1] = t2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment