Introduced adventures.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||
import com.gempukku.lotro.logic.modifiers.ModifiersLogic;
|
||||
|
||||
public interface Adventure {
|
||||
public void applyAdventureRules(LotroGame game, DefaultActionsEnvironment actionsEnvironment, ModifiersLogic modifiersLogic);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
public interface AdventureLibrary {
|
||||
public Adventure getAdventure(String adventureType);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.game.adventure.DefaultAdventure;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DefaultAdventureLibrary implements AdventureLibrary {
|
||||
private Adventure _defaultAdventure = new DefaultAdventure();
|
||||
private Map<String, Adventure> _customAdventures = new HashMap<String, Adventure>();
|
||||
|
||||
@Override
|
||||
public Adventure getAdventure(String adventureType) {
|
||||
final Adventure adventure = _customAdventures.get(adventureType);
|
||||
if (adventure != null)
|
||||
return adventure;
|
||||
return _defaultAdventure;
|
||||
}
|
||||
}
|
||||
@@ -37,4 +37,6 @@ public interface LotroFormat {
|
||||
public String getSurveyUrl();
|
||||
|
||||
public int getHandSize();
|
||||
|
||||
public Adventure getAdventure();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.gempukku.lotro.game.adventure;
|
||||
|
||||
import com.gempukku.lotro.game.Adventure;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||
import com.gempukku.lotro.logic.modifiers.ModifiersLogic;
|
||||
import com.gempukku.lotro.logic.timing.rules.WinConditionRule;
|
||||
|
||||
public class DefaultAdventure implements Adventure {
|
||||
@Override
|
||||
public void applyAdventureRules(LotroGame game, DefaultActionsEnvironment actionsEnvironment, ModifiersLogic modifiersLogic) {
|
||||
new WinConditionRule(actionsEnvironment).applyRule();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.gempukku.lotro.common.Zone;
|
||||
import com.gempukku.lotro.communication.GameStateListener;
|
||||
import com.gempukku.lotro.communication.UserFeedback;
|
||||
import com.gempukku.lotro.game.ActionsEnvironment;
|
||||
import com.gempukku.lotro.game.Adventure;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
@@ -19,7 +20,12 @@ import com.gempukku.lotro.logic.timing.rules.CharacterDeathRule;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultLotroGame implements LotroGame {
|
||||
private static final Logger log = Logger.getLogger(DefaultLotroGame.class);
|
||||
@@ -33,6 +39,7 @@ public class DefaultLotroGame implements LotroGame {
|
||||
private boolean _cancelled;
|
||||
private boolean _finished;
|
||||
|
||||
private Adventure _adventure;
|
||||
private LotroFormat _format;
|
||||
|
||||
private Set<String> _allPlayers;
|
||||
@@ -46,6 +53,7 @@ public class DefaultLotroGame implements LotroGame {
|
||||
private Set<String> _requestedCancel = new HashSet<String>();
|
||||
|
||||
public DefaultLotroGame(LotroFormat format, Map<String, LotroDeck> decks, UserFeedback userFeedback, final LotroCardBlueprintLibrary library) {
|
||||
_adventure = format.getAdventure();
|
||||
_format = format;
|
||||
_actionStack = new ActionStack();
|
||||
|
||||
@@ -85,6 +93,8 @@ public class DefaultLotroGame implements LotroGame {
|
||||
|
||||
RuleSet ruleSet = new RuleSet(this, _actionsEnvironment, _modifiersLogic);
|
||||
ruleSet.applyRuleSet();
|
||||
|
||||
_adventure.applyAdventureRules(this, _actionsEnvironment, _modifiersLogic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,19 @@ package com.gempukku.lotro.logic.timing;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||
import com.gempukku.lotro.logic.modifiers.ModifiersLogic;
|
||||
import com.gempukku.lotro.logic.timing.rules.*;
|
||||
import com.gempukku.lotro.logic.timing.rules.AmbushRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.CunningRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.DiscardedCardRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.EnduringRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.FrodoAndSamRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.HunterRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.KilledCardRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.MusterRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.ResolveSkirmishRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.RingBearerRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.RoamingRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.SanctuaryRule;
|
||||
import com.gempukku.lotro.logic.timing.rules.ThreatRule;
|
||||
|
||||
public class RuleSet {
|
||||
private LotroGame _game;
|
||||
@@ -29,8 +41,6 @@ public class RuleSet {
|
||||
|
||||
new SanctuaryRule(_actionsEnvironment, _modifiersLogic).applyRule();
|
||||
|
||||
new WinConditionRule(_actionsEnvironment).applyRule();
|
||||
|
||||
new DiscardedCardRule(_actionsEnvironment).applyRule();
|
||||
|
||||
new KilledCardRule(_actionsEnvironment).applyRule();
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.LeagueMatchDAO;
|
||||
import com.gempukku.lotro.db.LeagueParticipationDAO;
|
||||
import com.gempukku.lotro.db.PlayerDAO;
|
||||
import com.gempukku.lotro.game.AdventureLibrary;
|
||||
import com.gempukku.lotro.game.DefaultAdventureLibrary;
|
||||
import com.gempukku.lotro.game.GameHistoryService;
|
||||
import com.gempukku.lotro.game.GameRecorder;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
@@ -36,8 +38,12 @@ import java.util.Map;
|
||||
|
||||
public class ServerBuilder {
|
||||
public static void fillObjectMap(Map<Type, Object> objectMap) {
|
||||
objectMap.put(AdventureLibrary.class,
|
||||
new DefaultAdventureLibrary());
|
||||
|
||||
objectMap.put(LotroFormatLibrary.class,
|
||||
new LotroFormatLibrary(
|
||||
extract(objectMap, AdventureLibrary.class),
|
||||
extract(objectMap, LotroCardBlueprintLibrary.class)));
|
||||
|
||||
objectMap.put(GameHistoryService.class,
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.gempukku.lotro.common.Block;
|
||||
import com.gempukku.lotro.common.CardType;
|
||||
import com.gempukku.lotro.common.Keyword;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.game.Adventure;
|
||||
import com.gempukku.lotro.game.CardNotFoundException;
|
||||
import com.gempukku.lotro.game.DeckInvalidException;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprint;
|
||||
@@ -21,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DefaultLotroFormat implements LotroFormat {
|
||||
private Adventure _adventure;
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
private String _name;
|
||||
private Block _siteBlock;
|
||||
@@ -38,10 +40,12 @@ public class DefaultLotroFormat implements LotroFormat {
|
||||
private List<Integer> _validSets = new ArrayList<Integer>();
|
||||
private String _surveyUrl;
|
||||
|
||||
public DefaultLotroFormat(LotroCardBlueprintLibrary library, String name, String surveyUrl,
|
||||
public DefaultLotroFormat(Adventure adventure,
|
||||
LotroCardBlueprintLibrary library, String name, String surveyUrl,
|
||||
Block siteBlock,
|
||||
boolean validateShadowFPCount, int minimumDeckSize, int maximumSameName, boolean mulliganRule,
|
||||
boolean canCancelRingBearerSkirmish, boolean hasRuleOfFour, boolean winAtEndOfRegroup, boolean winOnControlling5Sites) {
|
||||
_adventure = adventure;
|
||||
_library = library;
|
||||
_name = name;
|
||||
_surveyUrl = surveyUrl;
|
||||
@@ -56,6 +60,11 @@ public class DefaultLotroFormat implements LotroFormat {
|
||||
_winOnControlling5Sites = winOnControlling5Sites;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Adventure getAdventure() {
|
||||
return _adventure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isOrderedSites() {
|
||||
return _siteBlock != Block.SHADOWS;
|
||||
@@ -233,7 +242,7 @@ public class DefaultLotroFormat implements LotroFormat {
|
||||
|
||||
for (Map.Entry<String, Integer> count : cardCountByName.entrySet()) {
|
||||
if (count.getValue() > _maximumSameName)
|
||||
throw new DeckInvalidException("Deck contains more of the same card than allowed ("+count.getValue()+">"+_maximumSameName+"): " + count.getKey());
|
||||
throw new DeckInvalidException("Deck contains more of the same card than allowed (" + count.getValue() + ">" + _maximumSameName + "): " + count.getKey());
|
||||
}
|
||||
|
||||
// Restricted cards
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.gempukku.lotro.game.formats;
|
||||
|
||||
import com.gempukku.lotro.common.Block;
|
||||
import com.gempukku.lotro.game.Adventure;
|
||||
import com.gempukku.lotro.game.AdventureLibrary;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -19,7 +21,7 @@ public class LotroFormatLibrary {
|
||||
private Map<String, LotroFormat> _allFormats = new HashMap<String, LotroFormat>();
|
||||
private Map<String, LotroFormat> _hallFormats = new LinkedHashMap<String, LotroFormat>();
|
||||
|
||||
public LotroFormatLibrary(LotroCardBlueprintLibrary library) {
|
||||
public LotroFormatLibrary(AdventureLibrary adventureLibrary, LotroCardBlueprintLibrary library) {
|
||||
try {
|
||||
final InputStreamReader reader = new InputStreamReader(LotroFormatLibrary.class.getResourceAsStream("/lotrFormats.json"), "UTF-8");
|
||||
try {
|
||||
@@ -27,6 +29,7 @@ public class LotroFormatLibrary {
|
||||
JSONArray object = (JSONArray) parser.parse(reader);
|
||||
for (Object formatDefObj : object) {
|
||||
JSONObject formatDef = (JSONObject) formatDefObj;
|
||||
final Adventure adventure = adventureLibrary.getAdventure((String) formatDef.get("adventure"));
|
||||
String formatCode = (String) formatDef.get("code");
|
||||
String name = (String) formatDef.get("name");
|
||||
String surveyUrl = (String) formatDef.get("surveyUrl");
|
||||
@@ -44,7 +47,7 @@ public class LotroFormatLibrary {
|
||||
if (winOnControlling5Sites == null)
|
||||
winOnControlling5Sites = false;
|
||||
|
||||
final DefaultLotroFormat format = new DefaultLotroFormat(library, name, surveyUrl, block, true, 60, 4, true,
|
||||
final DefaultLotroFormat format = new DefaultLotroFormat(adventure, library, name, surveyUrl, block, true, 60, 4, true,
|
||||
cancelRingBearerSkirmish, hasRuleOfFour, winAtEndOfRegroup, winOnControlling5Sites);
|
||||
|
||||
JSONArray sets = (JSONArray) formatDef.get("set");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.at;
|
||||
|
||||
import com.gempukku.lotro.game.DefaultAdventureLibrary;
|
||||
import com.gempukku.lotro.game.DefaultUserFeedback;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
@@ -15,7 +16,12 @@ import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -57,7 +63,7 @@ public abstract class AbstractAtTest {
|
||||
protected void initializeGameWithDecks(Map<String, LotroDeck> decks) throws DecisionResultInvalidException {
|
||||
_userFeedback = new DefaultUserFeedback();
|
||||
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(_library);
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(new DefaultAdventureLibrary(), _library);
|
||||
LotroFormat format = formatLibrary.getFormat("movie");
|
||||
|
||||
_game = new DefaultLotroGame(format, decks, _userFeedback, _library);
|
||||
|
||||
@@ -3,7 +3,12 @@ package com.gempukku.lotro.at;
|
||||
import com.gempukku.lotro.common.Phase;
|
||||
import com.gempukku.lotro.common.Token;
|
||||
import com.gempukku.lotro.common.Zone;
|
||||
import com.gempukku.lotro.game.*;
|
||||
import com.gempukku.lotro.game.CardNotFoundException;
|
||||
import com.gempukku.lotro.game.DefaultAdventureLibrary;
|
||||
import com.gempukku.lotro.game.DefaultUserFeedback;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.PhysicalCardImpl;
|
||||
import com.gempukku.lotro.game.formats.LotroFormatLibrary;
|
||||
import com.gempukku.lotro.logic.decisions.AwaitingDecision;
|
||||
import com.gempukku.lotro.logic.decisions.AwaitingDecisionType;
|
||||
@@ -838,7 +843,7 @@ public class IndividualCardAtTest extends AbstractAtTest {
|
||||
|
||||
_userFeedback = new DefaultUserFeedback();
|
||||
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(_library);
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(new DefaultAdventureLibrary(), _library);
|
||||
LotroFormat format = formatLibrary.getFormat("movie");
|
||||
|
||||
_game = new DefaultLotroGame(format, decks, _userFeedback, _library);
|
||||
@@ -879,7 +884,7 @@ public class IndividualCardAtTest extends AbstractAtTest {
|
||||
|
||||
_userFeedback = new DefaultUserFeedback();
|
||||
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(_library);
|
||||
LotroFormatLibrary formatLibrary = new LotroFormatLibrary(new DefaultAdventureLibrary(), _library);
|
||||
LotroFormat format = formatLibrary.getFormat("movie");
|
||||
|
||||
_game = new DefaultLotroGame(format, decks, _userFeedback, _library);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gempukku.lotro.game.formats;
|
||||
|
||||
import com.gempukku.lotro.game.DeckInvalidException;
|
||||
import com.gempukku.lotro.game.DefaultAdventureLibrary;
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.gempukku.lotro.game.LotroFormat;
|
||||
import org.junit.Test;
|
||||
@@ -8,12 +9,12 @@ import org.junit.Test;
|
||||
public class LotroFormatLibraryTest {
|
||||
@Test
|
||||
public void testLoad() {
|
||||
LotroFormatLibrary library = new LotroFormatLibrary(null);
|
||||
LotroFormatLibrary library = new LotroFormatLibrary(new DefaultAdventureLibrary(), null);
|
||||
}
|
||||
|
||||
@Test(expected = DeckInvalidException.class)
|
||||
public void legolasGreenleafNotLegalInStandard() throws DeckInvalidException {
|
||||
LotroFormatLibrary library = new LotroFormatLibrary(new LotroCardBlueprintLibrary());
|
||||
LotroFormatLibrary library = new LotroFormatLibrary(new DefaultAdventureLibrary(), new LotroCardBlueprintLibrary());
|
||||
LotroFormat standard = library.getFormat("standard");
|
||||
standard.validateCard("1_50");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user