- Player owned cards can now be used in casual games, in addition to the normal ones.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.gempukku.lotro;
|
package com.gempukku.lotro;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.collection.CollectionSerializer;
|
||||||
import com.gempukku.lotro.db.DbAccess;
|
import com.gempukku.lotro.db.DbAccess;
|
||||||
import com.gempukku.lotro.db.LeagueDAO;
|
import com.gempukku.lotro.db.LeagueDAO;
|
||||||
import com.gempukku.lotro.db.vo.League;
|
import com.gempukku.lotro.db.vo.League;
|
||||||
@@ -22,7 +23,7 @@ public class ServerManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void addLeague(DbAccess dbAccess) throws IOException, SQLException {
|
private static void addLeague(DbAccess dbAccess) throws IOException, SQLException {
|
||||||
LeagueDAO leagueDao = new LeagueDAO(dbAccess);
|
LeagueDAO leagueDao = new LeagueDAO(dbAccess, new CollectionSerializer());
|
||||||
DefaultCardCollection collection = new DefaultCardCollection();
|
DefaultCardCollection collection = new DefaultCardCollection();
|
||||||
collection.addItem("FotR - League Starter", 1);
|
collection.addItem("FotR - League Starter", 1);
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public class ServerManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static League getLeague(DbAccess dbAccess, String leagueType) {
|
private static League getLeague(DbAccess dbAccess, String leagueType) {
|
||||||
LeagueDAO leagueDao = new LeagueDAO(dbAccess);
|
LeagueDAO leagueDao = new LeagueDAO(dbAccess, new CollectionSerializer());
|
||||||
for (League league : leagueDao.getActiveLeagues()) {
|
for (League league : leagueDao.getActiveLeagues()) {
|
||||||
if (league.getType().equals(leagueType))
|
if (league.getType().equals(leagueType))
|
||||||
return league;
|
return league;
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ public class CollectionDAO {
|
|||||||
|
|
||||||
private Map<Integer, Map<String, MutableCardCollection>> _collections = new ConcurrentHashMap<Integer, Map<String, MutableCardCollection>>();
|
private Map<Integer, Map<String, MutableCardCollection>> _collections = new ConcurrentHashMap<Integer, Map<String, MutableCardCollection>>();
|
||||||
|
|
||||||
public CollectionDAO(DbAccess dbAccess) {
|
public CollectionDAO(DbAccess dbAccess, CollectionSerializer collectionSerializer) {
|
||||||
_dbAccess = dbAccess;
|
_dbAccess = dbAccess;
|
||||||
_collectionSerializer = new CollectionSerializer();
|
_collectionSerializer = collectionSerializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
|
|||||||
@@ -20,10 +20,9 @@ public class LeagueDAO {
|
|||||||
private int _dateLoaded;
|
private int _dateLoaded;
|
||||||
private Set<League> _activeLeagues = new HashSet<League>();
|
private Set<League> _activeLeagues = new HashSet<League>();
|
||||||
|
|
||||||
public LeagueDAO(DbAccess dbAccess) {
|
public LeagueDAO(DbAccess dbAccess, CollectionSerializer serializer) {
|
||||||
_dbAccess = dbAccess;
|
_dbAccess = dbAccess;
|
||||||
|
_serializer = serializer;
|
||||||
_serializer = new CollectionSerializer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package com.gempukku.lotro.game;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface CardCollection {
|
public interface CardCollection extends OwnershipCheck {
|
||||||
public Map<String, Integer> getAll();
|
public Map<String, Integer> getAll();
|
||||||
|
|
||||||
|
public int getItemCount(String blueprintId);
|
||||||
|
|
||||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library);
|
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library);
|
||||||
|
|
||||||
public static class Item {
|
public static class Item {
|
||||||
|
|||||||
@@ -176,6 +176,14 @@ public class DefaultCardCollection implements MutableCardCollection {
|
|||||||
return Collections.unmodifiableMap(_counts);
|
return Collections.unmodifiableMap(_counts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount(String blueprintId) {
|
||||||
|
Integer count = _counts.get(blueprintId);
|
||||||
|
if (count == null)
|
||||||
|
return 0;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library) {
|
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library) {
|
||||||
if (filter == null)
|
if (filter == null)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.gempukku.lotro.game;
|
||||||
|
|
||||||
|
public interface OwnershipCheck {
|
||||||
|
public int getItemCount(String blueprintId);
|
||||||
|
}
|
||||||
@@ -226,24 +226,27 @@ public class HallServer extends AbstractServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now check if player owns all the cards
|
// Now check if player owns all the cards
|
||||||
CardCollection collection;
|
OwnershipCheck ownershipCheck;
|
||||||
if (collectionType.getCode().equals("default"))
|
if (collectionType.getCode().equals("default")) {
|
||||||
collection = _lotroServer.getDefaultCollection();
|
// Merging player-owned cards in collection with the default one (containing all basic cards)
|
||||||
else
|
MutableCardCollection ownedCollection = _collectionDao.getCollectionForPlayer(player, "permanent");
|
||||||
collection = _collectionDao.getCollectionForPlayer(player, collectionType.getCode());
|
if (ownedCollection != null)
|
||||||
|
ownershipCheck = new MergedOwnershipCheck(_lotroServer.getDefaultCollection(), ownedCollection);
|
||||||
|
else
|
||||||
|
ownershipCheck = _lotroServer.getDefaultCollection();
|
||||||
|
} else
|
||||||
|
ownershipCheck = _collectionDao.getCollectionForPlayer(player, collectionType.getCode());
|
||||||
|
|
||||||
if (collection == null)
|
if (ownershipCheck == null)
|
||||||
throw new HallException("You don't have cards in the required collection to play in this format");
|
throw new HallException("You don't have cards in the required collection to play in this format");
|
||||||
|
|
||||||
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
|
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
|
||||||
final Map<String, Integer> collectionCardCounts = collection.getAll();
|
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> cardCount : deckCardCounts.entrySet()) {
|
for (Map.Entry<String, Integer> cardCount : deckCardCounts.entrySet()) {
|
||||||
final Integer collectionCount = collectionCardCounts.get(cardCount.getKey());
|
final int collectionCount = ownershipCheck.getItemCount(cardCount.getKey());
|
||||||
if (collectionCount == null || collectionCount < cardCount.getValue()) {
|
if (collectionCount < cardCount.getValue()) {
|
||||||
String cardName = _library.getLotroCardBlueprint(cardCount.getKey()).getName();
|
String cardName = _library.getLotroCardBlueprint(cardCount.getKey()).getName();
|
||||||
int owned = (collectionCount == null) ? 0 : collectionCount;
|
throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + collectionCount);
|
||||||
throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + owned);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.gempukku.lotro.hall;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.game.OwnershipCheck;
|
||||||
|
|
||||||
|
public class MergedOwnershipCheck implements OwnershipCheck {
|
||||||
|
private OwnershipCheck[] _ownershipChecks;
|
||||||
|
|
||||||
|
public MergedOwnershipCheck(OwnershipCheck... ownershipChecks) {
|
||||||
|
_ownershipChecks = ownershipChecks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount(String blueprintId) {
|
||||||
|
int count = 0;
|
||||||
|
for (OwnershipCheck ownershipCheck : _ownershipChecks)
|
||||||
|
count += ownershipCheck.getItemCount(blueprintId);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.gempukku.lotro.server;
|
package com.gempukku.lotro.server;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.collection.CollectionSerializer;
|
||||||
import com.gempukku.lotro.db.*;
|
import com.gempukku.lotro.db.*;
|
||||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||||
import com.sun.jersey.core.spi.component.ComponentScope;
|
import com.sun.jersey.core.spi.component.ComponentScope;
|
||||||
@@ -23,9 +24,11 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
|||||||
private Injectable<LeaguePointsDAO> _leaguePointsDAOInjectable;
|
private Injectable<LeaguePointsDAO> _leaguePointsDAOInjectable;
|
||||||
|
|
||||||
private DbAccess _dbAccess;
|
private DbAccess _dbAccess;
|
||||||
|
private CollectionSerializer _collectionSerializer;
|
||||||
|
|
||||||
public DaoProvider() {
|
public DaoProvider() {
|
||||||
_dbAccess = new DbAccess();
|
_dbAccess = new DbAccess();
|
||||||
|
_collectionSerializer = new CollectionSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,7 +93,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
|||||||
|
|
||||||
private synchronized Injectable<LeagueDAO> getLeagueDaoSafely() {
|
private synchronized Injectable<LeagueDAO> getLeagueDaoSafely() {
|
||||||
if (_leagueDaoInjectable == null) {
|
if (_leagueDaoInjectable == null) {
|
||||||
final LeagueDAO leagueDao = new LeagueDAO(_dbAccess);
|
final LeagueDAO leagueDao = new LeagueDAO(_dbAccess, _collectionSerializer);
|
||||||
_leagueDaoInjectable = new Injectable<LeagueDAO>() {
|
_leagueDaoInjectable = new Injectable<LeagueDAO>() {
|
||||||
@Override
|
@Override
|
||||||
public LeagueDAO getValue() {
|
public LeagueDAO getValue() {
|
||||||
@@ -129,7 +132,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
|||||||
|
|
||||||
private synchronized Injectable<CollectionDAO> getCollectionDaoSafely() {
|
private synchronized Injectable<CollectionDAO> getCollectionDaoSafely() {
|
||||||
if (_collectionDaoInjectable == null) {
|
if (_collectionDaoInjectable == null) {
|
||||||
final CollectionDAO collectionDao = new CollectionDAO(_dbAccess);
|
final CollectionDAO collectionDao = new CollectionDAO(_dbAccess, _collectionSerializer);
|
||||||
_collectionDaoInjectable = new Injectable<CollectionDAO>() {
|
_collectionDaoInjectable = new Injectable<CollectionDAO>() {
|
||||||
@Override
|
@Override
|
||||||
public CollectionDAO getValue() {
|
public CollectionDAO getValue() {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<pre style="font-size:80%">
|
<pre style="font-size:80%">
|
||||||
|
<b>8 Jan. 2012</b>
|
||||||
|
- Player owned cards can now be used in casual games, in addition to the normal ones.
|
||||||
|
|
||||||
<b>7 Jan. 2012</b>
|
<b>7 Jan. 2012</b>
|
||||||
- "Damrod" now correctly checks his spot play condition.
|
- "Damrod" now correctly checks his spot play condition.
|
||||||
- "Cave Troll's Hammer" from Black Rider now is of ORC culture, not MORIA.
|
- "Cave Troll's Hammer" from Black Rider now is of ORC culture, not MORIA.
|
||||||
|
|||||||
Reference in New Issue
Block a user