Win/lose conditions
This commit is contained in:
@@ -73,4 +73,9 @@ public class AbstractAlly extends AbstractLotroCardBlueprint {
|
|||||||
public int getVitality() {
|
public int getVitality() {
|
||||||
return _vitality;
|
return _vitality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResistance() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,4 +83,9 @@ public abstract class AbstractCompanion extends AbstractLotroCardBlueprint {
|
|||||||
public final int getVitality() {
|
public final int getVitality() {
|
||||||
return _vitality;
|
return _vitality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResistance() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ public abstract class AbstractLotroCardBlueprint implements LotroCardBlueprint {
|
|||||||
throw new UnsupportedOperationException("This method should not be called on this card");
|
throw new UnsupportedOperationException("This method should not be called on this card");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResistance() {
|
||||||
|
throw new UnsupportedOperationException("This method should not be called on this card");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSiteNumber() {
|
public int getSiteNumber() {
|
||||||
throw new UnsupportedOperationException("This method should not be called on this card");
|
throw new UnsupportedOperationException("This method should not be called on this card");
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ public interface LotroCardBlueprint {
|
|||||||
|
|
||||||
public int getVitality();
|
public int getVitality();
|
||||||
|
|
||||||
|
public int getResistance();
|
||||||
|
|
||||||
public Modifier getAlwaysOnEffect(PhysicalCard self);
|
public Modifier getAlwaysOnEffect(PhysicalCard self);
|
||||||
|
|
||||||
public List<? extends Action> getRequiredIsAboutToActions(LotroGame lotroGame, Effect effect, EffectResult effectResult, PhysicalCard self);
|
public List<? extends Action> getRequiredIsAboutToActions(LotroGame lotroGame, Effect effect, EffectResult effectResult, PhysicalCard self);
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class GameState {
|
|||||||
|
|
||||||
private Map<String, GameStateListener> _gameStateListeners = new HashMap<String, GameStateListener>();
|
private Map<String, GameStateListener> _gameStateListeners = new HashMap<String, GameStateListener>();
|
||||||
|
|
||||||
|
private String _winnerPlayerId;
|
||||||
|
private Set<String> _losers = new HashSet<String>();
|
||||||
|
|
||||||
private int _nextCardId = 0;
|
private int _nextCardId = 0;
|
||||||
|
|
||||||
private int nextCardId() {
|
private int nextCardId() {
|
||||||
@@ -58,6 +61,24 @@ public class GameState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWinnerPlayerId(String winnerPlayerId) {
|
||||||
|
_winnerPlayerId = winnerPlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setLoserPlayerId(String loserPlayerId) {
|
||||||
|
_losers.add(loserPlayerId);
|
||||||
|
if (_losers.size() + 1 == _playerOrder.getAllPlayers().size()) {
|
||||||
|
List<String> allPlayers = new LinkedList<String>(_playerOrder.getAllPlayers());
|
||||||
|
allPlayers.removeAll(_losers);
|
||||||
|
return allPlayers.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWinnerPlayerId() {
|
||||||
|
return _winnerPlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
private void addPlayerCards(String playerId, List<String> cards, LotroCardBlueprintLibrary library) {
|
private void addPlayerCards(String playerId, List<String> cards, LotroCardBlueprintLibrary library) {
|
||||||
for (String blueprintId : cards) {
|
for (String blueprintId : cards) {
|
||||||
LotroCardBlueprint card = library.getLotroCardBlueprint(blueprintId);
|
LotroCardBlueprint card = library.getLotroCardBlueprint(blueprintId);
|
||||||
|
|||||||
@@ -15,4 +15,8 @@ public interface LotroGame {
|
|||||||
public ActionsEnvironment getActionsEnvironment();
|
public ActionsEnvironment getActionsEnvironment();
|
||||||
|
|
||||||
public UserFeedback getUserFeedback();
|
public UserFeedback getUserFeedback();
|
||||||
|
|
||||||
|
public void playerWon(String currentPlayerId);
|
||||||
|
|
||||||
|
public void playerLost(String currentPlayerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import com.gempukku.lotro.logic.modifiers.ModifiersLogic;
|
|||||||
import com.gempukku.lotro.logic.modifiers.ModifiersQuerying;
|
import com.gempukku.lotro.logic.modifiers.ModifiersQuerying;
|
||||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class DefaultLotroGame implements LotroGame {
|
public class DefaultLotroGame implements LotroGame {
|
||||||
private GameState _gameState;
|
private GameState _gameState;
|
||||||
@@ -27,8 +24,10 @@ public class DefaultLotroGame implements LotroGame {
|
|||||||
private ActionStack _actionStack;
|
private ActionStack _actionStack;
|
||||||
|
|
||||||
private Map<String, GameStateListener> _gameStateListeners = new HashMap<String, GameStateListener>();
|
private Map<String, GameStateListener> _gameStateListeners = new HashMap<String, GameStateListener>();
|
||||||
|
private GameResultListener _gameResultListener;
|
||||||
|
|
||||||
public DefaultLotroGame(Map<String, LotroDeck> decks, UserFeedback userFeedback, final LotroCardBlueprintLibrary library) {
|
public DefaultLotroGame(Map<String, LotroDeck> decks, UserFeedback userFeedback, GameResultListener gameResultListener, final LotroCardBlueprintLibrary library) {
|
||||||
|
_gameResultListener = gameResultListener;
|
||||||
_actionStack = new ActionStack();
|
_actionStack = new ActionStack();
|
||||||
|
|
||||||
_actionsEnvironment = new DefaultActionsEnvironment(this, decks.keySet(), _actionStack);
|
_actionsEnvironment = new DefaultActionsEnvironment(this, decks.keySet(), _actionStack);
|
||||||
@@ -72,6 +71,26 @@ public class DefaultLotroGame implements LotroGame {
|
|||||||
_turnProcedure.carryOutPendingActionsUntilDecisionNeeded();
|
_turnProcedure.carryOutPendingActionsUntilDecisionNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerWon(String currentPlayerId) {
|
||||||
|
_gameState.setWinnerPlayerId(currentPlayerId);
|
||||||
|
if (_gameResultListener != null) {
|
||||||
|
Set<String> losers = new HashSet<String>(_gameState.getPlayerOrder().getAllPlayers());
|
||||||
|
losers.remove(currentPlayerId);
|
||||||
|
_gameResultListener.gameFinished(currentPlayerId, losers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerLost(String currentPlayerId) {
|
||||||
|
String winner = _gameState.setLoserPlayerId(currentPlayerId);
|
||||||
|
if (winner != null && _gameResultListener != null) {
|
||||||
|
Set<String> losers = new HashSet<String>(_gameState.getPlayerOrder().getAllPlayers());
|
||||||
|
losers.remove(winner);
|
||||||
|
_gameResultListener.gameFinished(winner, losers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameState getGameState() {
|
public GameState getGameState() {
|
||||||
return _gameState;
|
return _gameState;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.gempukku.lotro.logic.timing;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface GameResultListener {
|
||||||
|
public void gameFinished(String winnerPlayerId, Set<String> loserPlayerIds);
|
||||||
|
}
|
||||||
@@ -26,5 +26,7 @@ public class RuleSet {
|
|||||||
new CharacterDeathRule(_actionsEnvironment).applyRule();
|
new CharacterDeathRule(_actionsEnvironment).applyRule();
|
||||||
|
|
||||||
new SanctuaryRule(_actionsEnvironment).applyRule();
|
new SanctuaryRule(_actionsEnvironment).applyRule();
|
||||||
|
|
||||||
|
new WinConditionRule(_actionsEnvironment).applyRule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class TurnProcedure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void carryOutPendingActionsUntilDecisionNeeded() {
|
public void carryOutPendingActionsUntilDecisionNeeded() {
|
||||||
while (!_userFeedback.hasPendingDecisions()) {
|
while (!_userFeedback.hasPendingDecisions() && _game.getGameState().getWinnerPlayerId() == null) {
|
||||||
if (_actionStack.isEmpty()) {
|
if (_actionStack.isEmpty()) {
|
||||||
if (_playedGameProcess) {
|
if (_playedGameProcess) {
|
||||||
_gameProcess = _gameProcess.getNextProcess();
|
_gameProcess = _gameProcess.getNextProcess();
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.gempukku.lotro.logic.timing.rules;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.common.Keyword;
|
||||||
|
import com.gempukku.lotro.filters.Filters;
|
||||||
|
import com.gempukku.lotro.game.AbstractActionProxy;
|
||||||
|
import com.gempukku.lotro.game.PhysicalCard;
|
||||||
|
import com.gempukku.lotro.game.state.LotroGame;
|
||||||
|
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||||
|
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||||
|
import com.gempukku.lotro.logic.timing.Action;
|
||||||
|
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||||
|
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LoseConditionsRule {
|
||||||
|
private DefaultActionsEnvironment _actionsEnvironment;
|
||||||
|
|
||||||
|
public LoseConditionsRule(DefaultActionsEnvironment actionsEnvironment) {
|
||||||
|
_actionsEnvironment = actionsEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyRule() {
|
||||||
|
_actionsEnvironment.addAlwaysOnActionProxy(
|
||||||
|
new AbstractActionProxy() {
|
||||||
|
@Override
|
||||||
|
public List<? extends Action> getRequiredWhenActions(LotroGame game, EffectResult effectResult) {
|
||||||
|
if (!Filters.canSpot(game.getGameState(), game.getModifiersQuerying(), Filters.keyword(Keyword.RING_BEARER))) {
|
||||||
|
CostToEffectAction action = new CostToEffectAction(null, null, "Losing the game due to Ring-Bearer being killed");
|
||||||
|
action.addEffect(
|
||||||
|
new UnrespondableEffect() {
|
||||||
|
@Override
|
||||||
|
public void playEffect(LotroGame game) {
|
||||||
|
game.playerLost(game.getGameState().getCurrentPlayerId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.singletonList(action);
|
||||||
|
}
|
||||||
|
PhysicalCard ringBearer = Filters.findFirstActive(game.getGameState(), game.getModifiersQuerying(), Filters.keyword(Keyword.RING_BEARER));
|
||||||
|
int ringBearerResistance = ringBearer.getBlueprint().getResistance();
|
||||||
|
if (game.getGameState().getBurdens(game.getGameState().getCurrentPlayerId()) >= ringBearerResistance) {
|
||||||
|
CostToEffectAction action = new CostToEffectAction(null, null, "Losing the game due to Ring-Bearer corruption");
|
||||||
|
action.addEffect(
|
||||||
|
new UnrespondableEffect() {
|
||||||
|
@Override
|
||||||
|
public void playEffect(LotroGame game) {
|
||||||
|
game.playerLost(game.getGameState().getCurrentPlayerId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.singletonList(action);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.gempukku.lotro.logic.timing.rules;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.common.Phase;
|
||||||
|
import com.gempukku.lotro.game.AbstractActionProxy;
|
||||||
|
import com.gempukku.lotro.game.state.LotroGame;
|
||||||
|
import com.gempukku.lotro.game.state.actions.DefaultActionsEnvironment;
|
||||||
|
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||||
|
import com.gempukku.lotro.logic.timing.Action;
|
||||||
|
import com.gempukku.lotro.logic.timing.Effect;
|
||||||
|
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||||
|
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WinConditionRule {
|
||||||
|
private DefaultActionsEnvironment _actionsEnvironment;
|
||||||
|
|
||||||
|
public WinConditionRule(DefaultActionsEnvironment actionsEnvironment) {
|
||||||
|
_actionsEnvironment = actionsEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyRule() {
|
||||||
|
_actionsEnvironment.addAlwaysOnActionProxy(
|
||||||
|
new AbstractActionProxy() {
|
||||||
|
@Override
|
||||||
|
public List<? extends Action> getRequiredIsAboutToActions(final LotroGame lotroGame, Effect effect, EffectResult effectResult) {
|
||||||
|
if (effectResult.getType() == EffectResult.Type.START_OF_PHASE
|
||||||
|
&& lotroGame.getGameState().getCurrentPhase() == Phase.REGROUP
|
||||||
|
&& lotroGame.getGameState().getCurrentSiteNumber() == 9) {
|
||||||
|
CostToEffectAction action = new CostToEffectAction(null, null, "Winning the game");
|
||||||
|
action.addEffect(
|
||||||
|
new UnrespondableEffect() {
|
||||||
|
@Override
|
||||||
|
public void playEffect(LotroGame game) {
|
||||||
|
game.playerWon(lotroGame.getGameState().getCurrentPlayerId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Collections.singletonList(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ public class LotroGameMediator {
|
|||||||
participantSet.add(participantId);
|
participantSet.add(participantId);
|
||||||
decks.put(participantId, participant.getDeck());
|
decks.put(participantId, participant.getDeck());
|
||||||
}
|
}
|
||||||
_lotroGame = new DefaultLotroGame(decks, _userFeedback, library);
|
_lotroGame = new DefaultLotroGame(decks, _userFeedback, null, library);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String produceCardInfo(String participantId, int cardId) {
|
public synchronized String produceCardInfo(String participantId, int cardId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user