Code improvements.
This commit is contained in:
@@ -656,8 +656,7 @@ public class Olympiad extends ListenersContainer
|
||||
resetWeeklyMatches();
|
||||
_log.info("Olympiad System: Reset weekly matches to nobles");
|
||||
|
||||
final Calendar nextChange = Calendar.getInstance();
|
||||
_nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
|
||||
_nextWeeklyChange = Calendar.getInstance().getTimeInMillis() + WEEKLY_PERIOD;
|
||||
}, getMillisToWeekChange(), WEEKLY_PERIOD);
|
||||
}
|
||||
|
||||
@@ -1086,17 +1085,12 @@ public class Olympiad extends ListenersContainer
|
||||
{
|
||||
noble.set(POINTS, 0);
|
||||
}
|
||||
points *= Config.ALT_OLY_GP_PER_POINT;
|
||||
return points;
|
||||
return points *= Config.ALT_OLY_GP_PER_POINT;
|
||||
}
|
||||
|
||||
public int getNoblePoints(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(POINTS);
|
||||
return !NOBLES.containsKey(objId) ? 0 : NOBLES.get(objId).getInt(POINTS);
|
||||
}
|
||||
|
||||
public int getLastNobleOlympiadPoints(int objId)
|
||||
@@ -1123,29 +1117,17 @@ public class Olympiad extends ListenersContainer
|
||||
|
||||
public int getCompetitionDone(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_DONE);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_DONE) : 0;
|
||||
}
|
||||
|
||||
public int getCompetitionWon(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_WON);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_WON) : 0;
|
||||
}
|
||||
|
||||
public int getCompetitionLost(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_LOST);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_LOST) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1155,11 +1137,7 @@ public class Olympiad extends ListenersContainer
|
||||
*/
|
||||
public int getCompetitionDoneWeek(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_DONE_WEEK);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_DONE_WEEK) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1169,11 +1147,7 @@ public class Olympiad extends ListenersContainer
|
||||
*/
|
||||
public int getCompetitionDoneWeekClassed(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_DONE_WEEK_CLASSED);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_DONE_WEEK_CLASSED) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1183,11 +1157,7 @@ public class Olympiad extends ListenersContainer
|
||||
*/
|
||||
public int getCompetitionDoneWeekNonClassed(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_DONE_WEEK_NON_CLASSED);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_DONE_WEEK_NON_CLASSED) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1197,11 +1167,7 @@ public class Olympiad extends ListenersContainer
|
||||
*/
|
||||
public int getCompetitionDoneWeekTeam(int objId)
|
||||
{
|
||||
if (!NOBLES.containsKey(objId))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return NOBLES.get(objId).getInt(COMP_DONE_WEEK_TEAM);
|
||||
return NOBLES.containsKey(objId) ? NOBLES.get(objId).getInt(COMP_DONE_WEEK_TEAM) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -171,12 +171,7 @@ public class OlympiadGameManager implements Runnable
|
||||
|
||||
public final OlympiadGameTask getOlympiadTask(int id)
|
||||
{
|
||||
if ((id < 0) || (id >= _tasks.length))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tasks[id];
|
||||
return (id < 0) || (id >= _tasks.length) ? null : _tasks[id];
|
||||
}
|
||||
|
||||
public final int getNumberOfStadiums()
|
||||
|
||||
@@ -57,11 +57,6 @@ public class OlympiadGameNonClassed extends OlympiadGameNormal
|
||||
protected static final OlympiadGameNonClassed createGame(int id, List<Integer> list)
|
||||
{
|
||||
final Participant[] opponents = OlympiadGameNormal.createListOfParticipants(list);
|
||||
if (opponents == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OlympiadGameNonClassed(id, opponents);
|
||||
return opponents == null ? null : new OlympiadGameNonClassed(id, opponents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,12 +170,7 @@ public abstract class OlympiadGameNormal extends AbstractOlympiadGame
|
||||
@Override
|
||||
protected final boolean makeCompetitionStart()
|
||||
{
|
||||
if (!super.makeCompetitionStart())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((_playerOne.getPlayer() == null) || (_playerTwo.getPlayer() == null))
|
||||
if (!super.makeCompetitionStart() || (_playerOne.getPlayer() == null) || (_playerTwo.getPlayer() == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -181,12 +181,7 @@ public class OlympiadGameTeams extends AbstractOlympiadGame
|
||||
protected static OlympiadGameTeams createGame(int id, List<List<Integer>> list)
|
||||
{
|
||||
final Participant[][] teams = createListOfParticipants(list);
|
||||
if (teams == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OlympiadGameTeams(id, teams[0], teams[1]);
|
||||
return teams == null ? null : new OlympiadGameTeams(id, teams[0], teams[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -505,24 +500,18 @@ public class OlympiadGameTeams extends AbstractOlympiadGame
|
||||
for (int i = _teamOneSize; --i >= 0;)
|
||||
{
|
||||
par = _teamOne[i];
|
||||
if (!par.isDisconnected())
|
||||
if (!par.isDisconnected() && (par.getPlayer() != null) && (par.getPlayer().getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
if ((par.getPlayer() != null) && (par.getPlayer().getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
teamOneLost &= par.getPlayer().isDead();
|
||||
}
|
||||
teamOneLost &= par.getPlayer().isDead();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = _teamTwoSize; --i >= 0;)
|
||||
{
|
||||
par = _teamTwo[i];
|
||||
if (!par.isDisconnected())
|
||||
if (!par.isDisconnected() && (par.getPlayer() != null) && (par.getPlayer().getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
if ((par.getPlayer() != null) && (par.getPlayer().getOlympiadGameId() == _stadiumID))
|
||||
{
|
||||
teamTwoLost &= par.getPlayer().isDead();
|
||||
}
|
||||
teamTwoLost &= par.getPlayer().isDead();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,22 +521,7 @@ public class OlympiadGameTeams extends AbstractOlympiadGame
|
||||
@Override
|
||||
protected final boolean checkBattleStatus()
|
||||
{
|
||||
if (_aborted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (teamOneAllDisconnected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (teamTwoAllDisconnected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !_aborted && !teamOneAllDisconnected() && !teamTwoAllDisconnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -668,10 +642,7 @@ public class OlympiadGameTeams extends AbstractOlympiadGame
|
||||
}
|
||||
|
||||
// Choose minimum sum
|
||||
int min = Math.min(totalPointsTeamOne, totalPointsTeamTwo);
|
||||
|
||||
// make sure all team members got same number of the points: round down to 3x
|
||||
min = (min / MAX_TEAM_SIZE) * MAX_TEAM_SIZE;
|
||||
final int min = (Math.min(totalPointsTeamOne, totalPointsTeamTwo) / MAX_TEAM_SIZE) * MAX_TEAM_SIZE;
|
||||
|
||||
// calculating coefficients and trying to correct total number of points for each team
|
||||
// due to rounding errors total points after correction will always be lower or equal
|
||||
|
||||
@@ -492,12 +492,7 @@ public class OlympiadManager
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isRegistered(noble, player, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isInCompetition(noble, player, true))
|
||||
if (isRegistered(noble, player, true) || isInCompetition(noble, player, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user