League joining.

This commit is contained in:
marcins78@gmail.com
2012-04-04 17:34:37 +00:00
parent fb222513fd
commit f704eb3225
10 changed files with 42 additions and 34 deletions

View File

@@ -17,10 +17,10 @@ public class LeagueDAO {
_dbAccess = dbAccess;
}
public void addLeague(String name, String type, String clazz, String parameters, int startTime, int endTime) throws SQLException, IOException {
public void addLeague(int cost, String name, String type, String clazz, String parameters, int startTime, int endTime) throws SQLException, IOException {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("insert into league (name, type, class, parameters, start, end, status) values (?, ?, ?, ?, ?, ?, ?)");
PreparedStatement statement = conn.prepareStatement("insert into league (name, type, class, parameters, start, end, status, cost) values (?, ?, ?, ?, ?, ?, ?)");
try {
statement.setString(1, name);
statement.setString(2, type);
@@ -29,6 +29,7 @@ public class LeagueDAO {
statement.setInt(5, startTime);
statement.setInt(6, endTime);
statement.setInt(7, 0);
statement.setInt(8, cost);
statement.execute();
} finally {
statement.close();
@@ -41,7 +42,7 @@ public class LeagueDAO {
public List<League> loadActiveLeagues(int currentTime) throws SQLException, IOException {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("select id, name, type, class, parameters, start, end, status from league where start<=? and end>=? order by start desc");
PreparedStatement statement = conn.prepareStatement("select id, name, type, class, parameters, start, end, status, cost from league where start<=? and end>=? order by start desc");
try {
statement.setInt(1, currentTime);
statement.setInt(2, currentTime);
@@ -57,7 +58,8 @@ public class LeagueDAO {
int start = rs.getInt(6);
int end = rs.getInt(7);
int status = rs.getInt(8);
activeLeagues.add(new League(id, name, type, clazz, parameters, start, end, status));
int cost = rs.getInt(9);
activeLeagues.add(new League(id, cost, name, type, clazz, parameters, start, end, status));
}
return activeLeagues;
} finally {

View File

@@ -6,6 +6,7 @@ import java.lang.reflect.Constructor;
public class League {
private int _id;
private int _cost;
private String _name;
private String _type;
private String _clazz;
@@ -14,8 +15,9 @@ public class League {
private int _end;
private int _status;
public League(int id, String name, String type, String clazz, String parameters, int start, int end, int status) {
public League(int id, int cost, String name, String type, String clazz, String parameters, int start, int end, int status) {
_id = id;
_cost = cost;
_name = name;
_type = type;
_clazz = clazz;
@@ -29,6 +31,10 @@ public class League {
return _id;
}
public int getCost() {
return _cost;
}
public String getName() {
return _name;
}

View File

@@ -41,11 +41,6 @@ public class ConstructedLeagueData implements LeagueData {
}
}
@Override
public int getLeagueCost() {
return 5000;
}
@Override
public List<LeagueSerieData> getSeries() {
return _series;

View File

@@ -7,8 +7,6 @@ import com.gempukku.lotro.game.Player;
import java.util.List;
public interface LeagueData {
public int getLeagueCost();
public List<LeagueSerieData> getSeries();
public CardCollection joinLeague(CollectionsManager collecionsManager, Player player, int currentTime);

View File

@@ -123,10 +123,21 @@ public class LeagueService {
public synchronized boolean playerJoinsLeague(League league, Player player) {
if (isPlayerInLeague(league, player))
return false;
int cost = league.getLeagueData().getLeagueCost();
int cost = league.getCost();
if (_collectionsManager.removeCurrencyFromPlayerCollection(player, new CollectionType("permanent", "My cards"), cost)) {
league.getLeagueData().joinLeague(_collectionsManager, player, DateUtils.getCurrentDate());
return true;
try {
_leagueParticipationDAO.userJoinsLeague(league, player);
Set<String> notParticipating = _playersNotParticipating.get(league);
if (notParticipating != null)
notParticipating.remove(player.getName());
Set<String> participating = _playersParticipating.get(league);
if (participating != null)
participating.add(player.getName());
league.getLeagueData().joinLeague(_collectionsManager, player, DateUtils.getCurrentDate());
return true;
} catch (SQLException exp) {
throw new RuntimeException("Unable to add user to league");
}
} else {
return false;
}

View File

@@ -42,11 +42,6 @@ public class SealedLeagueData implements LeagueData {
}
}
@Override
public int getLeagueCost() {
return 5000;
}
@Override
public List<LeagueSerieData> getSeries() {
return Collections.unmodifiableList(_series);

View File

@@ -83,6 +83,7 @@ public class AdminResource extends AbstractResource {
@Path("/addLeague")
@POST
public String addLeague(
@FormParam("cost") int cost,
@FormParam("name") String name,
@FormParam("type") String type,
@FormParam("class") String clazz,
@@ -92,7 +93,7 @@ public class AdminResource extends AbstractResource {
@Context HttpServletRequest request) throws Exception {
validateAdmin(request);
_leagueDao.addLeague(name, type, clazz, parameters, start, end);
_leagueDao.addLeague(cost, name, type, clazz, parameters, start, end);
return "OK";
}

View File

@@ -73,7 +73,7 @@ public class LeagueResource extends AbstractResource {
leagueElem.setAttribute("joinable", String.valueOf(!inLeague && end >= DateUtils.getCurrentDate()));
leagueElem.setAttribute("type", league.getType());
leagueElem.setAttribute("name", league.getName());
leagueElem.setAttribute("cost", String.valueOf(leagueData.getLeagueCost()));
leagueElem.setAttribute("cost", String.valueOf(league.getCost()));
leagueElem.setAttribute("start", String.valueOf(series.get(0).getStart()));
leagueElem.setAttribute("end", String.valueOf(end));

View File

@@ -61,7 +61,7 @@ var GempLotrCommunication = Class.extend({
joinLeague: function(code, callback) {
$.ajax({
type: "POST",
url: this.url + "/league/code",
url: this.url + "/league/" + code,
cache: false,
data: {
participanId: getUrlParam("participantId") },

View File

@@ -9,12 +9,12 @@ var LeagueResultsUI = Class.extend({
this.questionDialog = $("<div></div>")
.dialog({
autoOpen: false,
closeOnEscape: true,
resizable: false,
modal: true,
title: "League operation"
});
autoOpen: false,
closeOnEscape: true,
resizable: false,
modal: true,
title: "League operation"
});
this.loadResults();
},
@@ -53,24 +53,24 @@ var LeagueResultsUI = Class.extend({
$("#leagueResults").append("<h1 class='leagueName'>" + leagueText + "</h1>");
var costStr = Math.floor(cost / 100) + "G " + cost % 100 + "S";
$("#leagueResults").append("<div class='leagueCost'>Cost: " + costStr + "</div>");
$("#leagueResults").append("<div class='leagueCost'><b>Cost:</b> " + costStr + "</div>");
var duration = this.getDateString(start) + " to " + this.getDateString(end);
$("#leagueResults").append("<div class='leagueDuration'>Duration (GMT+0): " + duration + "</div>");
$("#leagueResults").append("<div class='leagueDuration'><b>Duration (GMT+0):</b> " + duration + "</div>");
if (member == "true")
$("#leagueResults").append("<div class='leagueMembership'>You are already a member of this league.</div>");
else if (joinable == "true") {
var joinBut = $("<button>Join league</button>").button();
joinBut.click(
function() {
that.displayBuyAction("Do you want to join the league buy paying " + costStr + "?",
that.displayBuyAction("Do you want to join the league by paying " + costStr + "?",
function() {
that.communication.joinLeague(leagueType, function() {
that.loadResults();
});
});
});
var joinDiv = $("<div class='leagueMembership'></div>");
var joinDiv = $("<div class='leagueMembership'>You're not a member of this league. </div>");
joinDiv.append(joinBut);
$("#leagueResults").append(joinDiv);
}
@@ -147,7 +147,7 @@ var LeagueResultsUI = Class.extend({
var windowHeight = $(window).height();
var horSpace = 230;
var vertSpace = 45;
var vertSpace = 100;
this.questionDialog.dialog({width: Math.min(horSpace, windowWidth), height: Math.min(vertSpace, windowHeight)});
this.questionDialog.dialog("open");