- 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;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionSerializer;
|
||||
import com.gempukku.lotro.db.DbAccess;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
@@ -22,7 +23,7 @@ public class ServerManagement {
|
||||
}
|
||||
|
||||
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();
|
||||
collection.addItem("FotR - League Starter", 1);
|
||||
|
||||
@@ -30,7 +31,7 @@ public class ServerManagement {
|
||||
}
|
||||
|
||||
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()) {
|
||||
if (league.getType().equals(leagueType))
|
||||
return league;
|
||||
|
||||
@@ -20,9 +20,9 @@ public class CollectionDAO {
|
||||
|
||||
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;
|
||||
_collectionSerializer = new CollectionSerializer();
|
||||
_collectionSerializer = collectionSerializer;
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
|
||||
@@ -20,10 +20,9 @@ public class LeagueDAO {
|
||||
private int _dateLoaded;
|
||||
private Set<League> _activeLeagues = new HashSet<League>();
|
||||
|
||||
public LeagueDAO(DbAccess dbAccess) {
|
||||
public LeagueDAO(DbAccess dbAccess, CollectionSerializer serializer) {
|
||||
_dbAccess = dbAccess;
|
||||
|
||||
_serializer = new CollectionSerializer();
|
||||
_serializer = serializer;
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.gempukku.lotro.game;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CardCollection {
|
||||
public interface CardCollection extends OwnershipCheck {
|
||||
public Map<String, Integer> getAll();
|
||||
|
||||
public int getItemCount(String blueprintId);
|
||||
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library);
|
||||
|
||||
public static class Item {
|
||||
|
||||
@@ -176,6 +176,14 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
return Collections.unmodifiableMap(_counts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount(String blueprintId) {
|
||||
Integer count = _counts.get(blueprintId);
|
||||
if (count == null)
|
||||
return 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library) {
|
||||
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
|
||||
CardCollection collection;
|
||||
if (collectionType.getCode().equals("default"))
|
||||
collection = _lotroServer.getDefaultCollection();
|
||||
else
|
||||
collection = _collectionDao.getCollectionForPlayer(player, collectionType.getCode());
|
||||
OwnershipCheck ownershipCheck;
|
||||
if (collectionType.getCode().equals("default")) {
|
||||
// Merging player-owned cards in collection with the default one (containing all basic cards)
|
||||
MutableCardCollection ownedCollection = _collectionDao.getCollectionForPlayer(player, "permanent");
|
||||
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");
|
||||
|
||||
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
|
||||
final Map<String, Integer> collectionCardCounts = collection.getAll();
|
||||
|
||||
for (Map.Entry<String, Integer> cardCount : deckCardCounts.entrySet()) {
|
||||
final Integer collectionCount = collectionCardCounts.get(cardCount.getKey());
|
||||
if (collectionCount == null || collectionCount < cardCount.getValue()) {
|
||||
final int collectionCount = ownershipCheck.getItemCount(cardCount.getKey());
|
||||
if (collectionCount < cardCount.getValue()) {
|
||||
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 " + owned);
|
||||
throw new HallException("You don't have the required cards in collection: " + cardName + " required " + cardCount.getValue() + ", owned " + collectionCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.gempukku.lotro.collection.CollectionSerializer;
|
||||
import com.gempukku.lotro.db.*;
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.core.spi.component.ComponentScope;
|
||||
@@ -23,9 +24,11 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
private Injectable<LeaguePointsDAO> _leaguePointsDAOInjectable;
|
||||
|
||||
private DbAccess _dbAccess;
|
||||
private CollectionSerializer _collectionSerializer;
|
||||
|
||||
public DaoProvider() {
|
||||
_dbAccess = new DbAccess();
|
||||
_collectionSerializer = new CollectionSerializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +93,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
|
||||
private synchronized Injectable<LeagueDAO> getLeagueDaoSafely() {
|
||||
if (_leagueDaoInjectable == null) {
|
||||
final LeagueDAO leagueDao = new LeagueDAO(_dbAccess);
|
||||
final LeagueDAO leagueDao = new LeagueDAO(_dbAccess, _collectionSerializer);
|
||||
_leagueDaoInjectable = new Injectable<LeagueDAO>() {
|
||||
@Override
|
||||
public LeagueDAO getValue() {
|
||||
@@ -129,7 +132,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
|
||||
private synchronized Injectable<CollectionDAO> getCollectionDaoSafely() {
|
||||
if (_collectionDaoInjectable == null) {
|
||||
final CollectionDAO collectionDao = new CollectionDAO(_dbAccess);
|
||||
final CollectionDAO collectionDao = new CollectionDAO(_dbAccess, _collectionSerializer);
|
||||
_collectionDaoInjectable = new Injectable<CollectionDAO>() {
|
||||
@Override
|
||||
public CollectionDAO getValue() {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<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>
|
||||
- "Damrod" now correctly checks his spot play condition.
|
||||
- "Cave Troll's Hammer" from Black Rider now is of ORC culture, not MORIA.
|
||||
|
||||
Reference in New Issue
Block a user